Skip to content

Instantly share code, notes, and snippets.

View michael-cannon's full-sized avatar

Michael Cannon michael-cannon

View GitHub Profile
@michael-cannon
michael-cannon / testimonials_widget_widget_options.php
Created June 21, 2013 19:40
Filter testimonials_widget_widget_options example
add_filter( 'testimonials_widget_widget_options', array( &$this, 'widget_options' ) );
public function widget_options( $options ) {
foreach ( $options as $id => $parts ) {
if ( 'form' == $parts['section'] )
unset( $options[ $id ] );
}
return $options;
}
@michael-cannon
michael-cannon / testimonials_widget_version.php
Created June 21, 2013 19:39
Filter testimonials_widget_version example
add_filter( 'testimonials_widget_version', array( &$this, 'version' ) );
public function version( $version ) {
$version .= '-' . self::PLUGIN_SLUG . '-' . self::VERSION;
return $version;
}
@michael-cannon
michael-cannon / testimonials_widget_validate_settings.php
Created June 21, 2013 19:39
Filter testimonials_widget_validate_settings example
add_filter( 'testimonials_widget_validate_settings', array( &$this, 'validate_settings' ), 10, 2 );
public static function validate_settings( $input, $errors = array(), $do_errors = false ) {
if ( ! empty( $input['clearcache'] ) ) {
Testimonials_Widget_Premium_Cache::clear_cache_all();
unset( $input['clearcache'] );
}
if ( empty( $do_errors ) ) {
$validated = $input;
@michael-cannon
michael-cannon / testimonials_widget_options.php
Last active December 18, 2015 19:29
Filter testimonials_widget_sections and testimonials_widget_settings examples.
add_filter( 'testimonials_widget_sections', 'sections' );
add_filter( 'testimonials_widget_settings', 'settings' );
public function sections( $sections ) {
$sections[ 'premium' ] = __( 'Premium', 'testimonials-widget-premium' );
return $sections;
}
public function settings( $settings ) {
$settings['premium_expand_begin'] = array(
'section' => 'premium',
@michael-cannon
michael-cannon / testimonials_widget_query_args.php
Created June 21, 2013 19:35
Filter testimonials_widget_query_args example
add_filter( 'testimonials_widget_query_args', array( &$this, 'query_args' ), 10, 2 );
public function query_args( $args, $atts ) {
global $wpdb;
$args['post_type'] = $atts['post_type'];
$no_cache = $atts['no_cache'];
if ( $no_cache ) {
$args['no_cache'] = 1;
@michael-cannon
michael-cannon / testimonials_widget_posts_custom_column.php
Created June 21, 2013 19:33
Filter testimonials_widget_posts_custom_column example
add_filter( 'testimonials_widget_posts_custom_column', array( &$this, 'posts_custom_column' ), 10, 3 );
public function posts_custom_column( $result, $column, $post_id ) {
switch ( $column ) {
case 'testimonials-widget-read-more-link':
$url = get_post_meta( $post_id, $column, true );
if ( ! empty( $url ) && 0 === preg_match( '#https?://#', $url ) ) {
$url = 'http://' . $url;
}
$result = make_clickable( $url );
@michael-cannon
michael-cannon / testimonials_widget_meta_box.php
Last active December 18, 2015 19:29
Filter testimonials_widget_meta_box example
add_filter( 'testimonials_widget_meta_box', 'my_meta_box' );
function my_meta_box( $fields ) {
$read_more_link = array(
'name' => __( 'Read More Link', 'testimonials-widget-premium' ),
'id' => 'testimonials-widget-read-more-link',
'type' => 'text',
'desc' => __( 'Alternate destination for "Read more" link. Leave blank for normal linking to full testimonial.', 'testimonials-widget-premium' ),
);
$fields[] = $read_more_link;
@michael-cannon
michael-cannon / testimonials_widget_content.php
Created June 21, 2013 19:31
Filter testimonials_widget_content example
add_filter( 'testimonials_widget_content', array( &$this, 'truncate_content' ), 10, 4 );
public function truncate_content( $content, $widget_number, $source, $atts ) {
$char_limit = $atts['char_limit'];
$excerpt_read_more = $atts['excerpt_read_more'];
$force_read_more = $atts['force_read_more'];
$hide_read_more = $atts['hide_read_more'];
$nofollow_read_more = $atts['nofollow_read_more'];
$content_bare = strip_tags( $content );
if ( ! $force_read_more ) {
@michael-cannon
michael-cannon / testimonials_widget_columns.php
Created June 21, 2013 19:30
Filter testimonials_widget_columns example
add_filter( 'testimonials_widget_columns', array( &$this, 'columns' ) );
public function columns( $columns ) {
$columns['testimonials-widget-read-more-link'] = __( 'Read More Link', 'testimonials-widget-premium' );
return $columns;
}
@michael-cannon
michael-cannon / testimonials_widget_cache_.php
Last active December 18, 2015 19:29
Filter testimonials_widget_cache_get and testimonials_widget_cache_set example
add_filter( 'testimonials_widget_cache_get', array( $this, 'cache_get' ) );
add_filter( 'testimonials_widget_cache_set', array( $this, 'cache_set' ), 10, 2 );
public static function cache_get( $args ) {
$hash = self::create_hash( $args );
$do_cache = apply_filters( 'testimonials_widget_disable_cache', true );
$no_cache = isset( $args['no_cache'] ) && Testimonials_Widget_Settings::is_true( $args['no_cache'] );
if ( ! $do_cache || $no_cache ) {
delete_transient( $hash );
return false;
}