From adeb057915327fa11825b44ca0a33841f4b9ff55 Mon Sep 17 00:00:00 2001 From: Derek Ashauer Date: Tue, 25 Feb 2025 13:14:27 -0700 Subject: [PATCH] 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'] ) ); }