function rcl_update_post_custom_fields($post_id, $id_form = false) { require_once ABSPATH . "wp-admin" . '/includes/image.php'; require_once ABSPATH . "wp-admin" . '/includes/file.php'; require_once ABSPATH . "wp-admin" . '/includes/media.php'; $post = get_post($post_id); switch ($post->post_type) { case 'post': if (!$id_form) { $id_form = get_post_meta($post->ID, 'publicform-id', 1); if (!$id_form) { $id_form = 1; } } $id_field = 'custom_public_fields_' . $id_form; break; case 'products': $id_field = 'custom_saleform_fields'; break; default: $id_field = 'custom_fields_' . $post->post_type; } $get_fields = get_option($id_field); if ($get_fields) { $POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); foreach ((array) $get_fields as $custom_field) { $slug = $custom_field['slug']; if ($custom_field['type'] == 'checkbox') { $vals = array(); $select = explode('#', $custom_field['field_select']); $count_field = count($select); if (isset($POST[$slug])) { foreach ($POST[$slug] as $val) { for ($a = 0; $a < $count_field; $a++) { if ($select[$a] == $val) { $vals[] = $val; } } } } if ($vals) { $res = update_post_meta($post_id, $slug, $vals); } else { delete_post_meta($post_id, $slug); } } else { if ($custom_field['type'] == 'file') { $attach_id = rcl_upload_meta_file($custom_field, $post->post_author, $post_id); if ($attach_id) { update_post_meta($post_id, $slug, $attach_id); } } else { if ($POST[$slug]) { update_post_meta($post_id, $slug, $POST[$slug]); } else { if (get_post_meta($post_id, $slug, 1)) { delete_post_meta($post_id, $slug); } } } } } } }
function rcl_update_profile_fields($user_id) { //global $user_ID; require_once ABSPATH . "wp-admin" . '/includes/image.php'; require_once ABSPATH . "wp-admin" . '/includes/file.php'; require_once ABSPATH . "wp-admin" . '/includes/media.php'; $get_fields = get_option('custom_profile_field'); $get_fields = apply_filters('rcl_profile_fields', $get_fields); if ($get_fields) { foreach ((array) $get_fields as $custom_field) { $custom_field = apply_filters('update_custom_field_profile', $custom_field); if (!$custom_field || !$custom_field['slug']) { continue; } if (!is_admin() && $custom_field['admin'] == 1) { continue; } $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); $slug = $custom_field['slug']; if ($custom_field['type'] == 'checkbox') { $vals = array(); if (isset($_POST[$slug])) { $select = explode('#', $custom_field['field_select']); $count_field = count($select); foreach ($_POST[$slug] as $val) { for ($a = 0; $a < $count_field; $a++) { if ($select[$a] == $val) { $vals[] = $val; } } } } if ($vals) { update_user_meta($user_id, $slug, $vals); } else { delete_user_meta($user_id, $slug); } } else { if ($custom_field['type'] == 'file') { $attach_id = rcl_upload_meta_file($custom_field, $user_id); if ($attach_id) { update_user_meta($user_id, $slug, $attach_id); } } else { if ($_POST[$slug]) { update_user_meta($user_id, $slug, $_POST[$slug]); } else { if (get_user_meta($user_id, $slug, $_POST[$slug])) { delete_user_meta($user_id, $slug, $_POST[$slug]); } } } } } } do_action('rcl_update_profile_fields', $user_id); }
function register_user_metas($user_id) { require_once ABSPATH . "wp-admin" . '/includes/image.php'; require_once ABSPATH . "wp-admin" . '/includes/file.php'; require_once ABSPATH . "wp-admin" . '/includes/media.php'; $get_fields = get_option('custom_profile_field'); if (!$get_fields) { return false; } $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); foreach ((array) $get_fields as $custom_field) { $slug = $custom_field['slug']; if ($custom_field['type'] == 'checkbox') { $select = explode('#', $custom_field['field_select']); $count_field = count($select); if (isset($_POST[$slug])) { foreach ($_POST[$slug] as $val) { for ($a = 0; $a < $count_field; $a++) { if (trim($select[$a]) == $val) { $vals[] = $val; } } } if ($vals) { update_usermeta($user_id, $slug, $vals); } } } else { if ($custom_field['type'] == 'file') { $attach_id = rcl_upload_meta_file($custom_field, $user_id); if ($attach_id) { update_user_meta($user_id, $slug, $attach_id); } } else { if ($_POST[$slug]) { update_usermeta($user_id, $slug, $_POST[$slug]); } } } } }