| 1 |
<?php |
| 2 |
/** |
| 3 |
* Updates the script-loader.php file |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Registers vendor JavaScript files to be used as dependencies of the editor |
| 10 |
* and plugins. |
| 11 |
* |
| 12 |
* This function is called from a script during the plugin build process, so it |
| 13 |
* should not call any WordPress PHP functions. |
| 14 |
* |
| 15 |
* @since 13.0 |
| 16 |
* |
| 17 |
* @param WP_Scripts $scripts WP_Scripts instance. |
| 18 |
*/ |
| 19 |
function gutenberg_register_vendor_scripts_62( $scripts ) { |
| 20 |
$extension = SCRIPT_DEBUG ? '.js' : '.min.js'; |
| 21 |
|
| 22 |
$script = $scripts->query( 'wp-inert-polyfill', 'registered' ); |
| 23 |
if ( ! $script ) { |
| 24 |
$scripts->add( 'wp-inert-polyfill', gutenberg_url( 'build/vendors/inert-polyfill' . $extension ), array() ); |
| 25 |
} |
| 26 |
|
| 27 |
$script = $scripts->query( 'wp-polyfill', 'registered' ); |
| 28 |
$script->deps = array_merge( $script->deps, array( 'wp-inert-polyfill' ) ); |
| 29 |
} |
| 30 |
add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts_62' ); |
| 31 |
|
| 32 |
/** |
| 33 |
* This function takes care of adding inline styles |
| 34 |
* in the proper place, depending on the theme in use. |
| 35 |
* |
| 36 |
* This method was added to core in 5.9.1, but with a single param ($style). The second param ($priority) was |
| 37 |
* added post 6.0, so the 6.1 release needs to have wp_enqueue_block_support_styles updated to include this param. |
| 38 |
* |
| 39 |
* For block themes, it's loaded in the head. |
| 40 |
* For classic ones, it's loaded in the body |
| 41 |
* because the wp_head action happens before |
| 42 |
* the render_block. |
| 43 |
* |
| 44 |
* @link https://core.trac.wordpress.org/ticket/53494. |
| 45 |
* |
| 46 |
* @deprecated 6.2 Block supports styles are now stored for enqueuing via the style engine API. See: packages/style-engine/README.md. |
| 47 |
* |
| 48 |
* @param string $style String containing the CSS styles to be added. |
| 49 |
* @param int $priority To set the priority for the add_action. |
| 50 |
*/ |
| 51 |
function gutenberg_enqueue_block_support_styles( $style, $priority = 10 ) { |
| 52 |
_deprecated_function( __FUNCTION__, '6.2' ); |
| 53 |
|
| 54 |
$action_hook_name = 'wp_footer'; |
| 55 |
if ( wp_is_block_theme() ) { |
| 56 |
$action_hook_name = 'wp_head'; |
| 57 |
} |
| 58 |
add_action( |
| 59 |
$action_hook_name, |
| 60 |
static function () use ( $style ) { |
| 61 |
echo "<style>$style</style>\n"; |
| 62 |
}, |
| 63 |
$priority |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Sets the content assets for the block editor. |
| 69 |
* |
| 70 |
* Note for core merge: see inline comment on what's been updated. |
| 71 |
*/ |
| 72 |
function gutenberg_resolve_assets_override() { |
| 73 |
global $pagenow; |
| 74 |
|
| 75 |
$script_handles = array(); |
| 76 |
// Note for core merge: only 'wp-edit-blocks' should be in this array. |
| 77 |
$style_handles = array( |
| 78 |
'wp-edit-blocks', |
| 79 |
); |
| 80 |
|
| 81 |
if ( current_theme_supports( 'wp-block-styles' ) ) { |
| 82 |
$style_handles[] = 'wp-block-library-theme'; |
| 83 |
} |
| 84 |
|
| 85 |
if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { |
| 86 |
$style_handles[] = 'wp-widgets'; |
| 87 |
$style_handles[] = 'wp-edit-widgets'; |
| 88 |
} |
| 89 |
|
| 90 |
$block_registry = WP_Block_Type_Registry::get_instance(); |
| 91 |
|
| 92 |
foreach ( $block_registry->get_all_registered() as $block_type ) { |
| 93 |
$style_handles = array_merge( |
| 94 |
$style_handles, |
| 95 |
$block_type->style_handles, |
| 96 |
$block_type->editor_style_handles |
| 97 |
); |
| 98 |
|
| 99 |
$script_handles = array_merge( |
| 100 |
$script_handles, |
| 101 |
$block_type->script_handles |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
$style_handles = array_unique( $style_handles ); |
| 106 |
$done = wp_styles()->done; |
| 107 |
|
| 108 |
ob_start(); |
| 109 |
|
| 110 |
// We do not need reset styles for the iframed editor. |
| 111 |
wp_styles()->done = array( 'wp-reset-editor-styles' ); |
| 112 |
wp_styles()->do_items( $style_handles ); |
| 113 |
wp_styles()->done = $done; |
| 114 |
|
| 115 |
$styles = ob_get_clean(); |
| 116 |
|
| 117 |
$script_handles = array_unique( $script_handles ); |
| 118 |
$done = wp_scripts()->done; |
| 119 |
|
| 120 |
ob_start(); |
| 121 |
|
| 122 |
wp_scripts()->done = array(); |
| 123 |
wp_scripts()->do_items( $script_handles ); |
| 124 |
wp_scripts()->done = $done; |
| 125 |
|
| 126 |
$scripts = ob_get_clean(); |
| 127 |
|
| 128 |
return array( |
| 129 |
'styles' => $styles, |
| 130 |
'scripts' => $scripts, |
| 131 |
); |
| 132 |
} |
| 133 |
|
| 134 |
add_filter( |
| 135 |
'block_editor_settings_all', |
| 136 |
function( $settings ) { |
| 137 |
// We must override what core is passing now. |
| 138 |
$settings['__unstableResolvedAssets'] = gutenberg_resolve_assets_override(); |
| 139 |
return $settings; |
| 140 |
}, |
| 141 |
100 |
| 142 |
); |
| 143 |
|