Skip to content

Instantly share code, notes, and snippets.

View boonebgorges's full-sized avatar

Boone Gorges boonebgorges

View GitHub Profile
@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 / .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: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 / 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.
<?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: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 ) {
@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: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 / bbg-is-admin.php
Created November 28, 2012 22:20
A function for reliably testing whether you're in the WordPress Dashboard
<?php
/**
* Are we looking at the WordPress admin?
*
* Because AJAX requests are sent to wp-admin/admin-ajax.php, WordPress's
* is_admin() function returns true when DOING_AJAX. This function contains
* logic to test whether AJAX requests are coming from the front end or from
* the Dashboard.
*
* @return bool
@boonebgorges
boonebgorges / bbg-widget-setter.php
Created October 18, 2012 01:31
Class for clearing widget sidebars and adding widgets to sidebars
<?php
/**
* Recommended usage: Don't use this at all. Setting widgets programatically is generally a bad idea.
* Let your users do it - that's what the UI is for.
*
* However, if you must use it:
* BBG_Widget_Setter::clear_sidebar( 'sidebar-1' );
* to clear the widgets from the sidebar called 'sidebar-1' (they are moved to
* "Inactive Widgets".) And: