From 183fdba235406414d772d7dbaebd42b6a2d2fdfb Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Wed, 28 May 2025 10:46:26 -0600 Subject: [PATCH 1/3] Add wp_parsely_stats_posts_urls filter --- src/rest-api/stats/class-endpoint-posts.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/rest-api/stats/class-endpoint-posts.php b/src/rest-api/stats/class-endpoint-posts.php index 0af8a1cee1..3ab7faa1ea 100644 --- a/src/rest-api/stats/class-endpoint-posts.php +++ b/src/rest-api/stats/class-endpoint-posts.php @@ -326,6 +326,15 @@ public function get_posts( WP_REST_Request $request ) { $params['urls'] = $new_urls; } + /** + * Allow adjustments to post URLs before request. Useful for testing non-local URLs, or mirroring site content. + * + * @since 3.19.1 + * + * @param array|null $urls The URLs to be used in the request. + */ + $params['urls'] = apply_filters( 'wp_parsely_stats_posts_urls', $params['urls'] ); + // Build the request params. $request_params = array( 'period_start' => $params['period_start'] ?? null, From bd7036f29e0399cd87fe9af2e52a6a5d60f7ac18 Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Wed, 28 May 2025 10:52:52 -0600 Subject: [PATCH 2/3] Ensure $params['urls'] has a value or return null --- src/rest-api/stats/class-endpoint-posts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rest-api/stats/class-endpoint-posts.php b/src/rest-api/stats/class-endpoint-posts.php index 3ab7faa1ea..2944c28e6c 100644 --- a/src/rest-api/stats/class-endpoint-posts.php +++ b/src/rest-api/stats/class-endpoint-posts.php @@ -333,7 +333,7 @@ public function get_posts( WP_REST_Request $request ) { * * @param array|null $urls The URLs to be used in the request. */ - $params['urls'] = apply_filters( 'wp_parsely_stats_posts_urls', $params['urls'] ); + $params['urls'] = apply_filters( 'wp_parsely_stats_posts_urls', $params['urls'] ?? null ); // Build the request params. $request_params = array( From 96c715d645efd7968ea766e1133fc7ae77299c33 Mon Sep 17 00:00:00 2001 From: Alec Geatches Date: Wed, 28 May 2025 10:57:12 -0600 Subject: [PATCH 3/3] Only run filter when an array is present to avoid side-effects on returned parameters --- src/rest-api/stats/class-endpoint-posts.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/rest-api/stats/class-endpoint-posts.php b/src/rest-api/stats/class-endpoint-posts.php index 2944c28e6c..4429ac5bf8 100644 --- a/src/rest-api/stats/class-endpoint-posts.php +++ b/src/rest-api/stats/class-endpoint-posts.php @@ -326,14 +326,16 @@ public function get_posts( WP_REST_Request $request ) { $params['urls'] = $new_urls; } - /** - * Allow adjustments to post URLs before request. Useful for testing non-local URLs, or mirroring site content. - * - * @since 3.19.1 - * - * @param array|null $urls The URLs to be used in the request. - */ - $params['urls'] = apply_filters( 'wp_parsely_stats_posts_urls', $params['urls'] ?? null ); + if ( isset( $params['urls'] ) && is_array( $params['urls'] ) ) { + /** + * Allow adjustments to post URLs before request. Useful for testing non-local URLs, or mirroring site content. + * + * @since 3.19.1 + * + * @param array $urls The URLs to be used in the request. + */ + $params['urls'] = apply_filters( 'wp_parsely_stats_posts_urls', $params['urls'] ); + } // Build the request params. $request_params = array(