diff --git a/includes/classes/pmpro-testimonial-form.php b/includes/classes/pmpro-testimonial-form.php index 9cd0bde..c5ebc19 100644 --- a/includes/classes/pmpro-testimonial-form.php +++ b/includes/classes/pmpro-testimonial-form.php @@ -43,6 +43,7 @@ function __construct( $atts = array() ) { } public function display( $echo = true ) { + global $current_user; // If we are on the success message page, show it and bail. if ( isset( $_GET['testimonial_success'] ) ) { @@ -98,143 +99,207 @@ public function display( $echo = true ) {

- __( 'Testimonial', 'pmpro-testimonials' ), - 'required' => true, - 'showrequired' => 'label', - ) - ); - $title_field->displayAtCheckout(); + +
+ + +
+ '; + echo '
'; echo ''; - echo '
'; + echo '
'; $rating_value = isset( $_POST['rating'] ) ? intval( $_POST['rating'] ) : 0; for ( $i = 1; $i <= 5; $i++ ) { // Build the selectors for the star. $classes = array( 'pmpro_star' ); - $classes[] = ( $i <= $rating_value ) ? 'filled' : ''; // Add 'filled' class if previously selected - $class = implode( ' ', array_unique( $classes ) ); - echo ' + if ( $i <= $rating_value ) { + $classes[] = 'filled'; + } + if ( $i === $rating_value ) { + $checked = 'true'; + } else { + $checked = 'false'; + } + $class = join( ' ', $classes ); + $label = sprintf( esc_html__( '%s Star Rating', 'pmpro-testimonials' ), $i ); + echo ' '; } echo '
'; - echo ''; + echo ''; echo '
'; + ?> + + display_name; + } + ?> +
+ + +
+ + required_fields ) ) { + $required = true; + $classes[] = 'pmpro_form_field-required'; + } + ?> +
+ + +
+ + required_fields ) ) { + $required = true; + $classes[] = 'pmpro_form_field-required'; + } + ?> +
+ + +
+ + user_email; + } + $classes = array( 'pmpro_form_field', 'pmpro_form_field-email' ); + $required = false; + if ( in_array( 'email', $this->required_fields ) ) { + $required = true; + $classes[] = 'pmpro_form_field-required'; + } + $pmpro_email_field_type = apply_filters( 'pmpro_email_field_type', true ); + ?> +
+ + +
- // Name field. - $name_field = new PMPro_Field( - 'display_name', - 'text', - array( - 'label' => __( 'Name', 'pmpro-testimonials' ), - 'required' => true, - 'showrequired' => 'label', - ) - ); - $name_field->displayAtCheckout(); - - // Job Title field. - $job_title_field = new PMPro_Field( - 'job_title', - 'text', - array( - 'label' => __( 'Job Title', 'pmpro-testimonials' ), - 'required' => in_array( 'job_title', $this->required_fields ), - 'showrequired' => 'label', - ) - ); - $job_title_field->displayAtCheckout(); - - // Company field. - $company_field = new PMPro_Field( - 'company', - 'text', - array( - 'label' => __( 'Company', 'pmpro-testimonials' ), - 'required' => in_array( 'company', $this->required_fields ), - 'showrequired' => 'label', - ) - ); - $company_field->displayAtCheckout(); - - // Email field. - $email_field = new PMPro_Field( - 'user_email', - 'text', - array( - 'label' => __( 'Email', 'pmpro-testimonials' ), - 'required' => in_array( 'email', $this->required_fields ), - 'showrequired' => 'label', - ) - ); - $email_field->displayAtCheckout(); - - // URL field. - $url_field = new PMPro_Field( - 'url', - 'text', - array( - 'label' => __( 'URL', 'pmpro-testimonials' ), - 'required' => in_array( 'url', $this->required_fields ), - 'showrequired' => 'label', - ) - ); - $url_field->displayAtCheckout(); + required_fields ) ) { + $required = true; + $classes[] = 'pmpro_form_field-required'; + } + ?> +
+ + +
+ + category_dropdown, FILTER_VALIDATE_BOOLEAN ) ) { - $selected_category = isset( $_POST['testimonial_category'] ) ? intval( $_POST['testimonial_category'] ) : ''; - $category_field = new PMPro_Field( - 'testimonial_category', - 'select', + $categories = get_terms( array( - 'label' => __( 'Category', 'pmpro-testimonials' ), - 'options' => wp_list_pluck( - get_terms( - array( - 'taxonomy' => 'pmpro_testimonial_category', - 'hide_empty' => false, - ) - ), - 'name', - 'term_id' - ), - 'default' => $selected_category, + 'taxonomy' => 'pmpro_testimonial_category', + 'hide_empty' => false, ) ); - $category_field->displayAtCheckout(); + if ( $categories ) { + $selected_category = isset( $_POST['testimonial_category'] ) ? intval( $_POST['testimonial_category'] ) : ''; + $classes = array( 'pmpro_form_field', 'pmpro_form_field-select' ); + $required = false; + if ( in_array( 'url', $this->required_fields ) ) { + $required = true; + $classes[] = 'pmpro_form_field-required'; + } + ?> +
+ + +
+ tag_dropdown, FILTER_VALIDATE_BOOLEAN ) ) { - $selected_tags = isset( $_POST['testimonial_tags'] ) ? array_map( 'intval', $_POST['testimonial_tags'] ) : array(); - $tag_field = new PMPro_Field( - 'testimonial_tags', - 'select2', + $tags = get_terms( array( - 'label' => __( 'Tags', 'pmpro-testimonials' ), - 'options' => wp_list_pluck( - get_terms( - array( - 'taxonomy' => 'pmpro_testimonial_tag', - 'hide_empty' => false, - ) - ), - 'name', - 'term_id' - ), - 'default' => $selected_tags, + 'taxonomy' => 'pmpro_testimonial_tag', + 'hide_empty' => false, ) ); - $tag_field->displayAtCheckout(); + if ( $tags ) { + $selected_tags = isset( $_POST['testimonial_tags'] ) ? (array) $_POST['testimonial_tags'] : array(); + $classes = array( 'pmpro_form_field', 'pmpro_form_field-select' ); + $required = false; + if ( in_array( 'tags', $this->required_fields ) ) { + $required = true; + $classes[] = 'pmpro_form_field-required'; + } + ?> +
+ + + +
+ @@ -322,7 +387,7 @@ public function process() { $job_title = sanitize_text_field( $_POST['job_title'] ); $company = sanitize_text_field( $_POST['company'] ); $email = sanitize_email( $_POST['user_email'] ); - $url = esc_url_raw( $_POST['url'] ); + $url = sanitize_url( $_POST['url'] ); $rating = intval( $_POST['rating'] ); $categories = array(); @@ -339,7 +404,7 @@ public function process() { $tags_string = sanitize_text_field( $_POST['tags'] ); $tags = array_map( 'trim', explode( ',', $tags_string ) ); } - if ( isset( $_POST['testimonial_tags'] ) && is_array( $_POST['testimonial_tags'] ) ) { + if ( ! empty( $_POST['testimonial_tags'] ) && is_array( $_POST['testimonial_tags'] ) ) { $tags = array_merge( $tags, array_map( 'intval', $_POST['testimonial_tags'] ) ); } diff --git a/includes/post-types/testimonials.php b/includes/post-types/testimonials.php index 8bf7325..4e62e3c 100644 --- a/includes/post-types/testimonials.php +++ b/includes/post-types/testimonials.php @@ -109,7 +109,7 @@ function pmpro_testimonials_meta_box() { $company = get_post_meta( $post->ID, '_company', true ); $email = get_post_meta( $post->ID, '_email', true ); $url = get_post_meta( $post->ID, '_url', true ); - $rating = get_post_meta( $post->ID, '_rating', true ); + $rating = intval( get_post_meta( $post->ID, '_rating', true ) ); ?> @@ -154,21 +154,25 @@ function pmpro_testimonials_meta_box() {
- - - - - - - - - - - - - - - + + + '; + } + ?>