Skip to content

Instantly share code, notes, and snippets.

View boonebgorges's full-sized avatar

Boone Gorges boonebgorges

View GitHub Profile
@boonebgorges
boonebgorges / gist:2638943
Created May 8, 2012 20:13
Limit a bp_has_groups() loop to groups matching a groupmeta key/value pair
<?php
/**
* This is a quick and dirty class to work around the fact that bp_has_groups() does not have a
* meta_query parameter (or even an 'in' parameter). Usage:
*
* 1) Just before you fire up your bp_has_groups() loop, instantiate the BP_Groups_Meta_Filter
* class, with parameters $key and $value
* 2) Do your groups loop as normal
* 3) When you've closed the bp_has_groups() loop (endif;), call the method remove_filters() just
@boonebgorges
boonebgorges / gist:4714650
Last active December 12, 2015 04:28
Delete spam comments from every site on a WordPress network, slowly but surely
<?php
function qw_delete_spam_comments() {
$in_progress = (bool) get_site_option( 'qw_delete_in_progress' );
if ( ! $in_progress ) {
global $wpdb;
update_site_option( 'qw_delete_in_progress', '1' );
@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: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

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:

@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"
@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;