|
17 | 17 | */
|
18 | 18 | class WP_Theme_JSON_Resolver_6_2 extends WP_Theme_JSON_Resolver_Base {
|
19 | 19 |
|
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 |
| - |
100 | 20 | /**
|
101 | 21 | * Returns the data merged from multiple origins.
|
102 | 22 | *
|
|
0 commit comments