mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Add Site Editor and PHP changes from Gutenberg 10.1 - 11.9
- First pass at adding the site editor from the Gutenberg plugin to wp-admin/site-editor.php. - Adds miscellaneous PHP changes from Gutenberg 10.1 - 11.9. Follows [52042]. See #54337. Props youknowriad, aristath, hellofromtonya, gziolo. git-svn-id: https://develop.svn.wordpress.org/trunk@52069 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1182,3 +1182,117 @@ function get_query_pagination_arrow( $block, $is_next ) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue a stylesheet for a specific block.
|
||||
*
|
||||
* If the theme has opted-in to separate-styles loading,
|
||||
* then the stylesheet will be enqueued on-render,
|
||||
* otherwise when the block inits.
|
||||
*
|
||||
* @param string $block_name The block-name, including namespace.
|
||||
* @param array $args An array of arguments [handle,src,deps,ver,media].
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function wp_enqueue_block_style( $block_name, $args ) {
|
||||
$args = wp_parse_args(
|
||||
$args,
|
||||
array(
|
||||
'handle' => '',
|
||||
'src' => '',
|
||||
'deps' => array(),
|
||||
'ver' => false,
|
||||
'media' => 'all',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Callback function to register and enqueue styles.
|
||||
*
|
||||
* @param string $content When the callback is used for the render_block filter,
|
||||
* the content needs to be returned so the function parameter
|
||||
* is to ensure the content exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
$callback = static function( $content ) use ( $args ) {
|
||||
// Register the stylesheet.
|
||||
if ( ! empty( $args['src'] ) ) {
|
||||
wp_register_style( $args['handle'], $args['src'], $args['deps'], $args['ver'], $args['media'] );
|
||||
}
|
||||
|
||||
// Add `path` data if provided.
|
||||
if ( isset( $args['path'] ) ) {
|
||||
wp_style_add_data( $args['handle'], 'path', $args['path'] );
|
||||
|
||||
// Get the RTL file path.
|
||||
$rtl_file_path = str_replace( '.css', '-rtl.css', $args['path'] );
|
||||
|
||||
// Add RTL stylesheet.
|
||||
if ( file_exists( $rtl_file_path ) ) {
|
||||
wp_style_add_data( $args['hanle'], 'rtl', 'replace' );
|
||||
|
||||
if ( is_rtl() ) {
|
||||
wp_style_add_data( $args['handle'], 'path', $rtl_file_path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Enqueue the stylesheet.
|
||||
wp_enqueue_style( $args['handle'] );
|
||||
|
||||
return $content;
|
||||
};
|
||||
|
||||
$hook = did_action( 'wp_enqueue_scripts' ) ? 'wp_footer' : 'wp_enqueue_scripts';
|
||||
if ( wp_should_load_separate_core_block_assets() ) {
|
||||
$hook = "render_block_$block_name";
|
||||
}
|
||||
|
||||
/*
|
||||
* The filter's callback here is an anonymous function because
|
||||
* using a named function in this case is not possible.
|
||||
*
|
||||
* The function cannot be unhooked, however, users are still able
|
||||
* to dequeue the stylesheets registered/enqueued by the callback
|
||||
* which is why in this case, using an anonymous function
|
||||
* was deemed acceptable.
|
||||
*/
|
||||
add_filter( $hook, $callback );
|
||||
|
||||
// Enqueue assets in the editor.
|
||||
add_action( 'enqueue_block_assets', $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow multiple block styles.
|
||||
*
|
||||
* @param array $metadata Metadata for registering a block type.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function _wp_multiple_block_styles( $metadata ) {
|
||||
foreach ( array( 'style', 'editorStyle' ) as $key ) {
|
||||
if ( ! empty( $metadata[ $key ] ) && is_array( $metadata[ $key ] ) ) {
|
||||
$default_style = array_shift( $metadata[ $key ] );
|
||||
foreach ( $metadata[ $key ] as $handle ) {
|
||||
$args = array( 'handle' => $handle );
|
||||
if ( 0 === strpos( $handle, 'file:' ) && isset( $metadata['file'] ) ) {
|
||||
$style_path = remove_block_asset_path_prefix( $handle );
|
||||
$args = array(
|
||||
'handle' => sanitize_key( "{$metadata['name']}-{$style_path}" ),
|
||||
'src' => plugins_url( $style_path, $metadata['file'] ),
|
||||
);
|
||||
}
|
||||
|
||||
wp_enqueue_block_style( $metadata['name'], $args );
|
||||
}
|
||||
|
||||
// Only return the 1st item in the array.
|
||||
$metadata[ $key ] = $default_style;
|
||||
}
|
||||
}
|
||||
return $metadata;
|
||||
}
|
||||
add_filter( 'block_type_metadata', '_wp_multiple_block_styles' );
|
||||
|
||||
Reference in New Issue
Block a user