Skip to content

Instantly share code, notes, and snippets.

View evansolomon's full-sized avatar

Evan Solomon evansolomon

View GitHub Profile
@evansolomon
evansolomon / jetpack-share-shortlinks.php
Created July 18, 2012 21:45
Use shortlinks in Jetpack sharing
@evansolomon
evansolomon / gist:3186427
Created July 27, 2012 06:11
Generic function to add body classes on the fly in WordPress
<?php
/**
* Generic function to add body classes
* Can take either a string of space-separated classes or an array
*
* Requires PHP 5.3 for access to closures
*/
function es_add_body_class( $new_classes ) {
// Turn the input into an array we can loop through
@evansolomon
evansolomon / gist:3192076
Created July 28, 2012 06:22
WordPress: Only allow one post in a category at a time
<?php
/*
Plugin Name: Move Old Urgent Posts
*/
function es_update_urgent_post_cats( $post_id ) {
// Get our category
$the_category = 'urgent';
$the_category_obj = get_category_by_slug( $the_category );
$the_category_id = $the_category_obj->term_id;
define( 'WP_SITEURL_SUBDIR', 'wp' );
define('PATH_CURRENT_SITE', '/');
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ http://%{HTTP_HOST}/wp-admin/ [R,L]
Index: wp-content/mu-plugins/pig-setup.php
===================================================================
--- wp-content/mu-plugins/pig-setup.php (revision 228)
+++ wp-content/mu-plugins/pig-setup.php (working copy)
@@ -21,7 +21,7 @@
pig_register_question( 'Additional Comments', '%s waxes poetic about food&hellip;', false );
pig_register_question( 'What are some topics you are good at speaking about?', '%s knows a bit about&hellip;', false );
}
-add_action( 'bp_init', 'a8c_pig_setup_questions' );
+add_action( 'pig_loaded', 'a8c_pig_setup_questions' );
@evansolomon
evansolomon / var.php
Created August 12, 2012 05:56
Possibly the worst 18 lines of code ever written
<?php
/* Get all our options from the database */
global $options;
foreach ($options as $value) {
if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std'];
} else { $$value['id'] = get_settings( $value['id'] ); }
}
/* Get Portfolio category ID from the name */
@evansolomon
evansolomon / red-not-green.sh
Created August 23, 2012 18:43
Measure the added and deleted lines in patches
# For patches, lower numbers are better
function redgreen() {
ack "^[-|\+]" -oh | sort | uniq -c | ack [0-9]+ -oh | xargs | awk '{print $1 - $2}'
}
# Example usage
# $ svn di | redgreen
# $ -150
@evansolomon
evansolomon / first-paragraph-front-page.php
Created August 24, 2012 07:05
Only show the first paragraph of posts on a WordPress front page
<?php
/*
Plugin Name: Front page first paragraph
Plugin URI: http://example.com/
Description: Only use the first paragraph of posts on the front page
Version: 1.0
Author: Evan Solomon
Author URI: http://evansolomon.me
*/
@evansolomon
evansolomon / gist:3481592
Created August 26, 2012 16:47
Bash functions to find WordPress hooks
# Alias ST2's command line tool for a shorter (easier-to-remember) name
alias st="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
# Search for and open WordPress hooks
function action() {
ack "do_action\(\s*('|\")$1('|\")" | awk {'print $1'} | sed 's/:$//g' | xargs st
}
function filter() {
ack "apply_filters\(\s*('|\")$1('|\")" | awk {'print $1'} | sed 's/:$//g' | xargs st
}