当前位置: 首页>>代码示例>>PHP>>正文


PHP add_new_user_to_blog函数代码示例

本文整理汇总了PHP中add_new_user_to_blog函数的典型用法代码示例。如果您正苦于以下问题:PHP add_new_user_to_blog函数的具体用法?PHP add_new_user_to_blog怎么用?PHP add_new_user_to_blog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了add_new_user_to_blog函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: wpmu_activate_signup

/**
 * Activate a signup.
 *
 * Hook to 'wpmu_activate_user' or 'wpmu_activate_blog' for events
 * that should happen only when users or sites are self-created (since
 * those actions are not called when users and sites are created
 * by a Super Admin).
 *
 * @since MU
 * @uses wp_generate_password()
 * @uses wpmu_welcome_user_notification()
 * @uses add_user_to_blog()
 * @uses add_new_user_to_blog()
 * @uses wpmu_create_user()
 * @uses wpmu_create_blog()
 * @uses wpmu_welcome_notification()
 *
 * @param string $key The activation key provided to the user.
 * @return array An array containing information about the activated user and/or blog
 */
function wpmu_activate_signup($key)
{
    global $wpdb, $current_site;
    $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $key));
    if (empty($signup)) {
        return new WP_Error('invalid_key', __('Invalid activation key.'));
    }
    if ($signup->active) {
        if (empty($signup->domain)) {
            return new WP_Error('already_active', __('The user is already active.'), $signup);
        } else {
            return new WP_Error('already_active', __('The site is already active.'), $signup);
        }
    }
    $meta = unserialize($signup->meta);
    $user_login = $wpdb->escape($signup->user_login);
    $user_email = $wpdb->escape($signup->user_email);
    $password = wp_generate_password(12, false);
    $user_id = username_exists($user_login);
    if (!$user_id) {
        $user_id = wpmu_create_user($user_login, $password, $user_email);
    } else {
        $user_already_exists = true;
    }
    if (!$user_id) {
        return new WP_Error('create_user', __('Could not create user'), $signup);
    }
    $now = current_time('mysql', true);
    if (empty($signup->domain)) {
        $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        if (isset($user_already_exists)) {
            return new WP_Error('user_already_exists', __('That username is already activated.'), $signup);
        }
        wpmu_welcome_user_notification($user_id, $password, $meta);
        add_new_user_to_blog($user_id, $user_email, $meta);
        do_action('wpmu_activate_user', $user_id, $password, $meta);
        return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta);
    }
    $blog_id = wpmu_create_blog($signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid);
    // TODO: What to do if we create a user but cannot create a blog?
    if (is_wp_error($blog_id)) {
        // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and
        // setting the activation flag.  Let's just set the active flag and instruct the user to reset their password.
        if ('blog_taken' == $blog_id->get_error_code()) {
            $blog_id->add_data($signup);
            $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
        }
        return $blog_id;
    }
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key));
    wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
    do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
    return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
}
开发者ID:nhemsley,项目名称:wordpress,代码行数:74,代码来源:ms-functions.php

示例2: activate_signup

function activate_signup($key)
{
    global $wpdb;
    $signup = $wpdb->get_row($wpdb->prepare("select * from {$wpdb->signups} where activation_key = %s", $key));
    if (empty($signup)) {
        return new \WP_Error('invalid_key', __('Invalid activation key.', 'mtv'));
    }
    if ($signup->active) {
        return new \WP_Error('already_active', __('This account is already activated.', 'mtv'), $signup);
    }
    $user_meta = unserialize($signup->meta);
    $user_login = $wpdb->escape($signup->user_login);
    $user_email = $wpdb->escape($signup->user_email);
    $user_pass = $user_meta['user_pass'];
    $user_id = username_exists($user_login);
    if (!$user_id) {
        $user_id = wpmu_create_user($user_login, wp_generate_password(12, false), $user_email);
    }
    if (!$user_id) {
        return new \WP_Error('create_user', __('Could not create user', 'mtv'), $signup);
    }
    // Be sure to unset the user pass because
    // we don't want to store it as meta once
    // the user is activated
    unset($user_meta['user_pass']);
    foreach ($user_meta as $k => $v) {
        update_user_meta($user_id, $k, $v);
    }
    $wpdb->update($wpdb->users, array('user_pass' => $user_pass, 'user_activation_key' => ''), array('ID' => $user_id));
    $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => current_time('mysql', true), 'meta' => ''), array('activation_key' => $key));
    add_new_user_to_blog($user_id, $user_email, '');
    return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta);
}
开发者ID:newsapps,项目名称:wordpress-mtv,代码行数:33,代码来源:models.php


注:本文中的add_new_user_to_blog函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。