-
Notifications
You must be signed in to change notification settings - Fork 151
fix: Custom Taxonomies Pro Fields #1719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,10 +95,6 @@ | |
| wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) ); | ||
| } | ||
|
|
||
| if ( ! current_user_can( wpuf_admin_role() ) ) { | ||
| wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) ); | ||
| } | ||
|
|
||
| if ( isset( $post_type ) && empty( $post_data['post_type'] ) ) { | ||
| wp_send_json_error( __( 'Invalid post type', 'wp-user-frontend' ) ); | ||
| } | ||
|
|
@@ -146,10 +142,6 @@ | |
| wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) ); | ||
| } | ||
|
|
||
| if ( ! current_user_can( wpuf_admin_role() ) ) { | ||
| wp_send_json_error( __( 'Unauthorized operation', 'wp-user-frontend' ) ); | ||
| } | ||
|
|
||
| if ( isset( $post_type ) && empty( $post_data['post_type'] ) ) { | ||
| wp_send_json_error( __( 'Invalid post type', 'wp-user-frontend' ) ); | ||
| } | ||
|
|
@@ -186,7 +178,7 @@ | |
| $cat .= '<div class="wpuf-mt-6 wpuf-input-container taxonomy-container" data-taxonomy="' . esc_attr( $tax->name ) . '">'; | ||
| $cat .= '<div class="wpuf-flex wpuf-items-center">'; | ||
| $cat .= '<label for="' . esc_attr( $select_id ) . '" class="wpuf-text-sm wpuf-text-gray-700 wpuf-my-2">'; | ||
| $cat .= sprintf( __( 'Default %s %s', 'wp-user-frontend' ), $post_type, $tax->label ); | ||
| $cat .= sprintf( __( 'Default %s', 'wp-user-frontend' ), $tax->label ); | ||
|
Check failure on line 181 in includes/Ajax/Admin_Form_Builder_Ajax.php
|
||
| $cat .= '</label></div>'; | ||
|
Comment on lines
+181
to
182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainFix i18n placeholder and escape output (pipeline blocker). Add translators comment and escape both the string and the taxonomy label to satisfy PHPCS and prevent HTML injection. Apply: - $cat .= sprintf( __( 'Default %s', 'wp-user-frontend' ), $tax->label );
+ /* translators: %s: taxonomy label */
+ $cat .= sprintf( esc_html__( 'Default %s', 'wp-user-frontend' ), esc_html( $tax->label ) );Run PHPCS locally to confirm: 🏁 Script executed: #!/bin/bash
vendor/bin/phpcs includes/Ajax/Admin_Form_Builder_Ajax.php -qLength of output: 62 I'll examine the actual code context to verify the i18n and escaping issues. 🏁 Script executed: #!/bin/bash
# Inspect the problematic lines and surrounding context
sed -n '170,195p' includes/Ajax/Admin_Form_Builder_Ajax.phpLength of output: 1470 🏁 Script executed: #!/bin/bash
# Check for translators comments in the file
rg -n "translators:" includes/Ajax/Admin_Form_Builder_Ajax.php -B2 -A2Length of output: 0 🏁 Script executed: #!/bin/bash
# Search for other sprintf + __() patterns in file to see if translators comments exist elsewhere
rg -n "sprintf.*__\(" includes/Ajax/Admin_Form_Builder_Ajax.php -B1 -A1Length of output: 263 🏁 Script executed: #!/bin/bash
# Check WordPress escaping patterns for taxonomy properties
rg -n "tax->label" includes/Ajax/Admin_Form_Builder_Ajax.php -B3 -A3Length of output: 520 💡 Result: Short answer: add a translators comment (/* translators: ... */) directly above any translation string that contains placeholders (e.g. %s, %d, %1$s), and prefer using printf()/sprintf() with (numbered) placeholders so translators can reorder them. WordPress Coding Standards (WPCS) include an i18n sniff that flags missing/misplaced translator comments. What to do
Why
Sources
Would you like a PHPCS ruleset snippet or example to fail/auto-fix this in CI? 🌐 Web query: 💡 Result: Short answer
Best-practice rules
Examples
Sources Fix i18n placeholder and escape output (PHPCS blocker and XSS risk). Line 181 outputs - $cat .= sprintf( __( 'Default %s', 'wp-user-frontend' ), $tax->label );
+ /* translators: %s: taxonomy label */
+ $cat .= sprintf( esc_html__( 'Default %s', 'wp-user-frontend' ), esc_html( $tax->label ) );🧰 Tools🪛 GitHub Check: Run PHPCS inspection[failure] 181-181: 🤖 Prompt for AI Agents |
||
|
|
||
| $cat .= '<select | ||
|
|
@@ -201,7 +193,7 @@ | |
|
|
||
| if ( ! is_wp_error( $categories ) && ! empty( $categories ) ) { | ||
| foreach ( $categories as $category ) { | ||
| $selected = in_array( $category->term_id, (array) $current_value ) ? 'selected="selected"' : ''; | ||
| $cat .= '<option value="' . esc_attr( $category->term_id ) . '" ' . $selected . '>' . esc_html( $category->name ) . '</option>'; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ | |
| $taxonomy_templates['post_tag'] = new Form_Field_Post_Tags(); | ||
| } else { | ||
| $taxonomy_templates[ $tax_name ] = new Form_Field_Post_Taxonomy( $tax_name, $taxonomy ); | ||
| // $taxonomy_templates[ 'taxonomy' ] = new WPUF_Form_Field_Post_Taxonomy($tax_name, $taxonomy); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -69,25 +69,35 @@ | |
| public function set_wp_post_types() { | ||
| $args = [ '_builtin' => true ]; | ||
| $wpuf_post_types = wpuf_get_post_types( $args ); | ||
|
|
||
| // Add tribe_events if The Events Calendar post type is registered | ||
| if ( post_type_exists( 'tribe_events' ) && ! in_array( 'tribe_events', $wpuf_post_types, true ) ) { | ||
| $wpuf_post_types[] = 'tribe_events'; | ||
| } | ||
|
|
||
| // Add product if WooCommerce post type is registered | ||
| if ( post_type_exists( 'product' ) && ! in_array( 'product', $wpuf_post_types, true ) ) { | ||
| $wpuf_post_types[] = 'product'; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainTrailing whitespace trips PHPCS. Remove trailing spaces on these lines to appease CI. Also applies to: 87-87 🏁 Script executed: #!/bin/bash
vendor/bin/phpcbf includes/Traits/FieldableTrait.php && vendor/bin/phpcs includes/Traits/FieldableTrait.php -qLength of output: 63 I'll directly inspect the file to verify the trailing whitespace issue since the PHP tools aren't available in the sandbox. Length of output: 423 Remove trailing whitespace on lines 82 and 87. Lines 82 and 87 contain 8 spaces of indentation with no other content, creating trailing whitespace that violates PHPCS standards. These should be completely blank lines with no characters. 🧰 Tools🪛 GitHub Check: Run PHPCS inspection[failure] 82-82: 🤖 Prompt for AI Agents |
||
| // Add download if Easy Digital Downloads post type is registered | ||
| if ( post_type_exists( 'download' ) && ! in_array( 'download', $wpuf_post_types, true ) ) { | ||
| $wpuf_post_types[] = 'download'; | ||
| } | ||
|
|
||
| $ignore_taxonomies = apply_filters( 'wpuf-ignore-taxonomies', [ | ||
|
Check warning on line 88 in includes/Traits/FieldableTrait.php
|
||
| 'post_format', | ||
| ] ); | ||
| foreach ( $wpuf_post_types as $post_type ) { | ||
| $this->wp_post_types[ $post_type ] = []; | ||
| $taxonomies = get_object_taxonomies( $post_type, 'object' ); | ||
| foreach ( $taxonomies as $tax_name => $taxonomy ) { | ||
| if ( ! in_array( $tax_name, $ignore_taxonomies ) ) { | ||
| $this->wp_post_types[ $post_type ][ $tax_name ] = [ | ||
| 'title' => $taxonomy->label, | ||
| 'hierarchical' => $taxonomy->hierarchical, | ||
| ]; | ||
| $this->wp_post_types[ $post_type ][ $tax_name ]['terms'] = get_terms( [ | ||
| 'taxonomy' => $tax_name, | ||
| 'hide_empty' => false, | ||
| ] ); | ||
|
|
@@ -103,6 +113,26 @@ | |
| 'terms' => [], | ||
| ]; | ||
| } | ||
|
|
||
| // Special handling for product to include product_tag in free version | ||
| if ( 'product' === $post_type && ! isset( $this->wp_post_types[ $post_type ]['product_tag'] ) ) { | ||
| // Add product_tag as a canonical field for WooCommerce forms | ||
| $this->wp_post_types[ $post_type ]['product_tag'] = [ | ||
| 'title' => __( 'Product Tags', 'wp-user-frontend' ), | ||
| 'hierarchical' => false, | ||
| 'terms' => [], | ||
| ]; | ||
| } | ||
|
|
||
| // Special handling for download to include download_tag in free version | ||
| if ( 'download' === $post_type && ! isset( $this->wp_post_types[ $post_type ]['download_tag'] ) ) { | ||
| // Add download_tag as a canonical field for EDD forms | ||
| $this->wp_post_types[ $post_type ]['download_tag'] = [ | ||
| 'title' => __( 'Download Tags', 'wp-user-frontend' ), | ||
| 'hierarchical' => false, | ||
| 'terms' => [], | ||
| ]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -132,7 +162,7 @@ | |
|
|
||
| foreach ( $form_vars as $key => $value ) { | ||
| // get column field input fields | ||
| if ( $value['input_type'] == 'column_field' ) { | ||
| $inner_fields = $value['inner_fields']; | ||
|
|
||
| foreach ( $inner_fields as $column_key => $column_fields ) { | ||
|
|
@@ -144,12 +174,12 @@ | |
| } | ||
|
|
||
| //separate the post and custom fields | ||
| if ( isset( $column_field['is_meta'] ) && $column_field['is_meta'] == 'yes' ) { | ||
| $meta_vars[] = $column_field; | ||
| continue; | ||
| } | ||
|
|
||
| if ( $column_field['input_type'] == 'taxonomy' ) { | ||
|
|
||
| // don't add "category" | ||
| // if ( $column_field['name'] == 'category' ) { | ||
|
|
@@ -172,12 +202,12 @@ | |
| } | ||
|
|
||
| //separate the post and custom fields | ||
| if ( isset( $value['is_meta'] ) && $value['is_meta'] == 'yes' ) { | ||
| $meta_vars[] = $value; | ||
| continue; | ||
| } | ||
|
|
||
| if ( $value['input_type'] == 'taxonomy' ) { | ||
|
|
||
| // don't add "category" | ||
| // if ( $value['name'] == 'category' ) { | ||
|
|
@@ -221,10 +251,10 @@ | |
| wpuf()->ajax->send_error( __( 'Empty reCaptcha Field', 'wp-user-frontend' ) ); | ||
| } | ||
|
|
||
| if ( $recaptcha_type == 'enable_no_captcha' ) { | ||
| $no_captcha = 1; | ||
| $invisible_captcha = 0; | ||
| } elseif ( $recaptcha_type == 'invisible_recaptcha' ) { | ||
| $invisible_captcha = 1; | ||
| $no_captcha = 0; | ||
| } else { | ||
|
|
@@ -278,7 +308,7 @@ | |
| $remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; | ||
| $g_recaptcha_response = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : ''; | ||
|
|
||
| if ( $no_captcha == 1 && 0 == $invisible ) { | ||
| if ( ! class_exists( 'WPUF_ReCaptcha' ) ) { | ||
| require_once WPUF_ROOT . '/Lib/recaptchalib_noCaptcha.php'; | ||
| } | ||
|
|
@@ -498,6 +528,20 @@ | |
| register_taxonomy_for_object_type( 'post_tag', 'tribe_events' ); | ||
| } | ||
|
|
||
| // Auto-register product_tag taxonomy for product if not already registered | ||
| if ( 'product' === $this->form_settings['post_type'] && | ||
| 'product_tag' === $taxonomy['name'] && | ||
| ! is_object_in_taxonomy( $this->form_settings['post_type'], $taxonomy['name'] ) ) { | ||
| register_taxonomy_for_object_type( 'product_tag', 'product' ); | ||
| } | ||
|
|
||
| // Auto-register download_tag taxonomy for download if not already registered | ||
| if ( 'download' === $this->form_settings['post_type'] && | ||
| 'download_tag' === $taxonomy['name'] && | ||
| ! is_object_in_taxonomy( $this->form_settings['post_type'], $taxonomy['name'] ) ) { | ||
| register_taxonomy_for_object_type( 'download_tag', 'download' ); | ||
| } | ||
|
|
||
| if ( is_object_in_taxonomy( $this->form_settings['post_type'], $taxonomy['name'] ) ) { | ||
| $tax = $taxonomy_name; | ||
| // if it's not an array, make it one | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Padding inconsistency causes size mismatch with other field buttons.
The pro-feature field button uses
wpuf-p-4(16px on all sides), while failed-validation and regular field buttons usewpuf-px-3 wpuf-py-4(12px horizontal, 16px vertical) on lines 1173 and 1191. This padding mismatch creates visual misalignment when these field types are displayed together in the form builder sidebar, which likely explains the size mismatch reported by the reviewer for The Events Calendar template.Apply this diff to align the padding with other field button types:
📝 Committable suggestion
🤖 Prompt for AI Agents