function _wpcom_vip_custom_metadata_save_user_data_as_attributes($object_type, $object_id, $field_slug, $value) { if (!empty($value)) { update_user_attribute($object_id, $field_slug, $value); } else { delete_user_attribute($object_id, $field_slug); } }
/** * Handle adding user meta across potential hosting platforms. * * @param int $user_id * @param string $key * @param mixed $value * @static * @access private */ private static function add_user_meta($user_id, $key, $value) { // We can't use add_user_meta because there is no equivalent on VIP. // Instead manage values within the same variable for consistency. $values = self::get_user_meta($user_id, $key); if (empty($values)) { $values = array(); } // Add the new value $values[] = $value; // Save using the appropriate method if (defined('WPCOM_IS_VIP_ENV') && true === WPCOM_IS_VIP_ENV) { return update_user_attribute($user_id, $key, $values); } else { return update_user_meta($user_id, $key, $values); } }
/** * rinatkhaziev: This is modified version of dialog.php * */ function dialog_button() { define('IFRAME_REQUEST', true); if (!current_user_can('edit_posts')) { wp_die(__("You are not allowed to be here")); } //native WP string, no need to i18n @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); wp_enqueue_script('tiny_mce_popup.js', includes_url('js/tinymce/tiny_mce_popup.js')); if (isset($_POST['login']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'storify_login')) { $login = apply_filters('storify_login', $_POST['login']); if ($login) { update_user_attribute(get_current_user_id(), $this->login_meta, $login); } else { delete_user_attribute(get_current_user_id(), $this->login_meta); } } $callback = $this->get_login() ? 'insert_story_dialog' : 'login_dialog'; wp_iframe(array(&$this, $callback)); exit; }
function AtD_update_setting($user_id, $name, $value) { update_user_attribute($user_id, $name, $value); }
/** * Wrapper utility to for using WordPress.com update_user_attribute() when available. Falls back to update_user_meta() * * @param $user_id * @param $meta_key * @param $meta_value * * @return mixed */ public static function update_user_meta($user_id, $meta_key, $meta_value) { if (function_exists('update_user_attribute')) { $result = update_user_attribute($user_id, $meta_key, $meta_value); } else { $result = update_user_meta($user_id, $meta_key, $meta_value); } return $result; }
/** * Update user meta in a way that is also safe for VIP * * @param int $user_id * @param string $meta_key * @param mixed $meta_value * @param mixed $prev_value (optional) * * @return int|bool */ function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') { if (wp_stream_is_vip() && function_exists('update_user_attribute')) { return update_user_attribute($user_id, $meta_key, $meta_value); } return update_user_meta($user_id, $meta_key, $meta_value, $prev_value); }
/** * Handles our Ajax requests for the custom screen options. Called from dashboard-scripts.js. Only runs when a user is logged in (hence the wp_ajax_* action); * @return void */ function ajax_save_user_screen_options() { // Ensure that users with a role of Editor or higher can save these options if (!current_user_can($this->user_capabilities)) { return; } // Make sure everything is as it's supposed to. if (isset($_POST['submission']) && $_POST['submission'] == 'submit-current-faire-screen-options' && wp_verify_nonce($_POST['nonce'], 'current-faire-screen-save')) { // Turn our query string into an array parse_str(sanitize_text_field($_POST['data']), $data); $user_id = get_current_user_id(); $updates = update_user_attribute($user_id, 'metaboxhidden_current_faire', $data); } }
function fbwpcom_update_user_meta($original, $user_id, $meta_key, $meta_value, $prev_value) { update_user_attribute($user_id, $meta_key, $meta_value, $prev_value); return true; }
public function hsinsider_school_ajax() { if (!current_user_can('edit_others_posts')) { wp_send_json_error('unauthorized'); } if (empty($_GET['user_id']) || empty($_GET['school'])) { wp_send_json_error('incomplete'); } $user_id = (int) $_GET['user_id']; if (!wp_verify_nonce($_GET['_nonce'], 'user_school-' . $user_id)) { wp_send_json_error('invalid_nonce'); } $user = get_user_by('id', $user_id); if (!in_array('student', $user->roles)) { wp_send_json_error('not_student'); } $school = (int) $_GET['school']; if (term_exists($school, 'school')) { update_user_attribute($user->ID, '_hsinsider_school', $school); } else { delete_user_attribute($user->ID, '_hsinsider_school'); } wp_send_json_success(); }