Skip to content

Instantly share code, notes, and snippets.

<?php
function hack_jetpack_offline_mode() {
if ( ! file_exists( WP_PLUGIN_DIR . '/jetpack/' ) || class_exists( 'Jetpack' ) )
return;
require_once( WP_PLUGIN_DIR . '/jetpack/jetpack.php' );
// Disable Jetpack's notification messages
hack_disable_jetpack_notices();
<?php
// Start up the engine
class CPT_Archive_Content
{
/**
* Static property to hold our singleton instance
* @var CPT_Archive_Content
*
@maor
maor / gist:4714851
Last active December 12, 2015 04:29
<?php
function maor_reorder_categories_postbox( $args, $taxonomies ) {
global $pagenow;
$ok_pages = array( 'post-new.php', 'post.php' );
if ( ! in_array( $pagenow, $ok_pages ) || ! in_array( 'category', $taxonomies ) )
return $args;
<?php
function lt_admin_show_taxonomies_dropdowns() {
if ( 'lt_product' != get_current_screen()->post_type )
return;
$taxonomies = get_taxonomies( array(
'object_type' => array( 'lt_product' )
), 'objects' );
<?php
function mc_akismet_unbloat_db( $return, $object_id, $meta_key ) {
return ( 'akismet_history' == $meta_key ) ? true : $return;
}
add_filter( 'add_comment_metadata', 'mc_akismet_unbloat_db', 10, 3 );
@maor
maor / gist:5736517
Last active December 18, 2015 05:59
[hello][/hello]
<?php
function count_nested_shortcodes( $shortcode ) {
// each shortcode uses the "[" chatacter twice. The first is of the opening tag, the last is for the closing tag.
// The main shortcode also has 2 occurances. Since we're looking for the nested shortcodes, we'll ignore the main one by subtracting 2 from the total outcome
return (int) ( substr_count( $shortcode, '[' ) / 2 ) - 2;
}
@maor
maor / ninja-forms-countries-dd.php
Last active March 27, 2019 03:10
Ninja Forms countries dropdown select field
<?php
/**
* Add a new <select> field, pre-populated with all countries in our tiny, tiny world.
*
* @author Maor Chasen
*/
function aff_register_ninja_forms_fields() {
$args = array(
@maor
maor / gist:6079113
Created July 25, 2013 12:20
Adds a new class ("new-post") if a post is fresh (within X days). For WordPress.
<?php
/**
* @author Maor Chasen <[email protected]>
*/
function mc_497346850334383( $classes, $class, $post_id ) {
$post = get_post( $post_id );
if ( ! $post )
@maor
maor / gist:6098045
Created July 28, 2013 09:13
Conditionally display content depending on whether the user is logged in or not
<?php
// https://www.facebook.com/groups/wordpress.support/permalink/497037907031944
function mc_497037907031944( $content ) {
if ( is_user_logged_in() )
return $content;
else
return 'Sorry, you must be logged in...';
}
( function( $ ) {
// $ is safe to use here.
$(document).ready( function() {
// ...
} );
} )( jQuery );