Skip to content

Instantly share code, notes, and snippets.

View boonebgorges's full-sized avatar

Boone Gorges boonebgorges

View GitHub Profile
@boonebgorges
boonebgorges / gist:1331676
Created November 1, 2011 19:39
Display BuddyPress group content in the context of the associated groupblog
<?php
/**
* Does the grunt work
*/
function bbg_test_groupblog_idea2() {
global $wpdb, $bp, $current_blog;
// Never do this on the root blog
if ( bp_is_root_blog() )
@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 / gist:2401529
Created April 16, 2012 21:09
Add an "Other" option at the end of a list of BuddyPress profile checkbox options, where users can enter custom text
<?php
/**
* Add an 'Other' type to xprofile fields
*
* @link https://buddypress.trac.wordpress.org/ticket/3775
* @link http://redmine.gc.cuny.edu/issues/1199
*/
class CAC_Xprofile_Other {
function __construct() {
add_action( 'xprofile_field_additional_options', array( &$this, 'render_admin' ) );
@boonebgorges
boonebgorges / gist:2571318
Created May 1, 2012 20:56
Update Woo Framework for all WooThemes on an installation
<?php
/**
* Updates Woo Framework in all WooThemes on a WP installation
*
* To use:
*
* - Get the latest copy of the framework
* - Unzip to /wp-content/framework/
* - Visit wp-admin?cac_update_woo=1 as super admin
@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:3430079
Created August 22, 2012 22:27 — forked from markjaquith/gist:2628225
Script to sync WordPress SVN to GitHub
#!/bin/bash
# cd into the directory
cd ~/gitsync/github-wordpress-sync/;
# Make sure we are not already running
if [ -f .sync-running ];then
if test ! `find ".sync-running" -mmin +10`;then
# Currently running, but not stuck
exit 1;
fi
fi;
@boonebgorges
boonebgorges / gist:3657745
Created September 6, 2012 15:54
WP filter to turn email-style quotes into blockquotes
<?php
/**
* Turn email-style quotes into blockquotes
*
* For example:
*
* My friend said:
*
* > You are handsome and also
@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:
@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 / 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' );