https://github.com/WordPress/gutenberg/issues/22812 wp_add_inline_script( 'wp-blocks', 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' ); $block_registry = WP_Block_Type_Registry::get_instance(); foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { // Front-end script. if ( ! empty( $block_type->editor_script ) ) { wp_enqueue_script( $block_type->editor_script ); } } // Enqueue Scripts. wp_enqueue_style( 'block-manager-styles', plugins_url( 'build/style-block-manager-admin.css', __FILE__ ), [], BLOCK_MANAGER_VERSION ); wp_enqueue_script( 'block-manager-admin', plugins_url( 'build/block-manager-admin.js', __FILE__ ), [ 'wp-blocks', 'wp-element', 'wp-data', 'wp-components', 'wp-block-library' ], BLOCK_MANAGER_VERSION, true ); $filtered_blocks = Gutenberg_Block_Manager::gbm_get_filtered_blocks(); $filtered_categories = Gutenberg_Block_Manager::gbm_get_filtered_categories(); // Localize Scripts. wp_localize_script( 'block-manager-admin', 'gbm_localize', [ 'root' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'disabledBlocks' => $this->gbm_remove_duplicate_blocks( Gutenberg_Block_Manager::gbm_get_disabled_blocks(), $filtered_blocks ), 'filteredBlocks' => $filtered_blocks, 'disabledBlocksAll' => Gutenberg_Block_Manager::gbm_get_all_disabled_blocks(), 'blockCategories' => $this->gbm_remove_duplicate_categories( Gutenberg_Block_Manager::gbm_get_block_categories(), $filtered_categories ), 'filteredCategories' => $filtered_categories, 'filteredCategoriesAll' => Gutenberg_Block_Manager::gbm_get_all_block_categories(), ] ); } /** * Remove any duplicate block categories when using category hook. * * @param array $options The categories from WP options. * @param array $filtered The filtered categories. * @return array Modified options. */ public function gbm_remove_duplicate_blocks( $options, $filtered ) { if ( $options && $filtered ) { $updated = false; foreach ( $filtered as $filter ) { // Search array for filtered block. $key = array_search( $filter, $options, true ); if ( $key !== false ) { unset( $options[ $key ] ); // Remove filtered item from array. $options = array_values( $options ); // Reset array keys. $updated = true; } } if ( $updated ) { update_option( BLOCK_MANAGER_OPTION, $options ); } } return array_values( $options ); } /** * Remove any duplicate block categories when using category hook. * * @param array $options The categories from WP options. * @param array $filtered The filtered categories. * @return array Modified options. */ public function gbm_remove_duplicate_categories( $options, $filtered ) { if ( $options && $filtered ) { $updated = false; foreach ( $filtered as $filter ) { // Search array for filtered category. $key = array_search( $filter['block'], array_column( $options, 'block' ), true ); if ( $key !== false ) { unset( $options[ $key ] ); // Remove filtered item from array. $options = array_values( $options ); // Reset array keys. $updated = true; } } if ( $updated ) { update_option( BLOCK_MANAGER_CATEGORIES, $options ); } } return array_values( $options ); } /** * Register submenu item. * * @author ConnektMedia * @since 1.0 */ public function gbm_register_sub_menu() { add_submenu_page( 'options-general.php', esc_html__( 'Block Manager', 'block-manager' ), esc_html__( 'Block Manager', 'block-manager' ), apply_filters( 'block_manager_user_role', 'activate_plugins' ), 'block-manager', [ $this, 'gbm_submenu_page_callback', ] ); } /** * The Block Manager admin page. * * @author ConnektMedia * @since 1.0 */ public function gbm_submenu_page_callback() { $active = 'blocks'; if ( isset( $_GET ) && isset( $_GET['category-switcher'] ) && empty( $_GET['category-switcher'] ) ) { $active = 'categories'; } ?>