From c6498132ea5618d6aa41f67042450e471d8f298d Mon Sep 17 00:00:00 2001 From: coder-karen Date: Mon, 9 Dec 2024 12:27:50 +0000 Subject: [PATCH] Jetpack SEO: Ensure we add post type support for custom fields (#40334) Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12235386837 Upstream-Ref: Automattic/jetpack@d4db55165f1fc39f530096ea3f095b156f4f8f2c --- CHANGELOG.md | 1 + modules/seo-tools/class-jetpack-seo.php | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf09b4684..4b17d55dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This is an alpha version! The changes listed here are not final. ### Improved compatibility - External media: Google Photos Picker: Update UX opening picker right after pressing "change selection" CTA +- Jetpack SEO: Ensures we now support adding an SEO title and description for custom post types. ### Bug fixes - Google Fonts: Clean up the google fonts data if either google fonts module is disabled or Jetpack is disabled diff --git a/modules/seo-tools/class-jetpack-seo.php b/modules/seo-tools/class-jetpack-seo.php index 8aec75b411..283b1d8ccf 100644 --- a/modules/seo-tools/class-jetpack-seo.php +++ b/modules/seo-tools/class-jetpack-seo.php @@ -57,6 +57,39 @@ public function init() { Jetpack_SEO_Posts::register_post_meta(); // Exclude posts with 'jetpack_seo_noindex' set true from the Jetpack sitemap. add_filter( 'jetpack_sitemap_skip_post', array( 'Jetpack_SEO_Posts', 'exclude_noindex_posts_from_jetpack_sitemap' ), 10, 2 ); + add_action( 'rest_api_init', array( $this, 'add_custom_field_post_type_meta' ) ); + } + + /** + * Add custom field meta to all public post types that don't already have it. + */ + public function add_custom_field_post_type_meta() { + /** + * Filter the list of post types for which custom fields support is added. + * + * This filter allows modification of the post types that will be processed + * to add support for custom fields if they do not already support it. + * + * @since 14.2-a.0 + * + * @param array $post_types An array of post type names. + */ + $post_types = apply_filters( + 'jetpack_seo_custom_field_post_types', + get_post_types( + array( + 'public' => true, + 'show_ui' => true, + '_builtin' => false, + ) + ) + ); + + foreach ( $post_types as $post_type ) { + if ( ! post_type_supports( $post_type, 'custom-fields' ) ) { + add_post_type_support( $post_type, 'custom-fields' ); + } + } } /**