Skip to content

Instantly share code, notes, and snippets.

View spacedmonkey's full-sized avatar
🖐️
Open for work

Jonny Harris spacedmonkey

🖐️
Open for work
View GitHub Profile
@spacedmonkey
spacedmonkey / gist:0ef1258e70341b81e445
Created May 8, 2015 14:59
WordPress load jquery from CDN
<?php
class jQuery_CDN {
/**
* @var int
*/
private $jquery_version = 0;
/**
* @var int
*/
<?php
/*
Plugin Name: Advanced Nav Caching
Description: Cache nav output
Version: 1.0.0
Author: Spacedmonkey
*/
class Advanced_Nav_Cache {
/**
* Retrieve site option value based on name of option.
*
* @since 2.8.0
*
* @see get_option()
*
* @global wpdb $wpdb
*
* @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
callback: function ( elem, op ) {
if( op === 'load' ) {
if (elem.getAttribute('data-echo-srcset') !== null) {
elem.setAttribute('srcset', elem.getAttribute('data-echo-srcset'));
}
}
}
<?php
/*
Plugin name: Batcache Manager
Plugin URI: http://wordpress.org/extend/plugins/batcache/
Description: This optional plugin improves Batcache.
Author: Andy Skelton
Author URI: http://andyskelton.com/
Version: 1.3
*/
global $batcache, $wp_object_cache;
cd /path/to/root
for url in $(wp site list --field=domain)
do
echo ${url}
wp --url=${url} option update db_version 30133
echo
done
wp --url=${url} core update-db --network
<?php
class Red_Item {
private $id = null;
private $created;
private $referrer;
private $url = null;
private $regex = false;
private $action_data = null;
private $action_code = 0;
if ( count( $domains ) > 1 && count( $paths ) > 1 ) {
$sql = "SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1";
} elseif ( count( $domains ) > 1 ) {
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] );
$sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1";
} elseif ( count( $paths ) > 1 ) {
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] );
$sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1";
} else {
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) );
$sql = "LIMIT 10";
$cache_key = md5($sql);
$post_ids = wp_cache_get( $cache_key, 'keystone_redirects' );
if( false === $post_ids ){
$post_ids = $wpdb->get_col( $sql );
$cache_time = (count($post_ids) > 0 ) ? MINUTE_IN_SECONDS : DAY_IN_SECONDS;
wp_cache_set( $cache_key, $post_ids, 'keystone_redirects', $cache_time );
}
public function pre_get_posts( $wp_query ) {
$this->cache_queries = apply_filters( 'use_enhanced_post_cache', true, $wp_query );
if( $this->cache_queries ){
if ( $wp_query->is_404() ) {
$page_variable = array( 'error_404' );
} else {
$page_variable = $wp_query->query_vars;
}