From 7df3687192ad50f76fbd194682239b9c75f51fb0 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Thu, 24 Nov 2022 14:46:16 +0100 Subject: [PATCH] Don't check if constants set by `wp_initial_constants()` are defined (#45979) `wp_initial_constants()` makes sure that all the default constants are set. --- lib/block-supports/duotone.php | 4 ++-- lib/blocks.php | 2 +- lib/client-assets.php | 6 +++--- lib/compat/wordpress-6.0/get-global-styles-and-settings.php | 4 ++-- lib/compat/wordpress-6.2/get-global-styles-and-settings.php | 2 +- lib/experimental/html/class-wp-html-tag-processor.php | 2 +- packages/block-library/src/block/index.php | 3 +-- packages/block-library/src/post-content/index.php | 3 +-- packages/block-library/src/template-part/index.php | 3 +-- packages/style-engine/class-wp-style-engine-processor.php | 2 +- 10 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/block-supports/duotone.php b/lib/block-supports/duotone.php index 4a9a23d7b5af3..b4a8397d72ece 100644 --- a/lib/block-supports/duotone.php +++ b/lib/block-supports/duotone.php @@ -387,7 +387,7 @@ function gutenberg_get_duotone_filter_svg( $preset ) { $svg = ob_get_clean(); - if ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) { + if ( ! SCRIPT_DEBUG ) { // Clean up the whitespace. $svg = preg_replace( "/[\r\n\t ]+/", ' ', $svg ); $svg = str_replace( '> <', '><', $svg ); @@ -464,7 +464,7 @@ function gutenberg_render_duotone_support( $block_content, $block ) { // !important is needed because these styles render before global styles, // and they should be overriding the duotone filters set by global styles. - $filter_style = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG + $filter_style = SCRIPT_DEBUG ? $selector . " {\n\tfilter: " . $filter_property . " !important;\n}\n" : $selector . '{filter:' . $filter_property . ' !important;}'; diff --git a/lib/blocks.php b/lib/blocks.php index d991eac8ddbe4..669decebf2c36 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -190,7 +190,7 @@ function gutenberg_register_core_block_assets( $block_name ) { // When in production, use the plugin's version as the default asset version; // else (for development or test) default to use the current time. - $default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time(); + $default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); $style_path = "build/block-library/blocks/$block_name/"; $stylesheet_url = gutenberg_url( $style_path . 'style.css' ); diff --git a/lib/client-assets.php b/lib/client-assets.php index ea199750fa10b..e9716a2a54771 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -193,7 +193,7 @@ function gutenberg_override_style( $styles, $handle, $src, $deps = array(), $ver function gutenberg_register_packages_scripts( $scripts ) { // When in production, use the plugin's version as the default asset version; // else (for development or test) default to use the current time. - $default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time(); + $default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); foreach ( glob( gutenberg_dir_path() . 'build/*/index.min.js' ) as $path ) { // Prefix `wp-` to package directory to get script handle. @@ -249,7 +249,7 @@ function gutenberg_register_packages_scripts( $scripts ) { function gutenberg_register_packages_styles( $styles ) { // When in production, use the plugin's version as the asset version; // else (for development or test) default to use the current time. - $version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time(); + $version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time(); // Editor Styles. gutenberg_override_style( @@ -486,7 +486,7 @@ function gutenberg_enqueue_stored_styles( $options = array() ) { $style_tag_id = 'core'; foreach ( $core_styles_keys as $style_key ) { // Adds comment if code is prettified to identify core styles sections in debugging. - $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; + $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : SCRIPT_DEBUG; if ( $should_prettify ) { $compiled_core_stylesheet .= "/**\n * Core styles: $style_key\n */\n"; } diff --git a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php index d4f1f9ef03492..b64f7abbcb56b 100644 --- a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php @@ -44,8 +44,8 @@ function gutenberg_get_global_styles_svg_filters() { // It's cached by theme to make sure that theme switching clears the cache. $transient_name = 'gutenberg_global_styles_svg_filters_' . get_stylesheet(); $can_use_cached = ( - ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) && - ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) && + ! WP_DEBUG && + ! SCRIPT_DEBUG && ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) && ! is_admin() ); diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php index e74ef3144ef09..923c07b3f6e9a 100644 --- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php @@ -92,7 +92,7 @@ function _wp_theme_has_theme_json_clean_cache_upon_upgrading_active_theme( $upgr */ function gutenberg_get_global_stylesheet( $types = array() ) { // Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme developers workflow. - $can_use_cached = empty( $types ) && ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ); + $can_use_cached = empty( $types ) && ! WP_DEBUG; $cache_key = 'gutenberg_get_global_stylesheet'; $cache_group = 'theme_json'; if ( $can_use_cached ) { diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php index acdf8d97a95a9..5dc5981ef15f7 100644 --- a/lib/experimental/html/class-wp-html-tag-processor.php +++ b/lib/experimental/html/class-wp-html-tag-processor.php @@ -1265,7 +1265,7 @@ public function set_attribute( $name, $value ) { ']~Ssu', $name ) ) { - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + if ( WP_DEBUG ) { throw new Exception( 'Invalid attribute name' ); } diff --git a/packages/block-library/src/block/index.php b/packages/block-library/src/block/index.php index 2cfd672aa3ada..d51b35d68b23d 100644 --- a/packages/block-library/src/block/index.php +++ b/packages/block-library/src/block/index.php @@ -27,8 +27,7 @@ function render_block_core_block( $attributes ) { if ( isset( $seen_refs[ $attributes['ref'] ] ) ) { // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent // is set in `wp_debug_mode()`. - $is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG && - defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY; + $is_debug = WP_DEBUG && WP_DEBUG_DISPLAY; return $is_debug ? // translators: Visible only in the front end, this warning takes the place of a faulty block. diff --git a/packages/block-library/src/post-content/index.php b/packages/block-library/src/post-content/index.php index 228a0d52f4069..2be1ef77b3b85 100644 --- a/packages/block-library/src/post-content/index.php +++ b/packages/block-library/src/post-content/index.php @@ -25,8 +25,7 @@ function render_block_core_post_content( $attributes, $content, $block ) { if ( isset( $seen_ids[ $post_id ] ) ) { // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent // is set in `wp_debug_mode()`. - $is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG && - defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY; + $is_debug = WP_DEBUG && WP_DEBUG_DISPLAY; return $is_debug ? // translators: Visible only in the front end, this warning takes the place of a faulty block. diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index bef49341d7bb5..f320362c32f1d 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -105,8 +105,7 @@ function render_block_core_template_part( $attributes ) { // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent // is set in `wp_debug_mode()`. - $is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG && - defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY; + $is_debug = WP_DEBUG && WP_DEBUG_DISPLAY; if ( is_null( $content ) && $is_debug ) { if ( ! isset( $attributes['slug'] ) ) { diff --git a/packages/style-engine/class-wp-style-engine-processor.php b/packages/style-engine/class-wp-style-engine-processor.php index 9030cf8e24ca2..4974768c65267 100644 --- a/packages/style-engine/class-wp-style-engine-processor.php +++ b/packages/style-engine/class-wp-style-engine-processor.php @@ -93,7 +93,7 @@ public function add_rules( $css_rules ) { public function get_css( $options = array() ) { $defaults = array( 'optimize' => true, - 'prettify' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG, + 'prettify' => SCRIPT_DEBUG, ); $options = wp_parse_args( $options, $defaults );