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;
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCsvDataTable extends Migration
{
/**
* Run the migrations.
@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 / composer.json
Created April 18, 2013 13:07
Install PHPUnit globally with composer
{
"name": "phpunit",
"description": "PHPUnit Composer Package",
"require": {
"phpunit/phpunit": "3.7.*"
},
"config": {
"bin-dir": "/usr/local/bin/"
}
}
@johnpbloch
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.
(function($){
var media = wp.media,
jeditor = {
oldMainMenu : media.view.MediaFrame.Post.prototype.mainMenu,
init : function(){
media.view.MediaFrame.Post.prototype.mainMenu = function(view){
jeditor.oldMainMenu(view);
var jState = new media.controller.Library({
id: 'test',
library: media.query({uploadedTo: media.view.settings.post.id}),
@johnpbloch
johnpbloch / instance-provider.php
Last active June 23, 2018 04:15
PHP 5.3+ "Global" provider pattern for WordPress
<?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
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"

@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 / 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 / powerline-jpb.base.bash
Created August 4, 2017 17:03
My custom theme for bash_it based on powerline multiline
. "$BASH_IT/themes/powerline-multiline/powerline-multiline.base.bash"
function __powerline_docker_compose_prompt {
local prompt
if docker-compose config &>/dev/null
then
prompt+="${DOCKER_CHAR}"
else
return
fi