$block Parsed block. */ public static function enqueue_block_assets( string $content, array $block ): string { if ( is_admin() || empty( $content ) ) { return $content; } Visitor_Storage::enqueue_assets(); $block_type = \WP_Block_Type_Registry::get_instance()->get_registered( self::BLOCK_NAME ); if ( $block_type && ! empty( $block_type->view_script_handles ) ) { foreach ( $block_type->view_script_handles as $handle ) { wp_enqueue_script( $handle ); } } return $content; } /** * Run the toggle handler synchronously; defer breaks ordering inside Navigation. * * @param string $tag Script tag. * @param string $handle Script handle. * @param string $src Script src. */ public static function remove_view_script_defer( string $tag, string $handle, string $src ): string { if ( 'forwp-style-switcher-light-dark-toggle-view-script' !== $handle ) { return $tag; } return str_replace( array( " data-wp-strategy='defer'", ' data-wp-strategy="defer"', ' defer', " defer='defer'" ), '', $tag ); } /** * @param string[] $blocks Blocks that need a list item wrapper in navigation. * @return string[] */ public static function add_to_navigation_list( array $blocks ): array { if ( ! in_array( self::BLOCK_NAME, $blocks, true ) ) { $blocks[] = self::BLOCK_NAME; } return $blocks; } /** * @param array $settings Block type settings. * @param array $metadata Block metadata. * @return array */ public static function allow_in_navigation( array $settings, array $metadata ): array { if ( 'core/navigation' !== ( $metadata['name'] ?? '' ) ) { return $settings; } if ( ! isset( $settings['allowed_blocks'] ) || ! is_array( $settings['allowed_blocks'] ) ) { $settings['allowed_blocks'] = array(); } if ( ! in_array( self::BLOCK_NAME, $settings['allowed_blocks'], true ) ) { $settings['allowed_blocks'][] = self::BLOCK_NAME; } return $settings; } }