WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 10 months ago

Last modified 10 months ago

#51333 closed defect (bug) (fixed)

Assign 'sites_pre_query' and 'networks_pre_query' filter results to the class property

Reported by: SergeyBiryukov Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: good-first-bug has-patch has-unit-tests
Focuses: multisite Cc:

Description

Background: #45749, #47599, #50521.

[48990] assigns the array of comment data returned from the comments_pre_query filter to the comments property of the current WP_Comment_Query instance.

As noted by @spacedmonkey in comment:2:ticket:50521, since networks_pre_query and sites_pre_query follow the same pattern, the same should be done for them:

  • The array of network data returned from networks_pre_query should be assigned to the networks property of the current WP_Network_Query instance.
  • The array of site data returned from sites_pre_query should be assigned to the sites property of the current WP_Site_Query instance.

Change History (8)

This ticket was mentioned in PR #544 on WordPress/wordpress-develop by yakimun.


12 months ago

  • Keywords has-patch has-unit-tests added; needs-patch removed

Changes:

  • networks_pre_query filter result assigned to the networks property of the current WP_Network_Query instance.
  • sites_pre_query filter result assigned to the sites property of the current WP_Site_Query instance.

Trac ticket: https://core.trac.wordpress.org/ticket/51333

This ticket was mentioned in PR #545 on WordPress/wordpress-develop by campusboy87.


12 months ago

Added a check for the existence of a user, since the function can get the ID of the user (for example, the author of the page) that was deleted.

Trac ticket: https://core.trac.wordpress.org/ticket/51333

#3 @SergeyBiryukov
12 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#4 @SergeyBiryukov
12 months ago

For reference, just noting that the second PR here was accidental and is actually from #51370.

#6 @SergeyBiryukov
10 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49538:

Networks and Sites: Assign the array of site or network data returned from filters to the respective class property:

  • The array of network data returned from the networks_pre_query filter is assigned to the networks property of the current WP_Network_Query instance.
  • The array of site data returned from the sites_pre_query filter is assigned to the sites property of the current WP_Site_Query instance.

This avoids the performance overhead of calling WP_Network_Query::get_networks() or WP_Site_Query::get_sites() twice: first when creating the object instance, then to retrieve the filtered results.

This also makes the filters a bit more consistent with other similar filters, e.g. posts_pre_query, terms_pre_query, comments_pre_query, or users_pre_query.

Follow-up to [46086], [48990].

Props yakimun, spacedmonkey.
Fixes #51333.

#7 @SergeyBiryukov
10 months ago

Hi @yakimun, just wanted to say thanks for the PR, it is quite accurate and does exactly what's needed.

It even has an added bonus of reusing the existing fixtures instead of creating new ones, which is something I did not initially think of, but is the right thing to do here.

Great job :)

#8 @prbot
10 months ago

SergeyBiryukov commented on PR #544:

Merged in 31831c7.

Thanks for the patch @yakimun, it is quite accurate and does exactly what's needed.

It even has an added bonus of reusing the existing fixtures instead of creating new ones, which is something I did not initially think of, but is the right thing to do here.

Great job :)

Note: See TracTickets for help on using tickets.