Skip to content

Instantly share code, notes, and snippets.

View staylor's full-sized avatar
💭
GitHub is not a social network

Scott Taylor staylor

💭
GitHub is not a social network
View GitHub Profile
@staylor
staylor / images.php
Created January 24, 2013 18:16
Construct eMusic Image URLs by convention
<?php
/**
* Convenience Method to construct Artist Image URL
*
* @param int $id
* @return string Returns URL for Artist Image
*/
function artist_image_url( $id ) {
$one = substr( $id, 0, 3 );
$two = substr( $id, 3, 3 );
@staylor
staylor / wp-imagick-access.php
Created December 9, 2012 00:24
I am using a script called "test.php" in the root of WordPress with a folder for images called "test-images/*". The original image is called "scott.jpg" - change that value with your image to play along
<?php
error_reporting(-1);
require( 'wp-load.php' );
require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' );
require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );
/**
* Tosses Imagick methods up the chain to WP_Image_Editor_Imagick::image.
* WP_Image_Editor_Imagick::image is protected, so you can't act on
@staylor
staylor / balls.php
Created December 1, 2012 01:18
Balls
function _override_home_url( $url, $path = '' ) {
if ( $path && false === strpos( $url, $path ) )
$url .= $path;
return $url;
}
add_filter( 'home_url', '_override_home_url', 10, 2 );
@staylor
staylor / users.php
Created October 10, 2012 19:29
Unfuck User Query
add_action( 'pre_user_query', 'fix_users' );
function fix_users( &$query ) {
global $wpdb;
if ( 'authors' !== $query->query_vars['who'] )
return;
$query->query_vars['fields'] = array( 'ID', 'display_name' );
$query->query_fields = 'ID, display_name';
@staylor
staylor / house-ad.php
Created July 10, 2012 19:15
Multi-Armed Bandit
<?php
class HouseAd extends ModuleType {
const TYPE_QUERY_STRING = 0;
const TYPE_URL_PATH = 1;
const TYPE_COOKIE = 2;
const OPERATOR_EQUALS = 100;
const OPERATOR_NOT_EQUALS = 101;
const OPERATOR_GTE = 102;
const OPERATOR_LTE = 103;
@staylor
staylor / baller.css
Created June 13, 2012 21:41
Paste these into the Custom CSS box
#access {
background:#2b2b2b;
background:-moz-linear-gradient(#2b2b2b,#2b2b2b);
background:-o-linear-gradient(#2b2b2b,#2b2b2b);
background:-webkit-gradient(linear,0% 0%,0% 100%,from(#252525),to(#2b2b2b));
background:-webkit-linear-gradient(#2b2b2b,#2b2b2b);
}
.singular .hentry {
padding:0;
@staylor
staylor / facebook-dialog.php
Created June 6, 2012 22:23
Load barebones for Facebook OAuth handshake
<?php
/**
* Set DOING_AJAX so the app doesn't try to set eMusic cookies
*
*/
define( 'DOING_AJAX', 1 );
define( 'SHORTINIT', 1 );
require( $_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php' );
require( WP_CONTENT_DIR . '/mu-plugins/emusic-auth.php' );
@staylor
staylor / wp_ajax_autocomplete_site-patch.php
Created June 4, 2012 19:43
wp_ajax_autocomplete_site
<?php
function wp_ajax_autocomplete_site() {
if ( ! is_multisite() || ! current_user_can( 'manage_sites' ) || wp_is_large_network( 'sites' ) )
wp_die( -1 );
$return = array();
global $wpdb;
$value = stripslashes( $_REQUEST['term'] );
@staylor
staylor / comment-count.php
Created April 20, 2012 19:09
Get the actual number of comments + replies per page, WP comments_per_page is really top-level comments only: allows you to identify 1-12 of 13, etc for comments count UI instead of mistakenly labeling page 1 as 1-10
<?php
function get_cpage_comment_count() {
$counter = $start = 0;
wp_list_comments( array( 'callback' => function ( $comment ) use ( &$counter, &$start ) {
global $wpdb;
if ( 0 === $counter ) {
$sql = $wpdb->prepare(
"SELECT COUNT(comment_ID) FROM {$wpdb->comments}
WHERE comment_approved = 1 AND