Make WordPress Core

Changes between Version 1 and Version 2 of Ticket #61936, comment 3


Ignore:
Timestamp:
09/01/2024 11:14:03 PM (18 months ago)
Author:
marian1
Comment:

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:
     1Given 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
     3It is also necessary to review the other functions that call `wp_get_object_terms()`.
     4
     5While examining this issue, I found that this entire section seems incorrect:
    26
    37{{{#!php
     
    2327}}}
    2428
    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.
     29The `'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.
    2630
    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.
     31Fixing 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']`.
    2832
    29 It's also necessary to review the other functions that call `wp_get_object_terms()`.
     33Given that this is actually a separate issue, should I open a new ticket to address it?