get_condition( $node['type'] ); if ( $condition ) { $context = $condition->get_execution_context(); if ( $context === ConditionInterface::CONTEXT_FRONTEND_JS || $context === ConditionInterface::CONTEXT_FRONTEND_AJAX ) { return true; } } } elseif ( isset( $node['groups'] ) ) { // It's the new "Mailchimp-style" root node foreach ( (array) $node['groups'] as $group_node ) { if ( is_array( $group_node ) && self::check_node_for_frontend_conditions( $group_node ) ) { return true; // Found one in a subgroup } } } elseif ( isset( $node['conditions'] ) ) { // It's a group node foreach ( (array) $node['conditions'] as $condition_node ) { if ( is_array( $condition_node ) && self::check_node_for_frontend_conditions( $condition_node ) ) { return true; // Found one in a child condition } } } return false; // No frontend conditions found in this branch } /** * Helper function to create a summary from the "Mailchimp-style" condition tree. * * @param array $tree The full condition tree. * * @return array An associative array of [label => value] for the summary. */ public static function summarize_conditions_recursive( array $tree ): array { $summary = []; $registry = Condition_Registry::get(); $total_conditions = 0; // Flatten all conditions from all groups into a single list for the summary foreach ( $tree['groups'] ?? [] as $group ) { foreach ( $group['conditions'] ?? [] as $condition_node ) { $total_conditions++; if ( count( $summary ) >= 5 ) { continue; // Stop adding new items if max is reached } $condition = $registry->get_condition( $condition_node['type'] ?? '' ); if ( ! $condition ) { continue; } $label = $condition->get_label(); $operator_label = $condition->get_supported_operators()[ $condition_node['operator'] ?? '' ] ?? $condition_node['operator']; $formatted_value = $condition->format_value( $condition_node['value'] ?? null ); // Use a unique key to prevent overwriting if the same condition type is used multiple times $summary_key = $label; $i = 2; while ( isset( $summary[ $summary_key ] ) ) { $summary_key = $label . ' (' . $i++ . ')'; } $summary[ $summary_key ] = sprintf( '%s:
%s', $operator_label, $formatted_value ); } } if ( $total_conditions > count( $summary ) ) { $remaining = $total_conditions - count( $summary ); $summary['...'] = sprintf( /* translators: %d is the number of additional conditions to show. */ _n( '%d more condition', '%d more conditions', $remaining, 'adpresso' ), $remaining ); } return $summary; } }