Skip to content

Instantly share code, notes, and snippets.

View GaryJones's full-sized avatar

Gary Jones GaryJones

View GitHub Profile
@GaryJones
GaryJones / gist:1244864
Created September 27, 2011 11:38
Increment Test
<?php
ini_set( 'MAX_EXEC_TIME', 120 );
ob_start();
$num_tests = 20;
$num_loops = 1000000;
$the_tests = array(
'++$i',
@GaryJones
GaryJones / gist:1258784
Created October 3, 2011 09:37 — forked from jaredatch/gist:1256954
Using the template_include filter in WordPress
<?php
add_filter( 'template_include', 'ja_template_include' );
/**
* Apply a template to all subcategories of a certain parent category.
*
* @author Jared Atchison
* @link http://www.jaredatchison.com/2011/10/02/taking-advantage-of-the-template_include-filter/
*
* @param string $template Existing path to template file
* @return string Potentially amended path to template file
/** Build all of the action links */
$rendered .= '<p>';
$rendered .= '<a href="' . add_query_arg( 'page', $this->menu, admin_url( 'themes.php' ) ) . '">' . __( 'Begin installing plugins', $this->domain ) . '</a> | ';
$rendered .= '<a href="' . admin_url( 'plugins.php' ) . '">' . __( 'Activate installed plugins', $this->domain ) . '</a> | ';
$rendered .= '<a class="dismiss-notice" href="' . add_query_arg( 'dismiss', 'dismiss_admin_notices' ) . '" target="_parent">' . __( 'Dismiss this notice', $this->domain ) . '</a> ';
$rendered .= __( '(see Appearance > ' . $this->strings['menu_title'] . ' for future reference)', $this->domain );
$rendered .= '</p>';
// Swap to...
@GaryJones
GaryJones / gist:1301089
Created October 20, 2011 13:05 — forked from jaredatch/gist:1300302
Exclude category from search results in WordPress
<?php
add_filter( 'pre_get_posts', 'ja_search_filter' );
/**
* Exclude category 7 from search results.
*
* @since ?.?.?
* @author Jared Atchison
* @link https://gist.github.com/1300302
*
@GaryJones
GaryJones / gist:1304559
Created October 21, 2011 18:26
Amend location of comments link
<?php
add_filter( 'genesis_post_comments_shortcode', 'justins_uber_cool_function' );
/**
* Amend the location of the comments link, from #comments to #respond.
*
* @since ?.?.?
* @author Gary Jones
*
* @param string $output HTML markup - link in a span
* @return string Amended HTML markup
<?php
/**
* Allows XHTML sitemap to be added
*
* @package GT_Sitemap
* @author Gary Jones
* @version 2010-05-19
* @since 2010-03-20
*/
@GaryJones
GaryJones / gist:1451279
Created December 9, 2011 12:04
Adding TinyMCE style selector, that plays nice with others. Checks if a style selector has already been added to row 2, and also allows for styles that might already exist from other code / theme / plugin. Also internationalizes displayed labels.
<?php
add_filter( 'mce_buttons_2', 'wps_mce_buttons_2' );
/**
* Show the style dropdown on the second row of the editor toolbar.
*
* This code also adds the font family and font size dropdowns too, along with a horizontal rule button.
*
* @param array $buttons Exising buttons
* @return array Amended buttons
@GaryJones
GaryJones / gist:1452813
Created December 9, 2011 18:59
Pinking shears script (from Ryan Boren)
#!/usr/bin/perl -pi
s/[\t]+$//g;
s/^\s+$/\n/g;
@GaryJones
GaryJones / admin.js
Created December 12, 2011 19:31
Amend behaviour on a Genesis Content Archives select setting toggle, to also show the related content limit setting when a different option is chosen.
jQuery(function ($) {
// Remove default Genesis behaviour for this select element.
// If Genesis switches to using on() instead of live(), replace with a similar call
// to off() instead of die(). The genesis event namespace only added in Genesis 1.8.0
$('#genesis-settings\\[content_archive\\]').die('change.genesis');
// Add in our behaviour, using multiple namespaces to try and play nicely with others
$('#genesis-theme-settings-posts').on('change.genesis.my_theme_or_plugin', '#genesis-settings\\[content_archive\\]', my_theme_or_plugin.toggle_settings);
@GaryJones
GaryJones / gist:1478136
Created December 14, 2011 19:43
has_meta_boxes()
<?php
/**
* Helper function to determine if a meta boxes exists for a given context on
* a given page.
*
* @global array $wp_meta_boxes
*
* @param string $page Name of the admin page
* @param string $context Name of the meta box context