Skip to content

Instantly share code, notes, and snippets.

johnpbloch / query-thief.php
Created November 18, 2011 17:11
Hijacking the main WordPress query and loop for fun and profit
View query-thief.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;
View 2018_12_29_113449_create_csv_data_table.php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCsvDataTable extends Migration
* Run the migrations.
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
View disable-plugins-when-doing-local-dev.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:
johnpbloch / composer.json
Created April 18, 2013 13:07
Install PHPUnit globally with composer
View composer.json
"name": "phpunit",
"description": "PHPUnit Composer Package",
"require": {
"phpunit/phpunit": "3.7.*"
"config": {
"bin-dir": "/usr/local/bin/"
johnpbloch / media-wut.js
Created December 18, 2012 17:01
Add a custom page to the new media manager in WordPress that only shows attachments uploaded to this post with no controls to change it. This is undoubtedly bad programming, but that javascript is a huge mess of undocumented code with little to no help in figuring out how to extend it.
View media-wut.js
var media =,
jeditor = {
oldMainMenu : media.view.MediaFrame.Post.prototype.mainMenu,
init : function(){
media.view.MediaFrame.Post.prototype.mainMenu = function(view){
var jState = new media.controller.Library({
id: 'test',
library: media.query({uploadedTo:}),
johnpbloch / instance-provider.php
Last active June 23, 2018 04:15
PHP 5.3+ "Global" provider pattern for WordPress
View instance-provider.php
// Here we are, in any scope imaginable. It doesn't matter which
$my_object = new My_Class();
add_filter( 'jpb.provider.my_class', function() use ( $my_object ) {
return $my_object || new My_Class();
} );
// This is in the global scope
johnpbloch /
Created August 23, 2012 13:55
A bash script to make .pot files for WordPress plugins


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

sudo svn co /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"

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.
View .bashrc
# 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() {
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.
View protected-roles.php
class JPB_User_Caps {
* An array of all protected roles
* @var array
protected $protectedRoles = array(
johnpbloch / powerline-jpb.base.bash
Created August 4, 2017 17:03
My custom theme for bash_it based on powerline multiline
View powerline-jpb.base.bash
. "$BASH_IT/themes/powerline-multiline/powerline-multiline.base.bash"
function __powerline_docker_compose_prompt {
local prompt
if docker-compose config &>/dev/null