lib/experimental
connectors
3 months ago
content-types
3 months ago
dashboard-widgets
3 months ago
experiments
3 months ago
font-face
1 year ago
guidelines
3 months ago
interactivity-api
1 year ago
media-editor
3 months ago
pages
6 months ago
block-editor-settings-mobile.php
888 B
2 years ago
blocks.php
4.4 KB
7 months ago
class-gutenberg-hierarchical-sort.php
4.7 KB
6 months ago
class-wp-rest-block-editor-settings-controller.php
24.2 KB
7 months ago
editor-settings.php
3.3 KB
3 months ago
extensible-site-editor.php
975 B
7 months ago
kses-allowed-html.php
965 B
1 year ago
kses.php
6.2 KB
5 months ago
navigation-theme-opt-in.php
13.3 KB
6 months ago
rest-api-overrides.php
1.6 KB
9 months ago
rest-api.php
3.2 KB
7 months ago
script-modules.php
7.9 KB
6 months ago
workflow-palette.php
355 B
9 months ago
| 1 | <?php |
| 2 | /** |
| 3 | * Temporary compatibility shims for block APIs present in Gutenberg. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | if ( ! function_exists( 'wp_enqueue_block_view_script' ) ) { |
| 9 | /** |
| 10 | * Enqueues a frontend script for a specific block. |
| 11 | * |
| 12 | * Scripts enqueued using this function will only get printed |
| 13 | * when the block gets rendered on the frontend. |
| 14 | * |
| 15 | * @since 6.2.0 |
| 16 | * |
| 17 | * @param string $block_name The block name, including namespace. |
| 18 | * @param array $args An array of arguments [handle,src,deps,ver,media,textdomain]. |
| 19 | * |
| 20 | * @return void |
| 21 | */ |
| 22 | function wp_enqueue_block_view_script( $block_name, $args ) { |
| 23 | $args = wp_parse_args( |
| 24 | $args, |
| 25 | array( |
| 26 | 'handle' => '', |
| 27 | 'src' => '', |
| 28 | 'deps' => array(), |
| 29 | 'ver' => false, |
| 30 | 'in_footer' => false, |
| 31 | |
| 32 | // Additional args to allow translations for the script's textdomain. |
| 33 | 'textdomain' => '', |
| 34 | ) |
| 35 | ); |
| 36 | |
| 37 | /** |
| 38 | * Callback function to register and enqueue scripts. |
| 39 | * |
| 40 | * @param string $content When the callback is used for the render_block filter, |
| 41 | * the content needs to be returned so the function parameter |
| 42 | * is to ensure the content exists. |
| 43 | * @return string Block content. |
| 44 | */ |
| 45 | $callback = static function ( $content, $block ) use ( $args, $block_name ) { |
| 46 | |
| 47 | // Sanity check. |
| 48 | if ( empty( $block['blockName'] ) || $block_name !== $block['blockName'] ) { |
| 49 | return $content; |
| 50 | } |
| 51 | |
| 52 | // Register the stylesheet. |
| 53 | if ( ! empty( $args['src'] ) ) { |
| 54 | wp_register_script( $args['handle'], $args['src'], $args['deps'], $args['ver'], $args['in_footer'] ); |
| 55 | } |
| 56 | |
| 57 | // Enqueue the stylesheet. |
| 58 | wp_enqueue_script( $args['handle'] ); |
| 59 | |
| 60 | // If a textdomain is defined, use it to set the script translations. |
| 61 | if ( ! empty( $args['textdomain'] ) && in_array( 'wp-i18n', $args['deps'], true ) ) { |
| 62 | wp_set_script_translations( $args['handle'], $args['textdomain'], $args['domainpath'] ); |
| 63 | } |
| 64 | |
| 65 | return $content; |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * The filter's callback here is an anonymous function because |
| 70 | * using a named function in this case is not possible. |
| 71 | * |
| 72 | * The function cannot be unhooked, however, users are still able |
| 73 | * to dequeue the script registered/enqueued by the callback |
| 74 | * which is why in this case, using an anonymous function |
| 75 | * was deemed acceptable. |
| 76 | */ |
| 77 | add_filter( 'render_block', $callback, 10, 2 ); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Registers a new block style for one or more block types. |
| 83 | * |
| 84 | * WP_Block_Styles_Registry was marked as `final` in core so it cannot be |
| 85 | * updated via Gutenberg to allow registration of a style across multiple |
| 86 | * block types as well as with an optional style object. This function will |
| 87 | * support the desired functionality until the styles registry can be updated |
| 88 | * in core. |
| 89 | * |
| 90 | * @param string|array $block_name Block type name including namespace or array of namespaced block type names. |
| 91 | * @param array $style_properties Array containing the properties of the style name, label, |
| 92 | * style_handle (name of the stylesheet to be enqueued), |
| 93 | * inline_style (string containing the CSS to be added), |
| 94 | * style_data (theme.json-like object to generate CSS from). |
| 95 | * |
| 96 | * @return bool True if all block styles were registered with success and false otherwise. |
| 97 | */ |
| 98 | function gutenberg_register_block_style( $block_name, $style_properties ) { |
| 99 | if ( ! is_string( $block_name ) && ! is_array( $block_name ) ) { |
| 100 | _doing_it_wrong( |
| 101 | __METHOD__, |
| 102 | __( 'Block name must be a string or array.', 'gutenberg' ), |
| 103 | '6.6.0' |
| 104 | ); |
| 105 | |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | $block_names = is_string( $block_name ) ? array( $block_name ) : $block_name; |
| 110 | $result = true; |
| 111 | |
| 112 | foreach ( $block_names as $name ) { |
| 113 | if ( ! WP_Block_Styles_Registry::get_instance()->register( $name, $style_properties ) ) { |
| 114 | $result = false; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return $result; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Additional data to expose to the view script module in the Form block. |
| 123 | * |
| 124 | * @return array The script module data. |
| 125 | */ |
| 126 | function gutenberg_block_core_form_view_script_module( $data ) { |
| 127 | if ( ! gutenberg_is_experiment_enabled( 'gutenberg-form-blocks' ) ) { |
| 128 | return $data; |
| 129 | } |
| 130 | |
| 131 | $data['nonce'] = wp_create_nonce( 'wp-block-form' ); |
| 132 | $data['ajaxUrl'] = admin_url( 'admin-ajax.php' ); |
| 133 | $data['action'] = 'wp_block_form_email_submit'; |
| 134 | |
| 135 | return $data; |
| 136 | } |
| 137 | add_filter( |
| 138 | 'script_module_data_@wordpress/block-library/form/view', |
| 139 | 'gutenberg_block_core_form_view_script_module' |
| 140 | ); |
| 141 |