Skip to content

Instantly share code, notes, and snippets.

1CD8_rundll32.0
1E64_notepad.0
2DCB_Bridge.0
2EF4_wordpad.0
31B7_G2MInstaller.0
3F06_ProgramMenuShortcut_E9787678103300008E670000000001_1.0
406F_NewShortcut2_B74D4E10103300000000000000000001.0
4137_winhlp32.0
6B9F_AdobeBridge_B74D4E10103300000000000000000001_1.0
7765_winebrowser.0
@johnpbloch
johnpbloch / gist:5256345
Last active December 15, 2015 11:58 — forked from ericmann/gist:5256251
<?php
class MyTestClass extends PHPUnit_Framework_TestCase {
public function setUp() {
\WP_Mock::setUp();
}
public function tearDown() {
\WP_Mock::tearDown();
}
@johnpbloch
johnpbloch / pseudo-encapsulation.php
Created March 27, 2013 12:17
Get the hook suffix without an object or class
<?php
namespace JPB\Some_Plugin;
function get_hook_suffix() {
return apply_filters( 'jpb.some_plugin.get_hook_suffix', '' );
}
function register_page() {
$hook_suffix = add_submenu_page( /* Arguments */ );
@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 / grunt.js
Created February 7, 2013 03:22
Automatically commit changes to .md files in a directory on save using grunt watch.
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
exec: {
commit: {
command: function(grunt){
var d = new Date(),
datetime = d.toString();
console.log('Here');
<?php
if (WP_STAGE == 'production') {
return;
}
if(!class_exists('WP_Stack_Plugin')){class WP_Stack_Plugin{function hook($h){$p=10;$m=$this->sanitize_method($h);$b=func_get_args();unset($b[0]);foreach((array)$b as $a){if(is_int($a))$p=$a;else $m=$a;}return add_action($h,array($this,$m),$p,999);}private function sanitize_method($m){return str_replace(array('.','-'),array('_DOT_','_DASH_'),$m);}}}
class AVM_Staging_Url_Rewrite extends WP_Stack_Plugin {
@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 / plugin.php
Created October 25, 2012 16:49
Automatically add featured image
<?php
function _jpb_featured_image_setup(){
define( 'JPB_THEME_REALLY_SUPPORTS_POST_THUMBNAILS', current_theme_supports('post-thumbnails') );
if(!JPB_THEME_REALLY_SUPPORTS_POST_THUMBNAILS){
add_theme_support( 'post-thumbnails' );
}
}
add_action('after_setup_theme', '_jpb_featured_image_setup', 101);
@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"