Skip to content

Instantly share code, notes, and snippets.

@nacin
nacin / find-local-vars.php
Created January 20, 2012 22:34
Find Unset Local Variables
<?php
$path_to_file = '...';
$file = explode( "\n", file_get_contents( $path_to_file ) );
// Finds local variables that are undeclared.
//
// Doesn't understand foreach() variables, dockblocks, sprintf arguments,
// variables returned by reference from a function like preg_match() or parse_str(),
@nacin
nacin / svn-override.sh
Created January 25, 2012 00:27
Require `svn ci -m` calls to have explicit files
#!/bin/sh
function svn() {
if [ "$1" == "ci" ] && [ "$2" == "-m" ] && [ -z "$4" ] && [ "$(svn stat --ignore-externals | grep '^[^?X]' | wc -l | awk '{print $1}')" -gt 1 ]; then
svn stat --ignore-externals | grep '^[^?X]'
echo ""
echo $3
echo ""
echo "Unbounded commit... What are you doing, man?"
else
/usr/bin/svn "$@"
@nacin
nacin / highlight-scheduled-posts.php
Created February 23, 2012 22:39
Highlight scheduled posts (suggestion from Eric Meyer)
<?php
/* Plugin Name: Highlight Scheduled Posts
* Author: Andrew Nacin
* Author URI: http://nacin.com
*/
add_action( 'admin_head-edit.php', 'meyer_highlight_scheduled_posts' );
function meyer_highlight_scheduled_posts() {
echo "<style> tr.status-future { background-color: #ffffe0 }</style>\n";
}
@nacin
nacin / gist:1950612
Created March 1, 2012 15:44
Example insanity
<?php
class foo {
function bar() {}
}
$GLOBALS['fb'] =& new foo;
function foo_bar($buffer) {
$GLOBALS['fb']->bar();
@nacin
nacin / gist:1950630
Created March 1, 2012 15:49
Example insanity pt 2
<?php
register_shutdown_function( 'ob_end_flush' );
class foo {
function __construct() {
register_shutdown_function( array( &$this, '__destruct' ) );
}
function bar( $buffer ) {
@nacin
nacin / gist:2323060
Created April 6, 2012 21:23
Nacin's SVN override
# SVN override to prevent commits that try to implicitly commit more than one file.
# Has weaned me off of svn ci -m very effectively. I now almost always use svn ci,
# which usually results in me writing longer and more helpful commit messages.
# Also, it prevents me from committing unrelated code, so there's that.
#
# Also checks for error_log, var_dump, and console.log, and rejects these commits.
function svn() {
if [ "$1" == "ci" ] && [ "$2" == "-m" ] && [ -z "$4" ] && [ "$(svn stat --ignore-externals | grep '^[^?X]' | wc -l | awk '{print $1}')" -gt 1 ]; then
svn stat --ignore-externals | grep '^[^?X]'
@nacin
nacin / extending-xmlrpc.php
Created April 26, 2012 16:33
mu-plugins/extending-xmlrpc.php
<?php
/**
* Plugin Name: jQuery extends WordPress XML-RPC
* Description: Enables XML-RPC and adds custom methods.
*/
add_action( 'enable_xmlrpc', '__return_true' );
function jquery_get_post_paths( $args ) {
$post_type = sanitize_key( $args[0] );
<?php
function jquery_posts_only_for_searches( $query ) {
if ( $query->is_main_query() && $query->is_search() )
$query->set( 'post_type', 'post' );
}
add_action( 'pre_get_posts', 'jquery_posts_only_for_searches' );
<?php
add_action( 'init', function() {
register_post_type( 'plugin', array(
'name' => 'Plugin',
'public' => true,
'rewrite' => false,
) );
} );
@nacin
nacin / jquery-html-category-descriptions.php
Created June 19, 2012 13:33
HTML Category Descriptions
<?php
add_action( 'init', 'jquery_unfiltered_html_for_term_descriptions' );
add_action( 'set_current_user', 'jquery_unfiltered_html_for_term_descriptions' );
function jquery_unfiltered_html_for_term_descriptions() {
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'pre_term_description', 'wp_filter_post_kses' );
if ( ! current_user_can( 'unfiltered_html' ) )
add_filter( 'pre_term_description', 'wp_filter_post_kses' );
}