Skip to content

Instantly share code, notes, and snippets.

View gschoppe's full-sized avatar

Greg Schoppe gschoppe

View GitHub Profile
@gschoppe
gschoppe / WP_Persistent_Notices.php
Last active October 16, 2022 16:46 — forked from obenland/gist:5173811
Implements a standardized messaging system that allows admin notices to be passed across page redirects. usage: add_filter( 'wp_persistent_notices', function( $notices ) { $notices[] = array( 'type' => 'error', 'message' => "Houston, we have a problem!" ); return $notices; } );
<?php if( !defined( 'ABSPATH' ) ) { die(); } // Include in all php files, to prevent direct execution
/**
* Class Name : WP Persistent Notices
* Description : Implements a Standardized messaging system that allows admin messages to be passed across page redirects.
* Class URI : http://gschoppe.com/wordpress/pass-wordpress-admin-notices-across-page-redirects/
* Version : 1.0.0
* Author : Greg Schoppe
* Author URI : http://gschoppe.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@gschoppe
gschoppe / cat-like-custom-taxonomy.php
Created February 28, 2016 01:07
Use category (checkbox-based) interface with non-hierarchical custom taxonomies
<?php
// Event taxonomies
add_action( 'init', function() {
$labels = array(
'name' => _x( 'Terms', 'taxonomy general name' ),
'singular_name' => _x( 'Term', 'taxonomy singular name' ),
);
register_taxonomy( 'taxonomy_name', array( 'post' ), array(
'hierarchical' => false,
@gschoppe
gschoppe / cacheFunctionCalls.php
Last active August 29, 2015 14:21
PHP Minimal Filesystem Function Cache
<?php
// PHP Minimal Filesystem Function Cache
// by Greg Schoppe (http://gschoppe.com)
// 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
// WARNING: DO NOT USE WITH ANONYMOUS FUNCTIONS (AKA: CLOSURES), ANY FUNCTION THAT PRODUCES SIDE EFFECTS,
// OR WITH ANY FUNCTION THAT DOES NOT RETURN A SERIALIZABLE VALUE
function callFunctionWithCache($functionName, $arguments = array(), $TTL=3600, $purgeCache=false) {
@gschoppe
gschoppe / surnamesort.php
Created May 20, 2015 02:36
Surname Sort
<?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
gschoppe / archive-board.php
Created May 14, 2015 14:00
Wordpress Board of Directors Custom Post Type, with custom profile pictures and meta information (http://www.gschoppe.com)
<?php
// archiveboard.php (companion to cpt-board.php)
// by Greg Schoppe (http://gschoppe.com)
// 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">