Changeset 13464 for trunk/src/bp-core/bp-core-blocks.php
- Timestamp:
- 04/25/2023 10:17:33 PM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-blocks.php
r13441 r13464 36 36 * @since 9.0.0 Adds a dependency to `wp-server-side-render` if WP >= 5.3. 37 37 * Uses a dependency to `wp-editor` otherwise. 38 * @since 12.0.0 Uses the `@wordpress/scripts` `index.asset.php` generated file to get dependencies. 38 39 */ 39 40 function bp_register_block_components() { 41 $asset = array( 42 'dependencies' => array(), 43 'version' => bp_get_version(), 44 ); 45 $asset_file = trailingslashit( dirname( __FILE__ ) ) . 'blocks/block-components/index.asset.php'; 46 47 if ( file_exists( $asset_file ) ) { 48 $asset = require $asset_file; 49 } 50 40 51 wp_register_script( 41 52 'bp-block-components', 42 plugins_url( 'js/block-components.js', __FILE__ ), 43 array( 44 'wp-element', 45 'wp-components', 46 'wp-i18n', 47 'wp-api-fetch', 48 'wp-url', 49 ), 50 bp_get_version(), 53 plugins_url( 'blocks/block-components/index.js', __FILE__ ), 54 $asset['dependencies'], 55 $asset['version'], 51 56 false 52 57 ); 53 54 // Adds BP Block Components to the `bp` global.55 wp_add_inline_script(56 'bp-block-components',57 'window.bp = window.bp || {};58 bp.blockComponents = bpBlock.blockComponents;59 delete bpBlock;',60 'after'61 );62 58 } 63 59 add_action( 'bp_blocks_init', 'bp_register_block_components', 1 ); … … 67 63 * 68 64 * @since 9.0.0 65 * @since 12.0.0 Adds the BuddyPress Blocks collection & uses the `@wordpress/scripts` 66 * `index.asset.php` generated file to get dependencies. 69 67 */ 70 68 function bp_register_block_assets() { 69 $default_asset = array( 70 'dependencies' => array(), 71 'version' => bp_get_version(), 72 ); 73 $asset_data_file = trailingslashit( dirname( __FILE__ ) ) . 'blocks/block-data/index.asset.php'; 74 75 if ( file_exists( $asset_data_file ) ) { 76 $asset_data = require $asset_data_file; 77 } else { 78 $asset_data = $default_asset; 79 } 80 71 81 wp_register_script( 72 82 'bp-block-data', 73 plugins_url( 'js/block-data.js', __FILE__ ), 74 array( 75 'wp-data', 76 'wp-api-fetch', 77 'lodash', 78 ), 79 bp_get_version(), 83 plugins_url( 'blocks/block-data/index.js', __FILE__ ), 84 $asset_data['dependencies'], 85 $asset_data['version'], 80 86 false 81 87 ); 82 88 83 // Adds BP Block Assets to the `bp` global. 84 wp_add_inline_script( 85 'bp-block-data', 86 sprintf( 87 'window.bp = window.bp || {}; 88 bp.blockData = bpBlock.blockData; 89 bp.blockData.embedScriptURL = \'%s\'; 90 delete bpBlock;', 91 esc_url_raw( includes_url( 'js/wp-embed.min.js' ) ) 92 ), 93 'after' 89 $asset_collection_file = trailingslashit( dirname( __FILE__ ) ) . 'blocks/block-collection/index.asset.php'; 90 91 if ( file_exists( $asset_collection_file ) ) { 92 $asset_collection = require $asset_collection_file; 93 } else { 94 $asset_collection = $default_asset; 95 } 96 97 wp_register_script( 98 'bp-blocks-collection', 99 plugins_url( 'blocks/block-collection/index.js', __FILE__ ), 100 $asset_collection['dependencies'], 101 $asset_collection['version'], 102 false 94 103 ); 95 104 } 96 105 add_action( 'bp_blocks_init', 'bp_register_block_assets', 2 ); 106 107 /** 108 * Enqueue additional BP Assets for the Block Editor. 109 * 110 * @since 12.0.0 111 */ 112 function bp_enqueue_block_editor_assets() { 113 wp_enqueue_script( 'bp-blocks-collection' ); 114 115 /** 116 * Fires when it's time to enqueue BP Block assets. 117 * 118 * @since 12.0.0 119 */ 120 do_action( 'bp_enqueue_block_editor_assets' ); 121 } 122 add_action( 'enqueue_block_editor_assets', 'bp_enqueue_block_editor_assets', 9 ); 97 123 98 124 /**
Note: See TracChangeset
for help on using the changeset viewer.