Skip to content

Instantly share code, notes, and snippets.

View Hube2's full-sized avatar

John A. Huebner II Hube2

View GitHub Profile
<?php
/*
Usage:
$frag = new CWS_Fragment_Cache( 'unique-key', 3600 ); // Second param is TTL
if ( !$frag->output() ) { // NOTE, testing for a return of false
functions_that_do_stuff_live();
these_should_echo();
// IMPORTANT
$frag->store();
// YOU CANNOT FORGET THIS. If you do, the site will break.
<?php
/*
* Plugin Name: Query Thief
* Description: Hijacking the main WordPress query and loop for fun and profit
* Version: 0.1
*/
// I namespace everything now that PHP 5.2.4 is the minimum requirement. :D
namespace JPB;
<?php
add_filter( 'posts_request', 'pre_db_hit' );
function pre_db_hit( $request )
{
global $diy_cache_current_request;
$diy_cache_current_request = $request;
// use request string to see if expired...
@Hube2
Hube2 / gist:5eb1bbb01d44f86cd8a5
Last active August 29, 2015 14:06
Using pre_get_posts
<?php
// example, set posts_per_page on CTP "book"
function books_pre_get_posts($query=false) {
if (is_admin() ||
!$query ||
!is_a($query, 'WP_Query') ||
!$query->is_main_query()) {
return;
}
@Hube2
Hube2 / acf-page-granparent-location-rule.php
Last active September 14, 2021 11:36
Advanced Custom Fields - Page Grandparent Custom Location Rule
<?php
/*
Adds a custom location rule to ACF to select page grandparent
*/
add_filter('acf/location/rule_types', 'acf_location_rules_page_grandparent');
function acf_location_rules_page_grandparent($choices) {
$choices['Page']['page_grandparent'] = 'Page Grandparent';
return $choices;
@Hube2
Hube2 / acf-page-ancestor-location-rule.php
Last active September 14, 2021 11:36
Advanced Custom Fields - Page Ancestor Custom Location Rule
<?php
/*
ACF cusomt location rule : Page Ancestor
*/
add_filter('acf/location/rule_types', 'acf_location_rules_page_ancestor');
function acf_location_rules_page_ancestor($choices) {
$choices['Page']['page_ancestor'] = 'Page Ancestor';
return $choices;
}
BEFORE - UNSERIALIZED
Array
(
[width] => 500
[height] => 500
[file] => 2016/07/HAWK-1.jpg
[sizes] => Array
(
@Hube2
Hube2 / acf-focust-tab-on-validation-error.js
Created October 15, 2016 13:02
Cause Tab where error is located to be focused in ACF
acf.add_filter('validation_complete', function( json, $form ){
if(json.errors) {
var field = jQuery('[name="' + json.errors[0].input + '"]', $form).parents('.acf-field');
field = field[field.length - 1];
var tab = jQuery(field, $form).prev('.acf-field-tab').attr('data-key');
jQuery('.acf-tab-wrap a[data-key=' + tab + ']', $form).click();
}
return json;
});
(function($){
if (typeof acf.add_action !== 'undefined') {
acf.add_filter('select2_args', function(args, element, settings) {
if (element.hasClass('glyphicons-select') || element.hasClass('glyphicon_selector')) {
args['dropdownCss']['font-family'] = 'Glyphicons Regular';
}
return args;
});
@Hube2
Hube2 / case-study-results.php
Created January 25, 2017 22:59
Simple SEO/User friendly search
<?php
function excel_case_study_results($posts) {
/*
this function is called in the content area of
either the post type archive template or
the either taxonomy archive template like this
if (have_posts()) {