From adeb057915327fa11825b44ca0a33841f4b9ff55 Mon Sep 17 00:00:00 2001 From: Derek Ashauer Date: Tue, 25 Feb 2025 13:14:27 -0700 Subject: [PATCH 1/3] Remove displayAtCheckout usage Remove all usage of now deprecated displayAtCheckout and build form fields --- includes/classes/pmpro-testimonial-form.php | 261 ++++++++++++-------- 1 file changed, 153 insertions(+), 108 deletions(-) diff --git a/includes/classes/pmpro-testimonial-form.php b/includes/classes/pmpro-testimonial-form.php index 9cd0bde..dc044f7 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,21 +99,18 @@ public function display( $echo = true ) {

- __( 'Testimonial', 'pmpro-testimonials' ), - 'required' => true, - 'showrequired' => 'label', - ) - ); - $title_field->displayAtCheckout(); + +
+ + +
+ '; + echo '
'; echo ''; echo '
'; $rating_value = isset( $_POST['rating'] ) ? intval( $_POST['rating'] ) : 0; @@ -128,113 +126,160 @@ public function display( $echo = true ) { echo '
'; echo ''; echo '
'; + ?> + + display_name; + } + ?> +
+ + +
+ + required_fields ) ) { + $required = true; + } + ?> +
+ + +
+ + required_fields ) ) { + $required = true; + } + ?> +
+ + +
+ + user_email; + } + $required = false; + if ( in_array( 'email', $this->required_fields ) ) { + $required = true; + } + $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; + } + ?> +
+ + +
+ + 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'] ) : ''; + $required = false; + if ( in_array( 'url', $this->required_fields ) ) { + $required = true; + } + ?> +
+ + +
+ 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(); + $required = false; + if ( in_array( 'tags', $this->required_fields ) ) { + $required = true; + } + ?> +
+ + + +
+ @@ -322,7 +367,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 +384,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'] ) ); } From 765094d36e62143f4436164c58e2bdb77473ec04 Mon Sep 17 00:00:00 2001 From: Derek Ashauer Date: Fri, 28 Feb 2025 13:55:20 -0700 Subject: [PATCH 2/3] CSS/a11y issues, text-domains * FIx inconsistent CSS class usage * Addressed a11y issues with labels/ID and star selection * Fixed text domains --- includes/classes/pmpro-testimonial-form.php | 70 +++++++++++++-------- includes/post-types/testimonials.php | 36 ++++++----- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/includes/classes/pmpro-testimonial-form.php b/includes/classes/pmpro-testimonial-form.php index dc044f7..333cf95 100644 --- a/includes/classes/pmpro-testimonial-form.php +++ b/includes/classes/pmpro-testimonial-form.php @@ -102,29 +102,37 @@ public function display( $echo = true ) {
- +
'; 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 + if ( $i <= $rating_value ) { + $classes[] = 'filled'; + } + if ( $i === $rating_value ) { + $checked = 'true'; + } else { + $checked = 'false'; + } $class = implode( ' ', array_unique( $classes ) ); - echo ' + $label = sprintf( esc_html__( '%s Star Rating', 'pmpro-testimonials' ), $i ); + echo ' '; } echo '
'; - echo ''; + echo ''; echo '
'; ?> @@ -138,10 +146,10 @@ public function display( $echo = true ) { ?>
- +
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 ); ?> -
+
- +
required_fields ) ) { $required = true; + $classes[] = 'pmpro_form_field-required'; } ?> -
+
- +
required_fields ) ) { $required = true; + $classes[] = 'pmpro_form_field-required'; } ?> -
+
- @@ -261,14 +279,16 @@ public function display( $echo = true ) { ); 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'; } ?> -
+
- - - - - - - - - - - - - - - + + + '; + } + ?>
From 0bc890e20e2747ec9150783bd5ebfa7ad5a9659e Mon Sep 17 00:00:00 2001 From: Derek Ashauer Date: Fri, 28 Feb 2025 13:58:16 -0700 Subject: [PATCH 3/3] consistency in function usage --- includes/classes/pmpro-testimonial-form.php | 2 +- includes/post-types/testimonials.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/classes/pmpro-testimonial-form.php b/includes/classes/pmpro-testimonial-form.php index 333cf95..c5ebc19 100644 --- a/includes/classes/pmpro-testimonial-form.php +++ b/includes/classes/pmpro-testimonial-form.php @@ -125,7 +125,7 @@ public function display( $echo = true ) { } else { $checked = 'false'; } - $class = implode( ' ', array_unique( $classes ) ); + $class = join( ' ', $classes ); $label = sprintf( esc_html__( '%s Star Rating', 'pmpro-testimonials' ), $i ); echo ' diff --git a/includes/post-types/testimonials.php b/includes/post-types/testimonials.php index f595898..4e62e3c 100644 --- a/includes/post-types/testimonials.php +++ b/includes/post-types/testimonials.php @@ -166,7 +166,7 @@ function pmpro_testimonials_meta_box() { } else { $checked = 'false'; } - $class = implode( ' ', array_unique( $classes ) ); + $class = join( ' ', $classes ); $label = sprintf( esc_html__( '%s Star Rating', 'pmpro-testimonials' ), $i ); echo '