Skip to content

Scope wp_user query to specific user level#6699

Merged
georgestephanis merged 4 commits intomasterfrom
fix/user-query-only-authors
Mar 28, 2017
Merged

Scope wp_user query to specific user level#6699
georgestephanis merged 4 commits intomasterfrom
fix/user-query-only-authors

Conversation

@dereksmart
Copy link
Copy Markdown
Contributor

Fixes #6698

Scope the WP_User query to only include those with publishing abilities. Some sites were breaking since we were trying to get all subscribers as well. This will only get the users with minimum user level of 2, which grants the ability to publish posts.

https://codex.wordpress.org/User_Levels

To test:

  • Make sure the authors rule only lists those who can publish posts.

@tselaty
Copy link
Copy Markdown

tselaty commented Mar 20, 2017

I can confirm this change fixes the absolutely crazy page load times on the Widgets page for a 160,000+ user WordPress site.

@georgestephanis
Copy link
Copy Markdown
Contributor

The prior code is problematic on a number of grounds -- it has get_users() using the exclude_admin argument, which is a param of wp_list_authors() not get_users() --
https://github.com/WordPress/WordPress/blob/d327c92e4b3754bf598126fe007e435cabb78a56/wp-includes/author-template.php#L335-L472

That being said, wp_user_level is probably a bad thing to key off of, it's been deprecated for years.

@richardmtl
Copy link
Copy Markdown
Contributor

@dereksmart The other user confirms this works as well but with George's objection, sounds like you might be trying again. :/

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Mar 20, 2017
@samhotchkiss
Copy link
Copy Markdown
Contributor

This solution seems to work consistently. @dereksmart, @richardmtl, @georgestephanis

@samhotchkiss samhotchkiss added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Mar 28, 2017
$authors = get_users(
array(
'orderby' => 'name',
'who' => 'authors'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a trailing comma here to make phpcs happy?

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Mar 28, 2017
@dereksmart
Copy link
Copy Markdown
Contributor Author

@samhotchkiss's change LGTM -- someone else needs to approve to merge since I opened this :)

@dereksmart dereksmart added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Mar 28, 2017
@georgestephanis
Copy link
Copy Markdown
Contributor

We'll revisit this later for avoiding who=authors as that may scale badly on bbpress or buddypress sites, but for now it's not a regression, so merging.

@dereksmart
Copy link
Copy Markdown
Contributor Author

If/when we revisit for scaling, we'll also want to look at this query that also uses who to get authors https://github.com/Automattic/jetpack/blob/master/modules/widgets/authors.php#L86

@georgestephanis georgestephanis merged commit 86a84c6 into master Mar 28, 2017
@georgestephanis georgestephanis removed the [Status] Ready to Merge Go ahead, you can push that green button! label Mar 28, 2017
@dereksmart dereksmart deleted the fix/user-query-only-authors branch March 28, 2017 14:45
jeherve added a commit that referenced this pull request Mar 28, 2017
samhotchkiss pushed a commit that referenced this pull request Mar 29, 2017
* Readme: remove old release and add skeleton for 4.8.

* Changelog: add #6572

* Changelog: add #6567

* Changelog: add #6542

* Changelog: add #6527

* Changelog: add #6508

* Changelog: add #6478

* Changelog: add #6477

* Changelog: add #6249

* Update stable version and remove old version from readme.

* Changelog: add 4.7.1 to changelog.

* Readme: add new contributor.

* Sync: update docblock @SInCE version.

Related: #6053

* Changelog: add release post.

* changelog: add #6053

* Changelog: add #6413

* Changelog: add #6482

* Changelog: add #6584

* Changelog add #6603

* Changelog: add #6606

* Changelog: add #6611

* Changelog: add #6635

* Changelog: add #6639

* Changelog: add #6684

* Changelog: add #6710

* Changelog: add #6711

* Changelog: add #5461

* Testing list: update Settings UI feedback prompt.

Props @MichaelArestad

* Changelog: add #6789

* Changelog: add #6778

* Changelog: add #6777

* Changelog: add #6775

* Changelog: add #6755

* Changelog: add #6731

* Changelog: add #6721

* Changelog: add #6705

* Changelog: add #6702

* Changelog: add #6671

* Changelog: add #6637

* Changelog: add #6582

* Changelog: add #6566

* Changelog: add #6555

* Changelog: add #6529

* Changelog: add #6344

* Changelog: add #5763

* Changelog: add #5503

* Changelog: update #6637 changelog.

@see 40e115c#commitcomment-21523982

* Changelog: add #6699

* Changelog: add #6632

* Changelog: add #6769

* Changelog: add #6707

* Changelog: add #6590
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended [Feature] Widget Visibility [Pri] High Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants