Skip to content

Instantly share code, notes, and snippets.

View mboynes's full-sized avatar

Matthew Boynes mboynes

View GitHub Profile
@mboynes
mboynes / fieldmanager-demo-2.php
Last active August 29, 2015 14:19
Slideshow demo for Fieldmanager.org
<?php
// using Fieldmanager for a slideshow - any number of slides,
// with any number of related links
add_action( 'fm_post_post', function() {
$fm = new Fieldmanager_Group( array(
'name' => 'slideshow',
'limit' => 0,
'label' => __( 'New Slide', 'your-domain' ),
'label_macro' => array( __( 'Slide: %s', 'your-domain' ), 'title' ),
'add_more_label' => __( 'Add another slide', 'your-domain' ),
@mboynes
mboynes / fieldmanager-demo-1.php
Last active August 29, 2015 14:19
Demo for fieldmanager.org
<?php
// put this in functions.php or an include file
add_action( 'fm_post_post', function() {
$fm = new Fieldmanager_Group( array(
'name' => 'contact_information',
'children' => array(
'name' => new Fieldmanager_Textfield( __( 'Name', 'your-domain' ) ),
'phone_number' => new Fieldmanager_Textfield( __( 'Phone Number', 'your-domain' ) ),
'website' => new Fieldmanager_Link( __( 'Website', 'your-domain' ) ),
),
@mboynes
mboynes / codesniffer.ruleset.xml
Created March 20, 2015 15:42
WordPress Codesniffer ruleset starting point
<?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards Configuration">
<!-- Set a description for this ruleset. -->
<description>Code standard rules to check against a WordPress Theme.</description>
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>inc/cli.php</exclude-pattern>
<!-- Include the WordPress VIP ruleset -->
<rule ref="WordPress-VIP">
@mboynes
mboynes / path-dispatch.php
Created December 4, 2014 14:59
Path Dispatch
<?php
/**
* Path Dispatch
* =============
*
* Simply and easily add a URL which fires an action, triggers a callback, and/or loads a template.
*
* Basic Usage: at any point before init,
*
* Path_Dispatch()->add_path( array( 'path' => 'some-path', 'callback' => 'some_function' ) );
#!/bin/bash
# Testing changes
# Usage: ./distribute_user.sh [username] [role]
ARGS="$@"
echo "Adding user $1 as $2 to all sites"
SITES=$(wp site list --field=url --format=csv)
for site in $SITES
@mboynes
mboynes / term-split-update-examples.md
Last active December 7, 2015 19:57
Term split update examples

Preparing Plugins for Term Splitting

Historically, two terms in different taxonomies with the same slug (for instance, a tag and a category sharing the slug "news") have shared a single term ID. Beginning in WordPress 4.2, when one of these shared terms is updated, it will be split: the updated term will be assigned a new term ID.

In the vast majority of situations, this update will be seamless and uneventful. However, some plugins and themes store term IDs in options, post meta, user meta, or elsewhere. WP 4.2 will include two different tools to help authors of these plugins and themes with the transition.

The 'split_shared_term' action

When a shared term is assigned a new term ID, a new 'split_shared_term' action is fired. Plugins and themes that store term IDs should hook to this action to perform necessary migrations. The documentation for the hook is as follows:

@mboynes
mboynes / wp
Created October 28, 2014 16:45
wp wrapper for vagrant
#!/bin/bash
ARGS="$@"
DIR=`pwd 2>&1`
if [[ $DIR == *www* ]]; then
if [[ $ARGS != *--url* ]]; then
SITE=`pwd | sed 's/.*\/www\///' | cut -d "/" -f 1 2>&1`
if [[ $SITE == "wordpress" ]]; then
ARGS="$ARGS --url=wp.dev"
elif [[ $SITE == "trunk" ]]; then
@mboynes
mboynes / server.js
Created October 21, 2014 23:39
Simple node server
var http = require("http")
, url = require("url")
, path = require("path")
, fs = require("fs")
, qs = require('querystring')
, tasks = {}
, port = process.argv[2] || 8888
, next_id = 1
;
@mboynes
mboynes / user_recon.php
Last active August 29, 2015 14:01
Check a file of email addresses against the WP User database to see if they're in use or not. This is not part of a command; it can be added to any.
<?php
/**
* Check a file of email addresses against the user database to see if those
* email addresses are currently in use.
*
* ## OPTIONS
*
* <file>
* : The file of users to import.
<?php
/**
* Sidebar Picker
*/
if ( !class_exists( 'My_Sidebar_Picker' ) ) :
class My_Sidebar_Picker {