make_after_block_visitor

函数
make_after_block_visitor ( $hooked_blocks, $context )
Access
Private
参数
  • (array) $hooked_blocks An array of blocks hooked to another block.
    Required:
  • (WP_Block_Template|array) $context A block template, template part, or pattern that the blocks belong to.
    Required:
返回值
  • (callable) A function that returns the serialized markup for the given block, including the markup for any hooked blocks after it.
定义位置
相关方法
make_before_block_visitorregister_block_stylefilter_block_ksesunregister_block_styleregister_block_core_site_logo
引入
6.4.0
弃用
-

返回一个函数,用于在给定代码区块后注入钩选的代码区块。

返回的函数可用作 ` traverse_and_serialize_block(s) ` 的 ` $post_callback ` 参数,它将分别为给定代码区块之后和作为其父代码区块的 ` last_child` 被勾住的代码区块添加标记。

function make_after_block_visitor( $hooked_blocks, $context ) {
	/**
	 * Injects hooked blocks after the given block, and returns the serialized markup.
	 *
	 * Append the markup for any blocks hooked `after` the given block and as its parent's
	 * `last_child`, respectively, to the serialized markup for the given block.
	 *
	 * @param array $block        The block to inject the hooked blocks after. Passed by reference.
	 * @param array $parent_block The parent block of the given block. Passed by reference. Default null.
	 * @param array $next         The next sibling block of the given block. Default null.
	 * @return string The serialized markup for the given block, with the markup for any hooked blocks appended to it.
	 */
	return function ( &$block, &$parent_block = null, $next = null ) use ( $hooked_blocks, $context ) {
		$markup = '';

		$relative_position  = 'after';
		$anchor_block_type  = $block['blockName'];
		$hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
				? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
				: array();

		/** This filter is documented in wp-includes/blocks.php */
		$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
		foreach ( $hooked_block_types as $hooked_block_type ) {
			$markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' );
		}

		if ( $parent_block && ! $next ) {
			// Candidate for last-child insertion.
			$relative_position  = 'last_child';
			$anchor_block_type  = $parent_block['blockName'];
			$hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
				? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
				: array();

			/** This filter is documented in wp-includes/blocks.php */
			$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
			foreach ( $hooked_block_types as $hooked_block_type ) {
				$markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' );
			}
		}

		return $markup;
	};
}

常见问题

FAQs
查看更多 >