'1', 'key2' => '0' ] * @var array $options Hierarchical array structure * @var string $desc * @var string $link * @var bool $disabled * @var bool $premium * @var bool $section_premium */ use AdPresso\Infrastructure\Util; if ( ! defined( 'ABSPATH' ) ) { exit; } // Helper for recursion. if ( ! function_exists( 'adpresso_render_toggle_tree' ) ) { /** * @param $items * @param $parent_name * @param $current_values * @param int $depth * @param bool $premium * @param bool $disabled * @param bool $section_premium * @param string|bool $link * @param bool $locked Below a locked premium toggle. * * @return void */ function adpresso_render_toggle_tree( $items, $parent_name, $current_values, int $depth = 0, bool $premium = false, bool $disabled = false, bool $section_premium = false, string|bool $link = false, bool $locked = false ): void { foreach ( $items as $key => $item ) { $item_label = $item['label']; $has_children = ! empty( $item['children'] ); $item_is_premium = $premium || ! empty( $item['premium'] ); $item_is_disabled = $disabled || ! empty( $item['disabled'] ); $item_is_locked = $locked || $item_is_premium; // Detect the value. default is 1/true, when not set. $stored_value = isset( $current_values[ $key ] ) ? (bool) $current_values[ $key ] : (bool) ( $item['default'] ?? true ); // A locked premium toggle (and its children) shows off but keeps its stored value. $is_checked = $stored_value && ! $item_is_locked; // Input Name: e.g. adpresso_settings[display][pages] $input_name = $parent_name . '[' . $key . ']'; $input_id = 'toggle_' . md5( $input_name ); // Unique ID // Wrapper-Klasse for intendation. $wrapper_class = 'adpresso-hierarchy-item'; if ( $depth > 0 ) { $wrapper_class .= ' is-child level-' . $depth; } if ( $item_is_disabled ) { $wrapper_class .= ' is-disabled'; } if ( $item_is_premium ) { $wrapper_class .= ' is-premium'; } ?>