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_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_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_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_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_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_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_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 / custom_bulkquick_edit_settings_as_types.php
Created August 25, 2013 10:01
Filter `custom_bulkquick_edit_settings_as_types`. Modify the field input types offered.
<?php
add_filter( 'custom_bulkquick_edit_settings_as_types', 'settings_as_types' );
public function settings_as_types( $as_types ) {
$as_types['date'] = esc_html__( 'As date' );
return $as_types;
}
?>
@michael-cannon
michael-cannon / custom_bulkquick_edit_settings_display_setting.php
Created August 25, 2013 10:21
Filter `custom_bulkquick_edit_settings_display_setting`. Display the additional field input types offered.
<?php
add_filter( 'custom_bulkquick_edit_settings_display_setting', 'display_setting', 10, 2 );
public function display_setting( $args, $input ) {
$content = '';
extract( $args );
if ( is_null( $input ) ) {
$options = get_option( self::ID );
} else {
@michael-cannon
michael-cannon / custom_bulkquick_edit_manage_posts_custom_column_field_type.php
Created August 25, 2013 10:37
Filter `custom_bulkquick_edit_manage_posts_custom_column_field_type`. Customize post type column contents by `field_type`.
<?php
add_filter( 'custom_bulkquick_edit_manage_posts_custom_column_field_type', 'manage_posts_custom_column_field_type', 10, 4 );
public function manage_posts_custom_column_field_type( $current, $field_type, $column, $post_id ) {
$result = '';
switch ( $field_type ) {
case 'date':
$result = $current;
break;
}