From 02c15d24548e8156477b0c100392ac16c63b29bc Mon Sep 17 00:00:00 2001 From: Miguel Lezama Date: Wed, 21 Jun 2023 19:46:50 -0300 Subject: [PATCH 1/4] remove `rest_route` query arg --- .../trait-wpcom-rest-api-proxy-request-trait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php index 8d6d79d74fe3b..ec326f02ae302 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php @@ -23,7 +23,7 @@ trait WPCOM_REST_API_Proxy_Request_Trait { public function proxy_request_to_wpcom_as_user( $request, $path = '' ) { $blog_id = \Jetpack_Options::get_option( 'id' ); $path = '/sites/' . rawurldecode( $blog_id ) . rawurldecode( $this->rest_base ) . ( $path ? '/' . rawurldecode( $path ) : '' ); - $api_url = add_query_arg( $request->get_query_params(), $path ); + $api_url = remove_query_arg( 'rest_route', add_query_arg( $request->get_query_params(), $path ) ); $request_options = array( 'headers' => array( From 587ad0af08148616b1b52b56a5590ca40e76f3e3 Mon Sep 17 00:00:00 2001 From: Miguel Lezama Date: Wed, 21 Jun 2023 19:52:08 -0300 Subject: [PATCH 2/4] changelog --- .../plugins/jetpack/changelog/fix-send-email-preview-endpoint | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/fix-send-email-preview-endpoint diff --git a/projects/plugins/jetpack/changelog/fix-send-email-preview-endpoint b/projects/plugins/jetpack/changelog/fix-send-email-preview-endpoint new file mode 100644 index 0000000000000..5a52482855b58 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-send-email-preview-endpoint @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix +Comment: fixes send preview email not working when using plain permalink + From 1db72eb2b268ae39770138db92710d6566f222c2 Mon Sep 17 00:00:00 2001 From: Miguel Lezama Date: Thu, 22 Jun 2023 10:40:59 -0300 Subject: [PATCH 3/4] we could be a bit more verbose Co-authored-by: Jeremy Herve --- .../trait-wpcom-rest-api-proxy-request-trait.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php index ec326f02ae302..685c2a13fb119 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php @@ -23,7 +23,18 @@ trait WPCOM_REST_API_Proxy_Request_Trait { public function proxy_request_to_wpcom_as_user( $request, $path = '' ) { $blog_id = \Jetpack_Options::get_option( 'id' ); $path = '/sites/' . rawurldecode( $blog_id ) . rawurldecode( $this->rest_base ) . ( $path ? '/' . rawurldecode( $path ) : '' ); - $api_url = remove_query_arg( 'rest_route', add_query_arg( $request->get_query_params(), $path ) ); + $query_params = $request->get_query_params(); + + /* + * A rest_route parameter can be added when using plain permalinks. + * It is not necessary to pass them to WordPress.com, + * and may even cause issues with some endpoints. + * Let's remove it. + */ + if ( isset( $query_params['rest_route'] ) ) { + unset( $query_params['rest_route'] ); + } + $api_url = add_query_arg( $query_params, $path ); $request_options = array( 'headers' => array( From 6048eef5d9081ef6a54bd0e1cacab75d239b3e67 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Thu, 22 Jun 2023 16:07:54 +0200 Subject: [PATCH 4/4] Fix linting error --- .../trait-wpcom-rest-api-proxy-request-trait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php index 685c2a13fb119..242c1568414de 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/trait-wpcom-rest-api-proxy-request-trait.php @@ -21,8 +21,8 @@ trait WPCOM_REST_API_Proxy_Request_Trait { * @return mixed|WP_Error Response from wpcom servers or an error. */ public function proxy_request_to_wpcom_as_user( $request, $path = '' ) { - $blog_id = \Jetpack_Options::get_option( 'id' ); - $path = '/sites/' . rawurldecode( $blog_id ) . rawurldecode( $this->rest_base ) . ( $path ? '/' . rawurldecode( $path ) : '' ); + $blog_id = \Jetpack_Options::get_option( 'id' ); + $path = '/sites/' . rawurldecode( $blog_id ) . rawurldecode( $this->rest_base ) . ( $path ? '/' . rawurldecode( $path ) : '' ); $query_params = $request->get_query_params(); /*