Skip to content

Instantly share code, notes, and snippets.

<?php
class AllHipHop_Complex_Ads {
public function __construct() {
add_action( 'wp_head', array( $this, 'wp_head' ) );
add_filter( 'acm_default_url', 'acm_default_url' );
add_filter( 'acm_output_html', 'acm_output_html' );
add_filter( 'acm_output_tokens', 'acm_output_tokens', 10, 3 );
add_filter( 'acm_ad_tag_ids', 'acm_ad_tag_ids' );
<?php
public function event_content_relationship_meta_box( $post ) {
wp_nonce_field( 'tc_event_relationship_noncename', 'tc_event_relationship_nonce' );
$current_term = array();
if ( $current_relationship = get_post_meta( $post->ID, '_tc_event_relationship', true ) ) {
if ( $event_type = get_the_terms( (int) $current_relationship, 'tc_event_type_taxonomy' ) )
$current_term = get_term( $event_type[0]->term_id, 'tc_event_type_taxonomy' );
}
<?php
public function save_post( $post_id, $post ) {
// don't update on autosave (all our post types currently use page-based permissions)
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
// static variable prevents infinite loop when calling menu order update
static $skip_me = false;
if ( $skip_me ) return;
<?php
class AllHipHop_Complex_Ads {
public function __construct() {
add_action( 'wp_head', array( $this, 'wp_head' ) );
add_action( 'body_open', array( $this, 'body_open' ) );
add_action( 'wp_foot', array( $this, 'wp_foot' ) );
add_filter( 'acm_default_url', array( $this, 'acm_default_url' ) );
add_filter( 'acm_output_html', array( $this, 'acm_output_html' ), 10, 2 );
<?php
/**
* Complex Media Network Ad Provider for Ad Code manager
*
* @since 0.2.x
*/
class Complex_Media_Network_ACM_Provider extends ACM_Provider {
function __construct() {
// Default output HTML
$this->output_html = '<!-- cmnUNT | Begin ad tag --><script type="text/javascript">cmnUNT(\'%size_type%\', tile_num++);</script><!-- cmnUNT | End ad tag -->';
@lgedeon
lgedeon / gist:3784555
Created September 25, 2012 21:24
HTML Excerpt
function plugin_trim_by_characters_with_html( $text, $length = 400, $append = ' &hellip;', $allowable_tags = '<b><em><a>' ) {
$length = (int) $length;
$text = trim( strip_tags( $text, $allowable_tags ) );
$in_quote = false;
// if the length without tags is less than our target we are done
if ( strlen( strip_tags( $text ) ) <= $length )
return $text;
// count forward to find the $length character in unstripped $text not counting tags
for ($i = 0, $j = 0, $l = strlen( $text ), $in_tag = false; $i < $l && ( $in_tag || $j < $length ); $i++) :
switch ( $text[$i] ) :
@lgedeon
lgedeon / Admin Page Config Class
Created December 20, 2012 14:15
Framework for adding an Admin Page
<?php
class Plugin_Config_Page {
function plugin_config() { // switch to construct
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'wp_ajax_plugin_refresh', array( $this, 'ajax_plugin_refresh' ) );
add_action( 'wp_ajax_plugin_toggle_schedule', array( $this, 'ajax_plugin_toggle_schedule' ) );
}
@lgedeon
lgedeon / CPT taxonomy Class
Created December 20, 2012 14:20
Class to simplify CPT and taxonomy creation including pluralizer algorithm
<?php
/**
* A small, quick class to make Custom Post Types and Taxonomies easier
*/
class CPT_Builder {
static $plural = array( '/(quiz)$/i' => "$1zes",
'/^(ox)$/i' => "$1en", '/([m|l])ouse$/i' => "$1ice",
'/(matr|vert|ind)ix|ex$/i' => "$1ices", '/(x|ch|ss|sh)$/i' => "$1es",
'/([^aeiouy]|qu)y$/i' => "$1ies", '/(hive)$/i' => "$1s",
@lgedeon
lgedeon / JS Hooks
Created December 20, 2012 14:31
My first JS Hooks idea. Things got complex shortly after this :)
/* bind to variable */
jQuery(document).ready(function() {
// register a filter and override the functions
jQuery('body').bind('myTrig', function(event, obj) {
obj.valueOf=obj.toSource=obj.toString=function(){return "blue"};
});
// create a variable as an object and pass it to any filters that have been registered
var o = Object('green');
@lgedeon
lgedeon / Dashboard Widget
Created December 20, 2012 14:47
Dashboard Widget
function wp_dashboard_setup() {
wp_add_dashboard_widget( 'plugin_analytics_link', 'Analytics Link', array($this, 'wp_add_dashboard_widget_callback' ), array($this, 'wp_add_dashboard_widget_control_callback' ) );
}
function wp_add_dashboard_widget_callback() {
if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
$widget_options = array();
if ( !isset($widget_options['plugin_analytics_link']) )
$widget_options['plugin_analytics_link'] = array( 'label' => '', 'link' => '' );