本文整理汇总了PHP中add_user_to_blog函数的典型用法代码示例。如果您正苦于以下问题:PHP add_user_to_blog函数的具体用法?PHP add_user_to_blog怎么用?PHP add_user_to_blog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_user_to_blog函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jquery_install_remaining_sites
function jquery_install_remaining_sites($user)
{
$domains = jquery_domains();
$default_options = jquery_default_site_options();
$default_options['admin_email'] = $user->user_email;
foreach ($domains as $domain => $details) {
if (1 !== $details['blog_id']) {
$blog_id = insert_blog(JQUERY_STAGING_PREFIX . $domain, '/', 1);
if ($blog_id != $details['blog_id']) {
wp_die("Something went very wrong when trying to install {$domain} as site {$blog_id}-{$details['blog_id']}. Find nacin.");
}
switch_to_blog($blog_id);
install_blog($blog_id, $details['options']['blogname']);
add_user_to_blog($blog_id, $user->ID, 'administrator');
}
$options = array_merge($default_options, $details['options']);
foreach ($options as $option => $value) {
update_option($option, $value);
}
// Work around a superficial bug in install_blog(), fixed in WP r21172.
$home = untrailingslashit(get_option('home'));
$siteurl = untrailingslashit(get_option('siteurl'));
update_option('home', 'http://example.com');
// Please just don't ask.
update_option('siteurl', 'http://example.com');
update_option('home', $home);
update_option('siteurl', $siteurl);
flush_rewrite_rules();
restore_current_blog();
}
}
示例2: jquery_install_site
function jquery_install_site($site, $user)
{
$sites = jquery_sites();
$details = $sites[$site];
if (strpos($site, '/')) {
list($domain, $path) = explode('/', $site, 2);
$path = '/' . trim($path, '/') . '/';
} else {
$domain = $site;
$path = '/';
}
$default_options = jquery_default_site_options();
$default_options['admin_email'] = $user->user_email;
if (1 !== $details['blog_id']) {
$blog_id = insert_blog(JQUERY_STAGING_PREFIX . $domain, $path, 1);
if ($blog_id != $details['blog_id']) {
wp_die("Something went very wrong when trying to install {$domain} as site {$blog_id}-{$details['blog_id']}. Find nacin.");
}
switch_to_blog($blog_id);
install_blog($blog_id, $details['options']['blogname']);
add_user_to_blog($blog_id, $user->ID, 'administrator');
}
$options = array_merge($default_options, $details['options']);
foreach ($options as $option => $value) {
update_option($option, $value);
}
delete_option('rewrite_rules');
restore_current_blog();
}
示例3: maybe_import_post
function maybe_import_post($guid, $post_arr)
{
$results = array();
if ($this->post_exists($guid)) {
$results[] = "<p>{$guid} already exists</p>";
} else {
$results[] = "<p>{$guid} does not alread exist</p>";
$post_title = $post_arr['title'];
$post_content = $post_arr['content'];
$author_exists = $this->author_exists($post_arr['author']);
if (!$author_exists) {
$results[] = "<p>{$guid} author does not already exist</p>";
$author_id = $this->import_author($post_arr['author']);
if (!empty($author_id)) {
$results[] = "<p>{$guid} author added as author_id {$author_id}</p>";
}
} else {
$results[] = "<p>{$guid} author already exists as id {$author_exists}</p>";
$author_id = $author_exists;
add_user_to_blog(get_current_blog_id(), $author_id, 'subscriber');
}
$post_excerpt = $post_arr['description'];
$args = array('post_title' => $post_title, 'post_content' => $post_content, 'post_author' => $author_id, 'post_excerpt' => $post_excerpt);
$new_post_id = wp_insert_post($args);
if (!empty($new_post_id)) {
$results[] = "<p>{$guid} was inserted as post ID {$new_post_id}</p>";
add_post_meta($new_post_id, SJF_GF . "-guid", $guid, TRUE);
} else {
$results[] = "<p>{$guid} could not be inserted</p>";
}
}
return $results;
}
示例4: test_get_active_blog_for_user_with_spam_site
/**
* @ticket 38355
*/
public function test_get_active_blog_for_user_with_spam_site()
{
$current_site_id = get_current_blog_id();
$site_id = self::factory()->blog->create(array('user_id' => self::$user_id, 'meta' => array('spam' => 1)));
add_user_to_blog($site_id, self::$user_id, 'subscriber');
update_user_meta(self::$user_id, 'primary_blog', $site_id);
$result = get_active_blog_for_user(self::$user_id);
wpmu_delete_blog($site_id, true);
$this->assertEquals($current_site_id, $result->id);
}
示例5: on_activate_user
function on_activate_user($user_id, $password, $meta)
{
$default_role = get_option('default_role');
$blogid = empty($meta['register_blog_id']) ? 1 : intval($meta['register_blog_id']);
add_user_to_blog(1, $user_id, $default_role);
add_user_to_blog($blogid, $user_id, $default_role);
if ($this->debug) {
$this->write_to_log('Activate:' . print_r($meta, true));
}
}
示例6: join_site
static function join_site()
{
global $current_user, $blog_id;
$jmm_options = get_option('helfjmm_options');
if (!is_user_logged_in()) {
return false;
}
if (!is_user_member_of_blog()) {
add_user_to_blog($blog_id, $current_user->ID, $jmm_options['role']);
}
}
示例7: test_author_queried_object_fix
/**
* On author pages, the queried object should only be set
* to a user that's not a member of the blog if they
* have at least one published post. This matches core behavior.
*
* @see https://core.trac.wordpress.org/changeset/27290
*/
function test_author_queried_object_fix()
{
global $wp_rewrite, $coauthors_plus;
/**
* Set up
*/
$author1 = $this->factory->user->create(array('user_login' => 'msauthor1'));
$author2 = $this->factory->user->create(array('user_login' => 'msauthor2'));
$blog2 = $this->factory->blog->create(array('user_id' => $author1));
switch_to_blog($blog2);
$wp_rewrite->init();
$blog2_post1 = $this->factory->post->create(array('post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str(), 'post_author' => $author1));
/**
* Author 1 is an author on the blog
*/
$this->go_to(get_author_posts_url($author1));
$this->assertQueryTrue('is_author', 'is_archive');
/**
* Author 2 is not yet an author on the blog
*/
$this->go_to(get_author_posts_url($author2));
$this->assertQueryTrue('is_404');
// Add the user to the blog
add_user_to_blog($blog2, $author2, 'author');
/**
* Author 2 is now on the blog, but not yet published
*/
$this->go_to(get_author_posts_url($author2));
$this->assertQueryTrue('is_author', 'is_archive');
// Add the user as an author on the original post
$author2_obj = get_user_by('id', $author2);
$coauthors_plus->add_coauthors($blog2_post1, array($author2_obj->user_login), true);
/**
* Author 2 is now on the blog, and published
*/
$this->go_to(get_author_posts_url($author2));
$this->assertQueryTrue('is_author', 'is_archive');
// Remove the user from the blog
remove_user_from_blog($author2, $blog2);
/**
* Author 2 was removed from the blog, but still a published author
*/
$this->go_to(get_author_posts_url($author2));
$this->assertQueryTrue('is_author', 'is_archive');
// Delete the user from the network
wpmu_delete_user($author2);
/**
* Author 2 is no more
*/
$this->go_to(get_author_posts_url($author2));
$this->assertQueryTrue('is_404');
$this->assertEquals(false, get_user_by('id', $author2));
restore_current_blog();
}
示例8: test_get_dashboard_url_for_administrator_of_different_site
/**
* @ticket 39065
*/
public function test_get_dashboard_url_for_administrator_of_different_site()
{
if (!is_multisite()) {
$this->markTestSkipped('Test only runs in multisite.');
}
$site_id = self::factory()->blog->create(array('user_id' => self::$user_id));
remove_user_from_blog(self::$user_id, get_current_blog_id());
$expected = get_admin_url($site_id);
$result = get_dashboard_url(self::$user_id);
remove_user_from_blog(self::$user_id, $site_id);
add_user_to_blog(get_current_blog_id(), self::$user_id, 'administrator');
wpmu_delete_blog($site_id, true);
$this->assertEquals($expected, $result);
}
示例9: ns_wp_add_user
/**
* Create / Add users
*/
function ns_wp_add_user($target_id, $useremail, $username, $userpass = '', $userrole = 'administrator', $logfile = false)
{
global $ns_cloner;
ns_log_write("ENTER ns_wp_add_user - target_id:{$target_id}, useremail:{$useremail}, username:{$username}, userrole:{$userrole}", $logfile);
$useremail = stripslashes($useremail);
$username = stripslashes($username);
$userpass = stripslashes($userpass);
$user_by_email = get_user_by('email', $useremail);
$user_by_username = get_user_by('username', $username);
// check for existing user by email
if (!empty($user_by_email)) {
$user_id = $user_by_email->ID;
ns_log_write("Found user with email '{$useremail}' (id={$user_id})", $logfile);
} elseif (!empty($user_by_username)) {
$user_id = $user_by_username->ID;
ns_log_write("Found user with username '{$username}' (id={$user_id})", $logfile);
} else {
if (empty($userpass) || $userpass == strtolower('null')) {
$userpass = wp_generate_password();
}
$user_id = wpmu_create_user($username, $userpass, $useremail);
if ($user_id != false) {
ns_log_write("Created new user '{$username}' with email '{$useremail}'", $logfile);
// send notification to new users if the option is set
if (isset($ns_cloner->request['do_user_notify'])) {
wpmu_welcome_notification($target_id, $user_id, $userpass, 'New Site with ID: ' . $target_id);
ns_log_write("Sent welcome email to new user '{$username}' with email '{$useremail}'", $logfile);
}
} else {
ns_log_write("Failed creating user '{$username}' with email '{$useremail}' - that username or email is probably already taken for a different user.", $logfile);
}
}
// we now have a user id (or should) - give them privileges on this blog
if (!empty($target_id) && !empty($user_id) && !empty($userrole)) {
$result = add_user_to_blog($target_id, $user_id, $userrole);
if ($result === true) {
ns_log_write("Successfully added user with id {$user_id} to blog {$target_id}", $logfile);
} else {
$error_message = $result->get_error_message();
ns_log_write("Failed adding user to blog. WP error: {$error_message}", $logfile);
}
return $result;
} else {
$error_message = "Target id, user id, or user role were empty";
ns_log_write("Failed adding user to blog. {$error_message}", $logfile);
return new WP_Error(false, $error_message);
}
}
示例10: wpms_add_user_to_main_site
function wpms_add_user_to_main_site($user_id = null)
{
global $wpdb;
if (!is_multisite()) {
return;
}
if (!$user_id) {
$user_id = get_current_user_id();
}
if (defined('BLOG_ID_CURRENT_SITE')) {
$main_site = BLOG_ID_CURRENT_SITE;
} else {
$main_site = 1;
}
add_user_to_blog($main_site, $user_id, 'subscriber');
}
示例11: impose
/**
* Impose some state data onto a region
*
* @param string $key Site slug
* @param array $value Site data
* @return true|WP_Error
*/
public function impose($key, $value)
{
$site = $this->get_site($key);
if (!$site) {
$site = $this->create_site($key, $value);
if (is_wp_error($site)) {
return $site;
}
}
switch_to_blog($site['blog_id']);
foreach ($value as $field => $single_value) {
switch ($field) {
case 'title':
case 'description':
$map = array('title' => 'blogname', 'description' => 'blogdescription');
update_option($map[$field], $single_value);
break;
case 'active_theme':
if ($single_value !== get_option('stylesheet')) {
switch_theme($single_value);
}
break;
case 'active_plugins':
foreach ($single_value as $plugin) {
if (!is_plugin_active($plugin)) {
activate_plugin($plugin);
}
}
break;
case 'users':
foreach ($single_value as $user_login => $role) {
$user = get_user_by('login', $user_login);
if (!$user) {
continue;
}
add_user_to_blog($site['blog_id'], $user->ID, $role);
}
break;
}
}
restore_current_blog();
return true;
}
示例12: widget_suscribe
function widget_suscribe()
{
global $wpdb, $current_user;
$options = get_option('widget_suscribe');
$before_widget = "<li id='subscribe'>";
$before_title = "<h2>";
$title = empty($options['title']) ? 'Suscríbete a este blog' : $options['title'];
$after_title = "</h2>";
$content = "";
$after_widget = "</li>";
//error_log("[widget subscribe] current blog: ". $wpdb->blogid);
//error_log("[widget subscribe] current user: ". $current_user->ID);
// User is already in blog database
if (is_blog_user($wpdb->blogid)) {
//error_log("[widget subscribe] is blog user");
// User wants to unsubscribe
if (isset($_POST['unsuscribe'])) {
//error_log("[widget subscribe] POST[unsuscribe]");
remove_user_from_blog($current_user->ID, $wpdb->blogid);
$content .= '<p>Te has desuscrito de este blog</p>';
$content .= widget_subscribe_form();
} elseif ($current_user->has_cap('subscriber')) {
//error_log("[widget subscribe] has_cap('subscriber')");
$content .= widget_unsubscribe_form();
} elseif ($current_user->has_cap('edit_posts')) {
$content .= "<p>Este blog tiene activado el widget de suscripción</p>";
}
} else {
//error_log("[widget subscribe] not in log");
// User wants to subscribe
if (isset($_POST['suscribe'])) {
//error_log("[widget subscribe] POST[suscribe]");
add_user_to_blog($wpdb->blogid, $current_user->ID, 'subscriber');
$content .= '<p>Te has suscrito a este blog</p>';
$content .= widget_unsubscribe_form();
} else {
//error_log("[widget subscribe] subscribe form");
$content .= widget_subscribe_form();
}
}
echo $before_widget . $before_title . $title . $after_title . $content . $after_widget;
}
示例13: test_get_users_with_no_role_multisite_is_accurate
/**
* @ticket 22993
* @group multisite
*/
public function test_get_users_with_no_role_multisite_is_accurate()
{
if (!is_multisite()) {
$this->markTestSkipped('Test requires multisite');
}
// Setup users
$admin = self::factory()->user->create(array('role' => 'administrator'));
$editor = self::factory()->user->create(array('role' => 'editor'));
$nobody = self::factory()->user->create(array('role' => ''));
// Setup blogs
$blog_1 = (int) self::factory()->blog->create(array('user_id' => $editor));
// Add users to blogs
add_user_to_blog($blog_1, $editor, 'editor');
// Test users on root site
$users = wp_get_users_with_no_role();
$this->assertSame(array(), $users);
// Test users counts on blog 1
switch_to_blog($blog_1);
$users = wp_get_users_with_no_role();
restore_current_blog();
// Test users on root site
$this->assertSame(array(), $users);
}
示例14: test_sends_stats_data_on_heartbeat_on_multisite
public function test_sends_stats_data_on_heartbeat_on_multisite()
{
global $wpdb;
if (!is_multisite()) {
$this->markTestSkipped('Run it in multi site mode');
}
$user_id = $this->factory->user->create();
$mu_blog_user_id = $this->factory->user->create();
// create a different blog
$suppress = $wpdb->suppress_errors();
$other_blog_id = wpmu_create_blog('foo.com', '', "My Blog", $user_id);
$wpdb->suppress_errors($suppress);
// create a user from within that blog (won't be synced)
switch_to_blog($other_blog_id);
add_user_to_blog($other_blog_id, $mu_blog_user_id, 'administrator');
$heartbeat = Jetpack_Heartbeat::init();
$heartbeat->cron_exec();
$this->sender->do_sync();
$action = $this->server_event_storage->get_most_recent_event('jetpack_sync_heartbeat_stats');
restore_current_blog();
$this->assertEquals(JETPACK__VERSION, $action->args[0]['version']);
$this->assertFalse(isset($action->args[0]['users']));
}
示例15: test_count_users_multisite_is_accurate
/**
* @ticket 22993
* @group multisite
*
* @dataProvider data_count_users_strategies
*/
public function test_count_users_multisite_is_accurate($strategy)
{
if (!is_multisite()) {
$this->markTestSkipped('Test requires multisite');
}
// Setup users
$admin = self::factory()->user->create(array('role' => 'administrator'));
$editor = self::factory()->user->create(array('role' => 'editor'));
$author = self::factory()->user->create(array('role' => 'author'));
$contributor = self::factory()->user->create(array('role' => 'contributor'));
$subscriber = self::factory()->user->create(array('role' => 'subscriber'));
$none = self::factory()->user->create(array('role' => ''));
$nobody = self::factory()->user->create(array('role' => ''));
// Setup blogs
$blog_1 = (int) self::factory()->blog->create(array('user_id' => $editor));
$blog_2 = (int) self::factory()->blog->create(array('user_id' => $author));
// Add users to blogs
add_user_to_blog($blog_1, $subscriber, 'editor');
add_user_to_blog($blog_2, $none, 'contributor');
// Test users counts on root site
$count = count_users($strategy);
$this->assertEquals(8, $count['total_users']);
$this->assertEquals(array('administrator' => 2, 'editor' => 1, 'author' => 1, 'contributor' => 1, 'subscriber' => 1, 'none' => 0), $count['avail_roles']);
// Test users counts on blog 1
switch_to_blog($blog_1);
$count = count_users($strategy);
restore_current_blog();
$this->assertEquals(2, $count['total_users']);
$this->assertEquals(array('administrator' => 1, 'editor' => 1, 'none' => 0), $count['avail_roles']);
// Test users counts on blog 2
switch_to_blog($blog_2);
$count = count_users($strategy);
restore_current_blog();
$this->assertEquals(2, $count['total_users']);
$this->assertEquals(array('administrator' => 1, 'contributor' => 1, 'none' => 0), $count['avail_roles']);
}