Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
@westonruter
westonruter / init-plugin.sh
Last active August 29, 2015 14:14
Create plugin from scaffold at https://github.com/xwp/wp-foo-bar
#!/bin/bash
# Usage: ./init-plugin.sh "Hello World"
# Creates a subdirectory "hello-world" in the current working directory,
# performing substitutions on the scaffold "foo-bar" plugin at https://github.com/xwp/wp-foo-bar
set -e
if [ $# != 1 ]; then
echo "You must only supply one argument, the plugin name."
exit 1
<?php
$foo_color_default = '#f00';
$foo_text_default = 'Lorem';
// These add_option() eliminate the need for supplying default values for settings,
// and it eliminates the need to supply the 2nd $default arg to get_option()
add_option( 'foo_color', $foo_color_default );
add_option( 'foo_text', $foo_text_default );
add_action( 'customize_register', function() use ( $foo_color_default, $foo_text_default ) {
@westonruter
westonruter / trac-31484-monkey-patch.js
Last active August 29, 2015 14:16
Monkey patch for #31484: Widgets appearing in Customizer preview during a theme preview may not correspond to controls in Widgets panel
/*global wp */
(function ( api ) {
/**
* Mark a sidebars_widgets setting as dirty.
*
* @param {wp.customize.Setting} setting
*/
var markAddedSidebarsWidgetsAsDirty = function ( setting ) {
if ( 0 === setting.id.indexOf( 'sidebars_widgets[' ) ) {
<?php
/**
* Widget that takes random 0-5 seconds to save.
*
* @link https://github.com/xwp/wordpress-develop/pull/75/files
* @link https://core.trac.wordpress.org/ticket/31501
*/
add_action( 'widgets_init', function () {
#!/bin/bash
cd $(dirname $0)/..
twig_repo=https://github.com/twigphp/Twig.git
twig_tree=v1.18.0
twig_path=www/wp-content/plugins/twig
if [ ! -e "$twig_path" ]; then
git init "$twig_path"
cd "$twig_path"
<?php
/*
* Plugin Name: Report fatal error at shutdown
* Author: Weston Ruter, XWP
* Description: Workaround for Query Monitor suppressing the displaying of errors. Workaround for <https://github.com/Automattic/vip-quickstart/issues/404>
*
* Installation instructions:
* $ cd vip-quickstart/www/wp-content/mu-plugins
* $ git clone https://gist.github.com/187da1b14f0149243fd0.git report-fatal-error-at-shutdown
* $ ln -s report-fatal-error-at-shutdown/report-fatal-error-at-shutdown.php .
<?php
/*
Plugin Name: Test select[multiple] sync behavior in Widget Customizer
Description: Demonstration of Core issue #31885 via a widget undo/redo feature.
Plugin URI: https://core.trac.wordpress.org/ticket/31885
Author: Weston Ruter, David Lonjon, XWP
Author URI: https://xwp.co/
GitHub Plugin URI: https://gist.github.com/westonruter/2e56e08881ae296237ca
Copyright 2015 XWP.co Pty Ltd
<?php
add_action( 'init', function () {
if ( ! defined( 'MB_IN_BYTES' ) ) {
define( 'MB_IN_BYTES', 1024 * 1024 );
};
} );
<?php
class WPCOM_VIP_CLI_Command extends WP_CLI_Command {
/**
* Clear all of the caches for memory management
*/
protected function stop_the_insanity() {
/**
(function(){
var ids, values;
ids = _.filter( _.keys( wp.customize._value ), function ( id ) { return /menu/.test( id ) && !/^widget_/.test( id ); } );
values = {}; _.each( ids, function ( id ) {
var setting = wp.customize( id );
values[ id + ':' + setting.transport ] = setting.get();
} );
return values;
}());