Skip to content

Instantly share code, notes, and snippets.

View Viper007Bond's full-sized avatar
😎
Writing Code

Alex Mills Viper007Bond

😎
Writing Code
View GitHub Profile
@Viper007Bond
Viper007Bond / sync.php
Created August 1, 2011 23:11 — forked from anonymous/sync.php
Google Contacts Sync
<?php
/**
* Google Contacts Syncer
* by Alex Mills (http://www.viper007bond.com/)
*
* This script copies all contacts from Google account A to
* Google account B, wiping out all existing contacts in
* account B's account in the process.
*
@Viper007Bond
Viper007Bond / watermark-image-uploads.php
Created September 1, 2011 23:25
Watermark WordPress Image Uploads
<?php
/*
* Plugin Name: WordPress.com Watermark Image Uploads
* Author: Alex Mills
* Author URI: http://automattic.com/
*/
class WPcom_Watermark_Uploads {
public $watermark;
@Viper007Bond
Viper007Bond / example.php
Created September 30, 2011 00:14
Private post_status in a List_Table
<?php
class Your_Media_List_Table extends WP_Media_List_Table {
/* some stuff here */
// Adds a WHERE modify filter, calls parent version of prepare_items(), then removes filter
function prepare_items() {
add_filter( 'posts_where', array( &$this, 'modify_post_status_to_private' ) );
@Viper007Bond
Viper007Bond / gist:1297669
Created October 19, 2011 07:27
Determining if modifying the main query or not in WordPress
<?php
# See bigdawggi's comment below for a good combined example
// Pre-3.3
function cf_google_search_kill_wp_search( $where, $query ) {
global $wp_the_query;
if( ! is_admin() && $query->is_search() && $query === $wp_the_query ) {
$where = ' AND 1=0';
@Viper007Bond
Viper007Bond / gist:1325696
Created October 30, 2011 08:11
Limit results to post meta via URL
<?php
add_action( 'pre_get_posts', 'oomskaap_price_range_limiter' );
function oomskaap_price_range_limiter( $query ) {
// Only do something if both the start and end values are set in the URL
if ( empty( $_GET['pricestart'] ) || empty( $_GET['priceend'] ) )
return;
// Only modify the main query
@Viper007Bond
Viper007Bond / gist:1368983
Created November 16, 2011 01:28
Modify all posts
<?php
/**
* Fetching all posts from the database would suck up a lot of memory.
* So instead this code processes 25 posts at a time.
*/
$posts_at_a_time = 25;
$query_args = array(
@Viper007Bond
Viper007Bond / gist:1390918
Created November 24, 2011 08:51
My Sublime Text 2 Configuration Files
// File Settings - User
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_face": "Consolas", // Windows, you'll likely want default or something else
"font_size": 10,
//"spell_check": true,
@Viper007Bond
Viper007Bond / cli-db-upgrade.php
Created December 6, 2011 23:47
Updgrade the WordPress DB from the command line
<?php
# Stick this file in your wp-content folder
define( 'WP_INSTALLING', true );
require_once( dirname( __FILE__ ) . '/../wp-load.php' );
timer_start();
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
@Viper007Bond
Viper007Bond / add-another-category-to-posts.php
Created February 16, 2012 08:24
WordPress: Add Another Category To Posts
<?php
/**
* Takes posts that are in category A and also adds them to category B
*/
// Uncomment this to proceed
exit( "You need to edit the file and enter the hostname and category IDs.\n" );
// What blog? Asking for both for safety reasons.
@Viper007Bond
Viper007Bond / gist:1903147
Created February 24, 2012 19:27
Modify post_types searched
<?php
add_action( 'pre_get_posts', 'localtv_posts_and_pages_for_search' );
function localtv_posts_and_pages_for_search( $query ) {
if ( $query->is_main_query() && $query->is_search() )
$query->set( 'post_type', array( 'post', 'page' ) );
}