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


PHP WP_User::set_role方法代码示例

本文整理汇总了PHP中WP_User::set_role方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User::set_role方法的具体用法?PHP WP_User::set_role怎么用?PHP WP_User::set_role使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_User的用法示例。


在下文中一共展示了WP_User::set_role方法的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;
}
开发者ID:igniterealtime,项目名称:community-plugins,代码行数:34,代码来源:ofsocial.php

示例2: upgradeSubscriberToAuthor

function upgradeSubscriberToAuthor($user_id)
{
    $user = new WP_User($user_id);
    if (in_array('subscriber', $user->roles)) {
        $user->set_role('author');
    }
}
开发者ID:Cywaithaka,项目名称:bwawwp,代码行数:7,代码来源:example-18.php

示例3: array

 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '')
 {
     global $wp_rewrite;
     wp_check_mysql_version();
     wp_cache_flush();
     make_db_current_silent();
     populate_options();
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     $guessurl = wp_guess_url();
     update_option('siteurl', $guessurl);
     // If not a public blog, don't ping.
     if (!$public) {
         update_option('default_pingback_flag', 0);
     }
     // Create default user.  If the user already exists, the user tables are
     // being shared among blogs.  Just set the role in that case.
     $user_id = username_exists($user_name);
     if (!$user_id) {
         $random_password = wp_generate_password();
         $user_id = wp_create_user($user_name, $random_password, $user_email);
     } else {
         $random_password = __('User already exists.  Password inherited.');
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     wp_install_defaults($user_id);
     $wp_rewrite->flush_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
     wp_cache_flush();
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
 }
开发者ID:alx,项目名称:blogsfera,代码行数:34,代码来源:upgrade.php

示例4: isset

 function wp_install($blog_title, $user_name, $user_email, $public, $meta = '')
 {
     global $wp_rewrite;
     wp_check_mysql_version();
     wp_cache_flush();
     make_db_current_silent();
     populate_options();
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     $schema = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
     $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     update_option('siteurl', $guessurl);
     // If not a public blog, don't ping.
     if (!$public) {
         update_option('default_pingback_flag', 0);
     }
     // Create default user.  If the user already exists, the user tables are
     // being shared among blogs.  Just set the role in that case.
     $user_id = username_exists($user_name);
     if (!$user_id) {
         $random_password = substr(md5(uniqid(microtime())), 0, 6);
         $user_id = wp_create_user($user_name, $random_password, $user_email);
     } else {
         $random_password = __('User already exists.  Password inherited.');
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     wp_install_defaults($user_id);
     $wp_rewrite->flush_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
     wp_cache_flush();
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
 }
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:35,代码来源:upgrade-functions.php

示例5: wp_install

function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '')
{
    global $wpdb;
    $base = '/';
    $domain = JQUERY_STAGING_PREFIX . 'jquery.com';
    wp_check_mysql_version();
    wp_cache_flush();
    make_db_current_silent();
    populate_options();
    populate_roles();
    $user_id = wp_create_user($user_name, trim($user_password), $user_email);
    $user = new WP_User($user_id);
    $user->set_role('administrator');
    $guess_url = wp_guess_url();
    foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) {
        $wpdb->{$table} = $prefixed_table;
    }
    install_network();
    populate_network(1, $domain, $user_email, 'jQuery Network', $base, false);
    update_site_option('site_admins', array($user->user_login));
    update_site_option('allowedthemes', array());
    $wpdb->insert($wpdb->blogs, array('site_id' => 1, 'domain' => $domain, 'path' => $base, 'registered' => current_time('mysql')));
    $blog_id = $wpdb->insert_id;
    update_user_meta($user_id, 'source_domain', $domain);
    update_user_meta($user_id, 'primary_blog', $blog_id);
    if (!($upload_path = get_option('upload_path'))) {
        $upload_path = substr(WP_CONTENT_DIR, strlen(ABSPATH)) . '/uploads';
        update_option('upload_path', $upload_path);
    }
    update_option('fileupload_url', get_option('siteurl') . '/' . $upload_path);
    jquery_install_remaining_sites($user);
    wp_new_blog_notification($blog_title, $guess_url, $user_id, $message = __('The password you chose during the install.'));
    wp_cache_flush();
    return array('url' => $guess_url, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
}
开发者ID:ravasthi,项目名称:web-base-template,代码行数:35,代码来源:install.php

示例6: trim

 /**
  * Installs the blog
  *
  * {@internal Missing Long Description}}
  *
  * @since 2.1.0
  *
  * @param string $blog_title Blog title.
  * @param string $user_name User's username.
  * @param string $user_email User's email.
  * @param bool $public Whether blog is public.
  * @param string $deprecated Optional. Not used.
  * @param string $user_password Optional. User's chosen password. Will default to a random password.
  * @param string $language Optional. Language chosen.
  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
  */
 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '')
 {
     if (!empty($deprecated)) {
         _deprecated_argument(__FUNCTION__, '2.6');
     }
     wp_check_mysql_version();
     wp_cache_flush();
     make_db_current_silent();
     populate_options();
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     if ($language) {
         update_option('WPLANG', $language);
     }
     $guessurl = wp_guess_url();
     update_option('siteurl', $guessurl);
     // If not a public blog, don't ping.
     if (!$public) {
         update_option('default_pingback_flag', 0);
     }
     /*
      * Create default user. If the user already exists, the user tables are
      * being shared among blogs. Just set the role in that case.
      */
     $user_id = username_exists($user_name);
     $user_password = trim($user_password);
     $email_password = false;
     if (!$user_id && empty($user_password)) {
         $user_password = wp_generate_password(12, false);
         $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
         $user_id = wp_create_user($user_name, $user_password, $user_email);
         update_user_option($user_id, 'default_password_nag', true, true);
         $email_password = true;
     } else {
         if (!$user_id) {
             // Password has been provided
             $message = '<em>' . __('Your chosen password.') . '</em>';
             $user_id = wp_create_user($user_name, $user_password, $user_email);
         } else {
             $message = __('User already exists. Password inherited.');
         }
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     wp_install_defaults($user_id);
     flush_rewrite_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $email_password ? $user_password : __('The password you chose during the install.'));
     wp_cache_flush();
     /**
      * Fires after a site is fully installed.
      *
      * @since 3.9.0
      *
      * @param WP_User $user The site owner.
      */
     do_action('wp_install', $user);
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
 }
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:76,代码来源:upgrade.php

示例7: add_user

/**
 * Creates a new user from the "Users" form using $_POST information.
 *
 * It seems that the first half is for backwards compatibility, but only
 * has the ability to alter the user's role. WordPress core seems to
 * use this function only in the second way, running edit_user() with
 * no id so as to create a new user.
 *
 * @since 2.0
 *
 * @param int $user_id Optional. User ID.
 * @return null|WP_Error|int Null when adding user, WP_Error or User ID integer when no parameters.
 */
function add_user()
{
    if (func_num_args()) {
        // The hackiest hack that ever did hack
        global $current_user, $wp_roles;
        $user_id = (int) func_get_arg(0);
        if (isset($_POST['role'])) {
            $new_role = sanitize_text_field($_POST['role']);
            // Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
            if ($user_id != $current_user->id || $wp_roles->role_objects[$new_role]->has_cap('edit_users')) {
                // If the new role isn't editable by the logged-in user die with error
                $editable_roles = get_editable_roles();
                if (empty($editable_roles[$new_role])) {
                    wp_die(__('You can&#8217;t give users that role.'));
                }
                $user = new WP_User($user_id);
                $user->set_role($new_role);
            }
        }
    } else {
        add_action('user_register', 'add_user');
        // See above
        return edit_user();
    }
}
开发者ID:laiello,项目名称:cartonbank,代码行数:38,代码来源:user.php

示例8: acxu_createUser

function acxu_createUser($args)
{
    global $wp_xmlrpc_server;
    $wp_xmlrpc_server->escape($args);
    $nickname = $args[0];
    //$password = $args[1];
    //if ( ! $user = $wp_xmlrpc_server->login( $username, $password ) )
    //    return $wp_xmlrpc_server->error;
    $user_name = time() . "_" . rand(1000, 9999);
    $user_email = $user_name . "@bbuser.org";
    if (!username_exists($user_name) && !email_exists($user_email)) {
        $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
        $user_id = wp_create_user($user_name, $random_password, $user_email);
        if ($nickname == "") {
            $nickname = $user_email;
        }
        // Update the user to set the nickname
        wp_update_user(array('ID' => $user_id, 'nickname' => $nickname));
        // Get the user object to set the user's role
        $wp_user_object = new WP_User($user_id);
        //http://en.support.wordpress.com/user-roles/
        $wp_user_object->set_role('author');
        return $user_name . " " . $random_password;
    } else {
        return "ERROR: User Name or Email Already Exists";
    }
}
开发者ID:AurangZ,项目名称:securereader,代码行数:27,代码来源:auto-create-xmlrpc-user.php

示例9: isset

 /**
  * Installs the blog
  *
  * {@internal Missing Long Description}}
  *
  * @since 2.1.0
  *
  * @param string $blog_title Blog title.
  * @param string $user_name User's username.
  * @param string $user_email User's email.
  * @param bool $public Whether blog is public.
  * @param null $deprecated Optional. Not used.
  * @param string $user_password Optional. User's chosen password. Will default to a random password.
  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
  */
 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '')
 {
     if (!empty($deprecated)) {
         _deprecated_argument(__FUNCTION__, '2.6');
     }
     wp_check_mysql_version();
     wp_cache_flush();
     make_db_current_silent();
     if (!is_file(ABSPATH . 'wp-admin/install.sql')) {
         //[ysd]如果有install.sql不设置默认options数据
         populate_options();
     } else {
         validate_active_plugins();
         //[ysd] 禁用 不可用的插件
     }
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     $guessurl = isset($_SERVER['HTTP_APPNAME']) ? 'http://' . substr($_SERVER['HTTP_APPNAME'], 5) . '.1kapp.com' : wp_guess_url();
     //[ysd] 固定了guessurl
     update_option('siteurl', $guessurl);
     update_option('home', $guessurl);
     get_option('siteurl');
     // If not a public blog, don't ping.
     if (!$public) {
         update_option('default_pingback_flag', 0);
     }
     // Create default user. If the user already exists, the user tables are
     // being shared among blogs. Just set the role in that case.
     $user_id = username_exists($user_name);
     $user_password = trim($user_password);
     $email_password = false;
     if (!$user_id && empty($user_password)) {
         $user_password = wp_generate_password(12, false);
         $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
         $user_id = wp_create_user($user_name, $user_password, $user_email);
         update_user_option($user_id, 'default_password_nag', true, true);
         $email_password = true;
     } else {
         if (!$user_id) {
             // Password has been provided
             $message = '<em>' . __('Your chosen password.') . '</em>';
             $user_id = wp_create_user($user_name, $user_password, $user_email);
         } else {
             $message = __('User already exists. Password inherited.');
         }
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     if (!file_exists(ABSPATH . 'wp-admin/without_default')) {
         wp_install_defaults($user_id);
     }
     //[ysd],如果打包时设置了默认数据,才会设置默认数据
     flush_rewrite_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $email_password ? $user_password : __('The password you chose during the install.'));
     wp_cache_flush();
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
 }
开发者ID:ramo01,项目名称:1kapp,代码行数:74,代码来源:upgrade.php

示例10: wp_insert_user

function wp_insert_user($userdata)
{
    global $wpdb;
    extract($userdata);
    // Are we updating or creating?
    if (!empty($ID)) {
        $update = true;
    } else {
        $update = false;
        // Password is not hashed when creating new user.
        $user_pass = md5($user_pass);
    }
    if (empty($user_nicename)) {
        $user_nicename = sanitize_title($user_login);
    }
    if (empty($display_name)) {
        $display_name = $user_login;
    }
    if (empty($nickname)) {
        $nickname = $user_login;
    }
    if (empty($user_registered)) {
        $user_registered = gmdate('Y-m-d H:i:s');
    }
    if ($update) {
        $query = "UPDATE {$wpdb->users} SET user_pass='{$user_pass}', user_email='{$user_email}', user_url='{$user_url}', user_nicename = '{$user_nicename}', display_name = '{$display_name}' WHERE ID = '{$ID}'";
        $query = apply_filters('update_user_query', $query);
        $wpdb->query($query);
        $user_id = $ID;
    } else {
        $query = "INSERT INTO {$wpdb->users} \n\t\t(user_login, user_pass, user_email, user_url, user_registered, user_nicename, display_name)\n\tVALUES \n\t\t('{$user_login}', '{$user_pass}', '{$user_email}', '{$user_url}', '{$user_registered}', '{$user_nicename}', '{$display_name}')";
        $query = apply_filters('create_user_query', $query);
        $wpdb->query($query);
        $user_id = $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, 'jabber', $jabber);
    update_usermeta($user_id, 'aim', $aim);
    update_usermeta($user_id, 'yim', $yim);
    if ($update && !empty($role)) {
        $user = new WP_User($user_id);
        $user->set_role($role);
    }
    if (!$update) {
        $user = new WP_User($user_id);
        $user->set_role(get_settings('default_role'));
    }
    wp_cache_delete($user_id, 'users');
    wp_cache_delete($user_login, 'userlogins');
    if ($update) {
        do_action('profile_update', $user_id);
    } else {
        do_action('user_register', $user_id);
    }
    return $user_id;
}
开发者ID:robertlange81,项目名称:Website,代码行数:59,代码来源:registration-functions.php

示例11: sa_check_roles

function sa_check_roles()
{
    $user = new WP_User(1);
    if (!$user->has_cap("is_super")) {
        $user->set_role("administrator");
        $user->add_cap("is_super");
    }
}
开发者ID:phillipmadsen,项目名称:g_public,代码行数:8,代码来源:superadmin.php

示例12: update_status_unknown_to_success

 public static function update_status_unknown_to_success(Pronamic_Pay_Payment $payment, $can_redirect = false)
 {
     $data = new Pronamic_WP_Pay_Extensions_S2Member_PaymentData(array('level' => get_post_meta($payment->get_id(), '_pronamic_payment_s2member_level', true), 'period' => get_post_meta($payment->get_id(), '_pronamic_payment_s2member_period', true), 'ccaps' => get_post_meta($payment->get_id(), '_pronamic_payment_s2member_ccaps', true)));
     $email = $payment->get_email();
     // get account from email
     $user = get_user_by('email', $email);
     // No valid user?
     if (!$user) {
         // Make a random string for password
         $random_string = wp_generate_password(10);
         // Make a user with the username as the email
         $user_id = wp_create_user($email, $random_string, $email);
         // Subject
         $subject = __('Account Confirmation', 'pronamic_ideal') . ' | ' . get_bloginfo('name');
         // Message
         $message = get_option('pronamic_pay_s2member_signup_email_message');
         $message = str_replace(array('%%email%%', '%%password%%'), array($email, $password), $message);
         // Mail
         wp_mail($email, $subject, $message);
         $user = new WP_User($user_id);
     }
     $level = $data->get_level();
     $period = $data->get_period();
     $ccaps = $data->get_ccaps();
     $capability = 'access_s2member_level' . $level;
     $role = 's2member_level' . $level;
     // Update user role
     //$user->add_cap( $capability ); // TODO Perhaps this should line be removed. At s2Member EOT this capability is not removed, which allows the user to illegitimately view the protected content.
     $user->set_role($role);
     $note = sprintf(__('Update user "%s" to role "%s" and added custom capability "%s".', 'pronamic_ideal'), $email, $role, $capability);
     $payment->add_note($note);
     // Custom Capabilities
     if (!empty($ccaps)) {
         $ccaps = Pronamic_WP_Pay_Extensions_S2Member_Util::ccap_string_to_array($ccaps);
         Pronamic_WP_Pay_Extensions_S2Member_Util::ccap_user_update($user, $ccaps);
     }
     // Registration times
     $registration_time = time();
     $registration_times = get_user_option('s2member_paid_registration_times', $user->ID);
     if (empty($registration_times)) {
         $registration_times = array();
     }
     $registration_times['level' . $level] = $registration_time;
     update_user_option($user->ID, 's2member_paid_registration_times', $registration_times);
     if (in_array($period, array('1 L'))) {
         // Lifetime, delete end of time option
         delete_user_option($user->ID, 's2member_auto_eot_time');
     } else {
         // Auto end of time
         // @see https://github.com/WebSharks/s2Member/blob/131126/s2member/includes/classes/utils-time.inc.php#L100
         $eot_time_current = get_user_option('s2member_auto_eot_time', $user->ID);
         if (!is_numeric($eot_time_current)) {
             $eot_time_current = time();
         }
         $eot_time_new = c_ws_plugin__s2member_utils_time::auto_eot_time($user->ID, false, $period, false, $eot_time_current);
         update_user_option($user->ID, 's2member_auto_eot_time', $eot_time_new);
     }
 }
开发者ID:daanbakker1995,项目名称:vanteun,代码行数:58,代码来源:Extension.php

示例13:

 /**
  * Change role when user expires?
  */
 function handle_on_expire_default_to_role($expired_user)
 {
     if ($expired_user->on_expire_default_to_role) {
         if (get_role($expired_user->on_expire_default_to_role)) {
             $u = new WP_User($expired_user->user_id);
             $u->set_role($expired_user->on_expire_default_to_role);
         }
     }
 }
开发者ID:abhijagtap73,项目名称:expire-users,代码行数:12,代码来源:expire-users.php

示例14:

 function test_user_capability()
 {
     $user = new WP_User(1);
     $user->set_role('wpas_user');
     $open = user_can($user, 'create_ticket');
     $edit = user_can($user, 'edit_ticket');
     $this->assertTrue($open);
     $this->assertFalse($edit);
 }
开发者ID:alpha1,项目名称:Awesome-Support,代码行数:9,代码来源:test-install.php

示例15: um_setup_synced_wp_role

function um_setup_synced_wp_role($user_id, $role)
{
    global $ultimatemember;
    $meta = $ultimatemember->query->role_data($role);
    $meta = apply_filters('um_user_permissions_filter', $meta, $user_id);
    if (isset($meta['synced_role']) && $meta['synced_role']) {
        $wp_user_object = new WP_User($user_id);
        $wp_user_object->set_role($meta['synced_role']);
    }
}
开发者ID:jonfalcon,项目名称:ultimatemember,代码行数:10,代码来源:um-actions-user.php


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