Skip to content

Instantly share code, notes, and snippets.

View boonebgorges's full-sized avatar

Boone Gorges boonebgorges

View GitHub Profile
@boonebgorges
boonebgorges / gist:4754549
Created February 11, 2013 13:57
Dynamically add items to a wp_nav_menu list
<?php
function bbg_activity_subnav( $items, $menu, $args ) {
// Find the Activity item
$bp_pages = bp_core_get_directory_page_ids();
if ( isset( $bp_pages['activity'] ) ) {
$activity_directory_page = $bp_pages['activity'];
} else {
return $items;
@boonebgorges
boonebgorges / gist:5057165
Created February 28, 2013 14:36
Hide WordPress plugins from the plugins.php admin screen in a flexible way
<?php
/**
* Prevent specific plugins from being activated (or, in some cases, deactivated).
*
* Plugins that are to be deprecated should be added to the $disabled_plugins array.
*
* Plugins that should be un-deactivatable should be added to the $undeactivatable_plugins array
*/
function cac_hide_plugins( $plugins ) {
<?php
/* Plugin Name: Damn Vulnerable WordPress Plugin
* Description: Intentionally vulnerable plugin for plugin author education
* Version: 0.1
* Plugin URI: http://make.wordpress.org/plugins/2013/04/09/intentionally-vulnerable-plugin/
* Author: Jon Cave
* Author URI: http://joncave.co.uk
* License: GPLv2+
*
* DO NOT RUN THIS PLUGIN ON AN INTERNET ACCESSIBLE SITE
@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:5537311
Created May 8, 2013 00:27
Take the input of a "Twitter" field, decide whether it's a handle or a URL, and generate a URL
/**
* Note that it uses trailingslashit(), a WP function. Write your own logic if not using WP
*/
function sanitize_twitter_handle( $handle ) {
$parts = parse_url( $handle );
$url = '';
if ( empty( $parts['host'] ) ) {
// not a url
if ( 0 === strpos( $handle, '@' ) ) {
@boonebgorges
boonebgorges / .vimrc
Last active January 1, 2016 22:29
.vimrc command for WordPress-style whitespace correction in current buffer
command! WPCodingStandards call WPCodingStandards()
function! WPCodingStandards()
" Space after opening paren
execute '%s/(\([^\t) ]\)/( \1/ge'
" Space before closing paren
execute '%s/\([^\t( ]\))/\1 )/ge'
" No spaces when casting types
execute '%s/(\s*\(array\|int\|object\|string\|float\)\s*)/(\1)/ge'
@boonebgorges
boonebgorges / gist:8301715
Last active January 2, 2016 12:09
A filter to force BuddyPress's group search to work on a word-wise basis, instead of on exact matches using multiple words. In other words: out of the box, searching for "American History" will not return a group called "American Military History"; after this change, it will.
<?php
/**
* Modify BuddyPress group search to work on a word-wise basis
*/
function openlab_group_search_breakup( $sql, $s ) {
global $bp;
if ( ! empty( $s['search'] ) ) {
// Get the search terms
@boonebgorges
boonebgorges / bbg-csv-export.php
Created May 13, 2014 18:13
WordPress script for doing a .csv export of misc data
<?php
function bbg_csv_export() {
if ( ! is_super_admin() ) {
return;
}
if ( ! isset( $_GET['bbg_export'] ) ) {
return;
}
@boonebgorges
boonebgorges / gist:19f5aef3c406e7d3739b
Created June 14, 2014 19:39
vim search and replace string for replacing extract() variables with reference to the $r array
s/\$\([a-z_]\{2,\}\)/$r['\1']/gc

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: