Skip to content

Instantly share code, notes, and snippets.

View mboynes's full-sized avatar

Matthew Boynes mboynes

View GitHub Profile
@mboynes
mboynes / ks_timesheet.js
Created February 20, 2014 14:52
Global keyboard shortcut for the Bonus Time Redmine plugin
viewRmTimesheet = function() {
var timesheet_link = $('.bonus-time');
if (timesheet_link.length > 0) {
ks_dispatcher.go(timesheet_link.attr('href'));
}
}
if ( ks_dispatcher && ks_dispatcher.ks_managers && ks_dispatcher.ks_managers.length && ks_dispatcher.ks_managers[0] && ks_dispatcher.ks_managers[0].keys ) {
ks_dispatcher.ks_managers[0].keys.t = {
press: viewRmTimesheet.bind(this),
@mboynes
mboynes / functions.php
Created February 28, 2014 04:00
WPSE 135707
<?php
function add_video_post_type() {
$labels = array(
'name' => _x( 'Videos', 'Post Type General Name', 'kibble' ),
'singular_name' => _x( 'Video', 'Post Type Singular Name', 'kibble' ),
'menu_name' => __( 'Videos', 'kibble' ),
'parent_item_colon' => __( 'Parent Item:', 'kibble' ),
'all_items' => __( 'All Items', 'kibble' ),
@mboynes
mboynes / html_attributes.js
Last active August 29, 2015 13:57
Get html attributes from a given html tag
function get_html_attributes(s) {
var reg = /\s+([^\t\n\r\f \/>"'=]+)(?:\s*=\s*(['"])(.*?)\2)?/,attr = {};
while ((result = reg.exec(s)) !== null) {
attr[result[1]] = result[3];
s = s.replace(reg,'');
}
return attr;
}
<?php
/**
* Sidebar Picker
*/
if ( !class_exists( 'My_Sidebar_Picker' ) ) :
class My_Sidebar_Picker {
@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.
@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 / 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 / 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:

#!/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 / 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' ) );