From 65a419914916ab18f1096dca82e7c87dd8ca714e Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Tue, 14 Dec 2021 16:14:01 +0000 Subject: [PATCH] Themes: Rename public static functions in `WP_Theme_JSON_Resolver` to remove `custom_post_type` references. WordPress Core is not really custom and does not reference "custom post type" in its function naming. This commit renames 2 public static methods: * `WP_Theme_JSON_Resolver::get_user_custom_post_type_id()` renamed to `WP_Theme_JSON_Resolver::get_user_global_styles_post_id()`. * `WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type()` renamed to `WP_Theme_JSON_Resolver:: get_user_data_from_wp_global_styles()`. Follow-up to [52049], [52051], [52069], [52232], [52275], [52364]. Props antonvlasenko, bernhard-reiter, costdev, desrosj, hellofromTonya, noisysocks, oandregal, SergeyBiryukov. Fixes #54517. Built from https://develop.svn.wordpress.org/trunk@52372 git-svn-id: http://core.svn.wordpress.org/trunk@51964 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/site-editor.php | 2 +- wp-includes/class-wp-theme-json-resolver.php | 16 ++++++++-------- .../class-wp-rest-themes-controller.php | 4 ++-- wp-includes/version.php | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/wp-admin/site-editor.php b/wp-admin/site-editor.php index f038452b08..421ceb4861 100644 --- a/wp-admin/site-editor.php +++ b/wp-admin/site-editor.php @@ -64,7 +64,7 @@ if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { } } -$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id(); +$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); $active_theme = wp_get_theme()->get_stylesheet(); $preload_paths = array( array( '/wp/v2/media', 'OPTIONS' ), diff --git a/wp-includes/class-wp-theme-json-resolver.php b/wp-includes/class-wp-theme-json-resolver.php index 339a2ff0c5..38df6cebf1 100644 --- a/wp-includes/class-wp-theme-json-resolver.php +++ b/wp-includes/class-wp-theme-json-resolver.php @@ -225,7 +225,7 @@ class WP_Theme_JSON_Resolver { * * @param WP_Theme $theme The theme object. If empty, it * defaults to the current theme. - * @param bool $should_create_cpt Optional. Whether a new custom post + * @param bool $create_post Optional. Whether a new custom post * type should be created if none are * found. Default false. * @param array $post_status_filter Optional. Filter custom post type by @@ -233,7 +233,7 @@ class WP_Theme_JSON_Resolver { * so it only fetches published posts. * @return array Custom Post Type for the user's origin config. */ - public static function get_user_data_from_custom_post_type( $theme, $should_create_cpt = false, $post_status_filter = array( 'publish' ) ) { + public static function get_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' ) ) { if ( ! $theme instanceof WP_Theme ) { $theme = wp_get_theme(); } @@ -262,14 +262,14 @@ class WP_Theme_JSON_Resolver { } // Special case: '-1' is a results not found. - if ( -1 === $post_id && ! $should_create_cpt ) { + if ( -1 === $post_id && ! $create_post ) { return $user_cpt; } $recent_posts = wp_get_recent_posts( $args ); if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) { $user_cpt = $recent_posts[0]; - } elseif ( $should_create_cpt ) { + } elseif ( $create_post ) { $cpt_post_id = wp_insert_post( array( 'post_content' => '{"version": ' . WP_Theme_JSON::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }', @@ -296,7 +296,7 @@ class WP_Theme_JSON_Resolver { * * @since 5.9.0 * - * @return WP_Theme_JSON Entity that holds user data. + * @return WP_Theme_JSON Entity that holds styles for user data. */ public static function get_user_data() { if ( null !== self::$user ) { @@ -304,7 +304,7 @@ class WP_Theme_JSON_Resolver { } $config = array(); - $user_cpt = self::get_user_data_from_custom_post_type( wp_get_theme() ); + $user_cpt = self::get_user_data_from_wp_global_styles( wp_get_theme() ); if ( array_key_exists( 'post_content', $user_cpt ) ) { $decoded_data = json_decode( $user_cpt['post_content'], true ); @@ -381,12 +381,12 @@ class WP_Theme_JSON_Resolver { * * @return integer|null */ - public static function get_user_custom_post_type_id() { + public static function get_user_global_styles_post_id() { if ( null !== self::$user_custom_post_type_id ) { return self::$user_custom_post_type_id; } - $user_cpt = self::get_user_data_from_custom_post_type( wp_get_theme(), true ); + $user_cpt = self::get_user_data_from_wp_global_styles( wp_get_theme(), true ); if ( array_key_exists( 'ID', $user_cpt ) ) { self::$user_custom_post_type_id = $user_cpt['ID']; diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 76f963209f..0d6ffd0da2 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -318,9 +318,9 @@ class WP_REST_Themes_Controller extends WP_REST_Controller { if ( $theme->get_stylesheet() === wp_get_theme()->get_stylesheet() ) { // This creates a record for the current theme if not existent. - $id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id(); + $id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); } else { - $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( $theme ); + $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); $id = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 6d6cb89f1b..c859e32a78 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-beta2-52371'; +$wp_version = '5.9-beta2-52372'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.