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
This commit is contained in:
hellofromTonya 2021-12-14 16:14:01 +00:00
parent edf755823b
commit 65a4199149
4 changed files with 12 additions and 12 deletions

View File

@ -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' ),

View File

@ -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'];

View File

@ -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;
}

View File

@ -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.