Changeset 52372
- Timestamp:
- 12/14/2021 04:12:57 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/site-editor.php
r52364 r52372 65 65 } 66 66 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(); 68 68 $active_theme = wp_get_theme()->get_stylesheet(); 69 69 $preload_paths = array( -
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r52323 r52372 226 226 * @param WP_Theme $theme The theme object. If empty, it 227 227 * defaults to the current theme. 228 * @param bool $ should_create_cptOptional. Whether a new custom post228 * @param bool $create_post Optional. Whether a new custom post 229 229 * type should be created if none are 230 230 * found. Default false. … … 234 234 * @return array Custom Post Type for the user's origin config. 235 235 */ 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' ) ) { 237 237 if ( ! $theme instanceof WP_Theme ) { 238 238 $theme = wp_get_theme(); … … 263 263 264 264 // Special case: '-1' is a results not found. 265 if ( -1 === $post_id && ! $ should_create_cpt ) {265 if ( -1 === $post_id && ! $create_post ) { 266 266 return $user_cpt; 267 267 } … … 270 270 if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) { 271 271 $user_cpt = $recent_posts[0]; 272 } elseif ( $ should_create_cpt ) {272 } elseif ( $create_post ) { 273 273 $cpt_post_id = wp_insert_post( 274 274 array( … … 297 297 * @since 5.9.0 298 298 * 299 * @return WP_Theme_JSON Entity that holds user data.299 * @return WP_Theme_JSON Entity that holds styles for user data. 300 300 */ 301 301 public static function get_user_data() { … … 305 305 306 306 $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() ); 308 308 309 309 if ( array_key_exists( 'post_content', $user_cpt ) ) { … … 382 382 * @return integer|null 383 383 */ 384 public static function get_user_ custom_post_type_id() {384 public static function get_user_global_styles_post_id() { 385 385 if ( null !== self::$user_custom_post_type_id ) { 386 386 return self::$user_custom_post_type_id; 387 387 } 388 388 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 ); 390 390 391 391 if ( array_key_exists( 'ID', $user_cpt ) ) { -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
r52275 r52372 319 319 if ( $theme->get_stylesheet() === wp_get_theme()->get_stylesheet() ) { 320 320 // 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(); 322 322 } 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 ); 324 324 $id = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null; 325 325 } -
trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php
r52275 r52372 322 322 } 323 323 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() { 325 325 add_filter( 'query', array( $this, 'filter_db_query' ) ); 326 326 $query_count = count( $this->queries ); 327 327 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() ); 329 329 WP_Theme_JSON_Resolver::clean_cached_data(); 330 330 } 331 331 $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() ); 335 335 $this->assertEmpty( $user_cpt ); 336 336 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 ); 338 338 $this->assertNotEmpty( $user_cpt ); 339 339 340 340 $query_count = count( $this->queries ); 341 341 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() ); 343 343 WP_Theme_JSON_Resolver::clean_cached_data(); 344 344 }
Note: See TracChangeset
for help on using the changeset viewer.