From 6d148ee0407cd97154f40e93fcad3398d591f06e Mon Sep 17 00:00:00 2001 From: sergeymitr Date: Thu, 14 Nov 2024 10:56:56 -0500 Subject: [PATCH 1/4] Connection: work around a WP user caching bug. --- .../connection/changelog/fix-connection-dotorg-user-cache-bug | 4 ++++ projects/packages/connection/src/class-manager.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 projects/packages/connection/changelog/fix-connection-dotorg-user-cache-bug diff --git a/projects/packages/connection/changelog/fix-connection-dotorg-user-cache-bug b/projects/packages/connection/changelog/fix-connection-dotorg-user-cache-bug new file mode 100644 index 0000000000000..5bafeb387ad19 --- /dev/null +++ b/projects/packages/connection/changelog/fix-connection-dotorg-user-cache-bug @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Work around a WP user caching bug (https://core.trac.wordpress.org/ticket/62003). diff --git a/projects/packages/connection/src/class-manager.php b/projects/packages/connection/src/class-manager.php index 8783dbff1126f..d5523f879809e 100644 --- a/projects/packages/connection/src/class-manager.php +++ b/projects/packages/connection/src/class-manager.php @@ -1625,7 +1625,7 @@ public function get_assumed_site_creation_date() { 'role' => 'administrator', 'orderby' => 'user_registered', 'order' => 'ASC', - 'fields' => array( 'user_registered' ), + 'fields' => array( 'ID', 'user_registered' ), 'number' => 1, ) ); From 0a707bea7e3b45ee3a6a95b440ca5a7210cedaea Mon Sep 17 00:00:00 2001 From: sergeymitr Date: Thu, 14 Nov 2024 11:01:12 -0500 Subject: [PATCH 2/4] Add an explanatory comment. --- projects/packages/connection/src/class-manager.php | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/packages/connection/src/class-manager.php b/projects/packages/connection/src/class-manager.php index d5523f879809e..0710c3e06e8e6 100644 --- a/projects/packages/connection/src/class-manager.php +++ b/projects/packages/connection/src/class-manager.php @@ -1620,6 +1620,7 @@ 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 $earliest_registered_users = get_users( array( 'role' => 'administrator', From c19a13ac5a6d95a6e7d67bc7a610571e20349b01 Mon Sep 17 00:00:00 2001 From: sergeymitr Date: Thu, 14 Nov 2024 12:20:00 -0500 Subject: [PATCH 3/4] Fix unit tests. --- .../tests/php/test-class-connection-notice.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/packages/connection/tests/php/test-class-connection-notice.php b/projects/packages/connection/tests/php/test-class-connection-notice.php index 5fdc1ecfb5934..a93f342ba214f 100644 --- a/projects/packages/connection/tests/php/test-class-connection-notice.php +++ b/projects/packages/connection/tests/php/test-class-connection-notice.php @@ -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; From 38ac0c618132ce53166a43df8b9c5f3e4c7698a3 Mon Sep 17 00:00:00 2001 From: sergeymitr Date: Fri, 15 Nov 2024 10:35:45 -0500 Subject: [PATCH 4/4] Add a ToDo comment. --- projects/packages/connection/src/class-manager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/projects/packages/connection/src/class-manager.php b/projects/packages/connection/src/class-manager.php index 0710c3e06e8e6..5d56946f46609 100644 --- a/projects/packages/connection/src/class-manager.php +++ b/projects/packages/connection/src/class-manager.php @@ -1620,7 +1620,11 @@ 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 + /** + * 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',