Taxonomy: Fix warnings thrown by custom term count callbacks.

Add a `use` to a closure to avoid an undefined variable throwing a warning. Adds unit tests to ensure the custom callbacks run as expected when defined.

Follow up to [49141].
Props ocean90, dd32.
Fixes #40351.



git-svn-id: https://develop.svn.wordpress.org/trunk@49171 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2020-10-16 02:41:15 +00:00
parent 901edbe510
commit 3965584a04
2 changed files with 113 additions and 1 deletions
+1 -1
View File
@@ -426,7 +426,7 @@ final class WP_Taxonomy {
is_callable( $args['update_count_callback'] ) &&
empty( $args['update_count_by_callback'] )
) {
$args['update_count_by_callback'] = function( $tt_ids, $taxonomy, $modify_by ) {
$args['update_count_by_callback'] = function( $tt_ids, $taxonomy ) use ( $args ) {
return call_user_func( $args['update_count_callback'], $tt_ids, $taxonomy );
};
}