#50961 closed defect (bug) (fixed)
Fix missing ref array in pre_get_users
Reported by: | andy | Owned by: | adamsilverstein |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Users | Keywords: | has-patch |
Focuses: | Cc: |
Description
Code docs in class-wp-user-query.php mark this as passed by reference but the actual call uses do_action
instead of do_action_ref_array
.
Index: wp-includes/class-wp-user-query.php =================================================================== --- wp-includes/class-wp-user-query.php (revision 212073) +++ wp-includes/class-wp-user-query.php (working copy) @@ -227,7 +227,7 @@ * @param WP_User_Query $this The current WP_User_Query instance, * passed by reference. */ - do_action( 'pre_get_users', $this ); + do_action_ref_array( 'pre_get_users', array( &$this ) ); // Ensure that query vars are filled after 'pre_get_users'. $qv =& $this->query_vars;
Attachments (1)
Change History (21)
#1
@
4 years ago
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to 5.6
#3
@
4 years ago
- Owner set to adamsilverstein
- Status changed from new to assigned
Thanks for the ping @spacedmonkey.
This ticket was mentioned in PR #478 on WordPress/wordpress-develop by adamsilverstein.
4 years ago
#4
- Keywords has-patch added; needs-patch removed
Trac ticket:
#5
follow-up:
↓ 7
@
4 years ago
- Keywords needs-patch added; has-patch removed
@andy I noticed we have tests for this and also found extensive plugin use where the original $this is modified.
I believe this works because PHP passes objects by reference, however changing to do_action_ref_array
would certainly be easier to read code-wise. I'll give that change a test to make sure tests still work as expected.
#6
@
4 years ago
Running test suite with proposed change in https://github.com/WordPress/wordpress-develop/pull/478
#7
in reply to:
↑ 5
@
4 years ago
- Resolution set to invalid
- Status changed from assigned to closed
Hi Adam! Thanks for taking me back to school. :)
I went back and revisited the reason for the patch. The issue was that I used &$query
in the action function's signature and got a warning about getting a value when a reference was expected. In fact, the reference to the object was working. I just needed to remove the &
to stop the warning.
#8
@
4 years ago
- Keywords has-patch added; needs-patch good-first-bug removed
- Resolution invalid deleted
- Status changed from closed to reopened
I believe the change should still be made, not for functional difference but just for consistency with the other actions:
do_action_ref_array( 'pre_get_comments', array( &$this ) );
do_action_ref_array( 'pre_get_networks', array( &$this ) );
do_action_ref_array( 'pre_get_posts', array( &$this ) );
do_action_ref_array( 'pre_get_sites', array( &$this ) );
do_action_ref_array( 'pre_user_query', array( &$this ) );
50961.diff updates both pre_get_terms
and pre_get_users
to match.
#9
@
4 years ago
I believe the change should still be made, not for functional difference but just for consistency with the other actions
Good point. 50961.diff looks good to me, I'll run the tests in travis to confirm.
#10
follow-up:
↓ 17
@
4 years ago
Restarted failing Travis jobs. Passing now.
Note: PHP8 job fails. If merged, need to add this to php8
tasks.
#11
@
4 years ago
@SergeyBiryukov - reviewing 50961.diff - does changing $this
to array( &$this )
change anything in terms of filter consumers use? I guess if all the tests pass we are fine!
This ticket was mentioned in PR #674 on WordPress/wordpress-develop by adamsilverstein.
4 years ago
#12
Trac ticket: https://core.trac.wordpress.org/ticket/50961
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#15
@
4 years ago
Notes from yesterday's scrub.
@adamsilverstein noted to this question: Any risks for it being merged this late into 5.6?
I don't think so, on the other hand this is a purely internal change, so we could easily punt to 5.7 (not a priority)
This ticket was mentioned in Slack in #core by sergey. View the logs.
4 years ago
#17
in reply to:
↑ 10
@
4 years ago
Replying to hellofromTonya:
Note: PHP8 job fails. If merged, need to add this to
php8
tasks.
Just noting the PHP 8 failure is unrelated to the patch:
Warning: Class "PHPUnit\Util\Getopt" not found in /var/www/tests/phpunit/includes/phpunit6/compat.php on line 18 Error: Looks like you're using PHPUnit 9.4.2. WordPress requires at least PHPUnit 5.4 and is currently only compatible with PHPUnit up to 7.x. Please use the latest PHPUnit version from the 7.x branch.
It looks like a wrong PHPUnit version was used for some reason. That does not happen on WordPress trunk.
The patch should not have any functional difference, committing shortly.
hellofromtonya commented on PR #478:
4 years ago
#19
Merged in changeset https://core.trac.wordpress.org/changeset/49637
hellofromtonya commented on PR #674:
4 years ago
#20
Merged in changeset https://core.trac.wordpress.org/changeset/49637
Just noting this also applies to the
pre_get_terms
hook.