Skip to content

Instantly share code, notes, and snippets.

@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 / 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}),
<?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 {
console.log('Here');
@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();
@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 / 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 / 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();
}
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 / 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