Skip to content

Instantly share code, notes, and snippets.

@gyrus
gyrus / gist:3332597
Created August 12, 2012 16:19
Override a WordPress 404 with a specific template
<?php
/**
* Override a 404
*
* @param string $template If passed, this template will be included and
* the request will be terminated if the inclusion
* was successful
* @param string $type If not a 404, what type of request should this be
* flagged as? Must correspond to one of the
@gyrus
gyrus / preload-images.js
Last active March 3, 2021 11:57
WordPress image preloading
/**
* Image preloader
*
* @link http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
*/
var cache = [];
// Arguments are image paths relative to the current page.
function pilau_preload_images() {
var args_len, i, cache_image;
args_len = arguments.length;
@gyrus
gyrus / gist:3157198
Created July 21, 2012 21:09
Check if a WordPress page is "current"
<?php
/**
* Check if a WordPress page is "current", i.e. it's the current page or the ancestor of a current page
*
* @uses is_search()
* @uses get_post_type()
* @uses site_url()
* @uses get_permalink()
* @uses get_post_type_object()
<?php
function cmb_opt_groups( $args, $defaults, $field_object, $field_types_object ) {
// Only do this for the field we want (vs all select fields)
if ( '_cmb_option_field' != $field_types_object->_id() ) {
return $args;
}
$option_array = array(
'Group 1' => array(
@gyrus
gyrus / gfapigetentries.php
Created June 18, 2019 19:20
GFAPI::get_entries() 'in' operator
<?php
$most_recent_subscription = GFAPI::get_entries(
[ 1, 3 ],
[
'status' => 'active',
'field_filters' => [
[
'key' => 'transaction_type',
'value' => 2,
@gyrus
gyrus / gform_post_render.js
Created June 12, 2019 09:51
gform_post_render
jQuery( document ).bind( 'gform_post_render', function( ev, field, form ) {
console.log( ev );
});
@gyrus
gyrus / gist:3155971
Created July 21, 2012 14:35
WordPress custom post type taxonomy list filters
<?php
/**
* Taxonomy list filters and columns
*
* @todo Test!
* @todo Need replacement function for slt_terms_list()
* @link http://wordpress.stackexchange.com/questions/578/adding-a-taxonomy-filter-to-admin-list-for-a-custom-post-type/3215#3215
*/
add_action( 'restrict_manage_posts', 'pilau_restrict_manage_posts' );
@gyrus
gyrus / pilau-tabs.css
Created August 14, 2012 12:20
WordPress tabs shortcode
/*
* This is the bare minimum CSS necessary to make jQuery UI tabs "work".
* Obviously you'll need to do a lot more styling to make them "good" :)
*/
.ui-tabs-hide { display: none; }
@gyrus
gyrus / shortcodes.php
Last active June 11, 2018 20:40
TinyMCE button for WordPress shortcode
<?php
/**
* Skeletal sample shortcode
*/
add_shortcode( 'pilau-sample', 'pilau_sample_shortcode' );
function pilau_sample_shortcode( $atts ) {
extract( shortcode_atts( array(
'text' => ''
), $atts ) );
@gyrus
gyrus / gist:3155982
Created July 21, 2012 14:40
Rename WordPress "Posts" to "News"
<?php
/**
* Rename "Posts" to "News"
*
* @link http://new2wp.com/snippet/change-wordpress-posts-post-type-news/
*/
add_action( 'admin_menu', 'pilau_change_post_menu_label' );
add_action( 'init', 'pilau_change_post_object_label' );
function pilau_change_post_menu_label() {