/home/vianto5/cititower.mx/wp-content/plugins/wpforms/pro/includes
Edit: /home/vianto5/cititower.mx/wp-content/plugins/wpforms/pro/includes/class-conditional-logic-core.php (32537B)
__( 'is', 'wpforms' ),
'!=' => __( 'is not', 'wpforms' ),
'e' => __( 'empty', 'wpforms' ),
'!e' => __( 'not empty', 'wpforms' ),
'c' => __( 'contains', 'wpforms' ),
'!c' => __( 'does not contain', 'wpforms' ),
'^' => __( 'starts with', 'wpforms' ),
'~' => __( 'ends with', 'wpforms' ),
'>' => __( 'greater than', 'wpforms' ),
'<' => __( 'less than', 'wpforms' ),
];
$disabled_choice_operators = [ 'c', '!c', '^', '~', '>', '<' ];
ob_start();
// Block open markup.
printf(
'
',
esc_attr( $type ),
esc_attr( $type )
);
switch ( $type ) {
case 'field':
/*
* This settings block is for a field.
*/
// Define more data for this field.
$fields_instance = $args['instance'];
$field_id = wpforms_validate_field_id( $field['id'] );
$field_name = "fields[{$field_id}]";
$groups_id = "wpforms-conditional-groups-fields-{$field_id}";
$action_selected = ! empty( $field['conditional_type'] ) ? $field['conditional_type'] : '';
$conditionals = ! empty( $field['conditionals'] ) ? $field['conditionals'] : [ [ [] ] ];
$data_attrs = 'data-field-id="' . $field_id . '" ';
$reference = $field_id;
$enabled = isset( $field['conditional_logic'] ) ? $field['conditional_logic'] : false;
$action_desc = ! empty( $args['action_desc'] ) ? $args['action_desc'] : esc_html__( 'this field if', 'wpforms' );
if ( empty( $args['actions'] ) ) {
$actions = [
'show' => esc_attr__( 'Show', 'wpforms' ),
'hide' => esc_attr__( 'Hide', 'wpforms' ),
];
} else {
$actions = array_map( 'esc_attr', $args['actions'] );
}
// Output Conditional Logic toggle checkbox field option.
$fld = $fields_instance->field_element(
'toggle',
$field,
[
'slug' => 'conditional_logic',
'value' => $enabled,
'desc' => esc_html__( 'Enable Conditional Logic', 'wpforms' ),
'tooltip' => sprintf(
'
%2$s',
esc_url( wpforms_utm_link( 'https://wpforms.com/docs/how-to-use-conditional-logic-with-wpforms/', 'Field Options', 'Conditional Logic Documentation' ) ),
esc_html__( 'How to use Conditional Logic', 'wpforms' )
),
'data' => [
'name' => $field_name,
'actions' => $actions,
'action-desc' => esc_attr( $action_desc ),
'reference' => esc_attr( $reference ),
],
],
false
);
$fields_instance->field_element(
'row',
$field,
[
'slug' => 'conditional_logic',
'content' => $fld,
'class' => 'wpforms-conditionals-enable-toggle',
]
);
// Prevent conditional logic from being applied to itself.
if ( ! empty( $form_fields[ $field['id'] ] ) ) {
unset( $form_fields[ $field['id'] ] );
}
break;
case 'panel':
/*
* This settings block is for something else - connections / notifications etc.
*/
$form_data = $args['form'];
$action_desc = ! empty( $args['action_desc'] ) ? $args['action_desc'] : esc_html__( 'this connection if', 'wpforms' );
$reference = ! empty( $args['reference'] ) ? $args['reference'] : '';
if ( empty( $args['actions'] ) ) {
$actions = [
'go' => esc_attr__( 'Process', 'wpforms' ),
'stop' => esc_attr__( 'Don\'t process', 'wpforms' ),
];
} else {
$actions = array_map( 'esc_attr', $args['actions'] );
}
// Below we do a bunch of voodoo to determine where this block
// is located in the form builder - eg is it in a top level
// setting or in a subsection, etc.
if ( ! empty( $parent ) ) {
if ( ! empty( $subsection ) && ! wpforms_is_empty_string( $index ) ) {
$field_name = sprintf( '%s[%s][%s][%s]', $parent, $panel, $subsection, $index );
$groups_id = sprintf( 'wpforms-conditional-groups-%s-%s-%s', $parent, $panel, $subsection );
$enabled = ! empty( $form_data[ $parent ][ $panel ][ $subsection ][ $index ]['conditional_logic'] );
$action_selected = ! empty( $form_data[ $parent ][ $panel ][ $subsection ][ $index ]['conditional_type'] ) ? $form_data[ $parent ][ $panel ][ $subsection ][ $index ]['conditional_type'] : '';
$conditionals = ! empty( $form_data[ $parent ][ $panel ][ $subsection ][ $index ]['conditionals'] ) ? $form_data[ $parent ][ $panel ][ $subsection ][ $index ]['conditionals'] : [ [ [] ] ];
} elseif ( ! empty( $subsection ) ) {
$field_name = sprintf( '%s[%s][%s]', $parent, $panel, $subsection );
$groups_id = sprintf( 'wpforms-conditional-groups-%s-%s-%s', $parent, $panel, $subsection );
$enabled = ! empty( $form_data[ $parent ][ $panel ][ $subsection ]['conditional_logic'] );
$action_selected = ! empty( $form_data[ $parent ][ $panel ][ $subsection ]['conditional_type'] ) ? $form_data[ $parent ][ $panel ][ $subsection ]['conditional_type'] : '';
$conditionals = ! empty( $form_data[ $parent ][ $panel ][ $subsection ]['conditionals'] ) ? $form_data[ $parent ][ $panel ][ $subsection ]['conditionals'] : [ [ [] ] ];
} else {
$field_name = sprintf( '%s[%s]', $parent, $panel );
$groups_id = sprintf( 'wpforms-conditional-groups-%s-%s', $parent, $panel );
$enabled = ! empty( $form_data[ $parent ][ $panel ]['conditional_logic'] );
$action_selected = ! empty( $form_data[ $parent ][ $panel ]['conditional_type'] ) ? $form_data[ $parent ][ $panel ]['conditional_type'] : '';
$conditionals = ! empty( $form_data[ $parent ][ $panel ]['conditionals'] ) ? $form_data[ $parent ][ $panel ]['conditionals'] : [ [ [] ] ];
}
} else {
$field_name = sprintf( '%s', $panel );
$groups_id = sprintf( 'wpforms-conditional-groups-%s', $panel );
$enabled = ! empty( $form_data[ $panel ]['conditional_logic'] );
$action_selected = ! empty( $form_data[ $panel ]['conditional_type'] ) ? $form_data[ $panel ]['conditional_type'] : '';
$conditionals = ! empty( $form_data[ $panel ]['conditionals'] ) ? $form_data[ $panel ]['conditionals'] : [ [ [] ] ];
}
// Output Conditional Logic toggle checkbox panel setting.
wpforms_panel_field(
'toggle',
$panel,
'conditional_logic',
$args['form'],
esc_html__( 'Enable Conditional Logic', 'wpforms' ),
[
'tooltip' => sprintf(
'
%2$s',
esc_url( wpforms_utm_link( 'https://wpforms.com/docs/how-to-use-conditional-logic-with-wpforms/', 'Field Options', 'Conditional Logic Documentation' ) ),
esc_html__( 'How to use Conditional Logic', 'wpforms' )
),
'parent' => $parent,
'subsection' => $subsection,
'index' => $index,
'input_id' => 'wpforms-panel-field-' . implode( '-', array_filter( [ $parent, $panel, $subsection, 'conditional_logic', 'checkbox' ] ) ),
'input_class' => 'wpforms-panel-field-conditional_logic-checkbox',
'class' => 'wpforms-conditionals-enable-toggle',
'data' => [
'name' => $field_name,
'actions' => $actions,
'action-desc' => esc_attr( $action_desc ),
'reference' => esc_attr( $reference ),
],
]
);
break;
default:
$enabled = false;
$field_name = '';
$reference = '';
$action_selected = '';
$action_desc = '';
$groups_id = '';
$actions = [];
$conditionals = [];
}
// Only display the block details if conditional logic is enabled.
if ( $enabled ) :
$data_attrs .= 'data-input-name="' . esc_attr( $field_name ) . '"';
$style = $enabled ? '' : 'display:none;';
// Groups wrap open markup.
printf(
'
'; // Close Groups wrap markup.
endif; // End $enabled.
echo '
'; // Close block markup.
$output = ob_get_clean();
if ( $do_echo ) {
echo $output; //phpcs:ignore
} else {
return $output;
}
}
/**
* Process conditional rules.
*
* Check if a form passes the conditional logic rules that are provided.
*
* @since 1.3.8
* @since 1.6.1 Added multiple select support.
*
* @param array $fields List of fields with data and settings.
* @param array $form_data Form data and settings.
* @param array $conditionals List of conditionals.
*
* @return bool
*/
public function process( $fields, $form_data, $conditionals ) {
if ( empty( $conditionals ) ) {
return true;
}
$pass = false;
foreach ( $conditionals as $group_id => $group ) {
$pass_group = true;
if ( ! empty( $group ) ) {
foreach ( $group as $rule_id => $rule ) {
if (
! isset( $rule['field'] ) ||
$rule['field'] === '' ||
! isset( $rule['operator'] )
) {
continue;
}
if ( ! isset( $rule['value'] ) && ! in_array( $rule['operator'], [ 'e', '!e' ], true ) ) {
continue;
}
$rule_field = $rule['field'];
if ( empty( $fields[ $rule_field ]['type'] ) ) {
continue;
}
$rule_operator = $rule['operator'];
$rule_value = isset( $rule['value'] ) ? $rule['value'] : '';
if ( in_array( $fields[ $rule_field ]['type'], $this->get_text_based_fields(), true ) ) {
// Text based fields.
$left = isset( $fields[ $rule_field ]['value'] ) ? $fields[ $rule_field ]['value'] : '';
$left = strtolower( trim( wpforms_decode_string( $left ) ) );
$right = strtolower( trim( $rule_value ) );
switch ( $rule_operator ) {
case '==':
$pass_rule = $left === $right;
break;
case '!=':
$pass_rule = $left !== $right;
break;
case 'c':
$pass_rule = ( strpos( $left, $right ) !== false );
break;
case '!c':
$pass_rule = ( strpos( $left, $right ) === false );
break;
case '^':
$pass_rule = ( strrpos( $left, $right, -strlen( $left ) ) !== false );
break;
case '~':
// phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
$pass_rule = ( ( $temp = strlen( $left ) - strlen( $right ) ) >= 0 && strpos( $left, $right, $temp ) !== false );
break;
case 'e':
$pass_rule = $left === '';
break;
case '!e':
$pass_rule = $left !== '';
break;
case '>':
$left = preg_replace( '/[^-0-9.]/', '', $left );
$pass_rule = ( $left !== '' ) && ( floatval( $left ) > floatval( $right ) );
break;
case '<':
$left = preg_replace( '/[^-0-9.]/', '', $left );
$pass_rule = ( $left !== '' ) && ( floatval( $left ) < floatval( $right ) );
break;
default:
// phpcs:disable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
/**
* Allows developers to extend conditional logic with own rule operators.
*
* @since 1.2.3
*
* @param bool $pass_rule Pass rule, `false` by default.
* @param string $rule_operator Rule operator.
* @param string $field_value Field value.
* @param string $rule_value Rule value.
*/
$pass_rule = apply_filters( 'wpforms_process_conditional_logic', false, $rule_operator, $left, $right );
// phpcs:enable
break;
}
} else {
// Selector based fields.
$provided_id = false;
if (
in_array( $fields[ $rule_field ]['type'], [ 'payment-multiple', 'payment-checkbox', 'payment-select' ], true ) &&
isset( $fields[ $rule_field ]['value_raw'] ) &&
(string) $fields[ $rule_field ]['value_raw'] !== ''
) {
// Payment Multiple/Checkbox fields store the option key,
// so we can reference that easily.
$provided_id = explode( ',', (string) $fields[ $rule_field ]['value_raw'] );
} elseif ( isset( $fields[ $rule_field ]['value'] ) && (string) $fields[ $rule_field ]['value'] !== '' ) {
// Other select type fields we don't store the
// option key so we have to do the logic to locate
// it ourselves.
$provided_id = [];
if ( in_array( $fields[ $rule_field ]['type'], [ 'checkbox', 'select' ], true ) ) {
$values = explode( "\n", $fields[ $rule_field ]['value'] );
} else {
$values = (array) $fields[ $rule_field ]['value'];
}
foreach ( $form_data['fields'][ $rule_field ]['choices'] as $key => $choice ) {
// Use only the label for comparison.
$choice_label = wpforms_decode_string( $choice['label'] );
// Remove newlines from the choice (label or value) before comparing.
// Newlines can be pasted with a long text to the choice label (or value) in the form builder.
$choice_label = sanitize_text_field( $choice_label );
$values = array_map( 'wpforms_decode_string', $values );
// Check if the choice label is in the value array.
if ( in_array( $choice_label, $values, true ) ) {
$provided_id[] = $key;
}
}
}
$left = (array) $provided_id;
$right = strtolower( trim( (int) $rule_value ) );
switch ( $rule_operator ) {
case '==':
case 'c': // BC, no longer available.
case '^': // BC, no longer available.
case '~': // BC, no longer available.
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
$pass_rule = in_array( $right, $left );
break;
case '!=':
case '!c': // BC, no longer available.
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
$pass_rule = ! in_array( $right, $left );
break;
case 'e':
$pass_rule = empty( $left[0] );
break;
case '!e':
$pass_rule = ! empty( $left[0] );
break;
default:
// phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName
/** This filter is documented in the current file. */
$pass_rule = apply_filters( 'wpforms_process_conditional_logic', false, $rule_operator, $left, $right );
// phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName
break;
}
} // End `if()`.
/**
* Allows developers to extend conditional logic with own rules.
*
* @since 1.9.8.6
*
* @param bool $pass_rule Have we passed the rule?
* @param array $rule Rule data.
* @param array $form_data Form data and settings.
* @param array $fields Submitted fields.
*/
$pass_rule = (bool) apply_filters( 'wpforms_conditional_logic_core_process', $pass_rule, $rule, $form_data, $fields );
if ( ! $pass_rule ) {
$pass_group = false;
break;
}
} // End `foreach()`.
} // End `if()`.
if ( $pass_group ) {
$pass = true;
}
} // End `foreach()`.
return $pass;
}
/**
* Alias function for backwards compatibility.
*
* @since 1.0.0
*
* @param array $fields List of fields with data and settings.
* @param array $form_data Form data and settings.
* @param array $conditionals List of conditionals.
*
* @return bool
*/
public function conditionals_process( $fields, $form_data, $conditionals ) {
return $this->process( $fields, $form_data, $conditionals );
}
}
/**
* The function which returns the one WPForms_Conditional_Logic_Core instance.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* @since 1.1.0
*
* @return WPForms_Conditional_Logic_Core
*/
function wpforms_conditional_logic() {
return WPForms_Conditional_Logic_Core::instance();
}
wpforms_conditional_logic();