Skip to content

Instantly share code, notes, and snippets.

@johnpbloch
johnpbloch / query-thief.php
Created November 18, 2011 17:11
Hijacking the main WordPress query and loop for fun and profit
<?php
/*
* Plugin Name: Query Thief
* Description: Hijacking the main WordPress query and loop for fun and profit
* Version: 0.1
*/
// I namespace everything now that PHP 5.2.4 is the minimum requirement. :D
namespace JPB;
@johnpbloch
johnpbloch / short-circuit.php
Created November 21, 2011 20:10
Short Circuit a post save in WordPress and give the user a notice saying why.
<?php
namespace JPB;
function wp_insert_post_data( $data, $postarr ){
if($data['foo'] !== 'bar' || $data['baz'] !== 'bat'){
wp_redirect( add_query_arg( array( 'post' => $data['ID'], 'action' => 'edit', 'message' => 11 ), admin_url( 'post.php' ) ) );
exit;
}
return $data;
@johnpbloch
johnpbloch / tadv-ms-fixer.php
Created December 9, 2011 00:30
TinyMCE Advanced Network Fixer
<?php
/*
* Plugin Name: TinyMCE Advanced Multisite Fixer
* Description: Forces TinyMCE Advanced to use site options for its settings when it's network activated.
* Version: 0.1
* Author: John P. Bloch
* Author URI: http://www.johnpbloch.com/
*/
@johnpbloch
johnpbloch / node.js
Created January 19, 2012 20:55 — forked from lazypower/node.js
// Define a JSON data-structure that will look and perform like the real deal
// What is common to every post? Lets examine the details:
var forumData = { // Defining the object structure
"Posts" : [ // array of Posts
// single post item in the array
{
// definition of properties
"id" : "1",
"user" : "Melvin",
"title" : "Yes, I beleive you have my stapler...",
@johnpbloch
johnpbloch / disable-plugins-when-doing-local-dev.php
Created February 11, 2012 20:12 — forked from markjaquith/disable-plugins-when-doing-local-dev.php
Disables specified WordPress plugins when doing local development
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
@johnpbloch
johnpbloch / protected-roles.php
Created March 13, 2012 14:07
Define 'protected' WordPress roles that can only be deleted by users of at least one protected role. This allows you to enable clients to create, edit, and delete users without deleting your account.
<?php
class JPB_User_Caps {
/**
* An array of all protected roles
* @var array
*/
protected $protectedRoles = array(
'webmaster',
@johnpbloch
johnpbloch / JPB_Options.php
Created May 12, 2012 01:49
An abstract options class. To use, extend this class. All public properties defined for the class will be used as the keys in the options array. Comes with helper functions for updating, etc.
<?php
abstract class JPB_Options {
/**
* The database option name value. Must be declared in extending classes.
* @var string
*/
protected $_option_name = null;
@johnpbloch
johnpbloch / .htaccess
Created June 20, 2012 14:26
.htaccess Extras for WordPress-Skeleton
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(wp-admin/.*)$ /wp/$1 [L]
RewriteRule ^(wp-[^/]+\.php)$ /wp/$1 [L]
RewriteRule ^xmlrpc\.php$ /wp/xmlrpc.php [L]
RewriteRule ^(wp-includes/.*)$ /wp/$1 [L]
</IfModule>
# BEGIN WordPress
@johnpbloch
johnpbloch / .bashrc
Created August 20, 2012 17:37
Display the current git branch in your command prompt. Add an asterisk if there are unstaged updates.
# Will produce command line prompts like
# directory(branch) $
# in git repositories and like
# directory $
# elsewhere.
# If there are unstaged changes in the repository, there will be an asterisk next to the branch name:
# directory(branch*) $
parse_git_branch() {
hasmod=""
@johnpbloch
johnpbloch / README.md
Created August 23, 2012 13:55
A bash script to make .pot files for WordPress plugins

Installation

To install, you need to have the WordPress i18n library on your computer. Check it out using SVN:

sudo svn co http://i18n.svn.wordpress.org/tools/trunk/ /usr/lib/wpi18n

You don't have to put the library in /usr/lib/wpi18n, but if you don't put it there, make sure to set the $WP_I18N_LIB environment variable in your .bashrc file (with no trailing slash):

export WP_I18N_LIB="/path/to/i18n/lib"