| @@ -1,30 +1,79 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Module Name: Blocks | |
| 4 | - * Module Description: Add additional blocks to your site and post editors. | |
| 5 | - * Sort Order: 5 | |
| 6 | - * First Introduced: 13.9-a.8 | |
| 7 | - * Requires Connection: No | |
| 8 | - * Auto Activate: Yes | |
| 9 | - * Module Tags: blocks | |
| 10 | - * Feature: Writing | |
| 3 | + * Load code specific to Gutenberg blocks which are not tied to a module. | |
| 4 | + * This file is unusual, and is not an actual `module` as such. | |
| 5 | + * It is included in ./module-extras.php | |
| 11 | 6 | * |
| 12 | - * @package automattic/jetpack | |
| 13 | 7 | */ |
| 14 | 8 | |
| 15 | -add_action( 'jetpack_activate_module_blocks', 'jetpack_blocks_activate_module' ); | |
| 9 | +jetpack_register_block( | |
| 10 | + 'map', | |
| 11 | + array( | |
| 12 | + 'render_callback' => 'jetpack_map_block_load_assets', | |
| 13 | + ) | |
| 14 | +); | |
| 16 | 15 | |
| 16 | +jetpack_register_block( 'vr' ); | |
| 17 | + | |
| 17 | 18 | /** |
| 18 | - * Actions needed upon activating the blocks module. | |
| 19 | + * Tiled Gallery block. Depends on the Photon module. | |
| 19 | 20 | * |
| 20 | - * There is a legacy option to disable Jetpack blocks that we'll delete when this module is activated. | |
| 21 | - * Via jetpack_get_default_modules filter, we remove blocks from the default if the option is true. | |
| 22 | - * We'll leave that in place so _until the module is activated_ we will be sure to respect the previous | |
| 23 | - * setting. | |
| 21 | + * @since 6.9.0 | |
| 22 | +*/ | |
| 23 | +if ( class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) { | |
| 24 | + jetpack_register_block( | |
| 25 | + 'tiled-gallery', | |
| 26 | + array( | |
| 27 | + 'render_callback' => 'jetpack_tiled_gallery_load_block_assets', | |
| 28 | + ) | |
| 29 | + ); | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Tiled gallery block registration/dependency declaration. | |
| 33 | + * | |
| 34 | + * @param array $attr - Array containing the block attributes. | |
| 35 | + * @param string $content - String containing the block content. | |
| 36 | + * | |
| 37 | + * @return string | |
| 38 | + */ | |
| 39 | + function jetpack_tiled_gallery_load_block_assets( $attr, $content ) { | |
| 40 | + $dependencies = array( | |
| 41 | + 'lodash', | |
| 42 | + 'wp-i18n', | |
| 43 | + 'wp-token-list', | |
| 44 | + ); | |
| 45 | + Jetpack_Gutenberg::load_assets_as_required( 'tiled-gallery', $dependencies ); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Filter the output of the Tiled Galleries content. | |
| 49 | + * | |
| 50 | + * @module tiled-gallery | |
| 51 | + * | |
| 52 | + * @since 6.9.0 | |
| 53 | + * | |
| 54 | + * @param string $content Tiled Gallery block content. | |
| 55 | + */ | |
| 56 | + return apply_filters( 'jetpack_tiled_galleries_block_content', $content ); | |
| 57 | + } | |
| 58 | +} | |
| 59 | + | |
| 60 | +/** | |
| 61 | + * Map block registration/dependency declaration. | |
| 24 | 62 | * |
| 25 | - * @since 13.9 | |
| 26 | - * @return void | |
| 63 | + * @param array $attr - Array containing the map block attributes. | |
| 64 | + * @param string $content - String containing the map block content. | |
| 65 | + * | |
| 66 | + * @return string | |
| 27 | 67 | */ |
| 28 | -function jetpack_blocks_activate_module() { | |
| 29 | - delete_option( 'jetpack_blocks_disabled' ); // The function will check and return early if not present. | |
| 68 | +function jetpack_map_block_load_assets( $attr, $content ) { | |
| 69 | + $dependencies = array( | |
| 70 | + 'lodash', | |
| 71 | + 'wp-element', | |
| 72 | + 'wp-i18n', | |
| 73 | + ); | |
| 74 | + | |
| 75 | + $api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); | |
| 76 | + | |
| 77 | + Jetpack_Gutenberg::load_assets_as_required( 'map', $dependencies ); | |
| 78 | + return preg_replace( '/<div /', '<div data-api-key="'. esc_attr( $api_key ) .'" ', $content, 1 ); | |
| 30 | 79 | } |