Skip to content

Instantly share code, notes, and snippets.

@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;
}
<?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 );
<?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' );
@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
// Start up the engine
class CPT_Archive_Content
{
/**
* Static property to hold our singleton instance
* @var CPT_Archive_Content
*
<?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();
@maor
maor / wp3.5-attachments-filesize.php
Created January 27, 2013 10:52
Adds a new row that shows the file size under an individual attachment dashboard page
<?php
/**
* Adds a new row that shows the file size under an individual attachment dashboard page
*
* @author Maor Chasen
*/
function mc_attachment_submitbox_filesize() {
$post = get_post();
$filesize = @filesize( get_attached_file( $post->ID ) );
<?php
function illuminea_redirect_to_wordcamporg() {
if ( is_admin() )
return;
$year = date( 'Y' );
wp_redirect( "http://$year.jerusalem.wordcamp.org", 301 );
exit;
<?php
function roee_get_parent_page_title() {
global $post;
return ( ! empty( $post->post_parent ) ) ? get_the_title( $post->post_parent ) : false;
}
@maor
maor / jetpack-comments-rtl.css
Last active December 10, 2015 00:39
RTL support for Jetpack's Comments Module
/* RTL support for Jetpack's Comments Module */
body.rtl #respond form {
direction: rtl;
}