/** * Process our date submitted trigger. * When this function is called, it will be passed the value of the parameter and will expect a bool return. * * @since 1.2.8 * @return bool */ function compare($value, $compare) { $plugin_settings = nf_get_settings(); $date_format = $plugin_settings['date_format']; $now = date($date_format, current_time('timestamp')); return ninja_forms_conditional_compare($now, $value, $compare); }
/** * Process our date submitted trigger. * When this function is called, it will be passed the value of the parameter and will expect a bool return. * * @since 1.2.8 * @return bool */ function compare($value, $compare) { global $ninja_forms_processing; $form_id = $ninja_forms_processing->get_form_ID(); $sub_count = nf_get_sub_count($form_id); return ninja_forms_conditional_compare($sub_count, $value, $compare); }
function ninja_forms_conditionals_field_filter($form_id) { global $ninja_forms_loading, $ninja_forms_processing; if (isset($ninja_forms_loading)) { $all_fields = $ninja_forms_loading->get_all_fields(); } else { $all_fields = $ninja_forms_processing->get_all_fields(); } foreach ($all_fields as $field_id => $user_value) { if (isset($ninja_forms_loading)) { $field = $ninja_forms_loading->get_field_settings($field_id); } else { $field = $ninja_forms_processing->get_field_settings($field_id); } // echo "<pre>"; // var_dump( $field ); // echo "</pre>"; $data = apply_filters('ninja_forms_field', $field['data'], $field_id); $x = 0; $display_style = ''; if (isset($data['conditional']) and is_array($data['conditional']) and !empty($data['conditional'])) { $action_pass = array(); foreach ($data['conditional'] as $conditional) { $action = $conditional['action']; $con_value = $conditional['value']; if (is_array($con_value)) { if (isset($con_value['value']) and isset($con_value['label'])) { if ($con_value['value'] == '_ninja_forms_no_value') { $con_value = $con_value['label']; } } } if (isset($conditional['cr']) and is_array($conditional['cr']) and !empty($conditional['cr'])) { $pass_array = array(); $x = 0; foreach ($conditional['cr'] as $cr) { $pass_array[$x] = false; if (isset($ninja_forms_loading)) { $user_value = $ninja_forms_loading->get_field_value($cr['field']); } else { $user_value = $ninja_forms_processing->get_field_value($cr['field']); } if (isset($cr['value'])) { if (is_array($user_value)) { foreach ($user_value as $v) { if (!$pass_array[$x]) { $pass_array[$x] = ninja_forms_conditional_compare($v, $cr['value'], $cr['operator']); } else { break; } } } else { $pass_array[$x] = ninja_forms_conditional_compare($user_value, $cr['value'], $cr['operator']); } } else { $pass_array[$x] = true; } $x++; } } if (isset($pass_array) and is_array($pass_array)) { if ($conditional['connector'] == 'and') { $pass = true; } else { if ($conditional['connector'] == 'or') { $pass = false; } } foreach ($pass_array as $p) { if ($conditional['connector'] == 'and') { if ($pass) { $pass = $p; } else { break; } } else { if ($conditional['connector'] == 'or') { if ($pass) { break; } else { $pass = $p; } } } } } if (isset($pass) and (!isset($action_pass[$action][$con_value]) or !$action_pass[$action][$con_value])) { $action_pass[$action][$con_value] = $pass; } } foreach ($data['conditional'] as $conditional) { $action = $conditional['action']; $con_value = $conditional['value']; if (is_array($con_value)) { if (isset($con_value['value']) and isset($con_value['label'])) { if ($con_value['value'] == '_ninja_forms_no_value') { $con_value = $con_value['label']; } } } $pass = $action_pass[$action][$con_value]; switch ($conditional['action']) { case 'show': if (!$pass) { $data['display_style'] = 'display:none;'; $data['visible'] = false; //$data['class'] .= ',ninja-forms-field-calc-no-new-op,ninja-forms-field-calc-no-old-op'; // Set our $calc to 0 if we're dealing with a list field. if ($field['type'] == '_list') { if (isset($data['list']['options']) and is_array($data['list']['options'])) { for ($x = 0; $x < count($data['list']['options']); $x++) { //$data['list']['options'][$x]['calc'] = ''; } } } if (isset($ninja_forms_processing)) { if ($field['type'] != '_spam') { $ninja_forms_processing->update_field_value($field_id, false); } } } else { $data['display_style'] = ''; $data['visible'] = true; } break; case 'hide': if ($pass) { $data['display_style'] = 'display:none;'; $data['visible'] = false; //$data['class'] .= ',ninja-forms-field-calc-no-new-op,ninja-forms-field-calc-no-old-op'; // Set our $calc to 0 if we're dealing with a list field. if ($field['type'] == '_list') { if (isset($data['list']['options']) and is_array($data['list']['options'])) { for ($x = 0; $x < count($data['list']['options']); $x++) { //$data['list']['options'][$x]['calc'] = ''; } } } if (isset($ninja_forms_processing)) { if ($field['type'] != '_spam') { $ninja_forms_processing->update_field_value($field_id, false); } } } else { $data['display_style'] = ''; $data['visible'] = true; } break; case 'change_value': if ($pass) { $data['default_value'] = $conditional['value']; } break; case 'add_value': if ($pass) { if (!isset($conditional['value']['value'])) { $value = $conditional['value']['label']; } else { $value = $conditional['value']; } if (!isset($data['list']['options']) or !is_array($data['list']['options'])) { $data['list']['options'] = array(); } $found = false; for ($x = 0; $x < count($data['list']['options']); $x++) { if (isset($data['list_show_value']) and $data['list_show_value'] == 1) { if ($data['list']['options'][$x]['value'] == $con_value) { $found = true; } } else { if ($data['list']['options'][$x]['label'] == $con_value) { $found = true; } } } if (!$found) { array_push($data['list']['options'], $value); } } break; case 'remove_value': if ($pass) { if (isset($data['list']['options']) and is_array($data['list']['options'])) { for ($x = 0; $x < count($data['list']['options']); $x++) { if (isset($data['list_show_value']) and $data['list_show_value'] == 1) { if ($data['list']['options'][$x]['value'] == $conditional['value']) { $data['list']['options'][$x]['display_style'] = 'display:none;'; $data['list']['options'][$x]['disabled'] = true; } } else { if ($data['list']['options'][$x]['label'] == $conditional['value']) { $data['list']['options'][$x]['display_style'] = 'display:none;'; $data['list']['options'][$x]['disabled'] = true; } } } $data['list']['options'] = array_values($data['list']['options']); } } break; default: $data['conditional_action'] = $conditional['action']; $data['conditional_pass'] = $pass; } } $field['data'] = $data; if (isset($ninja_forms_loading)) { $ninja_forms_loading->update_field_settings($field_id, $field); } else { $ninja_forms_processing->update_field_settings($field_id, $field); } } } }
function ninja_forms_conditionals_field_filter($form_id) { global $pagenow, $ninja_forms_loading, $ninja_forms_processing; if (is_admin() && $pagenow != 'admin-ajax.php') { return false; } if (isset($ninja_forms_loading)) { $all_fields = $ninja_forms_loading->get_all_fields(); } else { $all_fields = $ninja_forms_processing->get_all_fields(); } if (!is_array($all_fields)) { return false; } foreach ($all_fields as $field_id => $user_value) { if (isset($ninja_forms_loading)) { $field = $ninja_forms_loading->get_field_settings($field_id); } else { $field = $ninja_forms_processing->get_field_settings($field_id); } // Quick and dirty way of cleaning up the label for required elements with inside label positions //$field['data']['req_added'] = 1; $data = apply_filters('ninja_forms_field', $field['data'], $field_id); // We don't want to use the default value if we are on a calc field. if ($field['type'] == '_calc') { $data['default_value'] = 0; } $x = 0; $display_style = ''; if (isset($data['conditional']) and is_array($data['conditional']) and !empty($data['conditional'])) { $action_pass = array(); foreach ($data['conditional'] as $conditional) { $action = $conditional['action']; $con_value = $conditional['value']; if (is_array($con_value)) { if (isset($con_value['value']) and isset($con_value['label'])) { if ($con_value['value'] == '_ninja_forms_no_value') { $con_value = $con_value['label']; } else { $con_value = $con_value['value']; } } } if (isset($conditional['cr']) and is_array($conditional['cr']) and !empty($conditional['cr'])) { $pass_array = array(); $x = 0; foreach ($conditional['cr'] as $cr) { $pass_array[$x] = false; if (isset($ninja_forms_loading)) { $user_value = $ninja_forms_loading->get_field_value($cr['field']); } else { $user_value = $ninja_forms_processing->get_field_value($cr['field']); } if (isset($cr['value'])) { if (is_array($user_value)) { foreach ($user_value as $v) { if (!$pass_array[$x]) { $pass_array[$x] = ninja_forms_conditional_compare($v, $cr['value'], $cr['operator']); } else { break; } } } else { $pass_array[$x] = ninja_forms_conditional_compare($user_value, $cr['value'], $cr['operator']); } } else { $pass_array[$x] = true; } $x++; } } if (isset($pass_array) and is_array($pass_array)) { if ($conditional['connector'] == 'and') { $pass = true; } else { if ($conditional['connector'] == 'or') { $pass = false; } } foreach ($pass_array as $p) { if ($conditional['connector'] == 'and') { if ($pass) { $pass = $p; } else { break; } } else { if ($conditional['connector'] == 'or') { if ($pass) { break; } else { $pass = $p; } } } } } if (isset($pass) and (!isset($action_pass[$action][$con_value]) or !$action_pass[$action][$con_value])) { $action_pass[$action][$con_value] = $pass; } } foreach ($data['conditional'] as $conditional) { $action = $conditional['action']; $con_value = $conditional['value']; if (is_array($con_value)) { if (isset($con_value['value']) and isset($con_value['label'])) { if ($con_value['value'] == '_ninja_forms_no_value') { $con_value = $con_value['label']; } else { $con_value = $con_value['value']; } } } $pass = $action_pass[$action][$con_value]; switch ($conditional['action']) { case 'show': if (!$pass) { $data['display_style'] = 'display:none;'; $data['visible'] = false; $data['class'] .= ',ninja-forms-field-calc-no-new-op,ninja-forms-field-calc-no-old-op'; // Set our $calc to 0 if we're dealing with a list field. if ($field['type'] == '_list') { if (isset($data['list']['options']) and is_array($data['list']['options'])) { for ($x = 0; $x < count($data['list']['options']); $x++) { //$data['list']['options'][$x]['calc'] = ''; } } } if (isset($ninja_forms_loading)) { if ($field['type'] != '_spam') { $ninja_forms_loading->update_field_value($field_id, false); } } else { if (isset($ninja_forms_processing)) { if ($field['type'] != '_spam') { $user_value = $ninja_forms_processing->get_field_value($field_id); $ninja_forms_processing->update_field_value($field_id, false); $ninja_forms_processing->update_extra_value('_' . $field_id, $user_value); } } } } else { $data['display_style'] = ''; $data['visible'] = true; if (isset($ninja_forms_processing)) { if ($field['type'] != '_spam') { $current_value = $ninja_forms_processing->get_field_value($field_id); $user_value = $ninja_forms_processing->get_extra_value('_' . $field_id); if (!$current_value && $user_value) { $ninja_forms_processing->update_field_value($field_id, $user_value); } } } } break; case 'hide': if ($pass) { $data['display_style'] = 'display:none;'; $data['visible'] = false; $data['class'] .= ',ninja-forms-field-calc-no-new-op,ninja-forms-field-calc-no-old-op'; // Set our $calc to 0 if we're dealing with a list field. if ($field['type'] == '_list') { if (isset($data['list']['options']) and is_array($data['list']['options'])) { for ($x = 0; $x < count($data['list']['options']); $x++) { //$data['list']['options'][$x]['calc'] = ''; } } } if (isset($ninja_forms_processing)) { if ($field['type'] != '_spam') { $ninja_forms_processing->update_field_value($field_id, false); } } } else { $data['display_style'] = ''; $data['visible'] = true; } break; case 'change_value': if ($pass) { $data['default_value'] = $conditional['value']; if (isset($ninja_forms_loading)) { $ninja_forms_loading->update_field_value($field_id, $conditional['value']); } else { if (isset($ninja_forms_processing)) { $ninja_forms_processing->update_field_value($field_id, $conditional['value']); } } } break; case 'add_value': if ($pass) { if (!isset($conditional['value']['value'])) { $value = $conditional['value']['label']; } else { $value = $conditional['value']; } if (!isset($data['list']['options']) or !is_array($data['list']['options'])) { $data['list']['options'] = array(); } $found = false; for ($x = 0; $x < count($data['list']['options']); $x++) { if (isset($data['list_show_value']) and $data['list_show_value'] == 1) { if ($data['list']['options'][$x]['value'] == $con_value) { $found = true; } } else { if ($data['list']['options'][$x]['label'] == $con_value) { $found = true; } } } if (!$found) { array_push($data['list']['options'], $value); } } break; case 'remove_value': if ($pass) { if (isset($data['list']['options']) and is_array($data['list']['options'])) { for ($x = 0; $x < count($data['list']['options']); $x++) { if (isset($data['list_show_value']) and $data['list_show_value'] == 1) { if ($data['list']['options'][$x]['value'] == $conditional['value']) { $data['list']['options'][$x]['display_style'] = 'display:none;'; $data['list']['options'][$x]['disabled'] = true; } } else { if ($data['list']['options'][$x]['label'] == $conditional['value']) { $data['list']['options'][$x]['display_style'] = 'display:none;'; $data['list']['options'][$x]['disabled'] = true; } } } $data['list']['options'] = array_values($data['list']['options']); } } break; default: $data['conditional_action'] = $conditional['action']; $data['conditional_pass'] = $pass; } } $field['data'] = $data; if (isset($ninja_forms_loading)) { $ninja_forms_loading->update_field_settings($field_id, $field); } else { $ninja_forms_processing->update_field_settings($field_id, $field); } } } }
/** * Hook into processing and modify our notifications * * @since 1.2.8 * @return void */ function nf_cl_notification_process($id) { global $ninja_forms_processing; // Check to see if this notification is active. If it isn't, we don't want to check anything else. if (!Ninja_Forms()->notification($id)->active) { return false; } // Check to see if we have any conditions on this notification $conditions = nf_cl_get_conditions($id); if (empty($conditions) || !is_array($conditions)) { return false; } foreach ($conditions as $cond_id) { // Grab our action $action = nf_get_object_meta_value($cond_id, 'action'); // Grab our connector $connector = nf_get_object_meta_value($cond_id, 'connector'); // Grab our criteria $criteria = nf_cl_get_criteria($cond_id); $pass_array = array(); foreach ($criteria as $cr_id) { $param = nf_get_object_meta_value($cr_id, 'param'); $compare = nf_get_object_meta_value($cr_id, 'compare'); $value = nf_get_object_meta_value($cr_id, 'value'); if (isset(Ninja_Forms()->cl_triggers[$param])) { $pass_array[] = Ninja_Forms()->cl_triggers[$param]->compare($value, $compare); } else { $user_value = $ninja_forms_processing->get_field_value($param); $pass_array[] = ninja_forms_conditional_compare($user_value, $value, $compare); } } // Check our connector. If it is set to "all", then all our criteria have to match. if ('and' == $connector) { $pass = true; foreach ($pass_array as $p) { if (!$p) { $pass = false; break; } } } else { // If our connector is set to "any", then only one criteria has to match. $pass = false; foreach ($pass_array as $p) { if ($p) { $pass = true; break; } } } if ($pass) { if ('process' == $action) { Ninja_Forms()->notification($id)->active = true; } else { if ('noprocess' == $action) { Ninja_Forms()->notification($id)->active = false; } } } else { if ('process' == $action) { Ninja_Forms()->notification($id)->active = false; } else { if ('noprocess' == $action) { Ninja_Forms()->notification($id)->active = true; } } } } }