Skip to content

Instantly share code, notes, and snippets.


Greg Schoppe gschoppe

View GitHub Profile
gschoppe / archive-board.php
Created May 14, 2015
Wordpress Board of Directors Custom Post Type, with custom profile pictures and meta information (
View archive-board.php
// archiveboard.php (companion to cpt-board.php)
// by Greg Schoppe (
// Licensed under GPL
// Renders archive page for board of directors custom post type
// Will need to be customized to match theme. This one is customized for the _TK bootstrap theme
get_header(); ?>
<?php // add the class "panel" below here to wrap the content-padder in Bootstrap style ;) ?>
<div class="content-padder">
View surnamesort.php
usort($array, function($a, $b) {
// explode name a by spaces
$parts_a = explode(' ', $a);
// remove the last name from the end of the array
$last_a = array_pop($parts_a);
// and shove it on the front
array_unshift($parts_a, $last_a);
// then re-implode into a string
$a = implode(' ', $parts_a);
gschoppe / cacheFunctionCalls.php
Last active Aug 29, 2015
PHP Minimal Filesystem Function Cache
View cacheFunctionCalls.php
// PHP Minimal Filesystem Function Cache
// by Greg Schoppe (
// copyright 2015 Greg Schoppe, GPL, BSD, and MIT licensed
// takes a function name as a string, and an array of the arguments to be passed to that function
// caches and returns the results of that function call (or the cached copy, if less than $TTL seconds old)
// Useful for rate-limiting cURL requests, or other high resource or rate limited functions
function callFunctionWithCache($functionName, $arguments = array(), $TTL=3600, $purgeCache=false) {
gschoppe / ClassSpeedUpBulkEdit.php
Created Nov 1, 2016
mu-plugin to defer term counting on all bulk edits
View ClassSpeedUpBulkEdit.php
<?php if(!defined('ABSPATH')) { die(); } // Include in all php files, to prevent direct execution
if( !class_exists('SpeedUpBulkEdit') ) {
class SpeedUpBulkEdit {
private static $_this;
private $is_bulk = false;
public static function Instance() {
static $instance = null;
if ($instance === null) {
gschoppe / blockade_custom_post_types.php
Last active Jan 7, 2017
Add Blockade to new post types or WP editors
View blockade_custom_post_types.php
<?php /* place in functions.php or in a custom plugin */
// Add Blockade to the custom post types "foo" and "bar"
add_filter('wp-blockade-override-post-types', 'add_my_blockade_post_types');
function add_my_blockade_post_types( $post_types ) {
$post_types[] = "foo";
$post_types[] = "bar";
return $post_types;
gschoppe / blockade_theme_setup.php
Created Jan 7, 2017
Customize Blockade for your theme
View blockade_theme_setup.php
<?php /* place in functions.php */
add_action( 'after_setup_theme', 'my_theme_setup' );
function my_theme_setup() {
add_editor_style(); // We recommend using an editor-style.css file , that includes all the styles that will apply to the content
add_theme_support( 'wp-blockade' ); // This tells Blockade that your theme includes Bootstrap
// add_theme_support( 'bootstrap', '3.3.7' ); // alternatively, you can just register bootstrap support, along with your version number
$palette = array( // set the colors available in the editor's colorpickers
'Primary' => '#811381',
'Black' => '#000000',
'White' => '#FFFFFF',
gschoppe / commentify_shortcodes.php
Last active Jan 23, 2017
Hide shortcodes if rendering fails in WordPress 4.7+
View commentify_shortcodes.php
* Hide shortcodes in excerpts or if rendering fails
* Usage: <!--[shortcode-name comment-wrapped=true]-->
add_filter( 'do_shortcode_tag', "comment_wrap_shortcodes", 10, 3 );
function comment_wrap_shortcodes( $output, $tag, $atts ) {
$args = shortcode_atts( array(
'comment-wrapped' => 'false'
), $atts );
gschoppe / better_auto_excerpts.php
Last active Feb 12, 2017
Micro-Plugin to improve auto excerpts generated from the_content. Can be placed in plugins, integrated in other projects, or called with an include statement in functions.php
View better_auto_excerpts.php
<?php if(!defined('ABSPATH')) { die(); } // Include in all php files, to prevent direct execution
* Plugin Name: Better Auto Excerpts
* Plugin URI:
* Description: replaces block-level elements with whitespace, to improve the_excerpt
* Version: 1.0.0
* Author: Burlington Bytes
* Author URI:
* Text Domain: better-auto-excerpts
* License: GPL-2.0+
View example_add_to_cart_button.php
$product_id = 147; // This is just for demonstration, you would use whatever product ID the page is referencing. if the page is the product page itself, you can use get_the_ID();
// we output a different version of the button, depending on whether the item is in the cart already
// note the class on the button... we are using that class to target our javascript handler
// note the data-attribute, that's how the product ID gets to our AJAX handler
if( !my_custom_cart_contains( $product_id ) ) {
<button class="my-custom-add-to-cart-button" data-product-id="<?php echo $product_id; ?>">add to cart</button>
View populate_cpt_labels.php
function populate_cpt_labels( $singular, $plural, $overrides = array(), $text_domain = "" ) {
return shortcode_atts( array(
'name' => _x( $plural, 'Post Type General Name', $text_domain ),
'singular_name' => _x( $singular, 'Post Type Singular Name', $text_domain ),
'menu_name' => __( $plural, $text_domain ),
'name_admin_bar' => __( $singular, $text_domain ),
'archives' => __( $singular . ' Archives', $text_domain ),
'attributes' => __( $singular . ' Attributes', $text_domain ),
'parent_item_colon' => __( 'Parent ' . $singular . ':', $text_domain ),