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

Connection: work around a WP user caching bug #40188

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Work around a WP user caching bug (https://core.trac.wordpress.org/ticket/62003).
7 changes: 6 additions & 1 deletion projects/packages/connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1620,12 +1620,17 @@ public function get_assumed_site_creation_date() {
return $cached_date;
}

/**
* We don't use the 'ID' field, but need it to overcome a WP caching bug: https://core.trac.wordpress.org/ticket/62003
*
* @todo Remote the 'ID' field from users fetching when the issue is fixed and Jetpack-supported WP versions move beyond it.
*/
$earliest_registered_users = get_users(
array(
'role' => 'administrator',
'orderby' => 'user_registered',
'order' => 'ASC',
'fields' => array( 'user_registered' ),
'fields' => array( 'ID', 'user_registered' ),
'number' => 1,
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ protected function set_up() {
\Jetpack_Options::update_option( 'master_user', $id_admin );

$this->users_query_filter = function ( $result, $query ) {
if ( str_starts_with( trim( $query ), 'SELECT wp_users.user_registered' )
if ( str_starts_with( trim( $query ), 'SELECT wp_users.ID,wp_users.user_registered' )
&& preg_match( '#wp_usermeta\.meta_value LIKE \'\{.*?\}"administrator"\{.*?\}\'#i', $query )
) {
return array( (object) array( 'user_registered' => '2012-03-19 00:00:00' ) );
return array(
(object) array(
'ID' => 12346,
'user_registered' => '2012-03-19 00:00:00',
),
);
}

return $result;
Expand Down
Loading