Changeset 54186 for trunk/src/wp-includes/class-wp-theme-json-resolver.php
- Timestamp:
- 09/16/2022 10:55:58 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r54162 r54186 305 305 $user_cpt = array(); 306 306 $post_type_filter = 'wp_global_styles'; 307 $stylesheet = $theme->get_stylesheet(); 307 308 $args = array( 308 'numberposts' => 1, 309 'orderby' => 'date', 310 'order' => 'desc', 311 'post_type' => $post_type_filter, 312 'post_status' => $post_status_filter, 313 'tax_query' => array( 309 'posts_per_page' => 1, 310 'orderby' => 'post_date', 311 'order' => 'desc', 312 'post_type' => $post_type_filter, 313 'post_status' => $post_status_filter, 314 'ignore_sticky_posts' => true, 315 'no_found_rows' => true, 316 'tax_query' => array( 314 317 array( 315 318 'taxonomy' => 'wp_theme', 316 319 'field' => 'name', 317 'terms' => $ theme->get_stylesheet(),320 'terms' => $stylesheet, 318 321 ), 319 322 ), … … 321 324 322 325 $cache_key = sprintf( 'wp_global_styles_%s', md5( serialize( $args ) ) ); 323 $post_id = wp_cache_get( $cache_key ); 324 325 if ( (int) $post_id > 0 ) { 326 return get_post( $post_id, ARRAY_A ); 327 } 328 326 $post_id = (int) get_transient( $cache_key ); 329 327 // Special case: '-1' is a results not found. 330 328 if ( -1 === $post_id && ! $create_post ) { … … 332 330 } 333 331 334 $recent_posts = wp_get_recent_posts( $args ); 335 if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) { 336 $user_cpt = $recent_posts[0]; 332 if ( $post_id > 0 && in_array( get_post_status( $post_id ), (array) $post_status_filter, true ) ) { 333 return get_post( $post_id, ARRAY_A ); 334 } 335 336 $global_style_query = new WP_Query(); 337 $recent_posts = $global_style_query->query( $args ); 338 if ( count( $recent_posts ) === 1 ) { 339 $user_cpt = get_post( $recent_posts[0], ARRAY_A ); 337 340 } elseif ( $create_post ) { 338 341 $cpt_post_id = wp_insert_post( … … 340 343 'post_content' => '{"version": ' . WP_Theme_JSON::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }', 341 344 'post_status' => 'publish', 342 'post_title' => 'Custom Styles',345 'post_title' => __( 'Custom Styles' ), 343 346 'post_type' => $post_type_filter, 344 'post_name' => 'wp-global-styles-' . urlencode( wp_get_theme()->get_stylesheet() ),347 'post_name' => sprintf( 'wp-global-styles-%s', urlencode( $stylesheet ) ), 345 348 'tax_input' => array( 346 'wp_theme' => array( wp_get_theme()->get_stylesheet()),349 'wp_theme' => array( $stylesheet ), 347 350 ), 348 351 ), 349 352 true 350 353 ); 351 $user_cpt = get_post( $cpt_post_id, ARRAY_A ); 354 if ( ! is_wp_error( $cpt_post_id ) ) { 355 $user_cpt = get_post( $cpt_post_id, ARRAY_A ); 356 } 352 357 } 353 358 $cache_expiration = $user_cpt ? DAY_IN_SECONDS : HOUR_IN_SECONDS; 354 wp_cache_set( $cache_key, $user_cpt ? $user_cpt['ID'] : -1, '', $cache_expiration );359 set_transient( $cache_key, $user_cpt ? $user_cpt['ID'] : -1, $cache_expiration ); 355 360 356 361 return $user_cpt;
Note: See TracChangeset
for help on using the changeset viewer.