Skip to content

Instantly share code, notes, and snippets.

@michael-cannon
Last active December 18, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-cannon/5833757 to your computer and use it in GitHub Desktop.
Save michael-cannon/5833757 to your computer and use it in GitHub Desktop.
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',
'desc' => __( 'Premium Options', 'testimonials-widget-premium' ),
'type' => 'expand_begin',
);
$settings['clearcache'] = array(
'section' => 'premium',
'title' => __( 'Clear Cache?', 'testimonials-widget-premium' ),
'type' => 'checkbox',
'class' => 'warning', // Custom class for CSS
'desc' => __( 'Check this box to clear the testimonials cache', 'testimonials-widget-premium' ),
'widget' => 0,
);
$settings['no_cache'] = array(
'section' => 'premium',
'title' => __( 'Disable Cache?', 'testimonials-widget-premium' ),
'type' => 'checkbox',
);
$settings['maximum_length'] = array(
'section' => 'premium',
'title' => __( 'Maximum Length', 'testimonials-widget-premium' ),
'desc' => __( 'Maximum number of allowed characters in testimonial', 'testimonials-widget-premium' ),
'validate' => 'min1',
);
$args = array(
'public' => true,
);
$post_types = get_post_types( $args, 'objects' );
self::$post_types[] = Testimonials_Widget::PT;
$choices = array(
Testimonials_Widget::PT => __( 'Testimonials Widget', 'testimonials-widget-premium' ),
);
foreach ( $post_types as $type => $data ) {
if ( 'attachment' == $type )
continue;
self::$post_types[] = $type;
$choices[ $type ] = $data->labels->name;
}
$settings['post_type'] = array(
'section' => 'premium',
'title' => __( 'Alternate Testimonial Post Type?', 'testimonials-widget-premium' ),
'desc' => __( 'Set this to use Posts, Posts or another custom post type for testimonials', 'testimonials-widget-premium' ),
'type' => 'select',
'choices' => $choices,
'std' => Testimonials_Widget::PT,
);
$settings['premium_expand_end'] = array(
'section' => 'premium',
'type' => 'expand_end',
);
return $settings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment