Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Cannon michael-cannon

View GitHub Profile
@michael-cannon
michael-cannon / testimonials_widget_widget_options.php
Created Jun 21, 2013
Filter testimonials_widget_widget_options example
View testimonials_widget_widget_options.php
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 Jun 21, 2013
Filter testimonials_widget_version example
View testimonials_widget_version.php
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 Jun 21, 2013
Filter testimonials_widget_validate_settings example
View testimonials_widget_validate_settings.php
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 Dec 18, 2015
Filter testimonials_widget_sections and testimonials_widget_settings examples.
View testimonials_widget_options.php
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 Jun 21, 2013
Filter testimonials_widget_query_args example
View testimonials_widget_query_args.php
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 Jun 21, 2013
Filter testimonials_widget_posts_custom_column example
View testimonials_widget_posts_custom_column.php
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 Dec 18, 2015
Filter testimonials_widget_meta_box example
View testimonials_widget_meta_box.php
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 Jun 21, 2013
Filter testimonials_widget_content example
View testimonials_widget_content.php
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 Jun 21, 2013
Filter testimonials_widget_columns example
View testimonials_widget_columns.php
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 Dec 18, 2015
Filter testimonials_widget_cache_get and testimonials_widget_cache_set example
View testimonials_widget_cache_.php
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;
}