Skip to content

Instantly share code, notes, and snippets.

View spencermorin's full-sized avatar

Spencer Cameron-Morin spencermorin

View GitHub Profile
@spencermorin
spencermorin / gist:4948165
Last active December 13, 2015 17:28
Remove default Facebook Comments placement on WordPress.com VIP.
<?php
// In theme's functions.php.
function pl_remove_facebook_comments() {
remove_filter( 'the_content', 'fb_comments_automatic', 30 );
remove_filter( 'comments_array', 'fb_close_wp_comments' );
remove_filter( 'the_posts', 'fb_set_wp_comment_status' );
remove_action( 'wp_enqueue_scripts', 'fb_hide_wp_comments' );
remove_filter( 'comments_number', 'fb_get_comments_count' );
}
<?php $color_palette = get_post_meta( get_the_ID(), 'color-palette' ); ?>
<?php foreach( $color_palette[ 0 ] as $color ) : ?>
<div style="width: 50px; height: 50px; background: #<?php echo $color; ?>"></div>
<?php endforeach; ?>
<?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
<?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
$author_id = 12;
$query = new WP_Query( array( 'author' => $author_id ) );
$authors_post_ids = wp_list_pluck( $query->posts, 'ID' );
?>
@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( ')' ) );
@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 / 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';
<?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.
<?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