Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add a field to Testimonials Premium
add_filter( 'testimonials_widget_cite_html', 'my_testimonials_widget_cite_html', 10, 3 );
function my_testimonials_widget_cite_html( $cite, $testimonial, $atts ) {
if ( ! empty( $testimonial['is-nurse'] ) ) {
$cite .= ', <b>' . $testimonial['is-nurse'] . '</b>';
}
return $cite;
}
add_filter( 'testimonials_widget_data', 'my_testimonials_widget_data', 10, 2 );
function my_testimonials_widget_data( $data, $atts ) {
if ( empty( $data ) ) {
return $data;
}
foreach( $data as $key => $testimonial ) {
$post_id = $testimonial['post_id'];
$is_nurse = get_post_meta( $post_id, 'testimonials-widget-is-nurse', true );
$testimonial['is-nurse'] = $is_nurse ? __( 'Is nurse' ) : __( 'Is not a nurse' );
$data[ $key ] = $testimonial;
}
return $data;
}
add_action( 'testimonials_widget_premium_form_save', 'my_testimonials_widget_premium_form_save', 10, 2 );
function my_testimonials_widget_premium_form_save( $post_id, $input ) {
if ( ! empty( $input['is_nurse'] ) ) {
update_post_meta( $post_id, 'testimonials-widget-is-nurse', $input['is_nurse'] );
}
}
add_filter( 'testimonials_widget_premium_form_options', 'my_testimonials_widget_premium_form_options' );
function my_testimonials_widget_premium_form_options( $array ) {
$array['meta_email']['validate'] = 'sanitize_email,required';
$is_nurse = array(
'title' => __( 'Nurse?', 'testimonials-widget-premium' ),
'type' => 'select',
'choices' => array(
0 => __( 'No' ),
1 => __( 'Yes' ),
),
'std' => 1,
);
$array['is_nurse'] = $is_nurse;
return $array;
}
add_filter( 'testimonials_widget_meta_box', 'my_testimonials_widget_meta_box' );
function my_testimonials_widget_meta_box( $fields ) {
$is_nurse = array(
'name' => __( 'Nurse?', 'testimonials-widget-premium' ),
'id' => 'testimonials-widget-is-nurse',
'type' => 'select',
'options' => array(
0 => __( 'No' ),
1 => __( 'Yes' ),
),
);
$fields[] = $is_nurse;
return $fields;
}
@subharanjanm

This comment has been minimized.

Copy link

subharanjanm commented Jul 6, 2015

@michael, We need to update the hooks being used here in the gist.

'testimonials_widget_cite_html' ---> 'tw_cite_html'
'testimonials_widget_data' ---> 'tw_data'
'testimonials_widget_premium_form_save' ---> 'twp_form_save'
'testimonials_widget_premium_form_options' ---> 'twp_form_options'
'testimonials_widget_meta_box' ---> 'tw_meta_box'

Forked: https://gist.github.com/subharanjanm/0264c4aaf8261d4c63be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.