/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } extract($args); global $post; $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $icon = isset($instance['icon']) ? $instance['icon'] : null; if ($icon) { $before_title = sprintf($before_title, 'ion-' . $icon); } ob_start(); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $methods = wp_get_user_contact_methods(); if (empty($methods)) { return; } $output = array(); foreach ($methods as $method => $label) { $value = get_the_author_meta($method, $post->post_author); if ('' == $value) { continue; } $output[] = sprintf('<a href="%s" class="ion-social-%s">%s</a>', $value, $method, $label); } echo '<ul class="social-profiles"><li>' . implode('</li><li>', $output) . '</li></ul>'; echo $after_widget; $content = ob_get_clean(); echo apply_filters($this->widget_id, $content); $this->cache_widget($args, $content); }
/** * Render the contact metabox for user profile screen * * @since 0.1.0 * * @param WP_User $user The WP_User object to be edited. */ function wp_user_profiles_contact_metabox($user = null) { // Get methods $methods = wp_get_user_contact_methods($user); ?> <table class="form-table"> <?php foreach ($methods as $name => $desc) { ?> <tr class="user-<?php echo esc_attr($name); ?> -wrap"> <th> <label for="<?php echo esc_attr($name); ?> "> <?php /** * Filter a user contactmethod label. * * The dynamic portion of the filter hook, `$name`, refers to * each of the keys in the contactmethods array. * * @since 2.9.0 * * @param string $desc The translatable label for the contactmethod. */ echo apply_filters("user_{$name}_label", $desc); ?> </label> </th> <td><input type="text" name="<?php echo esc_attr($name); ?> " id="<?php echo esc_attr($name); ?> " value="<?php echo esc_attr($user->{$name}); ?> " class="regular-text" /></td> </tr> <?php } ?> </table> <?php }
public function update_user_metadata($null, $object_id, $meta_key, $meta_value, $prev_value) { // prevent BP last activity back-comp, SEE: http://wp.me/pLVLj-gc if (function_exists('buddypress') && 'last_activity' === $meta_key) { return TRUE; } if (array_key_exists($meta_key, wp_get_user_contact_methods($object_id))) { if (!$meta_value) { if (get_metadata('user', $object_id, $meta_key)) { delete_metadata('user', $object_id, $meta_key); } return TRUE; } } return $null; }
/** * Add the default user profile metaboxes * * @since 0.1.0 * * @param string $type * @param mixed $user */ function wp_user_profiles_add_profile_meta_boxes($type = '', $user = null) { // Get types $types = wp_user_profiles_get_section_hooknames('profile'); // Bail if not user metaboxes if (empty($user) || !in_array($type, $types, true)) { return; } // Name add_meta_box('name', _x('Name', 'users user-admin edit screen', 'wp-user-profiles'), 'wp_user_profiles_name_metabox', $type, 'normal', 'core'); // About add_meta_box('about', _x('About', 'users user-admin edit screen', 'wp-user-profiles'), 'wp_user_profiles_about_metabox', $type, 'normal', 'core'); // Contact, if methods are registered if (wp_get_user_contact_methods($user)) { add_meta_box('contact', _x('Contact', 'users user-admin edit screen', 'wp-user-profiles'), 'wp_user_profiles_contact_metabox', $type, 'normal', 'core'); } }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } extract($args); global $post; $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $icon = isset($instance['icon']) ? $instance['icon'] : null; if ($icon) { $before_title = sprintf($before_title, 'ion-' . $icon); } $methods = wp_get_user_contact_methods(); $output = array(); foreach ($methods as $method => $label) { if ('user' == listify_theme_mod('social-association')) { $value = get_the_author_meta($method, $post->post_author); } else { $value = get_post_meta($post->ID, '_company_' . $method, true); } if ('' == $value) { continue; } if ($value && !strstr($value, 'http:') && !strstr($value, 'https:')) { $value = 'http://' . $value; } $output[] = sprintf('<a href="%s" target="_blank" class="ion-social-%s">%s</a>', $value, $method, $label); } if (empty($methods) || empty($output)) { return; } ob_start(); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } do_action('listify_widget_job_listing_social_before'); echo '<ul class="social-profiles"><li>' . implode('</li><li>', $output) . '</li></ul>'; do_action('listify_widget_job_listing_social_after'); echo $after_widget; $content = ob_get_clean(); echo apply_filters($this->widget_id, $content); $this->cache_widget($args, $content); }
/** * Return user contact methods Selectbox * * @since 2.0.0 bbPress (r2688) * * @uses _wp_get_user_contactmethods() To get the contact methods * @uses apply_filters() Calls 'bbp_edit_user_contact_methods' with the methods * @return string User contact methods */ function bbp_edit_user_contact_methods() { // Get the core WordPress contact methods $contact_methods = wp_get_user_contact_methods(bbpress()->displayed_user); return apply_filters('bbp_edit_user_contact_methods', $contact_methods); }
function save() { register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_public_evidence'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_css_bypass'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_alt_email'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_org_name'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_org_url'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_org_description'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_org_image'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_org_email'); register_setting('badgeos_obi_issuer_settings', 'badgeos_obi_issuer_org_revocationList'); // add your settings section add_settings_section('badgeos_obi_issuer_template-section-about', __('About', 'badgeos_obi_issuer'), array(&$this, 'badgeos_obi_issuer_settings_section_about'), 'badgeos_obi_issuer_template'); add_settings_section('badgeos_obi_issuer_template-section', __('General Settings', 'badgeos_obi_issuer'), array(&$this, 'badgeos_obi_issuer_settings_section_general'), 'badgeos_obi_issuer_template'); // add your setting's fields // add your setting's fields add_settings_field('badgeos_obi_issuer_alt_email', __('Alternative Email', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_select'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section', array('name' => 'badgeos_obi_issuer_alt_email', 'choices' => wp_get_user_contact_methods(), 'description' => __('Specify an optional additional email field if you would like users to be able to collect badges using a different address', 'badgeos_obi_issuer'))); add_settings_field('badgeos_obi_issuer_public_evidence', __('Public evidence', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_radio'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section', array('name' => 'badgeos_obi_issuer_public_evidence', 'choices' => array('true' => 'Enable', 'false' => 'Disable'), 'description' => __('Enable or Disable public badge evidence for submissions', 'badgeos_obi_issuer'))); add_settings_field('badgeos_obi_issuer_css_bypass', __('Plugin CSS', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_radio'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section', array('name' => 'badgeos_obi_issuer_css_bypass', 'choices' => array('true' => 'Enable', 'false' => 'Disable'), 'description' => __('Enable or Disable plugin CSS styling', 'badgeos_obi_issuer'))); add_settings_section('badgeos_obi_issuer_template-section2', __('Issuer Organization Override', 'badgeos_obi_issuer'), array(&$this, 'badgeos_obi_issuer_settings_section_override'), 'badgeos_obi_issuer_template'); add_settings_field('badgeos_obi_issuer_org_name', __('Name', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_text'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section2', array('name' => 'badgeos_obi_issuer_org_name', 'description' => __('The name of the issuing organization.', 'badgeos_obi_issuer'))); add_settings_field('badgeos_obi_issuer_org_url', __('Url', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_text'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section2', array('name' => 'badgeos_obi_issuer_org_url', 'description' => __('URL of the institution', 'badgeos_obi_issuer'))); add_settings_field('badgeos_obi_issuer_org_description', __('Description', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_textarea'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section2', array('name' => 'badgeos_obi_issuer_org_description', 'description' => __('A short description of the institution', 'badgeos_obi_issuer'))); add_settings_field('badgeos_obi_issuer_org_image', __('Image', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_text'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section2', array('name' => 'badgeos_obi_issuer_org_image', 'description' => __('An image representing the institution', 'badgeos_obi_issuer'))); add_settings_field('badgeos_obi_issuer_org_email', __('Email', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_text'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section2', array('name' => 'badgeos_obi_issuer_org_email', 'description' => __('Contact address for someone at the organization.', 'badgeos_obi_issuer'))); add_settings_field('badgeos_obi_issuer_org_revocationList', __('Revocation List Url', 'badgeos_obi_issuer'), array(&$this, 'settings_field_input_text'), 'badgeos_obi_issuer_template', 'badgeos_obi_issuer_template-section2', array('name' => 'badgeos_obi_issuer_org_revocationList', 'description' => __('URL of the Badge Revocation List. The endpoint should be a JSON representation of an object where the keys are the uid a revoked badge assertion, and the values are the reason for revocation. This is only necessary for signed badges.', 'badgeos_obi_issuer'))); }
public static function get_user_id_contact_methods($user_id) { $user = get_user_by('id', $user_id); if (function_exists('wp_get_user_contact_methods')) { // since wp 3.7 return wp_get_user_contact_methods($user); } else { $methods = array(); if (get_site_option('initial_db_version') < 23588) { $methods = array('aim' => __('AIM'), 'yim' => __('Yahoo IM'), 'jabber' => __('Jabber / Google Talk')); } return apply_filters('user_contactmethods', $methods, $user); } }
function extra_get_author_contact_methods($user_id = 0) { $user_id = !empty($user_id) ? $user_id : get_the_author_meta('ID'); $author = get_userdata($user_id); $methods = array(); foreach (wp_get_user_contact_methods($author) as $name => $desc) { if (!empty($author->{$name})) { $methods[$name] = array('slug' => $name, 'name' => $desc, 'url' => $author->{$name}); } } return $methods; }
/** * The old private function for setting up user contact methods. * * @since 2.9.0 * @access private */ function _wp_get_user_contactmethods($user = null) { return wp_get_user_contact_methods($user); }
/** * {@inheritdoc} */ public function register_fields($wp_fields) { $this->register_control_types($wp_fields); //////////////////////////// // Core: Personal Options // //////////////////////////// $wp_fields->add_section($this->object_type, $this->id . '-personal-options', null, array('label' => __('Personal Options'), 'form' => $this->id)); $field_args = array('sanitize_callback' => array($this, 'sanitize_rich_editing'), 'control' => array('type' => 'checkbox', 'section' => $this->id . '-personal-options', 'label' => __('Visual Editor'), 'description' => __('Disable the visual editor when writing'), 'capabilities_callback' => array($this, 'capability_is_subscriber_editing_profile'), 'checkbox_value' => 'false', 'internal' => true)); $wp_fields->add_field($this->object_type, 'rich_editing', null, $field_args); $field_args = array('control' => array('type' => 'user-color-scheme', 'section' => $this->id . '-personal-options', 'label' => __('Admin Color Scheme'), 'description' => __('Disable the visual editor when writing'), 'capabilities_callback' => array($this, 'capability_has_color_scheme_control'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'admin_color', null, $field_args); $field_args = array('sanitize_callback' => array($this, 'sanitize_comment_shortcuts'), 'control' => array('type' => 'checkbox', 'section' => $this->id . '-personal-options', 'label' => __('Keyboard Shortcuts'), 'description' => __('Enable keyboard shortcuts for comment moderation.') . ' ' . __('<a href="https://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">More information</a>'), 'capabilities_callback' => array($this, 'capability_is_subscriber_editing_profile'), 'checkbox_value' => 'true', 'internal' => true)); $wp_fields->add_field($this->object_type, 'comment_shortcuts', null, $field_args); $field_args = array('sanitize_callback' => array($this, 'sanitize_admin_bar_front'), 'control' => array('type' => 'checkbox', 'section' => $this->id . '-personal-options', 'label' => __('Toolbar'), 'description' => __('Show Toolbar when viewing site'), 'checkbox_value' => 'true', 'internal' => true)); $wp_fields->add_field($this->object_type, 'admin_bar_front', null, $field_args); //////////////// // Core: Name // //////////////// $wp_fields->add_section($this->object_type, $this->id . '-name', null, array('label' => __('Name'), 'form' => $this->id)); $field_args = array('control' => array('type' => 'text', 'section' => $this->id . '-name', 'label' => __('Username'), 'description' => __('Usernames cannot be changed.'), 'input_attrs' => array('disabled' => 'disabled'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'user_login', null, $field_args); $field_args = array('control' => array('type' => 'user-role', 'section' => $this->id . '-name', 'label' => __('Role'), 'capabilities_callback' => array($this, 'capability_show_roles'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'role', null, $field_args); $field_args = array('value_callback' => array($this, 'value_is_super_admin'), 'control' => array('type' => 'user-super-admin', 'section' => $this->id . '-name', 'label' => __('Super Admin'), 'description' => __('Grant this user super admin privileges for the Network.'), 'capabilities_callback' => array($this, 'capability_can_grant_super_admin'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'super_admin', null, $field_args); $field_args = array('control' => array('type' => 'text', 'section' => $this->id . '-name', 'label' => __('First Name'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'first_name', null, $field_args); $field_args = array('control' => array('type' => 'text', 'section' => $this->id . '-name', 'label' => __('Last Name'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'last_name', null, $field_args); $field_args = array('control' => array('id' => 'nickname', 'type' => 'text', 'section' => $this->id . '-name', 'label' => __('Nickname'), 'description' => __('(required)'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'user_nickname', null, $field_args); $field_args = array('control' => array('type' => 'user-display-name', 'section' => $this->id . '-name', 'label' => __('Display name publicly as'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'display_name', null, $field_args); //////////////////////// // Core: Contact Info // //////////////////////// $wp_fields->add_section($this->object_type, $this->id . '-contact-info', null, array('label' => __('Contact Info'), 'form' => $this->id)); $field_args = array('control' => array('id' => 'email', 'type' => 'user-email', 'section' => $this->id . '-contact-info', 'label' => __('E-mail'), 'description' => __('(required)'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'user_email', null, $field_args); $field_args = array('control' => array('type' => 'text', 'section' => $this->id . '-contact-info', 'label' => __('Website'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'user_url', null, $field_args); $contact_methods = wp_get_user_contact_methods(); foreach ($contact_methods as $method => $label) { /** * Filter a user contactmethod label. * * The dynamic portion of the filter hook, `$name`, refers to * each of the keys in the contactmethods array. * * @since 2.9.0 * * @param string $label The translatable label for the contactmethod. */ $label = apply_filters("user_{$method}_label", $label); $field_args = array('control' => array('type' => 'text', 'section' => $this->id . '-contact-info', 'label' => $label, 'internal' => true)); $wp_fields->add_field($this->object_type, $method, null, $field_args); } ///////////////// // Core: About // ///////////////// $about_title = __('About the user'); if (defined('IS_PROFILE_PAGE') && IS_PROFILE_PAGE) { $about_title = __('About Yourself'); } $wp_fields->add_section($this->object_type, $this->id . '-about', null, array('label' => $about_title, 'form' => $this->id)); $field_args = array('control' => array('type' => 'textarea', 'section' => $this->id . '-about', 'label' => __('Biographical Info'), 'description' => __('Share a little biographical information to fill out your profile. This may be shown publicly.'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'description', null, $field_args); ////////////////////////////// // Core: Account Management // ////////////////////////////// $wp_fields->add_section($this->object_type, $this->id . '-account-management', null, array('label' => __('Account Management'), 'form' => $this->id, 'capabilities_callback' => array($this, 'capability_show_password_fields'))); $field_args = array('control' => array('type' => 'user-password', 'section' => $this->id . '-account-management', 'label' => __('Password'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'user_pass', null, $field_args); $field_args = array('control' => array('type' => 'user-sessions', 'section' => $this->id . '-account-management', 'label' => __('Sessions'), 'internal' => true)); // If password fields not shown, show Sessions under About // @todo Change which section this control is in if password fields not shown /*if ( ! $show_password_fields ) { $field_args['control']['section'] = $this->id . '-about'; }*/ $wp_fields->add_field($this->object_type, 'sessions', null, $field_args); // @todo Figure out how best to run actions after section //if ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) { /** * Fires after the 'About Yourself' settings table on the 'Your Profile' editing form. * * The action only fires if the current user is editing their own profile. * * @since 2.0.0 * * @param WP_User $profileuser The current WP_User object. */ //do_action( 'show_user_profile', $profileuser ); //} else { /** * Fires after the 'About the User' settings table on the 'Edit User' form. * * @since 2.0.0 * * @param WP_User $profileuser The current WP_User object. */ //do_action( 'edit_user_profile', $profileuser ); //} /////////////////////////////////// // Core: Additional Capabilities // /////////////////////////////////// $wp_fields->add_section($this->object_type, 'additional-capabilities', null, array('label' => __('Additional Capabilities'), 'form' => $this->id, 'capabilities_callback' => array($this, 'capability_show_capabilities'))); $field_args = array('control' => array('type' => 'user-capabilities', 'section' => 'additional-capabilities', 'label' => __('Capabilities'), 'internal' => true)); $wp_fields->add_field($this->object_type, 'capabilities', null, $field_args); // Add example fields (maybe) parent::register_fields($wp_fields); }
/** * Register controls for User Profiles * * @todo Move out of wp-admin implementation */ public function register_controls() { /** * @var $wp_fields WP_Fields_API */ global $wp_fields; // Register control types $wp_fields->register_control_type('user-color-scheme', 'WP_Fields_API_Color_Scheme_Control'); $wp_fields->register_control_type('user-role', 'WP_Fields_API_User_Role_Control'); $wp_fields->register_control_type('user-super-admin', 'WP_Fields_API_User_Super_Admin_Control'); $wp_fields->register_control_type('user-display-name', 'WP_Fields_API_User_Display_Name_Control'); $wp_fields->register_control_type('user-email', 'WP_Fields_API_User_Email_Control'); $wp_fields->register_control_type('user-password', 'WP_Fields_API_User_Password_Control'); $wp_fields->register_control_type('user-sessions', 'WP_Fields_API_User_Sessions_Control'); $wp_fields->register_control_type('user-capabilities', 'WP_Fields_API_User_Capabilities_Control'); // Add Edit Profile screen $wp_fields->add_screen('user', 'edit-profile'); //////////////////////////// // Core: Personal Options // //////////////////////////// $wp_fields->add_section('user', 'personal-options', 'edit-profile', array('title' => __('Personal Options'))); // @todo Controls hidden if subscriber is editing their profile logic /*$user_can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); $is_subscriber_editing_profile = ! ( IS_PROFILE_PAGE && ! $user_can_edit );*/ $field_args = array('control' => array('type' => 'checkbox', 'section' => 'personal-options', 'label' => __('Visual Editor'), 'description' => __('Disable the visual editor when writing'))); $wp_fields->add_field('user', 'rich_editing', 'edit-profile', $field_args); // @todo Control hidden if no admin css colors AND color scheme picker set // $has_color_scheme_control = ( count($_wp_admin_css_colors) > 1 && has_action('admin_color_scheme_picker') ) $field_args = array('control' => array('type' => 'user-color-scheme', 'section' => 'personal-options', 'label' => __('Admin Color Scheme'), 'description' => __('Disable the visual editor when writing'))); $wp_fields->add_field('user', 'admin_color', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'checkbox', 'section' => 'personal-options', 'label' => __('Keyboard Shortcuts'), 'description' => __('Enable keyboard shortcuts for comment moderation.') . ' ' . __('<a href="https://codex.wordpress.org/Keyboard_Shortcuts" target="_blank">More information</a>'))); $wp_fields->add_field('user', 'comment_shortcuts', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'checkbox', 'section' => 'personal-options', 'label' => __('Toolbar'), 'description' => __('Show Toolbar when viewing site'))); $wp_fields->add_field('user', 'admin_bar_front', 'edit-profile', $field_args); //////////////// // Core: Name // //////////////// $wp_fields->add_section('user', 'name', 'edit-profile', array('title' => __('Name'))); $field_args = array('control' => array('type' => 'text', 'section' => 'name', 'label' => __('Username'), 'description' => __('Usernames cannot be changed.'), 'input_attrs' => array('disabled' => 'disabled'))); $wp_fields->add_field('user', 'user_login', 'edit-profile', $field_args); // @todo Roles $can_change_roles = !IS_PROFILE_PAGE && !is_network_admin(); $field_args = array('control' => array('type' => 'user-role', 'section' => 'name', 'label' => __('Role'))); $wp_fields->add_field('user', 'user_login', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'user-super-admin', 'section' => 'name', 'label' => __('Super Admin'), 'description' => __('Grant this user super admin privileges for the Network.'))); $wp_fields->add_field('user', 'super_admin', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'text', 'section' => 'name', 'label' => __('First Name'))); $wp_fields->add_field('user', 'first_name', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'text', 'section' => 'name', 'label' => __('Last Name'))); $wp_fields->add_field('user', 'last_name', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'text', 'section' => 'name', 'label' => __('Nickname'), 'description' => __('(required)'))); $wp_fields->add_field('user', 'user_nickname', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'user-display-name', 'section' => 'name', 'label' => __('Display name publicly as'))); $wp_fields->add_field('user', 'display_name', 'edit-profile', $field_args); //////////////////////// // Core: Contact Info // //////////////////////// $wp_fields->add_section('user', 'contact-info', 'edit-profile', array('title' => __('Contact Info'))); $field_args = array('control' => array('type' => 'user-email', 'section' => 'contact-info', 'label' => __('E-mail'), 'description' => __('(required)'))); $wp_fields->add_field('user', 'user_email', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'text', 'section' => 'contact-info', 'label' => __('Website'))); $wp_fields->add_field('user', 'user_url', 'edit-profile', $field_args); // @todo Setup $profileuser correctly $profileuser = new stdClass(); $contact_methods = wp_get_user_contact_methods($profileuser); foreach ($contact_methods as $method => $label) { /** * Filter a user contactmethod label. * * The dynamic portion of the filter hook, `$name`, refers to * each of the keys in the contactmethods array. * * @since 2.9.0 * * @param string $label The translatable label for the contactmethod. */ $label = apply_filters("user_{$method}_label", $label); $field_args = array('control' => array('type' => 'text', 'section' => 'contact-info', 'label' => $label)); $wp_fields->add_field('user', $method, 'edit-profile', $field_args); } ///////////////// // Core: About // ///////////////// $about_title = __('About the user'); if (IS_PROFILE_PAGE) { $about_title = __('About Yourself'); } $wp_fields->add_section('user', 'about', 'edit-profile', array('title' => $about_title)); $field_args = array('control' => array('type' => 'text', 'section' => 'about', 'label' => __('Biographical Info'), 'description' => __('Share a little biographical information to fill out your profile. This may be shown publicly.'))); $wp_fields->add_field('user', 'description', 'edit-profile', $field_args); ////////////////////////////// // Core: Account Management // ////////////////////////////// /** This filter is documented in wp-admin/user-new.php */ $show_password_fields = apply_filters('show_password_fields', true, $profileuser); $wp_fields->add_section('user', 'account-management', 'edit-profile', array('title' => __('Account Management'))); $field_args = array('control' => array('type' => 'user-password', 'section' => 'account-management', 'label' => __('Password'))); $wp_fields->add_field('user', 'user_pass', 'edit-profile', $field_args); $field_args = array('control' => array('type' => 'user-sessions', 'section' => 'account-management', 'label' => __('Sessions'))); // If password fields not shown, show Sessions under About if (!$show_password_fields) { $field_args['control']['section'] = 'about'; } $wp_fields->add_field('user', 'sessions', 'edit-profile', $field_args); // @todo Figure out how best to run actions after section //if ( IS_PROFILE_PAGE ) { /** * Fires after the 'About Yourself' settings table on the 'Your Profile' editing screen. * * The action only fires if the current user is editing their own profile. * * @since 2.0.0 * * @param WP_User $profileuser The current WP_User object. */ //do_action( 'show_user_profile', $profileuser ); //} else { /** * Fires after the 'About the User' settings table on the 'Edit User' screen. * * @since 2.0.0 * * @param WP_User $profileuser The current WP_User object. */ //do_action( 'edit_user_profile', $profileuser ); //} /////////////////////////////////// // Core: Additional Capabilities // /////////////////////////////////// /** * Filter whether to display additional capabilities for the user. * * The 'Additional Capabilities' section will only be enabled if * the number of the user's capabilities exceeds their number of * of roles. * * @since 2.8.0 * * @param bool $enable Whether to display the capabilities. Default true. * @param WP_User $profileuser The current WP_User object. */ $show_capabilities = count($profileuser->roles) < count($profileuser->caps) && apply_filters('additional_capabilities_display', true, $profileuser); $wp_fields->add_section('user', 'additional-capabilities', 'edit-profile', array('title' => __('Additional Capabilities'))); $field_args = array('control' => array('type' => 'user-capabilities', 'section' => 'additional-capabilities', 'label' => __('Capabilities'))); $wp_fields->add_field('user', 'capabilities', 'edit-profile', $field_args); ////////////// // Examples // ////////////// // Section $wp_fields->add_section('user', 'example-my-fields', 'edit-profile', array('title' => __('Fields API Example - My Fields'))); // Add example for each control type $control_types = array('text', 'checkbox', 'multi-checkbox', 'radio', 'select', 'dropdown-pages', 'color', 'media', 'upload', 'image'); foreach ($control_types as $control_type) { $id = 'example_my_' . $control_type . '_field'; $label = sprintf(__('%s Field'), ucwords(str_replace('-', ' ', $control_type))); $field_args = array('control' => array('type' => $control_type, 'section' => 'example-my-fields', 'label' => $label)); $wp_fields->add_field('user', $id, 'edit-profile', $field_args); } }
protected static function build_available_user_contact_methods() { return array_merge(array('email' => __('E-mail')), wp_get_user_contact_methods()); }
/** * Save the password/account details and redirect back to the my account page. */ public function save_account_details() { if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } if (empty($_POST['action']) || 'save_account_details' !== $_POST['action'] || empty($_POST['_wpnonce'])) { return; } wp_verify_nonce($_POST['_wpnonce'], 'bon_save_account_details'); $update = true; $user = new stdClass(); $user->ID = (int) get_current_user_id(); $current_user = get_user_by('id', $user->ID); if ($user->ID <= 0) { return; } /* Name */ $account_first_name = !empty($_POST['account_first_name']) ? sanitize_text_field($_POST['account_first_name']) : ''; $account_last_name = !empty($_POST['account_last_name']) ? sanitize_text_field($_POST['account_last_name']) : ''; $account_nickname = !empty($_POST['account_nickname']) ? sanitize_text_field($_POST['account_nickname']) : ''; $account_display_name = !empty($_POST['account_display_name']) ? sanitize_text_field($_POST['account_display_name']) : ''; /* Contact Info */ $account_email = !empty($_POST['account_email']) ? sanitize_email($_POST['account_email']) : ''; $account_url = !empty($_POST['account_url']) ? esc_url($_POST['account_url']) : ''; $account_description = !empty($_POST['account_description']) ? esc_textarea($_POST['account_description']) : ''; $pass1 = !empty($_POST['password_1']) ? $_POST['password_1'] : ''; $pass2 = !empty($_POST['password_2']) ? $_POST['password_2'] : ''; $user->first_name = $account_first_name; $user->last_name = $account_last_name; $user->nickname = $account_nickname; $user->display_name = $account_display_name; $user->user_email = $account_email; $user->user_url = $account_url; $user->description = $account_description; foreach (wp_get_user_contact_methods($user) as $name => $desc) { if (isset($_POST[$name])) { $user->{$name} = $_POST[$name]; } } if ($pass1) { $user->user_pass = $pass1; } if (empty($account_first_name) || empty($account_last_name)) { bon_error_notice()->add('name_empty', __('Please enter your name.', 'bon'), 'error'); } if (empty($account_email) || !is_email($account_email)) { bon_error_notice()->add('invalid_email', __('Please provide a valid email address.', 'bon'), 'error'); } elseif (email_exists($account_email) && $account_email !== $current_user->user_email) { bon_error_notice()->add('email_exists', __('This email address is already registered.', 'bon'), 'error'); } if (!empty($pass1) && empty($pass2)) { bon_error_notice()->add('password_mismatch', __('Please re-enter your password.', 'bon'), 'error'); } elseif (!empty($pass1) && $pass1 !== $pass2) { bon_error_notice()->add('password_mismatch', __('Passwords do not match.', 'bon'), 'error'); } $errors = bon_error_notice(); $errors_message = $errors->get_error_messages(); // Allow plugins to return their own errors. do_action_ref_array('user_profile_update_errors', array(&$errors, $update, &$user)); if (empty($errors_message)) { wp_update_user($user); do_action('bon_save_account_details', $user->ID); wp_safe_redirect(add_query_arg('updated', 'true', $this->my_account_url())); exit; } }
<p> <?php echo $current_user->description; ?> </p> </figcaption> </figure> <h4 class="bon-form-title"><?php _e('Contact Info', 'bon'); ?> </h4> <ul class="bon-account-social-contact"> <?php foreach (wp_get_user_contact_methods($current_user) as $name => $desc) { ?> <?php if (isset($current_user->{$name}) && !empty($current_user->{$name}) && class_exists('Bon_Toolkit_Widget_Social')) { ?> <li> <a href="<?php echo esc_url($current_user->{$name}); ?> "> <i class="bt-icon-<?php echo $name; ?> "></i> </a> </li>
/** * Save section data * * @since 0.2.0 * * @param WP_User $user */ public function save($user = null) { // User Login if (isset($_POST['user_login'])) { // Set the login $user->user_login = sanitize_user($_POST['user_login'], true); // Invalid login if (!validate_username($user->user_login)) { $this->errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); } // Login already exists if (username_exists($user->user_login)) { $this->errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); } // Checking that username has been typed if (empty($user->user_login)) { $this->errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.')); } // Return if errored if ($this->errors->get_error_code()) { return $this->errors; } } // First $user->first_name = isset($_POST['first_name']) ? sanitize_text_field($_POST['first_name']) : ''; // Last $user->last_name = isset($_POST['last_name']) ? sanitize_text_field($_POST['last_name']) : ''; // Nickname if (isset($_POST['nickname'])) { // Set the nick $user->nickname = sanitize_text_field($_POST['nickname']); // Nickname was empty if (empty($user->nickname)) { $this->errors->add('nickname', __('<strong>ERROR</strong>: Please enter a nickname.')); return $this->errors; } } // Display $user->display_name = isset($_POST['display_name']) ? sanitize_text_field($_POST['display_name']) : ''; // Description $user->description = isset($_POST['description']) ? trim($_POST['description']) : ''; // Website if (isset($_POST['url'])) { // Emptying URL if (empty($_POST['url']) || in_array($_POST['url'], wp_allowed_protocols(), true)) { $user->user_url = ''; // Validate } else { $user->user_url = esc_url_raw($_POST['url']); $protocols = implode('|', array_map('preg_quote', wp_allowed_protocols())); $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url; } } // Look for contact methods $methods = wp_get_user_contact_methods($user); // Contact methods foreach (array_keys($methods) as $method) { if (isset($_POST[$method])) { $user->{$method} = sanitize_text_field($_POST[$method]); } } // Allow third party plugins to save data in this section parent::save($user); }
public function woocommerce_save_account_details($user_id) { $methods = wp_get_user_contact_methods(get_current_user_id()); if (empty($methods)) { return; } foreach ($methods as $method => $label) { $value = isset($_POST[$method]) ? esc_url($_POST[$method]) : null; update_user_meta($user_id, $method, $value); } if (isset($_POST['biography'])) { $biography = esc_textarea($_POST['biography']); update_user_meta($user_id, 'description', $biography); } }
<?php /** * Template Name: Member actions * **/ global $tst_member; $member_data = array(); $social_ids = wp_get_user_contact_methods(); if (empty($_GET['member'])) { $refer = stristr(wp_get_referer(), $_SERVER['REQUEST_URI']) !== false ? home_url() : wp_get_referer(); $back_url = $refer ? $refer : home_url(); wp_redirect($back_url); die; } $member_id = (int) $_GET['member']; $member = get_user_by('id', $member_id); if (empty($member) || !current_user_can('edit_user', $member_id)) { wp_redirect(home_url('member-actions')); die; } $tst_member = $member; $member_data = array('member_id' => $member_id, 'user_login' => $member->user_login, 'user_email' => $member->user_email, 'first_name' => $member->first_name, 'last_name' => $member->last_name, 'user_city' => tst_get_member_field('user_city', $member), 'user_speciality' => tst_get_member_field('user_speciality', $member), 'user_bio' => tst_get_member_field('user_bio', $member), 'user_professional' => tst_get_member_field('user_professional', $member), 'user_contacts' => tst_get_member_field('user_contacts', $member), 'user_website' => tst_get_member_field('user_website', $member), 'user_workplace' => tst_get_member_field('user_workplace', $member)); $social = array(); if ($social_ids) { foreach ($social_ids as $id => $label) { $value = get_user_meta($member->ID, $id, true); $social[$id] = !empty($value) ? $value : ''; } } $member_data = array_merge($member_data, $social);
/** * Edit user settings based on contents of $_POST * * Largely based on the edit_user() function, this function only throws errors * when the user has posted invalid data, vs. when the mock user object does not * contain it. * * @since 0.1.0 * * @param int $user_id Optional. User ID. * @return int|WP_Error user id of the updated user */ function wp_user_profiles_edit_user($user_id = 0) { // Bail if no user ID if (empty($user_id)) { return; } // Setup the user being saved $user = new stdClass(); $user->ID = (int) $user_id; $userdata = get_userdata($user_id); // Setup the user login if (isset($_POST['user_login'])) { $user->user_login = sanitize_user($_POST['user_login'], true); } else { $user->user_login = wp_slash($userdata->user_login); } // Password changes $pass1 = isset($_POST['pass1']) ? $_POST['pass1'] : ''; $pass2 = isset($_POST['pass2']) ? $_POST['pass2'] : ''; // Role changes if (isset($_POST['role']) && current_user_can('edit_users')) { // New roles $new_roles = $_POST['role']; // Loop through new roles foreach ($new_roles as $blog_id => $new_role) { // Switch to the blog switch_to_blog($blog_id); // If the new role isn't editable by the logged-in user die with error $editable_roles = get_editable_roles(); if (!empty($new_role) && !empty($editable_roles[$new_role])) { $update_role = get_userdata($user_id); $update_role->set_role($new_role); } // Switch back restore_current_blog(); } } // Email if (isset($_POST['email'])) { $user->user_email = sanitize_text_field(wp_unslash($_POST['email'])); } // Website if (isset($_POST['url'])) { if (empty($_POST['url']) || $_POST['url'] == 'http://') { $user->user_url = ''; } else { $user->user_url = esc_url_raw($_POST['url']); $protocols = implode('|', array_map('preg_quote', wp_allowed_protocols())); $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url; } } // First if (isset($_POST['first_name'])) { $user->first_name = sanitize_text_field($_POST['first_name']); } // Last if (isset($_POST['last_name'])) { $user->last_name = sanitize_text_field($_POST['last_name']); } // Nick if (isset($_POST['nickname'])) { $user->nickname = sanitize_text_field($_POST['nickname']); } // Display if (isset($_POST['display_name'])) { $user->display_name = sanitize_text_field($_POST['display_name']); } // Description if (isset($_POST['description'])) { $user->description = trim($_POST['description']); } // Contact methods foreach (wp_get_user_contact_methods($user) as $method => $name) { if (isset($_POST[$method])) { $user->{$method} = sanitize_text_field($_POST[$method]); } } // Options $user->rich_editing = isset($_POST['rich_editing']) && 'false' === $_POST['rich_editing'] ? 'false' : 'true'; $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh'; $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false'; $user->comment_shortcuts = isset($_POST['comment_shortcuts']) && 'true' === $_POST['comment_shortcuts'] ? 'true' : ''; $user->use_ssl = 0; if (!empty($_POST['use_ssl'])) { $user->use_ssl = 1; } // Error checking $errors = new WP_Error(); // Checking that username has been typed if (isset($_POST['user_login']) && empty($user->user_login)) { $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.')); } // Checking that nickname has been typed if (isset($_POST['nickname']) && empty($user->nickname)) { $errors->add('nickname', __('<strong>ERROR</strong>: Please enter a nickname.')); } /** * Fires before the password and confirm password fields are checked for congruity. * * @since 1.5.1 * * @param string $user_login The username. * @param string &$pass1 The password, passed by reference. * @param string &$pass2 The confirmed password, passed by reference. */ do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2)); // Check for "\" in password if (false !== strpos(wp_unslash($pass1), "\\")) { $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1')); } // Checking the password has been typed twice the same if ($pass1 !== $pass2) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in both password fields.'), array('form-field' => 'pass1')); } if (!empty($pass1)) { $user->user_pass = $pass1; } if (isset($_POST['user_login'])) { if (!validate_username($_POST['user_login'])) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); } if (isset($_POST['user_login']) && username_exists($user->user_login)) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); } } // Checking email address if (isset($_POST['email'])) { if (empty($user->user_email)) { $errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an email address.'), array('form-field' => 'email')); } elseif (!is_email($user->user_email)) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address is not correct.'), array('form-field' => 'email')); } elseif (($owner_id = email_exists($user->user_email)) && $owner_id !== $user->ID) { $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already in use.'), array('form-field' => 'email')); } } /** * Fires before user profile update errors are returned. * * @since 2.8.0 * * @param WP_Error &$errors WP_Error object, passed by reference. * @param bool $update Whether this is a user update. * @param WP_User &$user WP_User object, passed by reference. */ do_action_ref_array('user_profile_update_errors', array(&$errors, true, &$user)); // Return errors if there are any if ($errors->get_error_codes()) { return $errors; } // Maybe save user status if (!empty($_POST['user_status'])) { wp_user_profiles_update_user_status($user, sanitize_key($_POST['user_status'])); } return wp_update_user($user); }
/** * Get user fields * * @package WP Idea Stream * @subpackage users/functions * * @since 2.1.0 * * @param string $type whether we're on a signup form or not */ function wp_idea_stream_user_get_fields($type = 'signup') { $fields = wp_get_user_contact_methods(); if ('signup' == $type) { $fields = array_merge(apply_filters('wp_idea_stream_user_get_signup_fields', array('user_login' => __('Username', 'wp-idea-stream'), 'user_email' => __('E-mail', 'wp-idea-stream'))), $fields); } return apply_filters('wp_idea_stream_user_get_fields', $fields, $type); }
function ipin_edit_user($user_id = 0) { global $wp_roles; $user = new stdClass(); if ($user_id) { $update = true; $user->ID = (int) $user_id; $userdata = get_userdata($user_id); $user->user_login = wp_slash($userdata->user_login); } else { $update = false; } if (!$update && isset($_POST['user_login'])) { $user->user_login = sanitize_user($_POST['user_login'], true); } $pass1 = $pass2 = ''; if (isset($_POST['pass1'])) { $pass1 = $_POST['pass1']; } if (isset($_POST['pass2'])) { $pass2 = $_POST['pass2']; } if (isset($_POST['role']) && current_user_can('edit_users')) { $new_role = sanitize_text_field($_POST['role']); $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false; // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. // Multisite super admins can freely edit their blog roles -- they possess all caps. if (is_multisite() && current_user_can('manage_sites') || $user_id != get_current_user_id() || $potential_role && $potential_role->has_cap('edit_users')) { $user->role = $new_role; } // If the new role isn't editable by the logged-in user die with error $editable_roles = get_editable_roles(); if (!empty($new_role) && empty($editable_roles[$new_role])) { wp_die(__('You can’t give users that role.', 'ipin')); } } //edited: store the original email $original_user_email = $userdata->user_email; if (isset($_POST['email'])) { $user->user_email = sanitize_text_field(wp_unslash($_POST['email'])); } if (isset($_POST['url'])) { if (empty($_POST['url']) || $_POST['url'] == 'http://') { $user->user_url = ''; } else { $user->user_url = esc_url_raw($_POST['url']); $protocols = implode('|', array_map('preg_quote', wp_allowed_protocols())); $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url; } } if (isset($_POST['first_name'])) { $user->first_name = sanitize_text_field($_POST['first_name']); } if (isset($_POST['last_name'])) { $user->last_name = sanitize_text_field($_POST['last_name']); } if (isset($_POST['nickname'])) { $user->nickname = sanitize_text_field($_POST['nickname']); } if (isset($_POST['display_name'])) { $user->display_name = sanitize_text_field($_POST['display_name']); } if (isset($_POST['description'])) { $user->description = trim($_POST['description']); } foreach (wp_get_user_contact_methods($user) as $method => $name) { if (isset($_POST[$method])) { $user->{$method} = sanitize_text_field($_POST[$method]); } } if ($update) { $user->rich_editing = isset($_POST['rich_editing']) && 'false' == $_POST['rich_editing'] ? 'false' : 'true'; $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh'; $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false'; } $user->comment_shortcuts = isset($_POST['comment_shortcuts']) && 'true' == $_POST['comment_shortcuts'] ? 'true' : ''; $user->use_ssl = 0; if (!empty($_POST['use_ssl'])) { $user->use_ssl = 1; } $errors = new WP_Error(); /* checking that username has been typed */ if ($user->user_login == '') { $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.', 'ipin')); } /* checking the password has been typed twice */ /** * Fires before the password and confirm password fields are checked for congruity. * * @since 1.5.1 * * @param string $user_login The username. * @param string &$pass1 The password, passed by reference. * @param string &$pass2 The confirmed password, passed by reference. */ do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2)); if ($update) { if (empty($pass1) && !empty($pass2)) { $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.', 'ipin'), array('form-field' => 'pass1')); } elseif (!empty($pass1) && empty($pass2)) { $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.', 'ipin'), array('form-field' => 'pass2')); } //edited: added to check password length if (!empty($pass1) && !empty($pass2)) { if (strlen($pass1) < 6) { $errors->add('password_too_short', "<strong>ERROR</strong>: Passwords must be at least 6 characters long", 'ipin'); } } } else { if (empty($pass1)) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password.', 'ipin'), array('form-field' => 'pass1')); } elseif (empty($pass2)) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.', 'ipin'), array('form-field' => 'pass2')); } } /* Check for "\" in password */ if (false !== strpos(wp_unslash($pass1), "\\")) { $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".', 'ipin'), array('form-field' => 'pass1')); } /* checking the password has been typed twice the same */ if ($pass1 != $pass2) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in the two password fields.', 'ipin'), array('form-field' => 'pass1')); } if (!empty($pass1)) { $user->user_pass = $pass1; } if (!$update && isset($_POST['user_login']) && !validate_username($_POST['user_login'])) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.', 'ipin')); } if (!$update && username_exists($user->user_login)) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.', 'ipin')); } /* checking e-mail address */ $verify_new_email = $user_id; //edited: verify new email if (empty($user->user_email)) { $errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an email address.', 'ipin'), array('form-field' => 'email')); } elseif (!is_email($user->user_email)) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.', 'ipin'), array('form-field' => 'email')); } elseif (($owner_id = email_exists($user->user_email)) && (!$update || $owner_id != $user->ID)) { $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.', 'ipin'), array('form-field' => 'email')); //edited: requires email verification if email is changed } elseif ($userdata->user_email != $_POST['email'] && !current_user_can('administrator') && !current_user_can('editor')) { //store new email temporarily update_user_meta($user_id, '_new_email', $user->user_email); $new_email_key = wp_generate_password(20, false); update_user_meta($user_id, '_new_email_key', $new_email_key); $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $message .= __('Please click the link to verify your email:', 'ipin') . "\r\n"; $message .= home_url('/settings/'); $message .= sprintf('?email=verify&login=%s&key=%s', rawurlencode($user->user_login), $new_email_key); wp_mail($user->user_email, sprintf(__('[%s] Email Verification', 'ipin'), $blogname), $message); $user->user_email = $original_user_email; $verify_new_email = 'verify_new_email'; } /** * Fires before user profile update errors are returned. * * @since 2.8.0 * * @param array &$errors An array of user profile update errors, passed by reference. * @param bool $update Whether this is a user update. * @param WP_User &$user WP_User object, passed by reference. */ do_action_ref_array('user_profile_update_errors', array(&$errors, $update, &$user)); if ($errors->get_error_codes()) { return $errors; } if ($update) { $user_id = wp_update_user($user); } else { $user_id = wp_insert_user($user); wp_new_user_notification($user_id, isset($_POST['send_password']) ? wp_unslash($pass1) : ''); } return $verify_new_email; //edited: verify new email }
/** * Edit user settings based on contents of $_POST * * Used on user-edit.php and profile.php to manage and process user options, passwords etc. * * @since 2.0.0 * * @param int $user_id Optional. User ID. * @return int|WP_Error user id of the updated user */ function edit_user($user_id = 0) { $wp_roles = wp_roles(); $user = new stdClass(); if ($user_id) { $update = true; $user->ID = (int) $user_id; $userdata = get_userdata($user_id); $user->user_login = wp_slash($userdata->user_login); } else { $update = false; } if (!$update && isset($_POST['user_login'])) { $user->user_login = sanitize_user($_POST['user_login'], true); } $pass1 = $pass2 = ''; if (isset($_POST['pass1'])) { $pass1 = $_POST['pass1']; } if (isset($_POST['pass2'])) { $pass2 = $_POST['pass2']; } if (isset($_POST['role']) && current_user_can('edit_users')) { $new_role = sanitize_text_field($_POST['role']); $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false; // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. // Multisite super admins can freely edit their blog roles -- they possess all caps. if (is_multisite() && current_user_can('manage_sites') || $user_id != get_current_user_id() || $potential_role && $potential_role->has_cap('edit_users')) { $user->role = $new_role; } // If the new role isn't editable by the logged-in user die with error $editable_roles = get_editable_roles(); if (!empty($new_role) && empty($editable_roles[$new_role])) { wp_die(__('You can’t give users that role.')); } } if (isset($_POST['email'])) { $user->user_email = sanitize_text_field(wp_unslash($_POST['email'])); } if (isset($_POST['url'])) { if (empty($_POST['url']) || $_POST['url'] == 'http://') { $user->user_url = ''; } else { $user->user_url = esc_url_raw($_POST['url']); $protocols = implode('|', array_map('preg_quote', wp_allowed_protocols())); $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url; } } if (isset($_POST['first_name'])) { $user->first_name = sanitize_text_field($_POST['first_name']); } if (isset($_POST['last_name'])) { $user->last_name = sanitize_text_field($_POST['last_name']); } if (isset($_POST['nickname'])) { $user->nickname = sanitize_text_field($_POST['nickname']); } if (isset($_POST['display_name'])) { $user->display_name = sanitize_text_field($_POST['display_name']); } if (isset($_POST['description'])) { $user->description = trim($_POST['description']); } foreach (wp_get_user_contact_methods($user) as $method => $name) { if (isset($_POST[$method])) { $user->{$method} = sanitize_text_field($_POST[$method]); } } if ($update) { $user->rich_editing = isset($_POST['rich_editing']) && 'false' == $_POST['rich_editing'] ? 'false' : 'true'; $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh'; $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false'; } $user->comment_shortcuts = isset($_POST['comment_shortcuts']) && 'true' == $_POST['comment_shortcuts'] ? 'true' : ''; $user->use_ssl = 0; if (!empty($_POST['use_ssl'])) { $user->use_ssl = 1; } $errors = new WP_Error(); /* checking that username has been typed */ if ($user->user_login == '') { $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.')); } /* checking that nickname has been typed */ if ($update && empty($user->nickname)) { $errors->add('nickname', __('<strong>ERROR</strong>: Please enter a nickname.')); } /* checking the password has been typed twice */ /** * Fires before the password and confirm password fields are checked for congruity. * * @since 1.5.1 * * @param string $user_login The username. * @param string &$pass1 The password, passed by reference. * @param string &$pass2 The confirmed password, passed by reference. */ do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2)); /* Check for "\" in password */ if (false !== strpos(wp_unslash($pass1), "\\")) { $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1')); } /* checking the password has been typed twice the same */ if ($pass1 != $pass2) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in both password fields.'), array('form-field' => 'pass1')); } if (!empty($pass1)) { $user->user_pass = $pass1; } if (!$update && isset($_POST['user_login']) && !validate_username($_POST['user_login'])) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); } if (!$update && username_exists($user->user_login)) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); } /** This filter is documented in wp-includes/user.php */ $illegal_logins = (array) apply_filters('illegal_user_logins', array()); if (in_array(strtolower($user->user_login), array_map('strtolower', $illegal_logins))) { $errors->add('illegal_user_login', __('<strong>ERROR</strong>: Sorry, that username is not allowed.')); } /* checking email address */ if (empty($user->user_email)) { $errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an email address.'), array('form-field' => 'email')); } elseif (!is_email($user->user_email)) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.'), array('form-field' => 'email')); } elseif (($owner_id = email_exists($user->user_email)) && (!$update || $owner_id != $user->ID)) { $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array('form-field' => 'email')); } /** * Fires before user profile update errors are returned. * * @since 2.8.0 * * @param WP_Error &$errors WP_Error object, passed by reference. * @param bool $update Whether this is a user update. * @param WP_User &$user WP_User object, passed by reference. */ do_action_ref_array('user_profile_update_errors', array(&$errors, $update, &$user)); if ($errors->get_error_codes()) { return $errors; } if ($update) { $user_id = wp_update_user($user); } else { $user_id = wp_insert_user($user); /** * Fires after a new user has been created. * * @since 4.4.0 * * @param int $user_id ID of the newly created user. */ do_action('edit_user_created_user', $user_id); } return $user_id; }
$url = $author->user_url ? $author->user_url : get_author_posts_url($author->ID); ?> <a href="<?php echo $url; ?> "><?php echo $url; ?> </a></li> <li>Follow <?php echo $author->display_name; ?> On: <ul> <?php $contacts = wp_get_user_contact_methods(); foreach ($contacts as $contact => $value) { if ($author->{$contact}) { ?> <li><a class="icon icon-<?php echo strtolower($value); ?> " $href="<?php echo $author->{$contact}; ?> "><?php echo $value; ?> </a></li> <?php
esc_attr_e('Last Name', 'simple-user-adding'); ?> " /> </td> </tr> <tr class="additional hidden"> <th scope="row"><label for="url"><?php _e('Website', 'simple-user-adding'); ?> </label></th> <td> <input name="url" type="url" id="url" class="regular-text code" /> </td> </tr> <?php foreach (wp_get_user_contact_methods() as $name => $desc) { ?> <tr class="additional hidden"> <th> <label for="<?php echo esc_attr($name); ?> "><?php echo esc_html(apply_filters('user_{$name}_label', $desc)); ?> </label> </th> <td> <input type="text" name="<?php echo esc_attr($name); ?>
/** * Edit user settings based on contents of $_POST * * Used on user-edit.php and profile.php to manage and process user options, passwords etc. * * @since 2.0 * * @param int $user_id Optional. User ID. * @return int user id of the updated user */ function edit_user($user_id = 0) { global $wp_roles, $wpdb; $user = new stdClass(); if ($user_id) { $update = true; $user->ID = (int) $user_id; $userdata = get_userdata($user_id); $user->user_login = wp_slash($userdata->user_login); } else { $update = false; } if (!$update && isset($_POST['user_login'])) { $user->user_login = sanitize_user($_POST['user_login'], true); } $pass1 = $pass2 = ''; if (isset($_POST['pass1'])) { $pass1 = $_POST['pass1']; } if (isset($_POST['pass2'])) { $pass2 = $_POST['pass2']; } if (isset($_POST['role']) && current_user_can('edit_users')) { $new_role = sanitize_text_field($_POST['role']); $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false; // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. // Multisite super admins can freely edit their blog roles -- they possess all caps. if (is_multisite() && current_user_can('manage_sites') || $user_id != get_current_user_id() || $potential_role && $potential_role->has_cap('edit_users')) { $user->role = $new_role; } // If the new role isn't editable by the logged-in user die with error $editable_roles = get_editable_roles(); if (!empty($new_role) && empty($editable_roles[$new_role])) { wp_die(__('You can’t give users that role.')); } } if (isset($_POST['email'])) { $user->user_email = sanitize_text_field($_POST['email']); } if (isset($_POST['url'])) { if (empty($_POST['url']) || $_POST['url'] == 'http://') { $user->user_url = ''; } else { $user->user_url = esc_url_raw($_POST['url']); $protocols = implode('|', array_map('preg_quote', wp_allowed_protocols())); $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url; } } if (isset($_POST['first_name'])) { $user->first_name = sanitize_text_field($_POST['first_name']); } if (isset($_POST['last_name'])) { $user->last_name = sanitize_text_field($_POST['last_name']); } if (isset($_POST['nickname'])) { $user->nickname = sanitize_text_field($_POST['nickname']); } if (isset($_POST['display_name'])) { $user->display_name = sanitize_text_field($_POST['display_name']); } if (isset($_POST['description'])) { $user->description = trim($_POST['description']); } foreach (wp_get_user_contact_methods($user) as $method => $name) { if (isset($_POST[$method])) { $user->{$method} = sanitize_text_field($_POST[$method]); } } if ($update) { $user->rich_editing = isset($_POST['rich_editing']) && 'false' == $_POST['rich_editing'] ? 'false' : 'true'; $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh'; $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false'; } $user->comment_shortcuts = isset($_POST['comment_shortcuts']) && 'true' == $_POST['comment_shortcuts'] ? 'true' : ''; $user->use_ssl = 0; if (!empty($_POST['use_ssl'])) { $user->use_ssl = 1; } $errors = new WP_Error(); /* checking that username has been typed */ if ($user->user_login == '') { $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.')); } /* checking the password has been typed twice */ do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2)); if ($update) { if (empty($pass1) && !empty($pass2)) { $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass1')); } elseif (!empty($pass1) && empty($pass2)) { $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass2')); } } else { if (empty($pass1)) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password.'), array('form-field' => 'pass1')); } elseif (empty($pass2)) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.'), array('form-field' => 'pass2')); } } /* Check for "\" in password */ if (false !== strpos(wp_unslash($pass1), "\\")) { $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1')); } /* checking the password has been typed twice the same */ if ($pass1 != $pass2) { $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in the two password fields.'), array('form-field' => 'pass1')); } if (!empty($pass1)) { $user->user_pass = $pass1; } if (!$update && isset($_POST['user_login']) && !validate_username($_POST['user_login'])) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.')); } if (!$update && username_exists($user->user_login)) { $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.')); } /* checking e-mail address */ if (empty($user->user_email)) { $errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an e-mail address.'), array('form-field' => 'email')); } elseif (!is_email($user->user_email)) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.'), array('form-field' => 'email')); } elseif (($owner_id = email_exists($user->user_email)) && (!$update || $owner_id != $user->ID)) { $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array('form-field' => 'email')); } // Allow plugins to return their own errors. do_action_ref_array('user_profile_update_errors', array(&$errors, $update, &$user)); if ($errors->get_error_codes()) { return $errors; } if ($update) { $user_id = wp_update_user($user); } else { $user_id = wp_insert_user($user); wp_new_user_notification($user_id, isset($_POST['send_password']) ? wp_unslash($pass1) : ''); } return $user_id; }
</td> </tr> <tr class="user-url-wrap"> <th><label for="url"><?php _e('Website'); ?> </label></th> <td><input type="url" name="url" id="url" value="<?php echo esc_attr($profileuser->user_url); ?> " class="regular-text code" /></td> </tr> <?php foreach (wp_get_user_contact_methods($profileuser) as $name => $desc) { ?> <tr class="user-<?php echo $name; ?> -wrap"> <th><label for="<?php echo $name; ?> "> <?php /** * Filter a user contactmethod label. * * The dynamic portion of the filter hook, `$name`, refers to * each of the keys in the contactmethods array.
public function admin_social_profiles($fields) { $methods = wp_get_user_contact_methods(get_current_user_id()); if (empty($methods)) { return $fields; } $user = wp_get_current_user(); foreach ($methods as $key => $label) { $fields['_company_' . $key] = array('label' => $label, 'type' => 'text', 'priority' => 99, 'placeholder' => 'http://', 'required' => false); } return $fields; }