Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Forms::get_block_path( array $block, array[] $block_list, int $iterations )

Returns a list of block parents plus the block itself in reverse order


Parameters Parameters

$block

(array) (Required) Parsed block array.

$block_list

(array[]) (Required) The list of WP Block array $block comes from.

$iterations

(int) (Required) Stores the number of iterations.


Top ↑

Return Return

(array[]) List of WP_Block arrays or an empty array if $block cannot be found within $block_list.


Top ↑

Source Source

File: includes/forms/class-llms-forms.php

978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
* @param int     $iterations Stores the number of iterations.
 * @return array[] List of WP_Block arrays or an empty array if `$block` cannot be found within `$block_list`.
 */
private function get_block_path( $block, $block_list, $iterations = 0 ) {
 
    foreach ( $block_list as $_block ) {
 
        // Found the block.
        if ( $block === $_block ) {
            return array( $block );
        }
 
        // No innerblocks, proceed to the next block.
        if ( empty( $_block['innerBlocks'] ) ) {
            continue;
        }
 
        // Look in innerblocks for the block.
        foreach ( $_block['innerBlocks'] as $inner_block ) {
 
            // The inner block needs to be merged to the path.
            $to_merge = array( $inner_block );
 
            if ( $block === $inner_block ) { // Inner block is the one we're looking for.
                $path     = array( $block );
                $to_merge = array(); // Inner block equals the path, no need to merge it.
            } else {
                $path = $this->get_block_path( $block, array( $inner_block ), $iterations + 1 );
            }
 
            if ( $path ) {
 
                // First iteration, append first block too.
                if ( ! $iterations ) {
                    $to_merge[] = $_block;
                }
 
                // Merge.
                return array_merge( $path, $to_merge );
 
            }
        }
    }
 
    // Block not found in the list.


Top ↑

Changelog Changelog

Changelog
Version Description
5.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.