public static function getCustomConditional($custom, $suffix = '', $cond_values = array()) { $c_fields = WPToolset_Forms_Conditional::extractFields($custom); $c_values = array(); // Loop over extracted fields and adjust custom statement foreach ($c_fields as $c_field_id) { // Get field settings $c_field = self::getConfig($c_field_id); // If it's Types field if (!empty($c_field)) { // Adjust custom statement $custom = preg_replace('/\\$\\(' . $c_field_id . '\\)/', "\$({$c_field['meta_key']}{$suffix})", $custom); $custom = preg_replace('/\\$' . $c_field_id . '[\\s\\)]/', "\${$c_field['meta_key']}{$suffix} ", $custom); // Apply filters from field (that is why we set 'type' property) wptoolset_form_field_add_filters($c_field['type']); $c_key = $c_field['meta_key']; if (isset($cond_values[$c_key])) { $c_values[$c_key . $suffix] = apply_filters('wptoolset_conditional_value_php', $cond_values[$c_key], $c_field['type']); } // Otherwise do nothing (leave statement as it is and just add [values]) // That allows checking for non-Types field } elseif (isset($cond_values[$c_field_id])) { $c_values[$c_field_id . $suffix] = $cond_values[$c_field_id]; } } // Set conditional setting $cond = array('custom' => $custom, 'values' => $c_values); return $cond; }
/** * Custom conditional AJAX check (called from bootstrap.php) */ public static function ajaxCustomConditional() { $res = array('passed' => array(), 'failed' => array()); $conditional = stripslashes_deep($_POST['conditions']); foreach ($conditional as $k => $c) { $post_values = stripslashes_deep($_POST['values']); $values = array(); foreach ($post_values as $fid => $value) { if (isset($_POST['field_types'][$fid])) { $field_type = stripslashes_deep($_POST['field_types'][$fid]); wptoolset_form_field_add_filters($field_type); $value = apply_filters('wptoolset_conditional_value_php', $value, $field_type); } $values[$fid] = $value; } if ($passed = self::evaluateCustom($c, $values)) { $res['passed'][] = $k; } else { $res['failed'][] = $k; } } echo json_encode($res); die; }