本文整理汇总了PHP中get_user_by函数的典型用法代码示例。如果您正苦于以下问题:PHP get_user_by函数的具体用法?PHP get_user_by怎么用?PHP get_user_by使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_by函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: openfire_authenticate
function openfire_authenticate($user, $username, $password)
{
global $openfire;
$openfire->of_logInfo("openfire_authenticate 1 " . $username . " " . $password);
if (!openfire_wants_to_login()) {
return new WP_Error('user_logged_out', sprintf(__('You are now logged out of Azure AD.', AADSSO), $username));
}
// Don't re-authenticate if already authenticated
if (strrpos($username, "@") == false || is_a($user, 'WP_User')) {
return $user;
}
$openfire->of_logInfo("openfire_authenticate 2 ");
// Try to find an existing user in WP where the UPN of the current AAD user is
// (depending on config) the 'login' or 'email' field
if ($username && $password && $openfire->of_authenticate_365($username, $password)) {
$user = get_user_by("email", $username);
if (!is_a($user, 'WP_User')) {
$openfire->of_logInfo("openfire_authenticate 3");
// Since the user was authenticated with AAD, but not found in WordPress,
// need to decide whether to create a new user in WP on-the-fly, or to stop here.
$openfire->of_logInfo("openfire_authenticate 4");
$paras = explode("@", $username);
$userid = $paras[0] . "." . $paras[1];
$new_user_id = wp_create_user($userid, $password, $username);
$user = new WP_User($new_user_id);
$user->set_role('subscriber');
$first_name = $openfire->of_get_given_name();
$last_name = $openfire->get_family_name();
$display_name = $first_name . " " . $last_name;
wp_update_user(array('ID' => $new_user_id, 'display_name' => $display_name, 'first_name' => $first_name, 'last_name' => $last_name));
}
}
return $user;
}
示例2: load_user
public function load_user()
{
if ($this->id > 0) {
$current_user = get_user_by('ID', $this->id);
} elseif (function_exists('is_user_logged_in') && is_user_logged_in()) {
$current_user = wp_get_current_user();
}
if (isset($current_user) && $current_user) {
$this->id = $current_user->ID;
$this->first_name = $current_user->user_firstname;
$this->last_name = $current_user->user_lastname;
$this->email = $current_user->user_email;
$this->address = get_user_meta($current_user->ID, 'address', TRUE);
$this->is_on_mailing_list = get_user_meta($current_user->ID, 'mailing_list', TRUE);
$this->is_on_mailing_list = $this->is_on_mailing_list == 1 ? TRUE : FALSE;
$neighborhood_id = get_user_meta($current_user->ID, 'neighborhood_id', TRUE);
if (!empty($neighborhood_id) && $neighborhood_id > 0) {
$args = array('post_type' => 'wbb_neighborhood', 'post_status' => 'publish');
$query = new \WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
if (get_the_ID() == $neighborhood_id) {
$this->neighborhood = new Neighborhood();
$this->neighborhood->post_id = get_the_ID();
$this->neighborhood->title = get_the_title();
break;
}
}
}
$this->get_locations();
}
}
示例3: xfac_get_avatar
function xfac_get_avatar($avatar = '', $id_or_email, $size = 96, $default = '', $alt = '')
{
if (is_numeric($id_or_email)) {
$wpUserId = (int) $id_or_email;
} elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) {
$wpUserId = $user->ID;
} elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) {
$wpUserId = (int) $id_or_email->user_id;
}
if (empty($wpUserId)) {
// cannot figure out the user id...
return $avatar;
}
$apiRecords = xfac_user_getRecordsByUserId($wpUserId);
if (empty($apiRecords)) {
// no api records
return $avatar;
}
$apiRecord = reset($apiRecords);
if (empty($apiRecord->profile['links']['avatar'])) {
// no avatar?
return $avatar;
}
$avatar = $apiRecord->profile['links']['avatar'];
$size = (int) $size;
if (empty($alt)) {
$alt = get_the_author_meta('display_name', $wpUserId);
}
$author_class = is_author($wpUserId) ? ' current-author' : '';
$avatar = "<img alt='" . esc_attr($alt) . "' src='" . esc_url($avatar) . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' />";
return $avatar;
}
示例4: _load_user
protected function _load_user($user = null)
{
if (is_user_logged_in() && !$user) {
$this->user = wp_get_current_user();
} else {
if ($user instanceof WP_User) {
$this->user = $user;
} else {
if (is_integer($user)) {
$this->user = get_user_by('id', $user);
} else {
if (is_string($user) && is_email($user)) {
$this->user = get_user_by('email', $user);
} else {
if (is_string($user)) {
$this->user = get_user_by('login', $user);
}
}
}
}
}
if (!$this->user) {
$message = __('User not found.', 'crb');
throw new Exception($message);
}
return $this;
}
示例5: add
/**
* Grant super-admin privileges to one or more users.
*
* <user>...
* : One or more user IDs, user emails, or user logins.
*/
public function add($args, $_)
{
$users = $this->fetcher->get_many($args);
$user_logins = wp_list_pluck($users, 'user_login');
$super_admins = self::get_admins();
$num_super_admins = count($super_admins);
foreach ($user_logins as $user_login) {
$user = get_user_by('login', $user_login);
if (!$user) {
WP_CLI::warning("Couldn't find {$user_login} user.");
continue;
}
if (in_array($user->user_login, $super_admins)) {
WP_CLI::warning("User {$user_login} already has super-admin capabilities.");
continue;
}
$super_admins[] = $user->user_login;
}
if ($num_super_admins === count($super_admins)) {
WP_CLI::log('No changes.');
} else {
if (update_site_option('site_admins', $super_admins)) {
WP_CLI::success('Granted super-admin capabilities.');
} else {
WP_CLI::error('Site options update failed!');
}
}
}
示例6: trigger
/**
* trigger function.
*
* @access public
* @return void
*/
function trigger($comment, $message)
{
global $woothemes_sensei, $sensei_email_data;
$this->comment = $comment;
$this->message = $message;
$this->commenter = get_userdata($comment->user_id);
$original_sender = get_post_meta($this->message->ID, '_sender', true);
$this->original_sender = get_user_by('login', $original_sender);
$original_receiver = get_post_meta($this->message->ID, '_receiver', true);
$this->original_receiver = get_user_by('login', $original_receiver);
$content_type = get_post_meta($this->message->ID, '_posttype', true);
$content_id = get_post_meta($this->message->ID, '_post', true);
$content_title = get_the_title($content_id);
$comment_link = get_comment_link($comment);
// Construct data array
$sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, 'heading' => $this->heading, 'commenter_name' => $this->commenter->display_name, 'message' => $this->comment->comment_content, 'comment_link' => $comment_link, 'content_title' => $content_title, 'content_type' => $content_type), $this->template);
// Set recipient
if ($this->commenter->user_login == $original_sender) {
$this->recipient = stripslashes($this->original_receiver->user_email);
} else {
$this->recipient = stripslashes($this->original_sender->user_email);
}
// Send mail
$woothemes_sensei->emails->send($this->recipient, $this->subject, $woothemes_sensei->emails->get_content($this->template));
}
示例7: sso_check
/**
Plugin Name: SSO
Author: Garth Mortensen, Mike Hansen
Version: 0.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
function sso_check()
{
if (!isset($_GET['salt']) || !isset($_GET['nonce']) || !isset($_GET['user'])) {
sso_req_login();
}
if (sso_check_blocked()) {
sso_req_login();
}
$nonce = esc_attr($_GET['nonce']);
$salt = esc_attr($_GET['salt']);
$user = esc_attr($_GET['user']);
$hash = base64_encode(hash('sha256', $nonce . $salt, false));
$hash = substr($hash, 0, 64);
if (get_transient('sso_token') == $hash) {
if (is_email($user)) {
$user = get_user_by('email', $user);
} else {
$user = get_user_by('id', (int) $user);
}
if (is_a($user, 'WP_User')) {
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
do_action('wp_login', $user->user_login);
delete_transient('sso_token');
wp_safe_redirect(admin_url());
} else {
sso_req_login();
}
} else {
sso_add_failed_attempt();
sso_req_login();
}
die;
}
示例8: edd_process_login_form
/**
* Process Login Form
*
* @since 1.0
* @param array $data Data sent from the login form
* @return void
*/
function edd_process_login_form($data)
{
if (wp_verify_nonce($data['edd_login_nonce'], 'edd-login-nonce')) {
$user_data = get_user_by('login', $data['edd_user_login']);
if (!$user_data) {
$user_data = get_user_by('email', $data['edd_user_login']);
}
if ($user_data) {
$user_ID = $user_data->ID;
$user_email = $user_data->user_email;
if (wp_check_password($data['edd_user_pass'], $user_data->user_pass, $user_data->ID)) {
edd_log_user_in($user_data->ID, $data['edd_user_login'], $data['edd_user_pass']);
} else {
edd_set_error('password_incorrect', __('The password you entered is incorrect', 'edd'));
}
} else {
edd_set_error('username_incorrect', __('The username you entered does not exist', 'edd'));
}
// Check for errors and redirect if none present
$errors = edd_get_errors();
if (!$errors) {
$redirect = apply_filters('edd_login_redirect', $data['edd_redirect'], $user_ID);
wp_redirect($redirect);
edd_die();
}
}
}
示例9: do_affiliates
public function do_affiliates($step = 1)
{
global $wpdb;
$offset = ($step - 1) * 100;
$affiliates = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}affiliates_tbl LIMIT {$offset}, 100;");
$to_delete = array();
if ($affiliates) {
foreach ($affiliates as $affiliate) {
if (empty($affiliate->email)) {
continue;
}
$user = get_user_by('email', $affiliate->email);
if (is_wp_error($user) || !$user) {
$user_id = wp_insert_user(array('user_email' => $affiliate->email, 'first_name' => $affiliate->firstname, 'last_name' => $affiliate->lastname, 'user_url' => $affiliate->website, 'user_pass' => '', 'user_login' => $affiliate->email));
} else {
$user_id = $user->ID;
}
$payment_email = !empty($affiliate->paypalemail) ? $affiliate->paypalemail : $affiliate->email;
$status = 'approved' == $affiliate->account_status ? 'active' : 'pending';
$args = array('date_registered' => date('Y-n-d H:i:s', strtotime($affiliate->date)), 'user_id' => $user_id, 'payment_email' => $payment_email, 'rate' => $affiliate->commissionlevel, 'status' => $status);
// Try to get an existing affiliate based on the user_id
$existing_affiliate = affiliate_wp()->affiliates->get_by('user_id', $user_id);
if ($existing_affiliate) {
continue;
}
// Insert a new affiliate - we need to always insert to make sure the affiliate_ids will match
$id = affiliate_wp()->affiliates->insert($args, 'affiliate');
}
return true;
} else {
// No affiliates found, so all done
return false;
}
}
示例10: activate
function activate($blog_id, $user_id, $domain, $path)
{
// mlog("FUNCTION: activate [$blog_id, $user_id, $domain, $path]");
$this->log("activate: {$blog_id}, {$user_id}, {$domain}, {$path}");
$email = '';
if ($user_id) {
$user = get_user_by('id', $user_id);
$email = $user ? $user->user_email : 'unknown';
}
$sk_subscription_id = get_option("sk_subscription_id");
$sk_selected_library = get_option("sk_selected_library");
if (isset($sk_selected_library) && $sk_selected_library && $sk_selected_library !== -1 && $sk_selected_library !== '-1') {
$data = array('domainName' => $domain . '/' . $path, 'productId' => $sk_selected_library);
} elseif (isset($sk_subscription_id) && intval($sk_subscription_id)) {
$data = array('domainName' => $domain . '/' . $path, 'subscriptionId' => $sk_subscription_id);
} else {
update_option('sk_auto_activation_error', "No selected library or subscriptionId set");
return false;
}
$result = $this->send_request('post', '/domains', $data);
if (isset($result->success) && $result->success == true && $result->payload->domainKey) {
$this->log("activate: success");
$this->activationSuccessful($result, $blog_id, $email);
} else {
$this->log("activate: error");
$this->activationError($result);
}
return $result;
}
示例11: checkUserExistance
public function checkUserExistance($resp = false)
{
$response = $resp;
if ($resp == false) {
$response = $_POST['fbResponse'];
}
$email = $response['email'];
$user = get_user_by('email', $email);
if ($user != false) {
//IF USER EXISTS PREPARE FOR LOGIN
$user_id = $user->ID;
if ($user_id > 0) {
wp_set_auth_cookie($user_id);
wp_set_current_user($user_id);
echo json_encode(array('result' => 'loggedIn', 'user_id' => $user_id));
die;
} else {
echo "User created with 0 id";
}
} else {
$new_user = $this->create_user($response);
if (is_wp_error($new_user)) {
echo $new_user->get_error_message();
} else {
$this->checkUserExistance($response);
}
}
}
示例12: lost_licence_key_form_handler
/**
* Handles actions on candidate dashboard
*/
public function lost_licence_key_form_handler()
{
if (!empty($_REQUEST['submit_lost_licence_form'])) {
$activation_email = sanitize_text_field($_REQUEST['activation_email']);
if (!is_email($activation_email)) {
wc_add_notice(__('Invalid email address.'), 'error');
return;
}
$keys = wppl_get_licences_from_activation_email($activation_email);
if (!$keys) {
wc_add_notice(__('No licences found.'), 'error');
} else {
ob_start();
// Try to get a user name
$user = get_user_by('email', $activation_email);
if ($user && !empty($user->first_name)) {
$user_first_name = $user->first_name;
} else {
$user_first_name = false;
}
wc_get_template('lost-licence-email.php', array('keys' => $keys, 'activation_email' => $activation_email, 'blogname' => get_option('blogname'), 'user_first_name' => $user_first_name), 'wp-plugin-licencing', WP_PLUGIN_LICENCING_PLUGIN_DIR . '/templates/');
// Get contents
$message = ob_get_clean();
if (wp_mail($activation_email, __('Your licence keys for WP Job Manager', 'wp-plugin-licencing'), $message)) {
wc_add_notice(sprintf(__('Your licences have been emailed to %s.'), $activation_email), 'success');
} else {
wc_add_notice(__('Your licences could not be sent. Please contact us for support.'), 'error');
}
}
}
}
示例13: pmxi_findDuplicates
/**
* Find duplicates according to settings
*/
function pmxi_findDuplicates($articleData, $custom_duplicate_name = '', $custom_duplicate_value = '', $duplicate_indicator = 'title')
{
global $wpdb;
if ('custom field' == $duplicate_indicator) {
$duplicate_ids = array();
if (!empty($articleData['post_type'])) {
$post_types = (class_exists('PMWI_Plugin') and $articleData['post_type'] == 'product') ? array('product', 'product_variation') : array($articleData['post_type']);
$args = array('post_type' => $post_types, 'post_status' => array('any'), 'meta_query' => array(array('key' => trim($custom_duplicate_name), 'value' => htmlspecialchars(trim($custom_duplicate_value)))), 'order' => 'ASC', 'orderby' => 'ID');
$query = new WP_Query($args);
if ($query->have_posts()) {
$duplicate_ids[] = $query->post->ID;
}
wp_reset_postdata();
if (empty($duplicate_ids)) {
$query = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON (" . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id) WHERE 1=1 AND " . $wpdb->posts . ".post_type IN ('" . implode("','", $post_types) . "') AND (" . $wpdb->posts . ".post_status = 'publish' OR " . $wpdb->posts . ".post_status = 'future' OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'trash' OR " . $wpdb->posts . ".post_status = 'private') AND ( (" . $wpdb->postmeta . ".meta_key = '%s' AND CAST(" . $wpdb->postmeta . ".meta_value AS CHAR) = '%s') ) GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC LIMIT 0, 20", trim($custom_duplicate_name), htmlspecialchars(trim($custom_duplicate_value))));
if (!empty($query)) {
foreach ($query as $p) {
$duplicate_ids[] = $p->ID;
}
}
}
} else {
$args = array('meta_query' => array(0 => array('key' => $custom_duplicate_name, 'value' => $custom_duplicate_value, 'compare' => '=')));
$user_query = new WP_User_Query($args);
if (!empty($user_query->results)) {
foreach ($user_query->results as $user) {
$duplicate_ids[] = $user->ID;
}
} else {
$query = $wpdb->get_results($wpdb->prepare("SELECT SQL_CALC_FOUND_ROWS " . $wpdb->users . ".ID FROM " . $wpdb->users . " INNER JOIN " . $wpdb->usermeta . " ON (" . $wpdb->users . ".ID = " . $wpdb->usermeta . ".user_id) WHERE 1=1 AND ( (" . $wpdb->usermeta . ".meta_key = '%s' AND CAST(" . $wpdb->usermeta . ".meta_value AS CHAR) = '%s') ) GROUP BY " . $wpdb->users . ".ID ORDER BY " . $wpdb->users . ".ID ASC LIMIT 0, 20", $custom_duplicate_name, $custom_duplicate_value));
if (!empty($query)) {
foreach ($query as $p) {
$duplicate_ids[] = $p->ID;
}
}
}
}
return $duplicate_ids;
} elseif ('parent' == $duplicate_indicator) {
$field = 'post_title';
// post_title or post_content
return $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT ID FROM " . $wpdb->posts . "\n\t\t\tWHERE\n\t\t\t\tpost_type = %s\n\t\t\t\tAND ID != %s\n\t\t\t\tAND post_parent = %s\n\t\t\t\tAND REPLACE(REPLACE(REPLACE({$field}, ' ', ''), '\\t', ''), '\\n', '') = %s\n\t\t\t", $articleData['post_type'], isset($articleData['ID']) ? $articleData['ID'] : 0, !empty($articleData['post_parent']) ? $articleData['post_parent'] : 0, preg_replace('%[ \\t\\n]%', '', $articleData[$field])));
} else {
if (!empty($articleData['post_type'])) {
$field = 'post_' . $duplicate_indicator;
// post_title or post_content
return $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT ID FROM " . $wpdb->posts . "\n\t\t\t\tWHERE\n\t\t\t\t\tpost_type = %s\n\t\t\t\t\tAND ID != %s\n\t\t\t\t\tAND REPLACE(REPLACE(REPLACE({$field}, ' ', ''), '\\t', ''), '\\n', '') = %s\n\t\t\t\t", $articleData['post_type'], isset($articleData['ID']) ? $articleData['ID'] : 0, preg_replace('%[ \\t\\n]%', '', $articleData[$field])));
} else {
if ($duplicate_indicator == 'title') {
$field = 'user_login';
$u = get_user_by('login', $articleData[$field]);
return !empty($u) ? array($u->ID) : false;
} else {
$field = 'user_email';
$u = get_user_by('email', $articleData[$field]);
return !empty($u) ? array($u->ID) : false;
}
}
}
}
示例14: wpum_get_user_by_data
/**
* Returns a wp user object containg user's data.
* The user is retrieved based on the current permalink structure.
* This function is currently used only through the wpum_profile shortcode.
* If no data is set, returns currently logged in user data.
*
* @since 1.0.0
* @access public
* @return object
*/
function wpum_get_user_by_data()
{
$user_data = null;
$permalink_structure = get_option('wpum_permalink', 'user_id');
$who = get_query_var('user') ? get_query_var('user') : null;
// Checks we are on the profile page
if (is_page(wpum_get_core_page_id('profile'))) {
// Verify the user isset
if ($who) {
switch ($permalink_structure) {
case 'user_id':
$user_data = get_user_by('id', intval(get_query_var('user')));
break;
case 'username':
$user_data = get_user_by('login', esc_attr(get_query_var('user')));
break;
case 'nickname':
// WP_User_Query arguments
$args = array('search' => esc_attr(get_query_var('user')), 'search_columns' => array('user_nicename'));
// The User Query
$user_query = new WP_User_Query($args);
$user_query = $user_query->get_results();
$user_data = $user_query[0];
break;
default:
$user_data = apply_filters("wpum_get_user_by_data", $permalink_structure, $who);
break;
}
} else {
$user_data = get_user_by('id', get_current_user_id());
}
}
return $user_data;
}
示例15: um_get_avatar
function um_get_avatar($avatar = '', $id_or_email = '', $size = '96', $avatar_class = '', $default = '', $alt = '')
{
if (is_numeric($id_or_email)) {
$user_id = (int) $id_or_email;
} elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) {
$user_id = $user->ID;
} elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) {
$user_id = (int) $id_or_email->user_id;
}
if (empty($user_id)) {
return $avatar;
}
um_fetch_user($user_id);
$avatar = um_user('profile_photo', $size);
if (!um_profile('profile_photo') && um_get_option('use_gravatars')) {
if (is_ssl()) {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
$default = get_option('avatar_default', 'mystery');
if ($default == 'gravatar_default') {
$default = '';
}
$rating = get_option('avatar_rating');
if (!empty($rating)) {
$rating = "&r={$rating}";
}
$avatar = '<img src="' . $protocol . 'gravatar.com/avatar/' . md5(um_user('user_email')) . '?d=' . $default . '&s=' . $size . $rating . '" class="gravatar avatar avatar-' . $size . ' um-avatar" width="' . $size . '" height="' . $size . '" alt="" />';
}
return $avatar;
}