Skip to content

Instantly share code, notes, and snippets.

@mauryaratan
mauryaratan / WP3.5 Media Uploader
Created December 14, 2012 06:08
WordPress 3.5 media uploader in easier steps. If using other than edit post screen, don't forget to use wp_enqueue_media(); in your functions.php
jQuery(document).ready(function($){
var _custom_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
$('.stag-metabox-table .button').click(function(e) {
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
var id = button.attr('id').replace('_button', '');
_custom_media = true;
wp.media.editor.send.attachment = function(props, attachment){
if ( _custom_media ) {
@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:
@MrMaz
MrMaz / ab-modal.php
Created September 18, 2012 13:50
WordPress Admin Bar: Modal Window Link
<?php
/**
* Setup admin bar item which opens URL in a thickbox window
*
* @param WP_Admin_Bar $wp_admin_bar
*/
function admin_bar_menu_modal_window( $wp_admin_bar )
{
// add "tools" node
@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: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: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();
@billerickson
billerickson / gist:1398077
Created November 27, 2011 20:14
Multilinqual - Add Photographer Name and URL fields to media uploader
<?php
/**
* Add Photographer Name and URL fields to media uploader
*
* @param $form_fields array, fields to include in attachment form
* @param $post object, attachment record in database
* @return $form_fields, modified form fields
*/
@billerickson
billerickson / gist:1243276
Created September 26, 2011 20:13
Include In Rotator option in Media Uploader
<?php
/**
* Add "Include in Rotator" option to media uploader
* Limited to Home page
*
* @param $form_fields array, fields to include in attachment form
* @param $post object, attachment record in database
* @return $form_fields, modified form fields
@billerickson
billerickson / gist:1243250
Created September 26, 2011 20:02
Photo Credit Fields in Media Gallery
<?php
/**
* Add Photographer Name and URL fields to media uploader
*
* @param $form_fields array, fields to include in attachment form
* @param $post object, attachment record in database
* @return $form_fields, modified form fields
*/