Make WordPress Core

Changeset 52372


Ignore:
Timestamp:
12/14/2021 04:12:57 PM (3 years ago)
Author:
hellofromTonya
Message:

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.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/site-editor.php

    r52364 r52372  
    6565}
    6666
    67 $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id();
     67$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
    6868$active_theme            = wp_get_theme()->get_stylesheet();
    6969$preload_paths           = array(
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r52323 r52372  
    226226     * @param WP_Theme $theme              The theme object. If empty, it
    227227     *                                     defaults to the current theme.
    228      * @param bool     $should_create_cpt  Optional. Whether a new custom post
     228     * @param bool     $create_post        Optional. Whether a new custom post
    229229     *                                     type should be created if none are
    230230     *                                     found. Default false.
     
    234234     * @return array Custom Post Type for the user's origin config.
    235235     */
    236     public static function get_user_data_from_custom_post_type( $theme, $should_create_cpt = false, $post_status_filter = array( 'publish' ) ) {
     236    public static function get_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' ) ) {
    237237        if ( ! $theme instanceof WP_Theme ) {
    238238            $theme = wp_get_theme();
     
    263263
    264264        // Special case: '-1' is a results not found.
    265         if ( -1 === $post_id && ! $should_create_cpt ) {
     265        if ( -1 === $post_id && ! $create_post ) {
    266266            return $user_cpt;
    267267        }
     
    270270        if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) {
    271271            $user_cpt = $recent_posts[0];
    272         } elseif ( $should_create_cpt ) {
     272        } elseif ( $create_post ) {
    273273            $cpt_post_id = wp_insert_post(
    274274                array(
     
    297297     * @since 5.9.0
    298298     *
    299      * @return WP_Theme_JSON Entity that holds user data.
     299     * @return WP_Theme_JSON Entity that holds styles for user data.
    300300     */
    301301    public static function get_user_data() {
     
    305305
    306306        $config   = array();
    307         $user_cpt = self::get_user_data_from_custom_post_type( wp_get_theme() );
     307        $user_cpt = self::get_user_data_from_wp_global_styles( wp_get_theme() );
    308308
    309309        if ( array_key_exists( 'post_content', $user_cpt ) ) {
     
    382382     * @return integer|null
    383383     */
    384     public static function get_user_custom_post_type_id() {
     384    public static function get_user_global_styles_post_id() {
    385385        if ( null !== self::$user_custom_post_type_id ) {
    386386            return self::$user_custom_post_type_id;
    387387        }
    388388
    389         $user_cpt = self::get_user_data_from_custom_post_type( wp_get_theme(), true );
     389        $user_cpt = self::get_user_data_from_wp_global_styles( wp_get_theme(), true );
    390390
    391391        if ( array_key_exists( 'ID', $user_cpt ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php

    r52275 r52372  
    319319        if ( $theme->get_stylesheet() === wp_get_theme()->get_stylesheet() ) {
    320320            // This creates a record for the current theme if not existent.
    321             $id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id();
     321            $id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
    322322        } else {
    323             $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( $theme );
     323            $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme );
    324324            $id       = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null;
    325325        }
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r52275 r52372  
    322322    }
    323323
    324     function test_get_user_data_from_custom_post_type_does_not_use_uncached_queries() {
     324    function test_get_user_data_from_wp_global_styles_does_not_use_uncached_queries() {
    325325        add_filter( 'query', array( $this, 'filter_db_query' ) );
    326326        $query_count = count( $this->queries );
    327327        for ( $i = 0; $i < 3; $i++ ) {
    328             WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme() );
     328            WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( wp_get_theme() );
    329329            WP_Theme_JSON_Resolver::clean_cached_data();
    330330        }
    331331        $query_count = count( $this->queries ) - $query_count;
    332         $this->assertEquals( 1, $query_count, 'Only one SQL query should be peformed for multiple invocations of WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type()' );
    333 
    334         $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme() );
     332        $this->assertEquals( 1, $query_count, 'Only one SQL query should be peformed for multiple invocations of WP_Theme_JSON_Resolver::get_global_styles_from_post()' );
     333
     334        $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( wp_get_theme() );
    335335        $this->assertEmpty( $user_cpt );
    336336
    337         $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme(), true );
     337        $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( wp_get_theme(), true );
    338338        $this->assertNotEmpty( $user_cpt );
    339339
    340340        $query_count = count( $this->queries );
    341341        for ( $i = 0; $i < 3; $i++ ) {
    342             WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( wp_get_theme() );
     342            WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( wp_get_theme() );
    343343            WP_Theme_JSON_Resolver::clean_cached_data();
    344344        }
Note: See TracChangeset for help on using the changeset viewer.