Skip to content

Instantly share code, notes, and snippets.

@nacin
nacin / p2-qa-comments.php
Created August 13, 2011 22:44
P2 Q&A Comments
<?php
/* Plugin Name: P2 Q&A Comments
* Description: Allows you to mark P2 comments as +1/-1 and as answered. Ideal for live Q&A sessions.
* Author: Andrew Nacin
* Author URI: http://andrewnacin.com/
*/
/* WARNING about studying and copying this code:
*
* P2 is not currently an ideal platform for developing extensions. Some of this
@nacin
nacin / p2-resolved-posts.php
Created August 14, 2011 21:24
P2 Resolved Posts
<?php
/* Plugin Name: P2 Resolved Posts
* Description: Allows you to mark P2 posts for resolution.
* Author: Andrew Nacin
* Author URI: http://andrewnacin.com/
*/
/* WARNING about studying and copying this code:
*
* P2 is not currently an ideal platform for developing extensions. Some of this
@nacin
nacin / p2-privately-published-posts.php
Created August 14, 2011 22:34
P2 Privately Published Posts
<?php
/* Plugin Name: P2 Privately Published Posts
* Description: Allows you to publish private posts to a P2.
* Author: Andrew Nacin
* Author URI: http://andrewnacin.com/
*/
/* WARNING about studying and copying this code:
*
* P2 is not currently an ideal platform for developing extensions. Some of this
@nacin
nacin / title-tag.php
Created August 29, 2011 19:19
Replacement for wp_title()?
<?php
// In a theme:
add_action( 'after_setup_theme', function() {
add_theme_support( 'title-tag', array( 'option' => true ) );
} );
// In core:
add_action( 'wp_head', '_wp_render_title_tag' );
function _wp_render_title_tag() {
@nacin
nacin / tweets.php
Created September 19, 2011 00:59
Random Custom Post Type Example from WCPDX
<?php
add_action( 'init', 'tweets_init' );
function tweets_init() {
register_post_type( 'tweets', array(
'public' => true,
'labels' => array(
'name' => 'Tweets',
'singular_name' => 'Tweet',
),
@nacin
nacin / attachment-block.php
Created October 12, 2011 01:36
Blocking Attachments from Editing/Deletion
<?php
// Plugin Name: Blocking Attachments from Editing/Deletion
/*
* The map_meta_cap_ filter runs on a meta capability, such as edit_post and delete_post.
* When these caps are caught by WordPress, it converts this to the required caps. For example,
* the edit_post meta capability, checked against a published post, requires the edit_published_posts
* capability. If the user isn't the same as the author, it also requires the edit_others_posts
* capability.
@nacin
nacin / wcphilly-admin.php
Created November 5, 2011 04:03 — forked from norcross/admin_htaccess.txt
WCPhilly Admin
<?php
/*
Plugin Name: WordCamp Philly 2011 Admin
Plugin URI: http://localhost/whitelabel
Description: Some swanky stuff to make your admin look GOOD
Author: Andrew Norcross
Version: 0.1
Requires at least: 3.0
Author URI: http://andrewnorcross.com
@nacin
nacin / some-plugin.php
Created November 5, 2011 20:54
Sample Taxonomy Column on edit.php
<?php
add_action( 'init', function() {
register_taxonomy( 'some-taxonomy', 'post', array(
'show_ui' => true,
'rewrite' => false,
'public' => true,
'labels' => array(
'name' => 'Some Taxonomy',
'singular_name' => 'Some Taxonomy',
@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 "$@"