Пример #1
0
 /**
  * Social Links
  *
  * @since Marketify 1.0
  *
  * @return void
  */
 function marketify_entry_author_social($user_id = null)
 {
     global $post;
     $methods = _wp_get_user_contactmethods();
     $social = array();
     if (!$user_id) {
         $user_id = get_the_author_meta('ID');
     }
     foreach ($methods as $key => $method) {
         $field = get_the_author_meta($key, $user_id);
         if (!$field) {
             continue;
         }
         $social[$key] = sprintf('<a href="%1$s" target="_blank"><i class="icon-%2$s"></i></a>', $field, $key);
     }
     $social = implode(' ', $social);
     return $social;
 }
Пример #2
0
 /**
  * Constructor
  *
  * $args contains 3 optional parameters, but at least 1 must be defined
  * - user_id: load userdata by ID
  * - user_login: load userdata by user_login
  * - user_email: load userdata by user_email
  * 
  * @param array $args 
  */
 public function __construct($args)
 {
     if (!empty($args['user_id'])) {
         $this->user = new WP_User($args['user_id']);
     } elseif (!empty($args['user_login'])) {
         $u = get_user_by('login', $args['user_login']);
         $this->user = new WP_User($u->ID);
         unset($u);
     } elseif (!empty($args['user_email'])) {
         $u = get_user_by('email', $args['user_email']);
         $this->user = new WP_User($u->ID);
         unset($u);
     }
     if (empty($this->user)) {
         throw new Exception(__('Could not start user', 'cf-deploy') . ': ' . print_r($args, true));
     }
     // add any additional profile fields as needed
     foreach (_wp_get_user_contactmethods() as $contact_method => $contact_method_name) {
         $this->profile_fields[$contact_method] = null;
     }
 }
Пример #3
0
		</tr>

		<tr>
			<th><label for="url"><?php 
_e('Website', 'theme-my-login');
?>
</label></th>
			<td><input type="text" name="url" id="url" value="<?php 
echo esc_attr($profileuser->user_url);
?>
" class="regular-text code" /></td>
		</tr>

		<?php 
if (function_exists('_wp_get_user_contactmethods')) {
    foreach (_wp_get_user_contactmethods() as $name => $desc) {
        ?>
		<tr>
			<th><label for="<?php 
        echo $name;
        ?>
"><?php 
        echo apply_filters('user_' . $name . '_label', $desc);
        ?>
</label></th>
			<td><input type="text" name="<?php 
        echo $name;
        ?>
" id="<?php 
        echo $name;
        ?>
Пример #4
0
/**
 * Insert an user into the database.
 *
 * Can update a current user or insert a new user based on whether the user's ID
 * is present.
 *
 * Can be used to update the user's info (see below), set the user's role, and
 * set the user's preference on whether they want the rich editor on.
 *
 * Most of the $userdata array fields have filters associated with the values.
 * The exceptions are 'rich_editing', 'role', 'jabber', 'aim', 'yim',
 * 'user_registered', and 'ID'. The filters have the prefix 'pre_user_' followed
 * by the field name. An example using 'description' would have the filter
 * called, 'pre_user_description' that can be hooked into.
 *
 * The $userdata array can contain the following fields:
 * 'ID' - An integer that will be used for updating an existing user.
 * 'user_pass' - A string that contains the plain text password for the user.
 * 'user_login' - A string that contains the user's username for logging in.
 * 'user_nicename' - A string that contains a nicer looking name for the user.
 *		The default is the user's username.
 * 'user_url' - A string containing the user's URL for the user's web site.
 * 'user_email' - A string containing the user's email address.
 * 'display_name' - A string that will be shown on the site. Defaults to user's
 *		username. It is likely that you will want to change this, for both
 *		appearance and security through obscurity (that is if you don't use and
 *		delete the default 'admin' user).
 * 'nickname' - The user's nickname, defaults to the user's username.
 * 'first_name' - The user's first name.
 * 'last_name' - The user's last name.
 * 'description' - A string containing content about the user.
 * 'rich_editing' - A string for whether to enable the rich editor. False
 *		if not empty.
 * 'user_registered' - The date the user registered. Format is 'Y-m-d H:i:s'.
 * 'role' - A string used to set the user's role.
 * 'jabber' - User's Jabber account.
 * 'aim' - User's AOL IM account.
 * 'yim' - User's Yahoo IM account.
 *
 * @since 2.0.0
 * @uses $wpdb WordPress database layer.
 * @uses apply_filters() Calls filters for most of the $userdata fields with the prefix 'pre_user'. See note above.
 * @uses do_action() Calls 'profile_update' hook when updating giving the user's ID
 * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
 *
 * @param array $userdata An array of user data.
 * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created.
 */
function wp_insert_user($userdata) {
	global $wpdb;

	extract($userdata, EXTR_SKIP);

	// Are we updating or creating?
	if ( !empty($ID) ) {
		$ID = (int) $ID;
		$update = true;
		$old_user_data = get_userdata($ID);
	} else {
		$update = false;
		// Hash the password
		$user_pass = wp_hash_password($user_pass);
	}

	$user_login = sanitize_user($user_login, true);
	$user_login = apply_filters('pre_user_login', $user_login);

	//Remove any non-printable chars from the login string to see if we have ended up with an empty username
	$user_login = trim($user_login);

	if ( empty($user_login) )
		return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );

	if ( !$update && username_exists( $user_login ) )
		return new WP_Error('existing_user_login', __('This username is already registered.') );

	if ( empty($user_nicename) )
		$user_nicename = sanitize_title( $user_login );
	$user_nicename = apply_filters('pre_user_nicename', $user_nicename);

	if ( empty($user_url) )
		$user_url = '';
	$user_url = apply_filters('pre_user_url', $user_url);

	if ( empty($user_email) )
		$user_email = '';
	$user_email = apply_filters('pre_user_email', $user_email);

	if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
		return new WP_Error('existing_user_email', __('This email address is already registered.') );

	if ( empty($display_name) )
		$display_name = $user_login;
	$display_name = apply_filters('pre_user_display_name', $display_name);

	if ( empty($nickname) )
		$nickname = $user_login;
	$nickname = apply_filters('pre_user_nickname', $nickname);

	if ( empty($first_name) )
		$first_name = '';
	$first_name = apply_filters('pre_user_first_name', $first_name);

	if ( empty($last_name) )
		$last_name = '';
	$last_name = apply_filters('pre_user_last_name', $last_name);

	if ( empty($description) )
		$description = '';
	$description = apply_filters('pre_user_description', $description);

	if ( empty($rich_editing) )
		$rich_editing = 'true';

	if ( empty($comment_shortcuts) )
		$comment_shortcuts = 'false';

	if ( empty($admin_color) )
		$admin_color = 'fresh';
	$admin_color = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color);

	if ( empty($use_ssl) )
		$use_ssl = 0;

	if ( empty($user_registered) )
		$user_registered = gmdate('Y-m-d H:i:s');

	$user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login));

	if ( $user_nicename_check ) {
		$suffix = 2;
		while ($user_nicename_check) {
			$alt_user_nicename = $user_nicename . "-$suffix";
			$user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $alt_user_nicename, $user_login));
			$suffix++;
		}
		$user_nicename = $alt_user_nicename;
	}

	$data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
	$data = stripslashes_deep( $data );

	if ( $update ) {
		$wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
		$user_id = (int) $ID;
	} else {
		$wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
		$user_id = (int) $wpdb->insert_id;
	}

	update_user_meta( $user_id, 'first_name', $first_name);
	update_user_meta( $user_id, 'last_name', $last_name);
	update_user_meta( $user_id, 'nickname', $nickname );
	update_user_meta( $user_id, 'description', $description );
	update_user_meta( $user_id, 'rich_editing', $rich_editing);
	update_user_meta( $user_id, 'comment_shortcuts', $comment_shortcuts);
	update_user_meta( $user_id, 'admin_color', $admin_color);
	update_user_meta( $user_id, 'use_ssl', $use_ssl);

	foreach ( _wp_get_user_contactmethods() as $method => $name ) {
		if ( empty($$method) )
			$$method = '';

		update_user_meta( $user_id, $method, $$method );
	}

	if ( isset($role) ) {
		$user = new WP_User($user_id);
		$user->set_role($role);
	} elseif ( !$update ) {
		$user = new WP_User($user_id);
		$user->set_role(get_option('default_role'));
	}

	wp_cache_delete($user_id, 'users');
	wp_cache_delete($user_login, 'userlogins');

	if ( $update )
		do_action('profile_update', $user_id, $old_user_data);
	else
		do_action('user_register', $user_id);

	return $user_id;
}
function ym_user_profile_form()
{
    get_currentuserinfo();
    global $current_user, $wpdb;
    $updated = false;
    $action = ym_post('ym_action');
    if ($action == 'ym_user_profile_update') {
        include 'wp-admin/includes/user.php';
        include 'wp-includes/registration.php';
        do_action('personal_options_update', $current_user->ID);
        $errors = edit_user($current_user->ID);
        if (!is_wp_error($errors)) {
            $html = '<p>' . __('Your Profile has been updated') . '</p>';
            $html .= '<meta http-equiv="refresh" content="3" />';
            return $html;
        }
    }
    $html = '';
    if (isset($errors) && is_wp_error($errors)) {
        $html .= '<div class="error"><p>' . implode("</p>\n<p>", $errors->get_error_messages()) . '</p></div>';
    } else {
        if (ym_get('updated')) {
            $html .= '<div id="message" class="updated"><p><strong>' . __('User updated.') . '</strong></p></div>';
        }
    }
    if (!function_exists(_wp_get_user_contactmethods)) {
        function _wp_get_user_contactmethods()
        {
            $user_contactmethods = array('aim' => __('AIM'), 'yim' => __('Yahoo IM'), 'jabber' => __('Jabber / Google Talk'));
            return apply_filters('user_contactmethods', $user_contactmethods);
        }
    }
    $html .= '
<form action="" method="post">
	<input type="hidden" name="ym_action" value="ym_user_profile_update" />
	
<table class="form-table">
	<tr><td colspan="2"><h3>' . __('Name') . '</h3></td></tr>
	<tr>
		<th><label for="first_name">' . __('First Name') . '</label></th>
		<td><input type="text" name="first_name" id="first_name" value="' . esc_attr($current_user->user_firstname) . '" class="regular-text" /></td>
	</tr>

	<tr>
		<th><label for="last_name">' . __('Last Name') . '</label></th>
		<td><input type="text" name="last_name" id="last_name" value="' . esc_attr($current_user->user_lastname) . '" class="regular-text" /></td>
	</tr>

	<tr>
		<th><label for="nickname">' . __('Nickname') . ' <span class="description">' . __('(required)') . '</span></label></th>
		<td><input type="text" name="nickname" id="nickname" value="' . esc_attr($current_user->nickname) . '" class="regular-text" /></td>
	</tr>

	<tr>
		<th><label for="display_name">' . __('Display name publicly as') . '</label></th>
		<td>
			<select name="display_name" id="display_name">
			';
    $public_display = array();
    $public_display['display_username'] = $current_user->user_login;
    $public_display['display_nickname'] = $current_user->nickname;
    if (!empty($profileuser->first_name)) {
        $public_display['display_firstname'] = $current_user->first_name;
    }
    if (!empty($profileuser->last_name)) {
        $public_display['display_lastname'] = $current_user->last_name;
    }
    if (!empty($profileuser->first_name) && !empty($current_user->last_name)) {
        $public_display['display_firstlast'] = $current_user->first_name . ' ' . $current_user->last_name;
        $public_display['display_lastfirst'] = $current_user->last_name . ' ' . $current_user->first_name;
    }
    if (!in_array($current_user->display_name, $public_display)) {
        // Only add this if it isn't duplicated elsewhere
        $public_display = array('display_displayname' => $current_user->display_name) + $public_display;
    }
    $public_display = array_map('trim', $public_display);
    $public_display = array_unique($public_display);
    foreach ($public_display as $id => $item) {
        $html .= '<option id="' . $id . '" value="' . esc_attr($item) . '"' . selected($current_user->display_name, $item, FALSE) . '>' . $item . '</option>';
    }
    $html .= '
			</select>
		</td>
	</tr>
	<tr><td colspan="2">
<h3>' . __('Contact Info') . '</h3>
	</td></tr>
<tr>
	<th><label for="email">' . __('E-mail') . ' <span class="description">' . __('(required)') . '</span></label></th>
	<td><input type="text" name="email" id="email" value="' . esc_attr($current_user->user_email) . '" class="regular-text" />
	';
    $new_email = get_option($current_user->ID . '_new_email');
    if ($new_email && $new_email != $current_user->user_email) {
        $html .= '
	<div class="updated inline">
	<p>' . sprintf(__('There is a pending change of your e-mail to <code>%1$s</code>. <a href="%2$s">Cancel</a>'), $new_email['newemail'], esc_url(admin_url('profile.php?dismiss=' . $current_user->ID . '_new_email'))) . '</p>
	</div>
		';
    }
    $html .= '
	</td>
</tr>

<tr>
	<th><label for="url">' . __('Website') . '</label></th>
	<td><input type="text" name="url" id="url" value="' . esc_attr($current_user->user_url) . '" class="regular-text code" /></td>
</tr>
';
    foreach (_wp_get_user_contactmethods() as $name => $desc) {
        $html .= '
<tr>
	<th><label for="' . $name . '">' . apply_filters('user_' . $name . '_label', $desc) . '</label></th>
	<td><input type="text" name="' . $name . '" id="' . $name . '" value="' . esc_attr($current_user->{$name}) . '" class="regular-text" /></td>
</tr>';
    }
    $html .= '
<tr><td colspan="2">
<h3>' . __('About Yourself') . '</h3>
</td></tr>
<tr>
	<th><label for="description">' . __('Biographical Info') . '</label></th>
	<td><textarea name="description" id="description" rows="5" cols="60">' . esc_html($current_user->description) . '</textarea><br />
	<span class="description">' . __('Share a little biographical information to fill out your profile. This may be shown publicly.') . '</span></td>
</tr>
<tr><td></td><td style="text-align: right;"><input type="submit" class="button-primary" value="' . __('Update Profile') . '" name="submit" /></td></tr>
</table>
</form>
';
    return $html;
}
Пример #6
0
								</tr>

								<tr>
									<th><label for="description"><?php 
_e('About Me:', APP_TD);
?>
</label></th>
									<td><textarea name="description" class="regular-text" id="description" rows="10" cols="50"><?php 
echo esc_textarea($current_user->description);
?>
</textarea></td>
								</tr>


<?php 
foreach (_wp_get_user_contactmethods($current_user) as $name => $desc) {
    ?>
								<tr>
									<th><label for="<?php 
    echo $name;
    ?>
"><?php 
    echo apply_filters('user_' . $name . '_label', $desc);
    ?>
:</label></th>
									<td>
										<input type="text" name="<?php 
    echo $name;
    ?>
" class="text regular-text" id="<?php 
    echo $name;
Пример #7
0
/**
 * 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 = $wpdb->escape($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&#8217;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']);
            $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/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_contactmethods($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(stripslashes($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 e-mail address isn&#8217;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(get_object_vars($user));
        // EKLEME USER DISABILITY DB UPDATE
        //require_once('./dbconnect.php');
        $connect = mysql_pconnect("localhost", "root", "");
        mysql_select_db("erisimdb", $connect);
        $updateDisSql = "UPDATE er_disability_user SET disability_id = " . $_POST['engelUserUpdate'] . " WHERE user_id = " . $user_id;
        mysql_query($updateDisSql);
        mysql_close($connect);
        //
    } else {
        $user_id = wp_insert_user(get_object_vars($user));
        wp_new_user_notification($user_id, isset($_POST['send_password']) ? $pass1 : '');
    }
    return $user_id;
}
Пример #8
0
	</td>
</tr>

<tr>
	<th><label for="url"><?php 
        _e('Website');
        ?>
</label></th>
	<td><input type="text" name="url" id="url" value="<?php 
        echo esc_attr($profileuser->user_url);
        ?>
" class="regular-text code" /></td>
</tr>

<?php 
        foreach (_wp_get_user_contactmethods($profileuser) as $name => $desc) {
            ?>
<tr>
	<th><label for="<?php 
            echo $name;
            ?>
"><?php 
            echo apply_filters('user_' . $name . '_label', $desc);
            ?>
</label></th>
	<td><input type="text" name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
Пример #9
0
 function wpmu_validate_user_signup($result)
 {
     $fields = $this->getFilters('gmember_extra_meta');
     if (!count($fields)) {
         // maybe filtered
         return $result;
     }
     $this->_signup_meta = array();
     $extra = gMemberHelper::buildMetaArray($fields, false, array(), 'member');
     $this->_signup_meta['extra'] = gMemberHelper::sanitizeMetaArray($result['errors'], $extra, $fields, false);
     foreach (_wp_get_user_contactmethods() as $method => $name) {
         if (isset($_POST['contacts-' . $method])) {
             $this->_signup_meta['contacts'][$method] = sanitize_text_field($_POST['contacts-' . $method]);
         }
     }
     return $result;
 }
Пример #10
0
/**
 * Return user contact methods Selectbox
 *
 * @since 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_contactmethods(bbpress()->displayed_user);
    return apply_filters('bbp_edit_user_contact_methods', $contact_methods);
}
Пример #11
0
 /**
  * Import a single user
  * 
  * @param array $user
  * @return array
  */
 protected function import_user($user)
 {
     $local_user = get_user_by('login', $user['data']['user_login']);
     $local_user_object = new WP_User($local_user->ID);
     $update = !empty($local_user) ? true : false;
     if (!function_exists('wp_insert_user')) {
         include_once ABSPATH . 'wp-includes/registration.php';
     }
     // args used by wp_insert_user & wp_update_user
     // makes for an easy merge and a reminder of just what is handled at that time
     $insert_user_args = array('user_login' => null, 'user_nicename' => null, 'user_url' => null, 'user_email' => null, 'display_name' => null, 'nickname' => null, 'first_name' => null, 'last_name' => null, 'description' => null, 'rich_editing' => null, 'user_registered' => null, 'role' => null, 'use_ssl' => 0, 'admin_color' => null, 'comment_shortcuts' => null);
     foreach (_wp_get_user_contactmethods() as $contact_method => $contact_method_name) {
         $insert_user_args[$contact_method] = null;
     }
     cfd_tmp_dbg('importing_user.txt', $user, 'print');
     foreach ($insert_user_args as $key => &$arg) {
         if ($key == 'role') {
             $arg = $user['roles'][0];
         } else {
             if (!empty($user['data'][$key])) {
                 $arg = $user['data'][$key];
             }
         }
     }
     cfd_tmp_dbg('importing_user_args.txt', $insert_user_args, 'print');
     if ($update) {
         $local_userdata = get_object_vars(get_userdata($local_user->ID));
         $insert_user_args = array_merge($local_userdata, $insert_user_args);
         unset($insert_user_args['user_pass']);
         $user_id = wp_update_user($insert_user_args);
     } else {
         if (email_exists($user['data']['user_email'])) {
             $this->add_import_message('users', '__error__', sprintf(__('Email address "%s" already exists for another user', 'cf-deploy'), $user['data']['user_email']));
             return false;
         }
         // set generic password for new user
         $insert_user_args['user_password'] = time();
         $user_id = wp_insert_user($insert_user_args);
     }
     if (empty($user_id) || is_wp_error($user_id)) {
         $errstring = sprintf(__('Import failed for user "%s".', 'cf-deploy'), $user['data']['user_nicename']);
         if (is_wp_error($user_id)) {
             $errstring .= ' ' . __('Error:', 'cf-deploy') . ' ' . $user_id->get_error_message();
         }
         $this->add_import_message('users', '__error__', $errstring);
         $ret = false;
     } else {
         // Set/Update Capabilities & Roles
         $u = new WP_User($user_id);
         // set roles, remove all existing and replace with what is being brought in
         foreach ($u->roles as $role) {
             $u->remove_role($role);
         }
         foreach ($user['roles'] as $role) {
             $u->add_role($role);
         }
         // set caps, remove all existing caps before setting them anew
         $u->remove_all_caps();
         foreach ($user['caps'] as $cap => $value) {
             $u->add_cap($cap, (bool) $value);
         }
         $this->add_import_message('users', '__notice__', sprintf(__('User "%s" successfully imported.', 'cf-deploy'), $user['data']['user_login']));
         $ret = true;
     }
     $item_change['users'][$user['data']['user_login']] = 'new';
     if (!empty($local_user)) {
         $log_users = array($local_user_object);
         array_walk_recursive($log_users, array($this, 'object_to_array'));
         $item_change['users'][$user['data']['user_login']] = current($log_users);
     }
     $this->log_item_change($item_change);
     return $ret;
 }
/**
 * Process shortcode submission.
 *
 * @since Astoundify Crowdfunding 0.8
 *
 * @return void
 */
function atcf_shortcode_profile_info_process()
{
    global $edd_options, $post;
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if (empty($_POST['action']) || 'atcf-profile-update' !== $_POST['action']) {
        return;
    }
    if (!wp_verify_nonce($_POST['_wpnonce'], 'atcf-profile-update')) {
        return;
    }
    $user = wp_get_current_user();
    $errors = new WP_Error();
    $bio = esc_attr($_POST['bio']);
    $nicename = esc_attr($_POST['nicename']);
    $url = esc_url($_POST['url']);
    do_action('atcf_shortcode_profile_info_process_validate', $_POST, $errors);
    if (!empty($errors->errors)) {
        // Not sure how to avoid empty instantiated WP_Error
        wp_die($errors);
    }
    wp_update_user(apply_filters('atcf_shortcode_profile_info_process_update', array('ID' => $user->ID, 'description' => $bio, 'display_name' => $nicename, 'user_nicename' => $user->user_nicename, 'user_url' => $url)));
    foreach (_wp_get_user_contactmethods() as $method => $name) {
        if (isset($_POST[$method])) {
            update_user_meta($user->ID, $method, sanitize_text_field($_POST[$method]));
        }
    }
    do_action('atcf_shortcode_profile_info_process_after', $user, $_POST);
    $redirect = apply_filters('atcf_shortcode_profile_info_success_redirect', add_query_arg(array('success' => 'true'), get_permalink()));
    wp_safe_redirect($redirect);
    exit;
}
Пример #13
0
/**
 * Shows the user profile form
 *
 * @global type $userdata
 * @param type $user_id
 */
function wpuf_user_edit_profile_form($user_id = null)
{
    global $userdata, $wp_http_referer;
    get_currentuserinfo();
    if (!function_exists('get_user_to_edit')) {
        require_once ABSPATH . '/wp-admin/includes/user.php';
    }
    if (!function_exists('_wp_get_user_contactmethods')) {
        require_once ABSPATH . '/wp-includes/registration.php';
    }
    if (!$user_id) {
        $current_user = wp_get_current_user();
        $user_id = $user_ID = $current_user->ID;
    }
    if (isset($_POST['submit'])) {
        check_admin_referer('update-profile_' . $user_id);
        $errors = edit_user($user_id);
        if (is_wp_error($errors)) {
            $message = $errors->get_error_message();
            $style = 'error';
        } else {
            $message = __('<strong>Success</strong>: Profile updated', 'wpuf');
            $style = 'success';
            do_action('personal_options_update', $user_id);
        }
    }
    $profileuser = get_user_to_edit($user_id);
    if (isset($message)) {
        echo '<div class="' . $style . '">' . $message . '</div>';
    }
    ?>
    <div class="wpuf-profile">
        <form name="profile" id="your-profile" action="" method="post">
            <?php 
    wp_nonce_field('update-profile_' . $user_id);
    ?>
            <?php 
    if ($wp_http_referer) {
        ?>
                <input type="hidden" name="wp_http_referer" value="<?php 
        echo esc_url($wp_http_referer);
        ?>
" />
            <?php 
    }
    ?>
            <input type="hidden" name="from" value="profile" />
            <input type="hidden" name="checkuser_id" value="<?php 
    echo $user_id;
    ?>
" />
            <table class="wpuf-table">
                <?php 
    do_action('personal_options', $profileuser);
    ?>
            </table>
            <?php 
    do_action('profile_personal_options', $profileuser);
    ?>

            <fieldset>
                <legend><?php 
    _e('Name');
    ?>
</legend>

                <table class="wpuf-table">
                    <tr>
                        <th><label for="user_login1"><?php 
    _e('Username');
    ?>
</label></th>
                        <td><input type="text" name="user_login" id="user_login1" value="<?php 
    echo esc_attr($profileuser->user_login);
    ?>
" disabled="disabled" class="regular-text" /><br /><em><span class="description"><?php 
    _e('Usernames cannot be changed.');
    ?>
</span></em></td>
                    </tr>
                    <tr>
                        <th><label for="first_name"><?php 
    _e('First Name');
    ?>
</label></th>
                        <td><input type="text" name="first_name" id="first_name" value="<?php 
    echo esc_attr($profileuser->first_name);
    ?>
" class="regular-text" /></td>
                    </tr>

                    <tr>
                        <th><label for="last_name"><?php 
    _e('Last Name');
    ?>
</label></th>
                        <td><input type="text" name="last_name" id="last_name" value="<?php 
    echo esc_attr($profileuser->last_name);
    ?>
" class="regular-text" /></td>
                    </tr>

                    <tr>
                        <th><label for="nickname"><?php 
    _e('Nickname');
    ?>
 <span class="description"><?php 
    _e('(required)');
    ?>
</span></label></th>
                        <td><input type="text" name="nickname" id="nickname" value="<?php 
    echo esc_attr($profileuser->nickname);
    ?>
" class="regular-text" /></td>
                    </tr>

                    <tr>
                        <th><label for="display_name"><?php 
    _e('Display to Public as');
    ?>
</label></th>
                        <td>
                            <select name="display_name" id="display_name">
                                <?php 
    $public_display = array();
    $public_display['display_username'] = $profileuser->user_login;
    $public_display['display_nickname'] = $profileuser->nickname;
    if (!empty($profileuser->first_name)) {
        $public_display['display_firstname'] = $profileuser->first_name;
    }
    if (!empty($profileuser->last_name)) {
        $public_display['display_lastname'] = $profileuser->last_name;
    }
    if (!empty($profileuser->first_name) && !empty($profileuser->last_name)) {
        $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
        $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
    }
    if (!in_array($profileuser->display_name, $public_display)) {
        // Only add this if it isn't duplicated elsewhere
        $public_display = array('display_displayname' => $profileuser->display_name) + $public_display;
    }
    $public_display = array_map('trim', $public_display);
    $public_display = array_unique($public_display);
    foreach ($public_display as $id => $item) {
        ?>
                                    <option id="<?php 
        echo $id;
        ?>
" value="<?php 
        echo esc_attr($item);
        ?>
"<?php 
        selected($profileuser->display_name, $item);
        ?>
><?php 
        echo $item;
        ?>
</option>
                                    <?php 
    }
    ?>
                            </select>
                        </td>
                    </tr>
                </table>
            </fieldset>

            <fieldset>
                <legend><?php 
    _e('Contact Info');
    ?>
</legend>

                <table class="wpuf-table">
                    <tr>
                        <th><label for="email"><?php 
    _e('E-mail');
    ?>
 <span class="description"><?php 
    _e('(required)');
    ?>
</span></label></th>
                        <td><input type="text" name="email" id="email" value="<?php 
    echo esc_attr($profileuser->user_email);
    ?>
" class="regular-text" /> </td>
                    </tr>

                    <tr>
                        <th><label for="url"><?php 
    _e('Website');
    ?>
</label></th>
                        <td><input type="text" name="url" id="url" value="<?php 
    echo esc_attr($profileuser->user_url);
    ?>
" class="regular-text code" /></td>
                    </tr>

                    <?php 
    foreach (_wp_get_user_contactmethods() as $name => $desc) {
        ?>
                        <tr>
                            <th><label for="<?php 
        echo $name;
        ?>
"><?php 
        echo apply_filters('user_' . $name . '_label', $desc);
        ?>
</label></th>
                            <td><input type="text" name="<?php 
        echo $name;
        ?>
" id="<?php 
        echo $name;
        ?>
" value="<?php 
        echo esc_attr($profileuser->{$name});
        ?>
" class="regular-text" /></td>
                        </tr>
                        <?php 
    }
    ?>
                </table>
            </fieldset>

            <fieldset>
                <legend><?php 
    _e('About Yourself');
    ?>
</legend>

                <table class="wpuf-table">
                    <tr>
                        <th><label for="description"><?php 
    _e('Biographical Info', 'wpuf');
    ?>
</label></th>
                        <td><textarea name="description" id="description" rows="5" cols="30"><?php 
    echo esc_html($profileuser->description);
    ?>
</textarea><br />
                            <span class="description"><?php 
    _e('Share a little biographical information to fill out your profile. This may be shown publicly.');
    ?>
</span></td>
                    </tr>
                    <tr id="password">
                        <th><label for="pass1"><?php 
    _e('New Password', 'wpuf');
    ?>
</label></th>
                        <td>
                            <input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" /><br /><br />
                        </td>
                    </tr>
                    <tr>
                        <th><label><?php 
    _e('Confirm Password', 'wpuf');
    ?>
</label></th>
                        <td>
                            <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" />&nbsp;<em><span class="description"><?php 
    _e("Type your new password again.");
    ?>
</span></em>
                        </td>
                    </tr>
                    <tr>

                        <th><label><?php 
    _e('Password Strength', 'wpuf');
    ?>
</label></th>
                        <td>
                            <div id="pass-strength-result"><?php 
    _e('Strength indicator');
    ?>
</div>
                            <script src="<?php 
    echo admin_url();
    ?>
/js/password-strength-meter.js"></script>
                            <script type="text/javascript">
                                var pwsL10n = {
                                    empty: "Strength indicator",
                                    short: "Very weak",
                                    bad: "Weak",
                                    good: "Medium",
                                    strong: "Strong",
                                    mismatch: "Mismatch"
                                };
                                try{convertEntities(pwsL10n);}catch(e){};
                            </script>
                        </td>
                    </tr>
                </table>
            </fieldset>

            <?php 
    do_action('show_user_profile', $profileuser);
    ?>

            <p class="submit">
                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="user_id" id="user_id" value="<?php 
    echo esc_attr($user_id);
    ?>
" />
                <input type="submit" class="wpuf-submit" value="<?php 
    _e('Update Profile', 'wpuf');
    ?>
" name="submit" />
            </p>
        </form>
    </div>
    <?php 
}
Пример #14
0
function Simplr_usr_profiler()
{
    if (isset($_POST['setopts'])) {
        //rich_editing, comment_shorcut, admin_bar_front, admin_bar_admin, admin_color
        update_option('usrprof_personal', $_POST['personal']);
        update_option('usrprof_name', $_POST['name']);
        update_option('usrprof_contact', $_POST['contact']);
        update_option('usrprof_about', $_POST['about']);
        update_option('usrprof_toRemove', $_POST['to_remove']);
        update_option('usrprof_toHigh', $_POST['to_hide']);
        update_option('simple_profile_default_uncheck_bar', $_POST['def_bar']);
        update_option('simple_profile_show_front', $_POST['page_id']);
        update_option('simple_profile_on_edit', $_POST['onAdmin']);
    }
    $rem = get_option('usrprof_toRemove');
    $toHide = get_option('usrprof_toHigh');
    $disBar = get_option('simple_profile_default_uncheck_bar');
    ?>

<div class="wrap">




<div style=" float:left;width:400px;" >

<h2>Disable Profile Options</h2>


<form action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
" method="POST"  enctype="multipart/form-data" >
<table class="form-table">

<thead><tr><th><h4><b>Select Profile fields to disable</b> <span><em style="font-size:9px;font-weight:regular;"> (Leave title fields blank to not show them)</em></span></h4></th></tr></thead> 

<tr> <td> Change Personal  Label to: <input name="personal" value="<?php 
    echo get_option('usrprof_personal');
    ?>
" /></td></tr>
<tr><td> <input type="checkbox"  name ="to_remove[]" value="rich_editing"  <?php 
    if (is_array($rem) && in_array('rich_editing', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 />Visual Editor </td></tr>
<tr><td> <input type="checkbox"  name ="to_remove[]" value="admin_color"  <?php 
    if (is_array($rem) && in_array('admin_color', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Admin Color Scheme</td></tr>
<tr><td> <input type="checkbox"  name= "to_remove[]" value="comment_shortcuts"  <?php 
    if (is_array($rem) && in_array('comment_shortcuts', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Keyboard Shortcuts</td></tr>
<tr><td> <input type="checkbox"  name ="to_remove[]" value="admin_bar_front"  <?php 
    if (is_array($rem) && in_array('admin_bar_front', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Toolbar</td></tr>
<tr><td>&nbsp;</td></tr>
<tr> <td> Change Name Label to: <input name="name" value="<?php 
    echo get_option('usrprof_name');
    ?>
" />
<tr><td> <input type="checkbox"  name ="to_remove[]" value="first_name"  <?php 
    if (is_array($rem) && in_array('first_name', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 /> First Name</td></tr>
<tr><td> <input type="checkbox"  name ="to_remove[]" value="last_name"  <?php 
    if (is_array($rem) && in_array('last_name', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Last Name</td></tr>
<tr><td> <input type="checkbox"  name ="to_hide[]" value="nickname"  <?php 
    if (is_array($toHide) && in_array('nickname', $toHide)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Nickname</td></tr>
<tr><td> <input type="checkbox"  name ="to_hide[]" value="display_name"  <?php 
    if (is_array($toHide) && in_array('display_name', $toHide)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Display Name</td></tr>


<tr><td>&nbsp;</td></tr>
<tr> <td> Change Contact Info Label to: <input name="contact" value="<?php 
    echo get_option('usrprof_contact');
    ?>
" /></td></tr>
<tr><td> <input type="checkbox"  name ="to_remove[]" value="url"  <?php 
    if (is_array($rem) && in_array('url', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Website</td></tr>


<?php 
    foreach (_wp_get_user_contactmethods() as $name => $desc) {
        ?>



<tr><td> <input type="checkbox"  name ="to_remove[]" value="<?php 
        echo $name;
        ?>
"  <?php 
        if (is_array($rem) && in_array($name, $rem)) {
            echo ' checked="checked" ';
        }
        ?>
 /><?php 
        echo apply_filters('user_' . $name . '_label', $desc);
        ?>
 </td></tr>

<?php 
    }
    ?>
<tr><td>&nbsp;</td></tr>
<tr> <td> Change About Yourself Label to: <input name="about" value="<?php 
    echo get_option('usrprof_about');
    ?>
" /></td></tr>
<tr><td> <input type="checkbox"  name ="to_remove[]" value="description"  <?php 
    if (is_array($rem) && in_array('description', $rem)) {
        echo ' checked="checked" ';
    }
    ?>
 /> Biographical Info </td></tr>

 



</table>

<br />


<h2>Other Options</h2>
<?php 
    $IsA = get_option('simple_profile_on_edit');
    ?>
<br />
Apply to Front Page:<br />
<?php 
    wp_dropdown_pages(array('name' => 'page_id', 'selected' => get_option('simple_profile_show_front'), 'show_option_none' => '-- No Page --'));
    ?>

<br /> 
<br />
<input type="checkbox" name="def_bar" value="yes" <?php 
    if ($disBar == 'yes') {
        echo ' checked="checked" ';
    }
    ?>
> Disable admin bar in users profile on registration 

<br />
<br />
<input type="checkbox" value="yes" <?php 
    if ($IsA == 'yes') {
        echo ' checked ';
    }
    ?>
 name="onAdmin" />Show on Admin Edit Page<br />

<br />
<input type="submit" value="Save Options" name="setopts" />

</form>
 



</div>

<div style="float:left;width:250px;margin-left:45px;margin-top:50px;" >
		<table class="widefat">
					<thead><tr><th>Need some code......</th></tr></thead>
					<tr><td style="padding:10px 5px 10px 5px;">
					<p>
					Scriptonite is available for hire.  If you need custom theme functions or plugins why not <a href="http://www.whereyoursolutionis.com/contact-scriptonite/">get a quote</a>?
					
				    </p>
					
					
					</td></tr>
					</table>
					

		<table class="widefat" style="margin-top:20px;">
					<thead><tr><th>Need Help?</th></tr></thead>
					<tr><td style="padding:10px 5px 10px 5px;">
					<p>
					You can find more information on the <a href="http://www.whereyoursolutionis.com/simpler-user-profile/">Simple Profile</a> page.
					
				    </p>
					
					
					</td></tr>
					</table>



</div>


<?php 
}
Пример #15
0
/**
 * Insert an user into the database.
 *
 * Can update a current user or insert a new user based on whether the user's ID
 * is present.
 *
 * Can be used to update the user's info (see below), set the user's role, and
 * set the user's preference on whether they want the rich editor on.
 *
 * Most of the $userdata array fields have filters associated with the values.
 * The exceptions are 'rich_editing', 'role', 'jabber', 'aim', 'yim',
 * 'user_registered', and 'ID'. The filters have the prefix 'pre_user_' followed
 * by the field name. An example using 'description' would have the filter
 * called, 'pre_user_description' that can be hooked into.
 *
 * The $userdata array can contain the following fields:
 * 'ID' - An integer that will be used for updating an existing user.
 * 'user_pass' - A string that contains the plain text password for the user.
 * 'user_login' - A string that contains the user's username for logging in.
 * 'user_nicename' - A string that contains a nicer looking name for the user.
 *		The default is the user's username.
 * 'user_url' - A string containing the user's URL for the user's web site.
 * 'user_email' - A string containing the user's email address.
 * 'display_name' - A string that will be shown on the site. Defaults to user's
 *		username. It is likely that you will want to change this, for both
 *		appearance and security through obscurity (that is if you don't use and
 *		delete the default 'admin' user).
 * 'nickname' - The user's nickname, defaults to the user's username.
 * 'first_name' - The user's first name.
 * 'last_name' - The user's last name.
 * 'description' - A string containing content about the user.
 * 'rich_editing' - A string for whether to enable the rich editor or not. False
 *		if not empty.
 * 'user_registered' - The date the user registered. Format is 'Y-m-d H:i:s'.
 * 'role' - A string used to set the user's role.
 * 'jabber' - User's Jabber account.
 * 'aim' - User's AOL IM account.
 * 'yim' - User's Yahoo IM account.
 *
 * @since 2.0.0
 * @uses $wpdb WordPress database layer.
 * @uses apply_filters() Calls filters for most of the $userdata fields with the prefix 'pre_user'. See note above.
 * @uses do_action() Calls 'profile_update' hook when updating giving the user's ID
 * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
 *
 * @param array $userdata An array of user data.
 * @return int The newly created user's ID.
 */
function wp_insert_user($userdata)
{
    global $wpdb;
    extract($userdata, EXTR_SKIP);
    // Are we updating or creating?
    if (!empty($ID)) {
        $ID = (int) $ID;
        $update = true;
        $old_user_data = get_userdata($ID);
    } else {
        $update = false;
        // Hash the password
        $user_pass = wp_hash_password($user_pass);
    }
    $user_login = sanitize_user($user_login, true);
    $user_login = apply_filters('pre_user_login', $user_login);
    if (empty($user_nicename)) {
        $user_nicename = sanitize_title($user_login);
    }
    $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
    if (empty($user_url)) {
        $user_url = '';
    }
    $user_url = apply_filters('pre_user_url', $user_url);
    if (empty($user_email)) {
        $user_email = '';
    }
    $user_email = apply_filters('pre_user_email', $user_email);
    if (empty($display_name)) {
        $display_name = $user_login;
    }
    $display_name = apply_filters('pre_user_display_name', $display_name);
    if (empty($nickname)) {
        $nickname = $user_login;
    }
    $nickname = apply_filters('pre_user_nickname', $nickname);
    if (empty($first_name)) {
        $first_name = '';
    }
    $first_name = apply_filters('pre_user_first_name', $first_name);
    if (empty($last_name)) {
        $last_name = '';
    }
    $last_name = apply_filters('pre_user_last_name', $last_name);
    if (empty($description)) {
        $description = '';
    }
    $description = apply_filters('pre_user_description', $description);
    if (empty($rich_editing)) {
        $rich_editing = 'true';
    }
    if (empty($comment_shortcuts)) {
        $comment_shortcuts = 'false';
    }
    if (empty($admin_color)) {
        $admin_color = 'fresh';
    }
    $admin_color = preg_replace('|[^a-z0-9 _.\\-@]|i', '', $admin_color);
    if (empty($use_ssl)) {
        $use_ssl = 0;
    }
    if (empty($user_registered)) {
        $user_registered = gmdate('Y-m-d H:i:s');
    }
    $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login));
    if ($user_nicename_check) {
        $suffix = 2;
        while ($user_nicename_check) {
            $alt_user_nicename = $user_nicename . "-{$suffix}";
            $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login));
            $suffix++;
        }
        $user_nicename = $alt_user_nicename;
    }
    $data = compact('user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered');
    $data = stripslashes_deep($data);
    if ($update) {
        $wpdb->update($wpdb->users, $data, compact('ID'));
        $user_id = (int) $ID;
    } else {
        $wpdb->insert($wpdb->users, $data + compact('user_login'));
        $user_id = (int) $wpdb->insert_id;
    }
    update_usermeta($user_id, 'first_name', $first_name);
    update_usermeta($user_id, 'last_name', $last_name);
    update_usermeta($user_id, 'nickname', $nickname);
    update_usermeta($user_id, 'description', $description);
    update_usermeta($user_id, 'rich_editing', $rich_editing);
    update_usermeta($user_id, 'comment_shortcuts', $comment_shortcuts);
    update_usermeta($user_id, 'admin_color', $admin_color);
    update_usermeta($user_id, 'use_ssl', $use_ssl);
    foreach (_wp_get_user_contactmethods() as $method => $name) {
        if (empty(${$method})) {
            ${$method} = '';
        }
        update_usermeta($user_id, $method, ${$method});
    }
    if (isset($role)) {
        $user = new WP_User($user_id);
        $user->set_role($role);
    } elseif (!$update) {
        $user = new WP_User($user_id);
        $user->set_role(get_option('default_role'));
    }
    wp_cache_delete($user_id, 'users');
    wp_cache_delete($user_login, 'userlogins');
    if ($update) {
        do_action('profile_update', $user_id, $old_user_data);
    } else {
        do_action('user_register', $user_id);
    }
    return $user_id;
}
Пример #16
0
/**
 * Return a list of meta keys that wp_insert_user() is supposed to set.
 *
 * @access private
 * @since 3.3.0
 *
 * @param object $user WP_User instance
 * @return array
 */
function _get_additional_user_keys($user)
{
    $keys = array('first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front');
    return array_merge($keys, array_keys(_wp_get_user_contactmethods($user)));
}
Пример #17
0
/**
 * Retrieve user data and filter it.
 *
 * @since unknown
 *
 * @param int $user_id User ID.
 * @return object WP_User object with user data.
 */
function get_user_to_edit($user_id)
{
    $user = new WP_User($user_id);
    $user_contactmethods = _wp_get_user_contactmethods();
    foreach ($user_contactmethods as $method => $name) {
        if (empty($user->{$method})) {
            $user->{$method} = '';
        }
    }
    if (empty($user->description)) {
        $user->description = '';
    }
    $user = sanitize_user_object($user, 'edit');
    return $user;
}
Пример #18
0
 function contact_methods()
 {
     $contact_methods = _wp_get_user_contactmethods();
     $fep_contact_methods = get_option('fep_contact_methods');
     if (!is_array($fep_contact_methods)) {
         $fep_contact_methods = array();
     }
     $new_contact_methods = array();
     foreach ($contact_methods as $name => $desc) {
         if (!in_array(strtolower($name), $fep_contact_methods)) {
             continue;
         }
         $new_contact_methods[] = $name;
     }
     return $new_contact_methods;
 }