Skip to content

Instantly share code, notes, and snippets.

@johnpbloch
johnpbloch / README.md
Last active December 21, 2015 06:28
Install Boris, PHPUnit, and Mockery globally with Composer
@johnpbloch
johnpbloch / help.php
Created August 13, 2013 21:33
Add a contextual help tab to the screen
<?php
add_action('current_screen', 'jpb_current_screen');
/**
* @param WP_Screen $screen The current screen object
*/
function jpb_current_screen($screen){
if($screen->post_type === 'my_custom_post_type'){
$screen->add_help_tab(array(
<?php
namespace Alpha\Beta\Gamma\Base\Echo;
use Alpha\Beta\Gamma\Base;
class Foxtrot extends Base\Echo
{
}
@johnpbloch
johnpbloch / gist:6029614
Created July 18, 2013 14:07
Remove a filter (or action) without a reference to an object
<?php
function remove_filter_by_classname( $filter, $classname, $priority ) {
global $wp_filter;
$match = false;
if( !empty( $wp_filter[$filter] ) && !empty( $wp_filter[$filter][$priority] ) ) {
foreach( $wp_filter[$filter][$priority] as $added_filter ) {
if( is_array( $added_filter['function'] ) && get_class( $added_filter['function'][0] ) === $classname ) {
$match = $added_filter;
break;
<?php
class Loopable_Query extends WP_Query implements Iterator {
/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Return the current element
* @link http://php.net/manual/en/iterator.current.php
* @return mixed Can return any type.
*/
curl https://github.com/WordPress/WordPress/compare/3.5...3.5.1.patch | patch -p1
@johnpbloch
johnpbloch / gist:5614379
Created May 20, 2013 18:50
Run PHPUnit tests by group and report on pass/incomplete/fail by group
function testsbygroup(){
# Grab a list of groups
groups=`phpunit --list-groups | sed -rn 's/ - (.+)/\1/p'`
if [[ ! $groups ]]; then
return 1
fi
# Set up some empty arrays
pass=()
incomplete=()
@johnpbloch
johnpbloch / composer.json
Created April 24, 2013 15:09
A composer file to install WP_Mock's dependencies.
{
"name": "your-name/your-project",
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"mockery/mockery": "dev-master@dev",
"hamcrest/hamcrest": "1.1.0"
},
"repositories": [
@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 / Vagrantfile
Created April 16, 2013 03:21
Puppet awesomesauce for Vagrant
config.vm.provision :puppet do |puppet|
# Add a folder in your root named .ppt
puppet.manifests_path = ".ppt/manifests"
# vagrant.pp is your main manifest and goes in .ppt/manifests
puppet.manifest_file = "vagrant.pp"
# Add puppet modules in .ppt/modules as git submodules; they will be pre-installed in Vagrant this way
puppet.module_path = ".ppt/modules"
# Config files, etc. go in .ppt/files. fileserver.conf (see below) defines the path for puppet to add
# when looking for files. That way, you can reference files with puppet:// protocols. Make sure you
# add the directory defined in fileserver.conf as a shared directory in the main Vagrantfile config