Skip to content

Instantly share code, notes, and snippets.

@blobaugh
blobaugh / gist:3132215
Created July 17, 2012 21:26
simple php recursion
function showit( $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $s )
showit( $s );
} else {
echo $stuff;
}
}
@blobaugh
blobaugh / tec_organizer_dropdown.php
Created October 16, 2012 23:38
More efficient TEC organizer dropdown at scale
public static function facilitatorSelect( $name, $current, $special = false){
if( $special ) {
$id = 'saved_organizer';
} else {
$id = str_replace(array('[',']'),'',$name);
}
$current_user = wp_get_current_user();
$s = '<select class="chosen organizer-dropdown" name="' . esc_attr( $name ) . '" id="'.$id.'">';
$s .= '<option value="0">' . __( 'Use New Facilitator' , 'tribe-events-calendar-pro' ) . '</option>';
@blobaugh
blobaugh / gist:3920430
Created October 19, 2012 20:15
Data Enterer Metabox
<?php
class WotDataEntererListMetabox {
public function __construct() {
add_action( 'add_meta_boxes', array( &$this, 'add' ) );
add_action( 'save_post', array( &$this, 'save' ) );
}
public function add() {
@blobaugh
blobaugh / gist:3982795
Created October 30, 2012 20:28
Insert media to WordPress
function insertAttachment($file_handler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
//if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $post_id, array(), array( 'test_form' => false, 'test_upload' => false ) );
@blobaugh
blobaugh / gist:4067886
Created November 13, 2012 19:38
ajax example
jQuery.post(ajaxurl, {
action: 'ajaxGetFacilitatorInfo',
org_id: org_id
}, function(data) {
jQuery('#eventRealOrganizerName').val( data.name );
jQuery('#eventRealOrganizerEmail').val( data.email );
jQuery('#eventRealOrganizerPhone').val( data.phone );
jQuery('#eventRealOrganizerBusinessName').val( '' );
},
@blobaugh
blobaugh / gist:5165142
Created March 14, 2013 20:53
Original options.php
<?php
// Grab the original options.php file
require_once( WOT_PLUGIN_DIR . '3rd-party/options.php' );
add_filter( 'wot_options_page', 'wot_theme_add_options' );
/**
* Add any custom fields that are required to the options framework
@blobaugh
blobaugh / gist:5165152
Created March 14, 2013 20:54
options.php in plugin
<?php
/**
* A unique identifier is defined to store the options in the database and reference them from the theme.
* By default it uses the theme name, in lowercase and without spaces, but this can be changed if needed.
* If the identifier changes, it'll appear as if the options have been reset.
*
*/
function optionsframework_option_name() {
@blobaugh
blobaugh / gist:6330219
Created August 24, 2013 20:21
Add custom post type to Jetpack
function tweakjp_allow_cpt( $allowed_post_types ) {
// my_cpt is the name of your <span class="hilite">Custom</span> <span class="hilite">Post</span> <span class="hilite">Type</span>
$allowed_post_types[] = 'my_cpt';
return $allowed_post_types;
}
add_filter( 'rest_api_allowed_post_types', 'tweakjp_allow_cpt' );
@blobaugh
blobaugh / gist:7223022
Created October 29, 2013 21:32
Add additional support for Infinite Scroll in Jetpack
function tweakjp_custom_is_support() {
$supported = current_theme_supports( 'infinite-scroll' ) && ( is_home() || is_archive() || is_search() );
return $supported;
}
add_filter( 'infinite_scroll_archive_supported', 'tweakjp_custom_is_support' );
@blobaugh
blobaugh / gist:7977545
Created December 15, 2013 20:13
server from wpcom
<?php
/*
Plugin Name: Serve from WordPress.com
Plugin URI: http://github.com/blobaugh/serve-from-wordpress-com
Description: Switches the URL on built-in WordPress javascript files to serve from WordPress.com rather than locally
Author: Ben Lobaugh
Version: 0.6
Author URI: http://ben.lobaugh.net
*/