Skip to content

Commit fe37493

Browse files
committed
6.2: port changes to get_user_data_from_wp_global_styles
#46043
1 parent fc639bc commit fe37493

File tree

2 files changed

+13
-91
lines changed

2 files changed

+13
-91
lines changed

lib/class-wp-theme-json-resolver.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
407407
/*
408408
* Bail early if the theme does not support a theme.json.
409409
*
410-
* Since wp_theme_has_theme_json() only supports the active
410+
* Since wp_theme_has_theme_json only supports the active
411411
* theme, the extra condition for whether $theme is the active theme is
412412
* present here.
413413
*/
@@ -419,14 +419,16 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
419419
$post_type_filter = 'wp_global_styles';
420420
$stylesheet = $theme->get_stylesheet();
421421
$args = array(
422-
'posts_per_page' => 1,
423-
'orderby' => 'date',
424-
'order' => 'desc',
425-
'post_type' => $post_type_filter,
426-
'post_status' => $post_status_filter,
427-
'ignore_sticky_posts' => true,
428-
'no_found_rows' => true,
429-
'tax_query' => array(
422+
'posts_per_page' => 1,
423+
'orderby' => 'date',
424+
'order' => 'desc',
425+
'post_type' => $post_type_filter,
426+
'post_status' => $post_status_filter,
427+
'ignore_sticky_posts' => true,
428+
'no_found_rows' => true,
429+
'update_post_meta_cache' => false,
430+
'update_post_term_cache' => false,
431+
'tax_query' => array(
430432
array(
431433
'taxonomy' => 'wp_theme',
432434
'field' => 'name',
@@ -438,7 +440,7 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
438440
$global_style_query = new WP_Query();
439441
$recent_posts = $global_style_query->query( $args );
440442
if ( count( $recent_posts ) === 1 ) {
441-
$user_cpt = get_post( $recent_posts[0], ARRAY_A );
443+
$user_cpt = get_object_vars( $recent_posts[0] );
442444
} elseif ( $create_post ) {
443445
$cpt_post_id = wp_insert_post(
444446
array(
@@ -454,7 +456,7 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
454456
true
455457
);
456458
if ( ! is_wp_error( $cpt_post_id ) ) {
457-
$user_cpt = get_post( $cpt_post_id, ARRAY_A );
459+
$user_cpt = get_object_vars( get_post( $cpt_post_id ) );
458460
}
459461
}
460462

lib/compat/wordpress-6.2/class-wp-theme-json-resolver-6-2.php

-80
Original file line numberDiff line numberDiff line change
@@ -17,86 +17,6 @@
1717
*/
1818
class WP_Theme_JSON_Resolver_6_2 extends WP_Theme_JSON_Resolver_Base {
1919

20-
/**
21-
* Returns the custom post type that contains the user's origin config
22-
* for the active theme or a void array if none are found.
23-
*
24-
* This can also create and return a new draft custom post type.
25-
*
26-
* @param WP_Theme $theme The theme object. If empty, it
27-
* defaults to the active theme.
28-
* @param bool $create_post Optional. Whether a new custom post
29-
* type should be created if none are
30-
* found. Default false.
31-
* @param array $post_status_filter Optional. Filter custom post type by
32-
* post status. Default `array( 'publish' )`,
33-
* so it only fetches published posts.
34-
* @return array Custom Post Type for the user's origin config.
35-
*/
36-
public static function get_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' ) ) {
37-
if ( ! $theme instanceof WP_Theme ) {
38-
$theme = wp_get_theme();
39-
}
40-
41-
/*
42-
* Bail early if the theme does not support a theme.json.
43-
*
44-
* Since wp_theme_has_theme_json only supports the active
45-
* theme, the extra condition for whether $theme is the active theme is
46-
* present here.
47-
*/
48-
if ( $theme->get_stylesheet() === get_stylesheet() && ! wp_theme_has_theme_json() ) {
49-
return array();
50-
}
51-
52-
$user_cpt = array();
53-
$post_type_filter = 'wp_global_styles';
54-
$stylesheet = $theme->get_stylesheet();
55-
$args = array(
56-
'posts_per_page' => 1,
57-
'orderby' => 'date',
58-
'order' => 'desc',
59-
'post_type' => $post_type_filter,
60-
'post_status' => $post_status_filter,
61-
'ignore_sticky_posts' => true,
62-
'no_found_rows' => true,
63-
'update_post_meta_cache' => false,
64-
'update_post_term_cache' => false,
65-
'tax_query' => array(
66-
array(
67-
'taxonomy' => 'wp_theme',
68-
'field' => 'name',
69-
'terms' => $stylesheet,
70-
),
71-
),
72-
);
73-
74-
$global_style_query = new WP_Query();
75-
$recent_posts = $global_style_query->query( $args );
76-
if ( count( $recent_posts ) === 1 ) {
77-
$user_cpt = get_object_vars( $recent_posts[0] );
78-
} elseif ( $create_post ) {
79-
$cpt_post_id = wp_insert_post(
80-
array(
81-
'post_content' => '{"version": ' . WP_Theme_JSON::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }',
82-
'post_status' => 'publish',
83-
'post_title' => 'Custom Styles', // Do not make string translatable, see https://core.trac.wordpress.org/ticket/54518.
84-
'post_type' => $post_type_filter,
85-
'post_name' => sprintf( 'wp-global-styles-%s', urlencode( $stylesheet ) ),
86-
'tax_input' => array(
87-
'wp_theme' => array( $stylesheet ),
88-
),
89-
),
90-
true
91-
);
92-
if ( ! is_wp_error( $cpt_post_id ) ) {
93-
$user_cpt = get_object_vars( get_post( $cpt_post_id ) );
94-
}
95-
}
96-
97-
return $user_cpt;
98-
}
99-
10020
/**
10121
* Returns the data merged from multiple origins.
10222
*

0 commit comments

Comments
 (0)