Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated 'who' argument for get_users/WP_User_Query #697

Closed
jerclarke opened this issue Feb 9, 2023 · 1 comment
Closed

Fix deprecated 'who' argument for get_users/WP_User_Query #697

jerclarke opened this issue Feb 9, 2023 · 1 comment

Comments

@jerclarke
Copy link
Contributor

jerclarke commented Feb 9, 2023

Expected/Desired Behavior

Clean error logs with WP_DEBUG enabled.

Actual Behavior

Deprecation notice caused by EF's use of get_users():

 PHP Deprecated:  Function WP_User_Query was called with an argument that is <strong>deprecated</strong> since version 5.9.0! <code>who</code> is deprecated. Use <code>capability</code> instead. in /.../wp-includes/functions.php on line 5667 

It's triggered by this code in /edit-flow/common/php/class-module.php:463:

		$args = array(
			'who' => 'authors',
			'fields' => array(
				'ID',
				'display_name',
				'user_email'
			),
			'orderby' => 'display_name',
		);
		$args = apply_filters( 'ef_users_select_form_get_users_args', $args );

		$users = get_users( $args );

That who argument is deprecated, I'm surprised it even worked this long! The error tells us it should instead use capability which makes total sense. The who=author section of the user query just converted it into a user_level != 0 query, which makes me feel dirty like I'm back in 2008.

So clearly we need to switch it for a proper cap test, to me it seems like edit_posts is a logical choice to replace "author", and is of course also logical because that's who will theoretically be able to interact with EF tools. Maybe not though? Maybe there's a reason to make it even more wide open, but in that case it seems like we can just remove this line entirely.

Anyway, here's the code I'm going to use in my local copy, pending someone doing something about this ticket:

	$args = array(
			'capability' => 'edit_posts',
			'fields' => array(
				'ID',
				'display_name',
				'user_email'
			),
			'orderby' => 'display_name',
		);

From what I can tell, this works fine and addresses the issue.

Steps to Reproduce the Problem

Seems like it happens every time I open the post editor with the Notifications box present. For me the deprecation was hidden in the WP Debug bar menu, I only noticed it during acceptance testing.

(Optional) Additional notes

Thanks for the patch this last summer! It was great to see someone at least keeping this thing running, and it gave me another year without having to switch to PublishPress, so I appreciate it!

@jerclarke jerclarke changed the title Fix deprecated Fix deprecated 'who' argument for get_users/WP_User_Query Feb 9, 2023
@ingeniumed
Copy link
Contributor

This has been fixed with #701.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants