Make WordPress Core

Ticket #54647: fix.diff

File fix.diff, 3.0 KB (added by whoisnegrello, 3 years ago)
  • src/wp-includes/blocks.php

    diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php
    index 0f34aac1df..f6e6764343 100644
    a b function register_block_script_handle( $metadata, $field_name ) { 
    106106        $wpinc_path_norm  = wp_normalize_path( ABSPATH . WPINC );
    107107        $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) );
    108108        $is_core_block    = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
     109        $is_plugin_block  = isset( $metadata['file'] ) && strpos( $metadata['file'], 'wp-content/plugins' );
     110        $is_theme_block   = isset( $metadata['file'] ) && strpos( $metadata['file'], 'wp-content/themes' );
     111        $script_uri       = false;
     112
     113        if ( false !== $is_plugin_block ) {
     114                $script_uri = plugins_url( $script_path, $metadata['file'] );
     115        }
     116
     117        if ( false !== $is_theme_block ) {
     118                $theme_pos         = strpos( $metadata['file'], '/themes' );
     119                $theme_block_path  = substr( $metadata['file'], $theme_pos );
     120                $theme_script_path = dirname( $theme_block_path ) . '/' . $script_path;
     121                $script_uri        = content_url( $theme_script_path );
     122        }
     123
     124        if ( $is_core_block ) {
     125                $script_uri = includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) );
     126        }
    109127
    110         $script_uri          = $is_core_block ?
    111                 includes_url( str_replace( $wpinc_path_norm, '', $script_path_norm ) ) :
    112                 plugins_url( $script_path, $metadata['file'] );
    113128        $script_asset        = require $script_asset_path;
    114129        $script_dependencies = isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : array();
    115130        $result              = wp_register_script(
    function register_block_style_handle( $metadata, $field_name ) { 
    147162        }
    148163        $wpinc_path_norm = wp_normalize_path( ABSPATH . WPINC );
    149164        $is_core_block   = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
     165        $is_plugin_block = isset( $metadata['file'] ) && strpos( $metadata['file'], 'wp-content/plugins' );
     166        $is_theme_block  = isset( $metadata['file'] ) && strpos( $metadata['file'], 'wp-content/themes' );
     167        $style_uri       = false;
     168
    150169        if ( $is_core_block && ! wp_should_load_separate_core_block_assets() ) {
    151170                return false;
    152171        }
    function register_block_style_handle( $metadata, $field_name ) { 
    161180                return $style_handle;
    162181        }
    163182
    164         $style_uri = plugins_url( $style_path, $metadata['file'] );
     183        if ( false !== $is_plugin_block ) {
     184                $style_uri = plugins_url( $style_path, $metadata['file'] );
     185        }
     186
     187        if ( false !== $is_theme_block ) {
     188                $theme_pos        = strpos( $metadata['file'], '/themes' );
     189                $theme_block_path = substr( $metadata['file'], $theme_pos );
     190                $theme_style_path = dirname( $theme_block_path ) . '/' . $style_path;
     191                $style_uri        = content_url( $theme_style_path );
     192        }
     193
    165194        if ( $is_core_block ) {
    166195                $style_path = "style$suffix.css";
    167196                $style_uri  = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" );