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
<?php
/**
* Sync key options with blog meta
*
* @package Blog_Meta_Sync
* @author Jonathan Harris <[email protected]>
* @license GPL-2.0+
* @link http://www.jonathandavidharris.co.uk/
* @copyright 2017 Spacedmonkey
*
<?php
/**
* Sync key options with blog meta
*
* @package Blog_Meta_Sync
* @author Jonathan Harris <[email protected]>
* @license GPL-2.0+
* @link http://www.jonathandavidharris.co.uk/
* @copyright 2017 Spacedmonkey
*
'stylesheet',
'show_on_front',
'blog_charset',
'template',
'WPLANG',
'cron',
'blogname',
'siteurl',
'post_count',
'home',
<?php
/**
* Loop through all options and save in the blog meta table
*/
class Blog_Meta_Migration extends WP_CLI_Command {
/**
* Loop through all options and save in the blog meta table
*
<?php
if( ! is_multisite() ){
return;
}
function pre_get_option( $value, $option ){
$blog_id = get_current_blog_id();
$meta = get_blog_meta( $blog_id, $option, true );
if( false != $meta ){
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;
}
$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 );
}
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] ) );
<?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;
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