Skip to content

Commit 227c16a

Browse files
authored
Forms: remove related-posts from API calls (#45928)
1 parent 2b61af7 commit 227c16a

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Forms: remove related-posts from API calls

projects/packages/forms/src/contact-form/class-contact-form-plugin.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ protected function __construct() {
268268
// Add to REST API post type allowed list.
269269
add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_feedback_rest_api_type' ) );
270270

271+
// Don't let related posts hook into feedback post type.
272+
add_filter( 'jetpack_related_posts_rest_api_allowed_post_types', array( $this, 'remove_from_related_posts_allowed_post_types' ) );
273+
271274
// Add "spam" as a post status
272275
register_post_status(
273276
'spam',
@@ -351,6 +354,16 @@ protected function __construct() {
351354
}
352355
}
353356

357+
/**
358+
* Remove feedback post type from the allowed post types for related posts.
359+
*
360+
* @param array $post_types The allowed post types.
361+
* @return array The allowed post types.
362+
*/
363+
public static function remove_from_related_posts_allowed_post_types( $post_types ) {
364+
return array_diff( $post_types, array( 'feedback' ) );
365+
}
366+
354367
/**
355368
* Prevent 'jp-forms-view' script from being concatenated.
356369
*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: enhancement
3+
4+
Forms: remove related-posts from API calls

projects/plugins/jetpack/modules/related-posts/jetpack-related-posts.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,16 @@ protected function allow_feature_toggle() {
20332033
public function rest_register_related_posts() {
20342034
/** This filter is already documented in class.json-api-endpoints.php */
20352035
$post_types = apply_filters( 'rest_api_allowed_post_types', array( 'post', 'page', 'revision' ) );
2036+
2037+
/**
2038+
* Filter the post types that are allowed to have related posts.
2039+
*
2040+
* @since $$next-version$$
2041+
*
2042+
* @param array $post_types The post types that are allowed to have related posts.
2043+
*/
2044+
$post_types = apply_filters( 'jetpack_related_posts_rest_api_allowed_post_types', $post_types );
2045+
20362046
foreach ( $post_types as $post_type ) {
20372047
register_rest_field(
20382048
$post_type,

0 commit comments

Comments
 (0)