Additional term arguments ignored in class Tribe__Ajax__Dropdown since v6.2.9
-
Documentation for this class is out-of-date and shows working version prior to
v6.2.9
changes… Reporting this bug here since this file is contained within the public calendar plugin and not in a premium add-on plugin.Issue
Additional term arguments?$params[args]?
for select2 taxonomy dropdowns breaks at?v6.2.9
?to current version. was working prior and the last working version was?v6.2.8.2
.
(e.g. passing exclude, parent etc. as additional arguments is no longer parsed and ignored in ajax response)- Example: ajax post will?NOT?exclude term_id 69, but should:
action=tribe_dropdown&source=search_terms&search%5B_type%5D=query&search%5Bterm%5D=&args%5Btaxonomy%5D=tribe_events_cat&args%5Borderby%5D=name&args%5Bexclude%5D%5B%5D=69
- Example: ajax post will?NOT?only show children of term_id 69, but should:
action=tribe_dropdown&source=search_terms&search%5B_type%5D=query&search%5Bterm%5D=&args%5Btaxonomy%5D=tribe_events_cat&args%5Borderby%5D=name&args%5Bparent%5D%5B%5D=69
Where
Issue found in class?Tribe__Ajax__Dropdown
?in file:?the-events-calendar/common/src/Tribe/Ajax/Dropdown.php
A change to functionparse_params($params)
as of?v6.2.9
?is breaking the ability to pass any additional arguments to?get_terms()
.
Specifically, the issue is on?line 251?as the default value ignores any additional params passed with the ajax post. Instead there’s 2 conditionals for the args array only checking fortaxonomy
andpost_type
preventing any additional term args to be parsed…
Quick fix
line 251:?'args'? => [ 'post_status' => 'publish' ],
a quick fix would be to change this line to:?'args'? => $params['args'] ?? [ 'post_status' => 'publish' ],
- 'args'? => [ 'post_status' => 'publish' ], + 'args'? => $params['args'] ?? [ 'post_status' => 'publish' ],
v6.3.6 parse_params()
Recommendation: Adjust whitelist to include all allowed term arguments accepted by get_terms()/** * Parses the Params coming from Select2 Search box. * * @since 4.6 * @since 5.1.17 Added an allow list of params to restrict the shape of the database queries. * * @param array<string|mixed> $params Params to overwrite the defaults. * * @return object */ public function parse_params( $params ) { $allowed_params = [ 'search' => $params['search'] ?? null, 'page' => $params['page'] ?? 0, 'source' => $params['source'] ?? null, 'args' => [ 'post_status' => 'publish' ], ]; if ( isset( $params['args']['taxonomy'] ) ) { $allowed_params['args']['taxonomy'] = $params['args']['taxonomy']; } if ( isset( $params['args']['post_type'] ) ) { $allowed_params['args']['post_type'] = $params['args']['post_type']; } // Return Object just for the sake of making it simpler to read. return (object) $allowed_params; }
v6.2.8.2 parse_params()
Passing additional term arguments for additional get_terms() filter is working properly./** * Parses the Params coming from Select2 Search box * * @since 4.6 * * @param array<string|mixed> $params Params to overwrite the defaults * * @return object */ public function parse_params( $params ) { $defaults = [ 'search' => null, 'page' => 0, 'args' => [], 'source' => null, ]; $arguments = wp_parse_args( $params, $defaults ); // Return Object just for the sake of making it simpler to read return (object) $arguments; }
Please this fix this,
Thanks!
– Scott TrsarThe page I need help with: [log in to see the link]
- Example: ajax post will?NOT?exclude term_id 69, but should:
- The topic ‘Additional term arguments ignored in class Tribe__Ajax__Dropdown since v6.2.9’ is closed to new replies.