if ($wp_http_referer) { $form->addField('wp_http_referer', '', VFORM_HIDDEN, array(), array(), array('default' => esc_url($wp_http_referer))); } $form->addField('from', '', VFORM_HIDDEN, array(), array(), array('default' => 'profile')); $form->addField('action', '', VFORM_HIDDEN, array(), array(), array('default' => 'update')); $form->addField('user_id', '', VFORM_HIDDEN, array(), array(), array('default' => $user->ID)); $form->addField('checkuser_id', '', VFORM_HIDDEN, array(), array(), array('default' => $user->ID)); /* * This handles extra fields ( basically reading the field info and putting it into ValidForm ) * Currently handles `radio`, `checkbox`, `select`, `input_text` ( text field ), and `textarea` */ if ($fields->description) { $fields = json_decode($fields->description); foreach ($fields as $field) { //get info $info = bum_get_field_info($field); $fid = 'bum_' . sanitize_title($info['title']); //this is handling `radio`, `checkbox`, `select` if (in_array($info['cssClass'], array('radio', 'checkbox', 'select'))) { if ($info['cssClass'] == 'radio') { $type = VFORM_RADIO_LIST; } elseif ($info['cssClass'] == 'checkbox') { $type = VFORM_CHECK_LIST; } else { $type = VFORM_SELECT_LIST; } //Multiple values are seperated by | ( pipe ) if (strpos($info['meta_value'], '|') !== false) { $info['meta_value'] = explode('|', $info['meta_value']); } $box = $form->addField('bum_' . $info['id'], $info['title'], $type, array('required' => $info['required'] == 'false' ? false : true), array('required' => 'The following field is required: ' . $info['title']), $info['tip'] ? array('tip' => $info['tip'], 'default' => $info['meta_value']) : array('default' => $info['meta_value']));
/** * Save user meta data * * @param $user_id */ function bum_save_user_meta_data($user_id, $role = false) { //initializing variables $user = new WP_User($user_id); $fields = array(); $role = $role === false ? $user->roles[0] : $role; $fields = get_custom_user_fields($role); //reasons to fail /*if (!isset($_REQUEST['user_meta_box_nonce']) || empty($fields)) return false; // verify nonce if (!wp_verify_nonce($_REQUEST['user_meta_box_nonce'], basename(__FILE__))) { return $user_id; }*/ // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $user_id; } //update metas if (is_array($fields)) { foreach ($fields as $field) { $info = bum_get_field_info($field); $fid = 'bum_' . $info['id']; if (!isset($_POST[$fid]) && !isset($_POST[$fid . '[]'])) { continue; } $old = $info['meta_value']; $new = $_REQUEST[$fid]; if ($new && $new != $old) { if (is_array($new)) { $new = implode('|', $new); } update_user_meta($user_id, $fid, $new); } elseif ('' == $new && $old) { delete_user_meta($user_id, $fid, $old); } } } return true; }