本文整理汇总了PHP中wpcf_form_simple_validate函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_form_simple_validate函数的具体用法?PHP wpcf_form_simple_validate怎么用?PHP wpcf_form_simple_validate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_form_simple_validate函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf_admin_post_add_attachment_hook
/**
*
* Only for attachments, only default checkboxes!
*
* @internal breakpoint
* @param type $post_ID
* @param type $post
*/
function wpcf_admin_post_add_attachment_hook($post_ID, $post)
{
global $wpcf;
/**
* Basic check: only attachment
*/
if ('attachment' != $post->post_type) {
return false;
}
/**
* Get all groups connected to this $post
*/
$groups = wpcf_admin_post_get_post_groups_fields($post);
if (empty($groups)) {
return false;
}
$all_fields = array();
$_not_valid = array();
$_error = false;
/**
* Loop over each group
*
* TODO Document this
* Connect 'wpcf-invalid-fields' with all fields
*/
foreach ($groups as $group) {
if (isset($group['fields'])) {
// Process fields
$fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation');
// Validate fields
$form = wpcf_form_simple_validate($fields);
$all_fields = $all_fields + $fields;
// Collect all not valid fields
if ($form->isError()) {
$_error = true;
// Set error only to true
$_not_valid = array_merge($_not_valid, (array) $form->get_not_valid());
}
}
}
// Set fields
foreach ($all_fields as $k => $v) {
// only Types field
if (empty($v['wpcf-id'])) {
continue;
}
$_temp = new WPCF_Field();
$_temp->set($wpcf->post, $v['wpcf-id']);
$all_fields[$k]['_field'] = $_temp;
}
foreach ($_not_valid as $k => $v) {
// only Types field
if (empty($v['wpcf-id'])) {
continue;
}
$_temp = new WPCF_Field();
$_temp->set($wpcf->post, $v['wpcf-id']);
$_not_valid[$k]['_field'] = $_temp;
}
/**
* Process all checkbox fields
*/
foreach ($all_fields as $field) {
/**
* only checkbox
*/
if (!isset($field['#type']) || 'checkbox' != $field['#type']) {
continue;
}
$field_data = wpcf_admin_fields_get_field($field['wpcf-id']);
/**
* check is checked for new!
*/
$checked = array_key_exists('checked', $field_data['data']) && $field_data['data']['checked'];
/**
* do not save empty and not checked? fine, go away...
*/
if ('no' == $field_data['data']['save_empty'] && !$checked) {
continue;
}
/**
* all other just save...
*/
$update_data = 0;
if ($checked) {
$update_data = $field_data['data']['set_value'];
}
add_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data);
}
do_action('wpcf_attachement_add', $post_ID);
}
示例2: wpcf_admin_userprofilesave_init
//.........这里部分代码省略.........
foreach ($field_data['data']['options'] as $option_id => $option_data) {
if (!isset($_POST['wpcf'][$field['id']][$option_id])) {
if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
$update_data[$option_id] = 0;
}
} else {
$update_data[$option_id] = $_POST['wpcf'][$field['id']][$option_id];
}
}
update_user_meta($user_id, $field['meta_key'], $update_data);
}
}
}
}
if ($errors) {
update_post_meta($user_id, '__wpcf-invalid-fields', true);
}
do_action('wpcf_user_saved', $user_id);
return;
}
global $wpcf;
$all_fields = array();
$_not_valid = array();
$_error = false;
$error = '';
$groups = $groups = wpcf_admin_usermeta_get_groups_fields();
if (empty($groups)) {
return false;
}
foreach ($groups as $group) {
// Process fields
$fields = wpcf_admin_usermeta_process_fields($user_id, $group['fields'], true, false, 'validation');
// Validate fields
$form = wpcf_form_simple_validate($fields);
$all_fields = $all_fields + $fields;
// Collect all not valid fields
if ($form->isError()) {
$_error = true;
// Set error only to true
$_not_valid = array_merge($_not_valid, (array) $form->get_not_valid());
}
}
// Set fields
foreach ($all_fields as $k => $v) {
// only Types field
if (empty($v['wpcf-id'])) {
continue;
}
$_temp = new WPCF_Usermeta_Field();
$_temp->set($user_id, $v['wpcf-id']);
$all_fields[$k]['_field'] = $_temp;
}
foreach ($_not_valid as $k => $v) {
// only Types field
if (empty($v['wpcf-id'])) {
continue;
}
$_temp = new WPCF_Usermeta_Field();
$_temp->set($user_id, $v['wpcf-id']);
$_not_valid[$k]['_field'] = $_temp;
}
$not_valid = apply_filters('wpcf_post_form_not_valid', $_not_valid, $_error, $all_fields);
// Notify user about error
if ($error) {
wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
}
示例3: wpcf_admin_post_save_post_hook
/**
* Important save_post hook.
*
* Core function. Works and stable. Do not move or change.
* If required, add hooks only.
*
* @internal breakpoint
* @param type $post_ID
* @param type $post
*/
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
global $wpcf;
// Basic cheks
/*
* Allow this hook to be triggered only if Types form is submitted
*/
if (!isset($_POST['_wpcf_post_wpnonce']) || !wp_verify_nonce($_POST['_wpcf_post_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) {
return false;
}
/*
* Do not save post if is type of:
* revision
* attachment
* wp-types-group
* view
* view-template
* cred-form
*/
if (in_array($post->post_type, $wpcf->excluded_post_types)) {
return false;
}
/*
*
*
* Get all groups connected to this $post
*/
$groups = wpcf_admin_post_get_post_groups_fields($post);
if (empty($groups)) {
return false;
}
$all_fields = array();
$_not_valid = array();
$_error = false;
/*
*
*
* Loop over each group
*
* TODO Document this
* Connect 'wpcf-invalid-fields' with all fields
*/
foreach ($groups as $group) {
// Process fields
$fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation');
// Validate fields
$form = wpcf_form_simple_validate($fields);
$all_fields = $all_fields + $fields;
// Collect all not valid fields
if ($form->isError()) {
$_error = true;
// Set error only to true
$_not_valid = array_merge($_not_valid, (array) $form->get_not_valid());
}
}
// Set fields
foreach ($all_fields as $k => $v) {
// only Types field
if (empty($v['wpcf-id'])) {
continue;
}
$_temp = new WPCF_Field();
$_temp->set($wpcf->post, $v['wpcf-id']);
$all_fields[$k]['_field'] = $_temp;
}
foreach ($_not_valid as $k => $v) {
// only Types field
if (empty($v['wpcf-id'])) {
continue;
}
$_temp = new WPCF_Field();
$_temp->set($wpcf->post, $v['wpcf-id']);
$_not_valid[$k]['_field'] = $_temp;
}
/*
*
* Allow interaction here.
* Conditional will set $error to false if field is conditional
* and not submitted.
*/
$error = apply_filters('wpcf_post_form_error', $_error, $_not_valid, $all_fields);
$not_valid = apply_filters('wpcf_post_form_not_valid', $_not_valid, $_error, $all_fields);
// Notify user about error
if ($error) {
wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
}
/*
* Save invalid elements so user can be informed after redirect.
*/
if (!empty($not_valid)) {
//.........这里部分代码省略.........
示例4: wpcf_admin_post_save_post_hook
/**
* save_post hook.
*
* @param type $post_ID
* @param type $post
*/
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
// TODO Check if this prevents saving from outside of post form
if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) {
return false;
}
if (!in_array($post->post_type, array('revision', 'attachment', 'wp-types-group', 'view', 'view-template'))) {
// Get groups
$groups = wpcf_admin_post_get_post_groups_fields($post);
if (empty($groups)) {
return false;
}
$all_fields = array();
foreach ($groups as $group) {
// Process fields
$fields = wpcf_admin_post_process_fields($post, $group['fields'], true);
// Validate fields
$form = wpcf_form_simple_validate($fields);
$all_fields = $all_fields + $fields;
$error = $form->isError();
// Trigger form error
if ($error) {
wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
}
}
// Save invalid elements so user can be informed after redirect
if (!empty($all_fields)) {
update_post_meta($post_ID, 'wpcf-invalid-fields', $all_fields);
}
// Save meta fields
if (!empty($_POST['wpcf'])) {
foreach ($_POST['wpcf'] as $field_slug => $field_value) {
// Don't save invalid
if (isset($all_fields[wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_slug)) . $field_slug]) && isset($all_fields[wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_slug)) . $field_slug]['#error'])) {
continue;
}
// Get field by slug
$field = wpcf_fields_get_field_by_slug($field_slug);
if (!empty($field)) {
// Apply filters
$field_value = apply_filters('wpcf_fields_value_save', $field_value, $field['type'], $field_slug);
$field_value = apply_filters('wpcf_fields_slug_' . $field_slug . '_value_save', $field_value);
$field_value = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_save', $field_value);
// Save field
update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field_slug, $field_value);
do_action('wpcf_fields_slug_' . $field_slug . '_save', $field_value);
do_action('wpcf_fields_type_' . $field['type'] . '_save', $field_value);
}
}
}
// Process checkboxes
foreach ($all_fields as $field) {
if ($field['#type'] == 'checkbox' && !isset($_POST['wpcf'][$field['wpcf-slug']])) {
delete_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug']);
}
}
}
}
示例5: wpcf_admin_post_save_post_hook
/**
* save_post hook.
*
* @param type $post_ID
* @param type $post
*/
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) {
return false;
}
if (!in_array($post->post_type, array('revision', 'attachment', 'wp-types-group', 'view', 'view-template'))) {
// Get groups
$groups = wpcf_admin_post_get_post_groups_fields($post);
if (empty($groups)) {
return false;
}
$all_fields = array();
foreach ($groups as $group) {
// Process fields
// Fix duplicates for repetitive fields
foreach ($group['fields'] as $temp_field_id => $temp_field_data) {
if (isset($temp_field_data['data']['repetitive']) && isset($_REQUEST['wpcf'][$temp_field_id])) {
if (count($_POST['wpcf'][$temp_field_id]) < 2) {
continue;
}
$temp_check_duplicates_old_value = array();
$temp_check_duplicates_new_value = array();
foreach ($_POST['wpcf'][$temp_field_id] as $posted_field_key => $posted_field_value) {
$temp_old_value = base64_decode($posted_field_value['old_value']);
$temp_new_value = isset($posted_field_value['new_value']) ? $posted_field_value['new_value'] : serialize($posted_field_value);
$temp_field_key = wpcf_types_get_meta_prefix($temp_field_data) . $temp_field_id;
// Check new values
if (in_array(md5($temp_new_value), $temp_check_duplicates_new_value)) {
unset($_POST['wpcf'][$temp_field_id][$posted_field_key]);
if ($temp_old_value != '__wpcf_repetitive_new_field') {
// Rebuild
delete_post_meta($post_ID, $temp_field_key, $temp_old_value);
update_post_meta($post_ID, $temp_field_key, $temp_old_value);
}
} else {
if ($temp_old_value == '__wpcf_repetitive_new_field') {
$_POST['wpcf'][$temp_field_id][intval($posted_field_key) * 1000] = $_POST['wpcf'][$temp_field_id][$posted_field_key];
unset($_POST['wpcf'][$temp_field_id][$posted_field_key]);
continue;
}
$temp_check_duplicates_new_value[] = md5($temp_new_value);
}
// Check old values
// if ($temp_old_value != '__wpcf_repetitive_new_field') {
// if (in_array(md5($temp_old_value),
// $temp_check_duplicates_old_value)) {
// unset($_POST['wpcf'][$temp_field_id][$posted_field_key]);
// if ($temp_old_value != '__wpcf_repetitive_new_field') {
// // Rebuild
// delete_post_meta($post_ID, $temp_field_key,
// $temp_old_value);
// update_post_meta($post_ID, $temp_field_key,
// $temp_old_value);
// }
// } else {
// if ($temp_old_value == '__wpcf_repetitive_new_field') {
// $_POST['wpcf'][$temp_field_id][intval($posted_field_key) * 1000] = $_POST['wpcf'][$temp_field_id][$posted_field_key];
// unset($_POST['wpcf'][$temp_field_id][$posted_field_key]);
// continue;
// }
// $temp_check_duplicates_old_value[] = md5($temp_old_value);
// }
// }
}
}
}
$_REQUEST['wpcf'] = $_POST['wpcf'];
// Fix indexes for repetitive
foreach ($group['fields'] as $temp_field_id => $temp_field_data) {
if (isset($temp_field_data['data']['repetitive']) && isset($_REQUEST['wpcf'][$temp_field_id])) {
$temp_count = 1;
$temp_data = $_REQUEST['wpcf'][$temp_field_id];
unset($_REQUEST['wpcf'][$temp_field_id]);
$_REQUEST['wpcf'][$temp_field_id] = array();
foreach ($temp_data as $temp_post_key => $temp_post_data) {
$_REQUEST['wpcf'][$temp_field_id][$temp_count] = $temp_post_data;
$temp_count += 1;
}
}
}
$_POST['wpcf'] = $_REQUEST['wpcf'];
$fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation');
// Validate fields
$form = wpcf_form_simple_validate($fields);
$all_fields = $all_fields + $fields;
$error = $form->isError();
// Trigger form error
if ($error) {
wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
}
}
// Save invalid elements so user can be informed after redirect
if (!empty($all_fields)) {
update_post_meta($post_ID, 'wpcf-invalid-fields', $all_fields);
//.........这里部分代码省略.........
示例6: wpcf_admin_post_save_post_hook
/**
* save_post hook.
*
* @param type $post_ID
* @param type $post
*/
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'update-' . $post->post_type . '_' . $post_ID)) {
return false;
}
if (in_array($post->post_type, array('revision', 'attachment', 'wp-types-group', 'view', 'view-template'))) {
return false;
}
// Get groups
$groups = wpcf_admin_post_get_post_groups_fields($post);
if (empty($groups)) {
return false;
}
$all_fields = array();
foreach ($groups as $group) {
// Process fields
$fields = wpcf_admin_post_process_fields($post, $group['fields'], true, false, 'validation');
// Validate fields
$form = wpcf_form_simple_validate($fields);
$all_fields = $all_fields + $fields;
$error = $form->isError();
// Trigger form error
if ($error) {
wpcf_admin_message_store(__('Please check your input data', 'wpcf'), 'error');
}
}
// Save invalid elements so user can be informed after redirect
if (!empty($all_fields)) {
update_post_meta($post_ID, 'wpcf-invalid-fields', $all_fields);
}
// Save meta fields
if (!empty($_POST['wpcf'])) {
foreach ($_POST['wpcf'] as $field_slug => $field_value) {
// Skip copied fields
if (isset($_POST['wpcf_repetitive_copy'][$field_slug])) {
continue;
}
$field = wpcf_fields_get_field_by_slug($field_slug);
if (empty($field)) {
continue;
}
$meta_key = wpcf_types_get_meta_prefix($field) . $field_slug;
// Don't save invalid
if (isset($all_fields[$meta_key]['#error'])) {
continue;
}
// Repetitive fields
if (isset($_POST['wpcf_repetitive'][$field_slug])) {
delete_post_meta($post_ID, $meta_key);
foreach ($field_value as $temp_id => $repetitive_data) {
// Skype specific
if ($field['type'] == 'skype') {
unset($repetitive_data['old_value']);
wpcf_admin_post_save_field($post_ID, $meta_key, $field, $repetitive_data, true);
} else {
wpcf_admin_post_save_field($post_ID, $meta_key, $field, $repetitive_data['new_value'], true);
}
}
} else {
wpcf_admin_post_save_field($post_ID, $meta_key, $field, $field_value);
}
}
}
// Process checkboxes
foreach ($all_fields as $field) {
if (!isset($field['#type'])) {
continue;
}
if ($field['#type'] == 'checkbox' && !isset($_POST['wpcf'][$field['wpcf-slug']])) {
$field_data = wpcf_admin_fields_get_field($field['wpcf-id']);
if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], 0);
} else {
delete_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug']);
}
}
if ($field['#type'] == 'checkboxes') {
$field_data = wpcf_admin_fields_get_field($field['wpcf-id']);
if (!empty($field_data['data']['options'])) {
$update_data = array();
foreach ($field_data['data']['options'] as $option_id => $option_data) {
if (!isset($_POST['wpcf'][$field['wpcf-slug']][$option_id])) {
if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
$update_data[$option_id] = 0;
}
} else {
$update_data[$option_id] = $_POST['wpcf'][$field['wpcf-slug']][$option_id];
}
}
update_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['wpcf-slug'], $update_data);
}
}
}
}