wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_get_first_block › WordPress Function

Seit6.3.0
Veraltetn/v
wp_get_first_block ( $blocks, $block_name )
Parameter: (2)
  • (array) $blocks Array of blocks.
    Erforderlich: Ja
  • (string) $block_name Name of the block to find.
    Erforderlich: Ja
Gibt zurück:
  • (array) Found block, or empty array if none found.
Definiert in:
Codex:

Finds the first occurrence of a specific block in an array of blocks.



Quellcode

function wp_get_first_block( $blocks, $block_name ) {
	foreach ( $blocks as $block ) {
		if ( $block_name === $block['blockName'] ) {
			return $block;
		}
		if ( ! empty( $block['innerBlocks'] ) ) {
			$found_block = wp_get_first_block( $block['innerBlocks'], $block_name );

			if ( ! empty( $found_block ) ) {
				return $found_block;
			}
		}
	}

	return array();
}