Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of static methods and properties in WP_Theme_JSON_Resolver. #3540

Draft
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-admin/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @global string $title
* @global array $wp_meta_boxes
*/
global $post_type, $post_type_object, $post, $title, $wp_meta_boxes;
global $post_type, $post_type_object, $post, $title, $wp_meta_boxes, $wp_theme_json_resolver;

$block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) );

Expand Down Expand Up @@ -203,7 +203,7 @@ static function( $classes ) {
'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
),
'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(),
'supportsLayout' => $wp_theme_json_resolver->theme_has_support(),
'supportsTemplateMode' => current_theme_supports( 'block-templates' ),

// Whether or not to load the 'postcustom' meta box is stored as a user meta
Expand Down
6 changes: 3 additions & 3 deletions src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @subpackage Administration
*/

global $editor_styles;
global $editor_styles, $wp_theme_json_resolver;

/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';
Expand Down Expand Up @@ -74,7 +74,7 @@ static function( $classes ) {
'styles' => get_block_editor_theme_styles(),
'defaultTemplateTypes' => $indexed_template_types,
'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(),
'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(),
'supportsLayout' => $wp_theme_json_resolver->theme_has_support(),
'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
'__unstableHomeTemplate' => $home_template,
);
Expand All @@ -100,7 +100,7 @@ static function( $classes ) {
}
}

$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
$active_global_styles_id = $wp_theme_json_resolver->get_user_global_styles_post_id();
$active_theme = get_stylesheet();
$preload_paths = array(
array( '/wp/v2/media', 'OPTIONS' ),
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ function _wp_get_iframed_editor_assets() {
* @return array The contextualized block editor settings.
*/
function get_block_editor_settings( array $custom_settings, $block_editor_context ) {
global $wp_theme_json_resolver;
$editor_settings = array_merge(
get_default_block_editor_settings(),
array(
Expand Down Expand Up @@ -417,7 +418,7 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
}
}

if ( WP_Theme_JSON_Resolver::theme_has_support() ) {
if ( $wp_theme_json_resolver->theme_has_support() ) {
$block_classes = array(
'css' => 'styles',
'__unstableType' => 'theme',
Expand Down
5 changes: 3 additions & 2 deletions src/wp-includes/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ function _load_remote_featured_patterns() {
* @access private
*/
function _register_remote_theme_patterns() {
global $wp_theme_json_resolver;
/** This filter is documented in wp-includes/block-patterns.php */
if ( ! apply_filters( 'should_load_remote_block_patterns', true ) ) {
return;
}

if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
if ( ! $wp_theme_json_resolver->theme_has_support() ) {
return;
}

$pattern_settings = WP_Theme_JSON_Resolver::get_theme_data()->get_patterns();
$pattern_settings = $wp_theme_json_resolver->get_theme_data()->get_patterns();
if ( empty( $pattern_settings ) ) {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions src/wp-includes/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,15 @@ function wp_render_layout_support_flag( $block_content, $block ) {
* @return string Filtered block content.
*/
function wp_restore_group_inner_container( $block_content, $block ) {
global $wp_theme_json_resolver;
$tag_name = isset( $block['attrs']['tagName'] ) ? $block['attrs']['tagName'] : 'div';
$group_with_inner_container_regex = sprintf(
'/(^\s*<%1$s\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/U',
preg_quote( $tag_name, '/' )
);

if (
WP_Theme_JSON_Resolver::theme_has_support() ||
$wp_theme_json_resolver->theme_has_support() ||
1 === preg_match( $group_with_inner_container_regex, $block_content ) ||
( isset( $block['attrs']['layout']['type'] ) && 'flex' === $block['attrs']['layout']['type'] )
) {
Expand Down Expand Up @@ -500,6 +501,7 @@ static function( $matches ) {
* @return string Filtered block content.
*/
function wp_restore_image_outer_container( $block_content, $block ) {
global $wp_theme_json_resolver;
$image_with_align = "
/# 1) everything up to the class attribute contents
(
Expand Down Expand Up @@ -527,7 +529,7 @@ function wp_restore_image_outer_container( $block_content, $block ) {
)/iUx";

if (
WP_Theme_JSON_Resolver::theme_has_support() ||
$wp_theme_json_resolver->theme_has_support() ||
0 === preg_match( $image_with_align, $block_content, $matches )
) {
return $block_content;
Expand Down
18 changes: 10 additions & 8 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,12 @@ function _get_block_templates_files( $template_type ) {
* @return array Template item.
*/
function _add_block_template_info( $template_item ) {
if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
global $wp_theme_json_resolver;
if ( ! $wp_theme_json_resolver->theme_has_support() ) {
return $template_item;
}

$theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates();
$theme_data = $wp_theme_json_resolver->get_theme_data()->get_custom_templates();
if ( isset( $theme_data[ $template_item['slug'] ] ) ) {
$template_item['title'] = $theme_data[ $template_item['slug'] ]['title'];
$template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes'];
Expand All @@ -370,8 +371,9 @@ function _add_block_template_info( $template_item ) {
* @return array Template info.
*/
function _add_block_template_part_area_info( $template_info ) {
if ( WP_Theme_JSON_Resolver::theme_has_support() ) {
$theme_data = WP_Theme_JSON_Resolver::get_theme_data()->get_template_parts();
global $wp_theme_json_resolver;
if ( $wp_theme_json_resolver->theme_has_support() ) {
$theme_data = $wp_theme_json_resolver->get_theme_data()->get_template_parts();
}

if ( isset( $theme_data[ $template_info['slug'] ]['area'] ) ) {
Expand Down Expand Up @@ -1205,8 +1207,8 @@ function wp_is_theme_directory_ignored( $path ) {
* @return WP_Error|string Path of the ZIP file or error on failure.
*/
function wp_generate_block_templates_export_file() {
global $wp_version;

global $wp_theme_json_resolver, $wp_version;
if ( ! class_exists( 'ZipArchive' ) ) {
return new WP_Error( 'missing_zip_package', __( 'Zip Export not supported.' ) );
}
Expand Down Expand Up @@ -1267,9 +1269,9 @@ function wp_generate_block_templates_export_file() {
}

// Load theme.json into the zip file.
$tree = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) );
$tree = $wp_theme_json_resolver->get_theme_data( array(), array( 'with_supports' => false ) );
// Merge with user data.
$tree->merge( WP_Theme_JSON_Resolver::get_user_data() );
$tree->merge( $wp_theme_json_resolver->get_user_data() );

$theme_json_raw = $tree->get_data();
// If a version is defined, add a schema.
Expand Down
Loading