Changes between Version 1 and Version 2 of Ticket #61936, comment 3
- Timestamp:
- 09/01/2024 11:14:03 PM (18 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #61936, comment 3
v1 v2 1 This is a first step. However, while examining this issue, I found that this entire section seems incorrect: 1 Given the changes made in [https://github.com/WordPress/wordpress-develop/pull/7278 PR #7278 ], the function returns the expected count when requesting a count. Like `get_terms()` and `WP_Term_Query->get_terms()`, it does not correct for double counting if the same term is assigned to multiple objects or taxonomies. 2 3 It is also necessary to review the other functions that call `wp_get_object_terms()`. 4 5 While examining this issue, I found that this entire section seems incorrect: 2 6 3 7 {{{#!php … … 23 27 }}} 24 28 25 The ` $args` that the taxonomies are registered with are located in `$t->args['args']`, not `$t->args`. Therefore, the condition `array_merge( $args, $t->args ) != $args )` is always true, but the incorrect array is merged. The statement "those parameters override the `$args` passed to this function" will never occur, except for `'hierarchical'`, which is part of both arrays. However, I am unsure whether this overriding should occur at all. If the `array_merge` worked as intended, each taxonomy could have a different `'fields'` value, resulting in a relatively unpredictable return type.29 The `'args'` that the taxonomies are registered with are located in `$t->args['args']`, not `$t->args`. Therefore, the condition `array_merge( $args, $t->args ) != $args` is always true, but the incorrect array is merged. The statement "those parameters override the `$args` passed to this function" only holds for `'hierarchical'`, which is part of both arrays. As far as I can tell, whether `'hierarchical'` is overridden or not does not change the return value of `wp_get_object_terms()`, as it requires `$object_ids` to be set. 26 30 27 The function new returns the expected count when requesting a count. Like `get_terms()` and `WP_Term_Query->get_terms()`, it does not correct for double counting if the same term is assigned to multiple objects or taxonomies.31 Fixing this by replacing `$t->args` with `$t->args['args']` is straightforward; however, I am unsure whether this overriding should occur at all. If the `array_merge` worked as intended, each taxonomy could have, for example, a different `'fields'` value, resulting in a relatively unpredictable return type and value. Additionally, one taxonomy could have been registered with `$args['args'] = ['fields' => 'count']`. When requesting an array of taxonomies, the return value would be a mix of term objects and term counts. This is not only unpredictable but would also result in `WP_Term_Query::format_terms()` accessing non-existent term properties. I suggest at least excluding `'fields'` when merging `$args` with `$t->args['args']`. 28 32 29 It's also necessary to review the other functions that call `wp_get_object_terms()`. 33 Given that this is actually a separate issue, should I open a new ticket to address it?