Skip to content

Commit 4eff2e9

Browse files
arcangelinimatticbot
authored andcommitted
Help Center: extend post fetch endpoint (#38445)
Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/10160265035 Upstream-Ref: Automattic/jetpack@d94211b
1 parent ea89d6e commit 4eff2e9

File tree

6 files changed

+121
-98
lines changed

6 files changed

+121
-98
lines changed

composer.lock

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
This is an alpha version! The changes listed here are not final.
1111

12+
### Added
13+
- Help Center: extended post fetch endpoint to accept URLs
14+
1215
### Changed
1316
- Admin bar: Force mobile viewport to have the same icon color as desktop
1417
- Blog Privacy: Update Applebot-Extended disallow rule

vendor/automattic/jetpack-mu-wpcom/src/features/help-center/class-wp-rest-help-center-fetch-post.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ public function register_rest_route() {
3333
'methods' => \WP_REST_Server::READABLE,
3434
'callback' => array( $this, 'get_post' ),
3535
'permission_callback' => 'is_user_logged_in',
36+
'args' => array(
37+
'blog_id' => array(
38+
'type' => 'number',
39+
),
40+
'post_id' => array(
41+
'type' => 'number',
42+
),
43+
'post_url' => array(
44+
'type' => 'string',
45+
),
46+
),
3647
)
3748
);
49+
3850
register_rest_route(
3951
$this->namespace,
4052
'/articles',
@@ -60,9 +72,9 @@ public function register_rest_route() {
6072
}
6173

6274
/**
63-
* Should return blog post articles
75+
* Should return blog post articles.
6476
*
65-
* @param \WP_REST_Request $request The request sent to the API.
77+
* @param \WP_REST_Request $request The request sent to the API.
6678
*/
6779
public function get_blog_post_articles( \WP_REST_Request $request ) {
6880
$query_parameters = array(
@@ -83,22 +95,30 @@ public function get_blog_post_articles( \WP_REST_Request $request ) {
8395
}
8496

8597
/**
86-
* Should return the search results
98+
* Should return the post.
8799
*
88-
* @param \WP_REST_Request $request The request sent to the API.
100+
* @param \WP_REST_Request $request The request sent to the API.
89101
*/
90102
public function get_post( \WP_REST_Request $request ) {
91-
$alternate_data = $this->get_post_alternate_data( $request['blog_id'], $request['post_id'] );
92-
if ( is_wp_error( $alternate_data ) ) {
93-
return $alternate_data;
103+
if ( isset( $request['post_url'] ) ) {
104+
$body = Client::wpcom_json_api_request_as_user(
105+
'/help/article?post_url=' . $request['post_url']
106+
);
107+
} else {
108+
$alternate_data = $this->get_post_alternate_data( $request['blog_id'], $request['post_id'] );
109+
if ( is_wp_error( $alternate_data ) ) {
110+
return $alternate_data;
111+
}
112+
113+
$body = Client::wpcom_json_api_request_as_user(
114+
'/help/article/' . $alternate_data['blog_id'] . '/' . $alternate_data['post_id']
115+
);
94116
}
95117

96-
$body = Client::wpcom_json_api_request_as_user(
97-
'/help/article/' . $alternate_data['blog_id'] . '/' . $alternate_data['post_id']
98-
);
99118
if ( is_wp_error( $body ) ) {
100119
return $body;
101120
}
121+
102122
$response = json_decode( wp_remote_retrieve_body( $body ) );
103123

104124
return rest_ensure_response( $response );

vendor/automattic/jetpack-sync/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"automattic/jetpack-changelogger": "^4.2.5",
1717
"yoast/phpunit-polyfills": "1.1.0",
1818
"automattic/jetpack-search": "@dev",
19-
"automattic/jetpack-waf": "@dev",
19+
"automattic/jetpack-waf": "^0.18.0-alpha",
2020
"automattic/wordbless": "@dev"
2121
},
2222
"suggest": {

0 commit comments

Comments
 (0)