registry = $registry; } /** * Renders the fields for one rule. * * @param string $name Field name prefix, e.g. "yangra_conditional_rule[12]". * @param string $id Unique ID for the settings container. * @param array $rule Sanitized rule. * @param array{toggle: string, action: string, tips: array} $labels The switch label, the text after Show / Hide, * and the tips shown while the rule is on. * @return void */ public function render( string $name, string $id, array $rule, array $labels ): void { // Free has one condition group. Saved extra groups (from Pro) are kept and shown. $groups = $rule['groups']; if ( empty( $groups ) ) { $groups = array( array( 'id' => strtolower( wp_generate_password( 12, false ) ), 'conditions' => array(), ), ); } $settings_id = 'yangra-conditional-rule-' . $id; ?>

>

render_groups( $name, $groups ); ?>

registry->all() as $type => $available ) : ?>

}>}> $groups Groups. * @return void */ public function render_groups( string $name, array $groups ): void { foreach ( array_values( $groups ) as $group_index => $group ) { if ( $group_index > 0 ) { echo '

' . esc_html__( 'or', 'yangra-conditional' ) . '

'; } $this->render_group( $name . '[groups][' . $group_index . ']', $group ); } } /** * Renders one condition group: its conditions, its "Add condition" button * and the template for new conditions. * * @param string $name Field name prefix of the group, e.g. "yangra_conditional_rule[12][groups][0]". * @param array{id: string, conditions: array}>} $group Group. An empty `id` gets a new one when saved. * @return void */ public function render_group( string $name, array $group ): void { ?>
    $condition ) { $this->render_condition( $name . '[conditions][' . $condition_index . ']', $condition ); } ?>
} $condition Condition. * @return void */ private function render_condition( string $name, array $condition ): void { $registered = $this->registry->get( $condition['type'] ); ?>
  • registry->is_pro_type( $condition['type'] ) ) { /* translators: %s: condition name, e.g. "Visitor location". */ echo esc_html( sprintf( __( '%s: requires Pro, skipped.', 'yangra-conditional' ), $this->registry->pro_type_label( $condition['type'] ) ) ); } else { /* translators: %s: condition type ID. */ echo esc_html( sprintf( __( '%s: not recognised by this version, skipped.', 'yangra-conditional' ), $condition['type'] ) ); } ?> render_values( $name, $registered, $condition['values'] ); ?>
  • $values Saved values. * @return void */ private function render_values( string $name, Condition $condition, array $values ): void { $options = $condition->options(); $picked = array(); if ( $condition instanceof SearchableCondition ) { $picked = array_diff_key( $condition->labels( $values ), $options ); } $missing = array_diff( $values, array_map( 'strval', array_keys( $options ) ), array_map( 'strval', array_keys( $picked ) ) ); ?> is_multiple() && array() !== $options ) : ?>
    label() ); ?> $label ) : ?>
    is_multiple() ) : ?> render_picker( $name, $condition, $picked ); } ?> type() ) as $notice ) : ?>
    $picked Picked items that still exist, as value => label. * @return void */ private function render_picker( string $name, SearchableCondition $condition, array $picked ): void { $picker = $condition->picker(); ?>
        $label ) : /* translators: %s: item name, e.g. "Category: News". */ $remove_label = sprintf( __( 'Remove %s', 'yangra-conditional' ), $label ); ?>
      >