Skip to content

Instantly share code, notes, and snippets.

View boonebgorges's full-sized avatar

Boone Gorges boonebgorges

View GitHub Profile
@boonebgorges
boonebgorges / gist:5510970
Created May 3, 2013 16:42
A recursive sorta-version of wp_parse_args()
<?php
/**
* Recursive argument parsing
*
* This acts like a multi-dimensional version of wp_parse_args() (minus
* the querystring parsing - you must pass arrays).
*
* Values from $a override those from $b; keys in $b that don't exist
* in $a are passed through.
@boonebgorges
boonebgorges / gist:2185537
Created March 24, 2012 17:47
Recursively sort the output of get_categories() in order of parent-child hierarchy
<?php
$categories = get_the_category();
// Assemble a tree of category relationships
// Also re-key the category array for easier
// reference
$category_tree = array();
$keyed_categories = array();
@boonebgorges
boonebgorges / cac-asset-ver.php
Created June 16, 2015 13:50
Custom version querystring appending for WordPress JS and CSS assets
<?php
/**
* Note that CAC_VERSION is a custom constant. Replace as necessary.
*/
function cac_asset_ver( $tag, $handle, $src = '' ) {
// 'style_loader_tag' doesn't pass a src, so we sniff it from the tag.
if ( ! $src ) {
preg_match( '/href\=\'([^\']+)\'/', $tag, $src_matches );
if ( $src_matches ) {
$src = $src_matches[1];
@boonebgorges
boonebgorges / populate.php
Created September 21, 2016 03:03
populate comments and posts in bp-activity
<?php
$site_id = 7177;
switch_to_blog( $site_id );
$links = get_bookmarks( array(
'category_name' => 'Course Blogs',
) );
$urls = wp_list_pluck( $links, 'link_url' );
<?php
$comment = get_comment( 12345 );
$post_id = $comment->comment_post_ID();
$post = get_post( $post_id ); // Let's say post_title = Foo
do_action( 'comment_goodies', $comment, $post );
var_dump( $post );
@boonebgorges
boonebgorges / LaTeX.js
Created September 9, 2016 04:00
React component for rendering a chunk of LaTeX to be processed by MathJax
import React, { Component } from 'react';
export default class LaTeX extends Component {
componentDidMount() {
this.updateTeX()
}
componentDidUpdate() {
this.updateTeX()
}
@boonebgorges
boonebgorges / FormattedProblem.js
Created September 9, 2016 03:59
React component for content that may contain LaTeX chunks
import React from 'react';
import LaTeX from './LaTeX'
const FormattedProblem = React.createClass( {
getDefaultProps: function() {
return {
isVisible: true
}
},
@boonebgorges
boonebgorges / parsley-iff.js
Last active September 8, 2016 20:31
Better "equalto" implementation for Parsley.js
var iffRecursion = false;
window.Parsley.addValidator( 'iff', {
validateString: function( value, requirement, instance ) {
var $partner = $( requirement );
var isValid = $partner.val() == value;
if ( iffRecursion ) {
iffRecursion = false;
} else {
iffRecursion = true;
@boonebgorges
boonebgorges / parsley-iff.html
Created September 8, 2016 20:30
Markup for parsley-iff
<input
name="password"
id="password"
data-parsley-trigger="blur"
data-parsley-iff="#password-confirm"
data-parsley-iff-message=""
/>
<input
name="password-confirm"

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: