-
Notifications
You must be signed in to change notification settings - Fork 154
fix: correctly detect ACF taxonomies by checking post_content #1748
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
base: develop
Are you sure you want to change the base?
Changes from 2 commits
bb1fc6b
62bdbec
a95e20f
9fb0e06
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 |
|---|---|---|
|
|
@@ -5704,3 +5704,163 @@ function wpuf_field_profile_photo_allowed_mimes() { | |
| return apply_filters( 'wpuf_field_profile_photo_allowed_mimes', $profile_photo_mimes ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check if a taxonomy is registered by Advanced Custom Fields (ACF) | ||
| * | ||
| * ACF taxonomies should be available in the free version as they are user-created | ||
| * via ACF, not plugin-specific custom taxonomies. | ||
| * | ||
| * @since WPUF_SINCE | ||
| * | ||
| * @param string $taxonomy_name The taxonomy name to check | ||
| * @return bool True if taxonomy is registered by ACF, false otherwise | ||
| */ | ||
| if ( ! function_exists( 'wpuf_is_acf_taxonomy' ) ) { | ||
| function wpuf_is_acf_taxonomy( $taxonomy_name ) { | ||
| // If taxonomy doesn't exist, it can't be an ACF taxonomy | ||
| if ( ! taxonomy_exists( $taxonomy_name ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| // Get the taxonomy object | ||
| $taxonomy = get_taxonomy( $taxonomy_name ); | ||
|
|
||
| if ( ! $taxonomy ) { | ||
| return false; | ||
| } | ||
|
|
||
| // ACF taxonomies typically have these characteristics: | ||
| // 1. They are not built-in (_builtin = false) | ||
| // 2. They are registered by ACF (check for ACF-specific properties) | ||
|
|
||
| // Check if ACF is active | ||
| if ( ! class_exists( 'acf' ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| // ACF stores taxonomy configuration in the database | ||
| // Check if there's an ACF post type that registered this taxonomy | ||
| global $wpdb; | ||
|
|
||
| // ACF saves custom taxonomies as posts of type 'acf-taxonomy' | ||
| // The taxonomy slug is stored in the serialized post_content, not post_name | ||
| // post_name is ACF's internal key like 'taxonomy_69242380c35d7' | ||
| $acf_taxonomies = $wpdb->get_results( | ||
| "SELECT post_content FROM {$wpdb->posts} | ||
| WHERE post_type = 'acf-taxonomy' | ||
| AND post_status = 'publish'" | ||
| ); | ||
|
|
||
| if ( ! empty( $acf_taxonomies ) ) { | ||
| foreach ( $acf_taxonomies as $acf_tax ) { | ||
| // ACF stores the taxonomy configuration as serialized data | ||
| $config = maybe_unserialize( $acf_tax->post_content ); | ||
|
|
||
| // Check if the taxonomy key matches our taxonomy name | ||
| if ( is_array( $config ) && isset( $config['taxonomy'] ) && $config['taxonomy'] === $taxonomy_name ) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Additional check: ACF taxonomies often have 'acf' in their labels or registration | ||
| // Check if the taxonomy object has ACF-specific metadata | ||
| if ( isset( $taxonomy->acf ) || isset( $taxonomy->_builtin ) && ! $taxonomy->_builtin ) { | ||
| // Check if registered via ACF by looking for ACF functions | ||
| if ( function_exists( 'acf_get_internal_post_type' ) ) { | ||
| $internal_types = acf_get_internal_post_type( 'acf-taxonomy', 'names' ); | ||
| if ( is_array( $internal_types ) && in_array( $taxonomy_name, $internal_types, true ) ) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
|
||
|
|
||
| /** | ||
| * Get taxonomy object types (post types the taxonomy is associated with) | ||
| * | ||
| * This works for all taxonomies - built-in, custom, ACF, or any other. | ||
| * | ||
| * @since WPUF_SINCE | ||
| * | ||
| * @param string $taxonomy_name The taxonomy name to check | ||
| * @return array Array of post type names associated with the taxonomy | ||
| */ | ||
| if ( ! function_exists( 'wpuf_get_taxonomy_post_types' ) ) { | ||
| function wpuf_get_taxonomy_post_types( $taxonomy_name ) { | ||
| // If taxonomy doesn't exist, return empty array | ||
| if ( ! taxonomy_exists( $taxonomy_name ) ) { | ||
| return []; | ||
| } | ||
|
|
||
| // Get the taxonomy object | ||
| $taxonomy = get_taxonomy( $taxonomy_name ); | ||
|
|
||
| if ( ! $taxonomy ) { | ||
| return []; | ||
| } | ||
|
|
||
| // WordPress stores associated post types in object_type property | ||
| if ( isset( $taxonomy->object_type ) && is_array( $taxonomy->object_type ) ) { | ||
| return $taxonomy->object_type; | ||
| } | ||
|
|
||
| return []; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get list of taxonomies that should be available in free version | ||
| * | ||
| * This includes built-in taxonomies and ACF-registered taxonomies. | ||
| * | ||
| * @since WPUF_SINCE | ||
| * | ||
| * @return array Array of taxonomy names that are available in free version | ||
| */ | ||
| if ( ! function_exists( 'wpuf_get_free_taxonomies' ) ) { | ||
| function wpuf_get_free_taxonomies() { | ||
| // Built-in taxonomies that are always available | ||
| $free_taxonomies = array( 'category', 'post_tag' ); | ||
|
|
||
| // Allow filtering to add more free taxonomies | ||
| //$free_taxonomies = apply_filters( 'wpuf_free_taxonomies', $free_taxonomies ); | ||
|
|
||
| // Get all registered taxonomies (built-in and custom) | ||
| $all_taxonomies = get_taxonomies( array(), 'names' ); | ||
|
|
||
| foreach ( $all_taxonomies as $taxonomy_name ) { | ||
| // Skip if already in free list | ||
| if ( in_array( $taxonomy_name, $free_taxonomies, true ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| // Get the post types this taxonomy is associated with | ||
| $post_types = wpuf_get_taxonomy_post_types( $taxonomy_name ); | ||
|
|
||
| // Only allow taxonomies that are associated with 'post' or 'page' in free version | ||
| if ( ! empty( $post_types ) ) { | ||
| $allowed_post_types = array( 'post', 'page' ); | ||
| $has_allowed_type = false; | ||
|
|
||
| foreach ( $post_types as $post_type ) { | ||
| if ( in_array( $post_type, $allowed_post_types, true ) ) { | ||
| $has_allowed_type = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // If this taxonomy is for post or page, add it to free list | ||
| if ( $has_allowed_type ) { | ||
| $free_taxonomies[] = $taxonomy_name; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return $free_taxonomies; | ||
| } | ||
| } | ||
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
Verify the fallback to
taxonomykey is necessary.Line 571 extracts the taxonomy slug with
$f['name'] ?? ($f['taxonomy'] ?? null), falling back to thetaxonomykey. However, the other methods (filter_pro_taxonomy_fieldsandget_hidden_taxonomy_ids) only check$field['name'].Ensure this fallback is intentional and that taxonomy fields can indeed have the slug under either key, or consider aligning the extraction logic across all three methods for consistency.
🏁 Script executed:
Length of output: 16231
🏁 Script executed:
Length of output: 4029
🏁 Script executed:
Length of output: 3215
Align the taxonomy slug extraction with other methods for consistency.
Line 571 extracts the slug with a fallback to
$f['taxonomy'], butfilter_pro_taxonomy_fields(line 528) andget_hidden_taxonomy_ids(line 607) only check$field['name']. Since all observed field definitions consistently populate thenamekey, the fallback appears unnecessary. Either document why thetaxonomykey fallback is needed for nested fields, or remove it to align with the other methods.🤖 Prompt for AI Agents