-
Notifications
You must be signed in to change notification settings - Fork 152
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 1 commit
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 |
|---|---|---|
|
|
@@ -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.
🧩 Analysis chain
Fix 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:
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:
Length of output: 1470
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 263
🏁 Script executed:
Length 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
/* translators: %s: Name of a city */
printf( __( 'Your city is %s.', 'my-plugin' ), $city );
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
[1] WordPress — Escaping data (Developer Handbook).
[2] Function reference: esc_html__ (WordPress Code Reference).
[3] Internationalization guidelines — escaping strings (WordPress Handbook).
[4] esc_attr() reference (WordPress Code Reference).
[5] wp_kses / wp_kses_post guidance (WordPress Handbook).
[6] Plugin Handbook — common issues: using __ without escaping.
Fix i18n placeholder and escape output (PHPCS blocker and XSS risk).
Line 181 outputs
$tax->labelunescaped inside an HTML label tag and is missing the required translators comment. Add the translators comment and escape both the string and label usingesc_html__()andesc_html()to satisfy PHPCS i18n standards and prevent HTML injection.🧰 Tools
🪛 GitHub Check: Run PHPCS inspection
[failure] 181-181:
A function call to __() with texts containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
🤖 Prompt for AI Agents