Skip to content

Instantly share code, notes, and snippets.

View spencermorin's full-sized avatar

Spencer Cameron-Morin spencermorin

View GitHub Profile
<?php
/*
* Plugin Name: Import Meta Backup
* Plugin URI: http://somesite.com/where-this-plugin-lives/
* Description: Backs up original data in meta.
* Author: Automattic
* Author URI: http://theauthor.com/
* Version: 1.0
* Text Domain: import-meta-backup
<?php
function my_add_twitter_card_extras( $tags ) {
$tags[ 'twitter:site' ] = 'automattic'; // set @username of website
return $tags;
}
add_filter( 'jetpack_open_graph_tags', 'my_add_twitter_card_extras' );
?>
<?php
function modify_contact_form_field_html( $field_html, $field_label, $post_id ) {
// Add HTML before the field.
$field_html = '<span>Before the field.</span>' . $field_html;
// Add HTML after the field.
$field_html .= '<span>After the field.</span>';
// Conditionally add based on field label and post id
<?php
WP_CLI::add_command( 'export-feedback', 'Export_Feedback_Command' );
class Export_Feedback_Command extends WP_CLI_Command {
private $args = array();
/**
* This command can be used to export all feedbacks for the current site.
@spencermorin
spencermorin / attach-thumbnails.php
Created July 5, 2013 19:29
Attach thumbnails to the correct posts if this process fails during import. This is for SQL Azure powered Project Nami. However, the logic is the same for a standard install of WordPress.
<?php
$server_name = 'example.database.windows.net';
$database = 'database-name';
$username = 'user@example';
$password = 'thepassword';
@spencermorin
spencermorin / move-wp-multisite.sql
Created June 28, 2013 20:40
Move Project Nami ( or WordPress ) multisite install to a new domain.
update wp_options set option_value='http://example.com' where option_name = 'siteurl' or option_name = 'home'
update wp_blogs set domain='example.com' where blog_id = '1' or blog_id = '2'
update wp_2_options set option_value='http://example.com/second-blog-path' where option_name='siteurl' or option_name='home'
update wp_site set domain='example.com' where id='1'
update wp_sitemeta set meta_value='http://example.com' where meta_key='siteurl'
@spencermorin
spencermorin / autofill-wp-importer.js
Last active December 18, 2015 19:39
Auto fill author data in WordPress importer. Very useful for sites with many authors. Note: Should be run from the browser console when on the import-author page.
var authors_import = jQuery( '#authors li' );
authors_import.each( function() {
var name_data = jQuery( this ).find( 'strong' ).html();
var username, nicename;
username = name_data.substring( name_data.indexOf( '(' ) + 1, name_data.indexOf( ')' ) );
<?php
$author_id = 12;
$query = new WP_Query( array( 'author' => $author_id ) );
$authors_post_ids = wp_list_pluck( $query->posts, 'ID' );
?>
<?php
global $wpdb;
$author_id = 12;
$result = $wpdb->query( $wpdb->prepare( "SELECT ID from $wpdb->posts where post_author = %d AND post_status = 'publish' AND post_type = 'post' LIMIT 10", $author_id ) );
$authors_post_ids = wp_list_pluck( $result, 'ID' );
<?php
$cs_remote_cache = new CS_Remote_Cache();
$key = 'whatever-key-you-want'; // needs to be unique
$data = ''; // the data you want to cache
$expire = 30; // expiration in seconds