本文整理汇总了PHP中wpmu_create_user函数的典型用法代码示例。如果您正苦于以下问题:PHP wpmu_create_user函数的具体用法?PHP wpmu_create_user怎么用?PHP wpmu_create_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpmu_create_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fu_add_new_user
function fu_add_new_user($fu = false)
{
//echo "wtf?";
require_once '../../../wp-includes/registration.php';
global $blog_id;
$email = sanitize_email($fu['email']);
//$current_site = get_current_site();
$pass = $fu['password'];
$user_id = email_exists($email);
//echo "hi";
if (!$user_id) {
$password = $pass ? $pass : generate_random_password();
$user_id = wpmu_create_user($fu['username'], $password, $email);
if (false == $user_id) {
//echo "uh oh";
wp_die(__('There was an error creating the user'));
} else {
//echo "sending mail";
wp_new_user_notification($user_id, $password);
}
if (get_user_option('primary_blog', $user_id) == $blog_id) {
update_user_option($user_id, 'primary_blog', $blog_id, true);
}
}
$redirect = $fu['referer'] ? $fu['referer'] : get_bloginfo('url');
wp_redirect($redirect);
}
示例2: test_enable_live_network_user_counts_filter
/**
* @ticket 22917
*/
function test_enable_live_network_user_counts_filter() {
// false for large networks by default
add_filter( 'enable_live_network_counts', '__return_false' );
// Refresh the cache
wp_update_network_counts();
$start_count = get_user_count();
wpmu_create_user( 'user', 'pass', 'email' );
// No change, cache not refreshed
$count = get_user_count();
$this->assertEquals( $start_count, $count );
wp_update_network_counts();
$start_count = get_user_count();
add_filter( 'enable_live_network_counts', '__return_true' );
wpmu_create_user( 'user2', 'pass2', 'email2' );
$count = get_user_count();
$this->assertEquals( $start_count + 1, $count );
remove_filter( 'enable_live_network_counts', '__return_false' );
remove_filter( 'enable_live_network_counts', '__return_true' );
}
示例3: msxmlrpc_create_blog
/**
* Creates a new blog calling wpmu_create_blog
* the wpmu_create_blog parameters are:
* $domain The domain of the new blog.
* $path The path of the new blog.
* $title The title of the new blog.
* $user_id The user id of the user account who will be the blog admin. (you can use an email instead of the user_id. If so, a new user will be created)
* $meta Other meta information.
* $site_id The site_id of the blog to be created.
*
* @param array $args Array with username, password and wpmu_create_blog function parameters
* @return mixed The new blog id or an error message
*/
function msxmlrpc_create_blog($args)
{
$parameters = check_arguments($args);
if (!is_array($parameters)) {
return $parameters;
}
// if the user_id is the user's e-mail
if (!is_int($parameters['user_id'])) {
if (!($user_id = get_user_id_from_string($parameters['user_id']))) {
$error = wpmu_validate_user_signup($parameters['path'], $parameters['user_id']);
if (is_wp_error($error)) {
return new IXR_Error(500, $error->get_error_message());
}
$user_id = wpmu_create_user($parameters['path'], wp_generate_password(), $parameters['user_id']);
}
$parameters['user_id'] = $user_id;
}
if (get_blog_id($parameters['domain'], $parameters['path']) !== false) {
return new IXR_Error(500, __("Site already exists."));
}
if (!isset($parameters['meta'])) {
$parameters['meta'] = "";
}
if (!isset($parameters['site_id'])) {
$parameters['site_id'] = 1;
}
return wpmu_create_blog($parameters['domain'], $parameters['path'], $parameters['title'], $parameters['user_id'], $parameters['meta'], $parameters['site_id']);
}
示例4: 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);
}
}
示例5: signup_blog
/**
* Add a blog to *_signups table.
*
* Copied from core because we need the activation key and
* we need to avoid the blog activation email. This can/is done
* via a hook, but the double AJAX call kills our AJAX registration
* so its left out here.
*
* @param $domain
* @param $path
* @param $title
* @param $user
* @param $user_email
* @param array $meta
*
* @return string $key Activation key
*/
public static function signup_blog($domain, $path, $title, $user, $user_email, $meta = array())
{
global $wpdb;
$key = substr(md5(time() . rand() . $domain), 0, 16);
$meta = serialize($meta);
$result = $wpdb->insert($wpdb->signups, array('domain' => $domain, 'path' => sanitize_text_field($path), 'title' => sanitize_text_field($title), 'user_login' => sanitize_text_field($user), 'user_email' => sanitize_email($user_email), 'registered' => current_time('mysql', true), 'activation_key' => $key, 'meta' => $meta));
$password = false;
// Activate the user and attempt a login (because we want WP sessions)
$user_id = username_exists($user);
if (!$user_id) {
$password = wp_generate_password(12, false);
$user_id = wpmu_create_user($user, $password, $user_email);
$creds = array('user_login' => $user, 'user_password' => $password, 'remember' => true);
$user = wp_signon($creds);
}
$result = array('activation_key' => $key, 'user_pass' => $password);
return $result;
}
示例6: test_with_another_site
function test_with_another_site()
{
global $current_site, $base;
$domain = 'blogoptiontest';
if (is_subdomain_install()) {
$newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain);
$path = $base;
} else {
$newdomain = $current_site->domain;
$path = $base . $domain . '/';
}
$email = 'foo@foo.foo';
$password = wp_generate_password(12, false);
$user_id = wpmu_create_user($domain, $password, $email);
$this->assertInternalType('integer', $user_id);
$blog_id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id);
$this->assertInternalType('integer', $blog_id);
$key = rand_str();
$key2 = rand_str();
$value = rand_str();
$value2 = rand_str();
$this->assertFalse(get_blog_option($blog_id, 'doesnotexist'));
//$this->assertFalse( get_option( 'doesnotexist' ) ); // check get_option()
$this->assertTrue(add_blog_option($blog_id, $key, $value));
// Assert all values of $blog_id that means the current or main blog (the same here).
$this->assertEquals($value, get_blog_option($blog_id, $key));
$this->assertEquals($value, get_blog_option("{$blog_id}", $key));
//$this->assertEquals( $value, get_option( $key ) ); // check get_option()
$this->assertFalse(add_blog_option($blog_id, $key, $value));
// Already exists
$this->assertFalse(update_blog_option($blog_id, $key, $value));
// Value is the same
$this->assertTrue(update_blog_option($blog_id, $key, $value2));
$this->assertEquals($value2, get_blog_option($blog_id, $key));
//$this->assertEquals( $value2, get_option( $key ) ); // check get_option()
$this->assertFalse(add_blog_option($blog_id, $key, $value));
$this->assertEquals($value2, get_blog_option($blog_id, $key));
//$this->assertEquals( $value2, get_option( $key ) ); // check get_option()
$this->assertTrue(delete_blog_option($blog_id, $key));
$this->assertFalse(get_blog_option($blog_id, $key));
//$this->assertFalse( get_option( $key ) ); // check get_option()
$this->assertFalse(delete_blog_option($blog_id, $key));
$this->assertTrue(update_blog_option($blog_id, $key2, $value2));
$this->assertEquals($value2, get_blog_option($blog_id, $key2));
//$this->assertEquals( $value2, get_option( $key2 ) ); // check get_option()
$this->assertTrue(delete_blog_option($blog_id, $key2));
$this->assertFalse(get_blog_option($blog_id, $key2));
//$this->assertFalse( get_option( $key2 ) ); // check get_option()
}
示例7: add_user
/**
* Create / Add users
*/
function add_user($useremail, $username, $userpass = '', $userrole = 'administrator')
{
global $wpdb;
$useremail = stripslashes($useremail);
$username = stripslashes($username);
$userpass = stripslashes($userpass);
$is_new_user = 0;
$user_id = '';
$user = get_user_by_email($useremail);
if (!empty($user)) {
// user exists
$user_id = $user->ID;
} else {
// create user
if ($userpass == '' || $userpass == strtolower('null')) {
$userpass = wp_generate_password();
}
$user_id = wpmu_create_user($username, $userpass, $useremail);
$is_new_user = 1;
}
if (false == $user_id) {
//die( '<p>' . __( 'There was an error creating a user', 'ns_cloner' ) . '</p> name: ' . $username . ' email: ' . $useremail . ' pass: ' . $userpass );
$this->status = $this->status . '<font style="color:red;">' . "FAILED to create Username: <br>{$username}</b> with Email: <b>{$useremail}</b> - that username or email is probably already taken for a different user.</font><br />";
$is_new_user = 0;
} else {
// add the user
add_user_to_blog($this->target_id, $user_id, $userrole);
$this->status = $this->status . 'Added user: <b>' . $username . ' | ' . $useremail . '</b>';
if ($is_new_user) {
$this->status = $this->status . " created with Password: {$userpass}";
$this->log('Added user: <b>' . $username . ' | ' . $useremail . " created with Password: {$userpass}");
}
$this->status = $this->status . '<br />';
}
}
示例8: wp_redirect
wp_redirect(add_query_arg(array('updated' => 'true', 'action' => $userfunction), $_SERVER['HTTP_REFERER']));
}
exit;
break;
case "adduser":
check_admin_referer('add-user');
$user = $_POST['user'];
if (empty($user['username']) && empty($user['email'])) {
wp_die(__('Missing username and email.'));
} elseif (empty($user['username'])) {
wp_die(__('Missing username.'));
} elseif (empty($user['email'])) {
wp_die(__('Missing email.'));
}
$password = generate_random_password();
$user_id = wpmu_create_user(wp_specialchars(strtolower($user['username'])), $password, wp_specialchars($user['email']));
if (false == $user_id) {
wp_die(__('Duplicated username or email address.'));
} else {
wp_new_user_notification($user_id, $password);
}
if (get_site_option('dashboard_blog') == false) {
add_user_to_blog('1', $user_id, get_site_option('default_user_role', 'subscriber'));
} else {
add_user_to_blog(get_site_option('dashboard_blog'), $user_id, get_site_option('default_user_role', 'subscriber'));
}
wp_redirect(add_query_arg(array('updated' => 'true', 'action' => 'add'), $_SERVER['HTTP_REFERER']));
exit;
break;
default:
wpmu_admin_do_redirect("wpmu-admin.php");
示例9: wp_die
if (!current_user_can('manage_network_users')) {
wp_die(__('You do not have permission to access this page.'));
}
if (is_array($_POST['user']) == false) {
wp_die(__('Cannot create an empty user.'));
}
$user = $_POST['user'];
if (empty($user['username']) && empty($user['email'])) {
wp_die(__('Missing username and email.'));
} elseif (empty($user['username'])) {
wp_die(__('Missing username.'));
} elseif (empty($user['email'])) {
wp_die(__('Missing email.'));
}
$password = wp_generate_password();
$user_id = wpmu_create_user(esc_html(strtolower($user['username'])), $password, esc_html($user['email']));
if (false == $user_id) {
wp_die(__('Duplicated username or email address.'));
} else {
wp_new_user_notification($user_id, $password);
}
if (get_site_option('dashboard_blog') == false) {
add_user_to_blog($current_site->blog_id, $user_id, get_site_option('default_user_role', 'subscriber'));
} else {
add_user_to_blog(get_site_option('dashboard_blog'), $user_id, get_site_option('default_user_role', 'subscriber'));
}
wp_redirect(add_query_arg(array('updated' => 'true', 'action' => 'add'), wp_get_referer()));
exit;
break;
default:
wp_redirect(admin_url('ms-admin.php'));
示例10: create
/**
* Create a site in a multisite install.
*
* ## OPTIONS
*
* --slug=<slug>
* : Path for the new site. Subdomain on subdomain installs, directory on subdirectory installs.
*
* [--title=<title>]
* : Title of the new site. Default: prettified slug.
*
* [--email=<email>]
* : Email for Admin user. User will be created if none exists. Assignement to Super Admin if not included.
*
* [--network_id=<network-id>]
* : Network to associate new site with. Defaults to current network (typically 1).
*
* [--private]
* : If set, the new site will be non-public (not indexed)
*
* [--porcelain]
* : If set, only the site id will be output on success.
*/
public function create($_, $assoc_args)
{
if (!is_multisite()) {
WP_CLI::error('This is not a multisite install.');
}
global $wpdb, $current_site;
$base = $assoc_args['slug'];
$title = \WP_CLI\Utils\get_flag_value($assoc_args, 'title', ucfirst($base));
$email = empty($assoc_args['email']) ? '' : $assoc_args['email'];
// Network
if (!empty($assoc_args['network_id'])) {
$network = $this->_get_network($assoc_args['network_id']);
if ($network === false) {
WP_CLI::error(sprintf('Network with id %d does not exist.', $assoc_args['network_id']));
}
} else {
$network = $current_site;
}
$public = !\WP_CLI\Utils\get_flag_value($assoc_args, 'private');
// Sanitize
if (preg_match('|^([a-zA-Z0-9-])+$|', $base)) {
$base = strtolower($base);
}
// If not a subdomain install, make sure the domain isn't a reserved word
if (!is_subdomain_install()) {
$subdirectory_reserved_names = apply_filters('subdirectory_reserved_names', array('page', 'comments', 'blog', 'files', 'feed'));
if (in_array($base, $subdirectory_reserved_names)) {
WP_CLI::error('The following words are reserved and cannot be used as blog names: ' . implode(', ', $subdirectory_reserved_names));
}
}
// Check for valid email, if not, use the first Super Admin found
// Probably a more efficient way to do this so we dont query for the
// User twice if super admin
$email = sanitize_email($email);
if (empty($email) || !is_email($email)) {
$super_admins = get_super_admins();
$email = '';
if (!empty($super_admins) && is_array($super_admins)) {
// Just get the first one
$super_login = $super_admins[0];
$super_user = get_user_by('login', $super_login);
if ($super_user) {
$email = $super_user->user_email;
}
}
}
if (is_subdomain_install()) {
$path = '/';
$url = $newdomain = $base . '.' . preg_replace('|^www\\.|', '', $network->domain);
} else {
$newdomain = $network->domain;
$path = '/' . trim($base, '/') . '/';
$url = $network->domain . $path;
}
$user_id = email_exists($email);
if (!$user_id) {
// Create a new user with a random password
$password = wp_generate_password(12, false);
$user_id = wpmu_create_user($base, $password, $email);
if (false == $user_id) {
WP_CLI::error("Can't create user.");
} else {
wp_new_user_notification($user_id, $password);
}
}
$wpdb->hide_errors();
$id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => $public), $network->id);
$wpdb->show_errors();
if (!is_wp_error($id)) {
if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) {
update_user_option($user_id, 'primary_blog', $id, true);
}
// Prevent mailing admins of new sites
// @TODO argument to pass in?
// $content_mail = sprintf(__( "New site created by WP Command Line Interface\n\nAddress: %2s\nName: %3s"), get_site_url($id), stripslashes($title));
// wp_mail(get_site_option('admin_email'), sprintf(__('[%s] New Site Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <'.get_site_option( 'admin_email').'>');
} else {
//.........这里部分代码省略.........
示例11: step3
function step3()
{
global $wpdb, $current_site, $dirs, $wpmu_version;
$base = stripslashes(dirname($_SERVER["SCRIPT_NAME"]));
if ($base != "/") {
$base .= "/";
}
$domain = get_clean_basedomain();
$email = $wpdb->escape($_POST['email']);
if ($email == '') {
die('You must enter an email address!');
}
// set up site tables
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'site_name', '" . $wpdb->escape($_POST['weblog_title']) . "')");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'admin_email', '" . $email . "')");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'admin_user_id', '1')");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'registration', 'none')");
$wpdb->query("INSERT INTO " . $wpdb->site . " ( id, domain, path ) VALUES ( NULL, '{$domain}', '{$base}' )");
$wpdb->query("INSERT INTO " . $wpdb->sitecategories . " ( cat_ID, cat_name, category_nicename, last_updated ) VALUES (1, 'Uncategorized', 'uncategorized', NOW())");
$wpdb->query("INSERT INTO " . $wpdb->sitecategories . " ( cat_ID, cat_name, category_nicename, last_updated ) VALUES (2, 'Blogroll', 'blogroll', NOW())");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'upload_filetypes', 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf' )");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'blog_upload_space', '10' )");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'fileupload_maxk', '1500' )");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'site_admins', '" . serialize(array('admin')) . "' )");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'allowedthemes', '" . serialize(array('classic' => 1, 'default' => 1)) . "' )");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'illegal_names', '" . serialize(array("www", "web", "root", "admin", "main", "invite", "administrator")) . "' )");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'welcome_email', 'Dear User,\n\nYour new SITE_NAME blog has been successfully set up at:\nBLOG_URL\n\nYou can log in to the administrator account with the following information:\nUsername: USERNAME\nPassword: PASSWORD\nLogin Here: BLOG_URLwp-login.php\n\nWe hope you enjoy your new blog.\nThanks!\n\n--The Team @ SITE_NAME')");
$wpdb->query("INSERT INTO " . $wpdb->sitemeta . " (meta_id, site_id, meta_key, meta_value) VALUES (NULL, 1, 'first_post', 'Welcome to <a href=\"SITE_URL\">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' )");
$weblog_title = stripslashes($_POST['weblog_title']);
$pass = substr(md5(rand()), 5, 12);
$user_id = wpmu_create_user('admin', $pass, $email);
$current_site->domain = $domain;
$current_site->path = $base;
$current_site->site_name = ucfirst($domain);
wpmu_create_blog($domain, $base, $weblog_title, $user_id, array('blog_public' => 1, 'public' => 1));
update_blog_option(1, 'template', 'home');
update_blog_option(1, 'stylesheet', 'home');
if (constant('VHOST') == 'yes') {
update_blog_option(1, 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
} else {
update_blog_option(1, 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/');
}
$msg = "Your new WordPress MU site has been created at\nhttp://{$domain}{$base}\n\nLogin details:\nUsername: admin\nPassword: {$pass}\nLogin: http://{$domain}{$base}wp-login.php\n";
wp_mail($email, "Your new WordPress MU site is ready!", $msg, "From: wordpress@" . $_SERVER['HTTP_HOST']);
?>
<h2>Installation Finished!</h2>
<p>Congratulations! <br />Your <a href='http://<?php
echo $domain . $base;
?>
'>WordPress µ site</a> has been configured.</p>
<p>You can <a class="button" href='wp-login.php'>log in</a> using the username "admin" and password <?php
echo $pass;
?>
</p>
<?php
if ($_POST['vhost'] == 'yes') {
$vhost_ok = false;
$hostname = substr(md5(time()), 0, 6) . '.' . $domain;
// Very random hostname!
if (include_once 'wp-includes/http.php') {
$page = wp_remote_get('http://' . $hostname, array('timeout' => 5, 'httpversion' => '1.1'));
if (is_object($page) && is_wp_error($page)) {
foreach ($page->get_error_messages() as $err) {
$errstr = $err;
}
} elseif ($page['response']['code'] == 200) {
$vhost_ok = true;
}
} else {
$fp = fsockopen($hostname, 80, $errno, $errstr, 5);
// Very random hostname!
if ($fp) {
$vhost_ok = true;
fclose($fp);
}
}
if (!$vhost_ok) {
echo "<h2>Warning! Wildcard DNS may not be configured correctly!</h2>";
echo "<p>To use the subdomain feature of WordPress MU you must have a wildcard entry in your dns. The installer attempted to contact a random hostname ({$hostname}) on your domain but failed. It returned this error message:<br /> <strong>{$errstr}</strong></p><p>From the README.txt:</p>";
echo "<p><blockquote> If you want to host blogs of the form http://blog.domain.tld/ where domain.tld is the domain name of your machine then you must add a wildcard record to your DNS records.<br />\nThis usually means adding a '*' hostname record pointing at your webserver in your DNS configuration tool. Matt has a more detailed <a href='http://ma.tt/2003/10/10/wildcard-dns-and-sub-domains/'>explanation</a> on his blog. If you still have problems, these <a href='http://mu.wordpress.org/forums/tags/wildcard'>forum messages</a> may help.</blockquote></p>";
echo "<p>You can still use your site but any subdomain you create may not be accessible. This check is not foolproof so ignore if you know your dns is correct.</p>";
}
}
?>
<h2>Directory Permissions</h2>
<p>Please remember to reset the permissions on the following directories:
<ul>
<?php
reset($dirs);
foreach ((array) $dirs as $dir) {
echo "<li>{$dir}</li>";
}
?>
</ul>
</p>
<p>You can probably use the following command to fix the permissions but check with your host if it doubt:
<br />
<code>chmod 755
//.........这里部分代码省略.........
示例12: ldapAddUserOptions
//.........这里部分代码省略.........
if ($result[0]) {
wp_new_user_notification($result[1]);
ldapAddUserResult(array('updated' => 'true', 'action' => 'add', 'username' => $username));
} else {
ldapAddUserResult(array('updated' => 'false', 'action' => 'notfound', 'username' => $username));
}
}
} else {
// Add User to Blog
if (wpmuLdapAddUserToBlog($login->ID, $blog_id, $user['bulk_new_role'])) {
wp_new_user_notification($login->ID);
ldapAddUserResult(array('updated' => 'true', 'action' => 'add', 'username' => $username));
} else {
ldapAddUserResult(array('updated' => 'false', 'action' => 'exists', 'username' => $username));
}
}
}
} else {
ldapAddUserResult(array('updated' => 'false', 'action' => 'auth'));
}
} elseif ($_POST['addLocalUser']) {
check_admin_referer('add-local-user');
$ldapCreateLocalUser = get_site_option('ldapCreateLocalUser');
if ($ldapCreateLocalUser || is_super_admin()) {
$user = $_POST['user'];
if (empty($user['username']) && empty($user['email'])) {
wp_die(__("<p>Missing username and email.</p>"));
} elseif (empty($user['username'])) {
wp_die(__("<p>Missing username.</p>"));
} elseif (empty($user['email'])) {
wp_die(__("<p>Missing email.</p>"));
}
$password = generate_random_password();
$user_id = wpmu_create_user(wp_specialchars(strtolower($user['username'])), $password, wp_specialchars($user['email']));
if (false == $user_id) {
wp_die(__("<p>Duplicated username or email address.</p>"));
} else {
wp_new_user_notification($user_id, $password);
}
// Update User Meta
update_usermeta($user_id, 'primary_blog', $blog_id);
// Configure User Role
add_user_to_blog($blog_id, $user_id, $user['role']);
ldapAddUserResult(array('updated' => 'true', 'action' => 'add', 'username' => $user['username']));
} else {
wp_die(__("<p>Access denied.</p>"));
}
}
?>
<div class="wrap">
<?php
// Add User
$ldapAddUser = get_site_option('ldapAddUser');
if (is_super_admin() || ($ldapAddUser == 'enabled' || empty($ldapAddUser))) {
?>
<div id="icon-users" class="icon32">
<br />
</div>
<h2><?php
_e('Add User');
?>
</h2>
<?php
$ldapCreateLocalUser = get_site_option('ldapCreateLocalUser');
if ($ldapCreateLocalUser) {
示例13: eMember_wp_create_user
function eMember_wp_create_user($user_name, $password, $email, $more = array())
{
$more['role'] = isset($more['role']) ? $more['role'] : 'subscriber';
if (eMember_is_multisite_install()) {
//MS install
global $blog_id;
if ($wp_user_id = email_exists($email)) {
// if user exists then just add him to current blog.
add_existing_user_to_blog(array('user_id' => $wp_user_id, 'role' => 'subscriber'));
return $wp_user_id;
}
$wp_user_id = wpmu_create_user($user_name, $password, $email);
if (is_wp_error($wp_user_id)) {
eMember_log_debug("Error: " . $wp_user_id->get_error_message(), true);
return $wp_user_id;
}
eMember_log_debug("Creating WP User using Multi site API. User ID: " . $wp_user_id . " Blog ID: " . $blog_id, true);
$more['ID'] = $wp_user_id;
wp_update_user($more);
update_wp_user_Role($wp_user_id, $more['role']);
$role = $more['role'];
if (add_user_to_blog($blog_id, $wp_user_id, $role)) {
//Add user to the current blog
eMember_log_debug("WP MS user successfully added to blog ID: " . $blog_id, true);
} else {
eMember_log_debug("WP MS user addition to blog failed!", false);
}
return $wp_user_id;
} else {
//Single site install
$wp_user_id = wp_create_user($user_name, $password, $email);
if (is_wp_error($wp_user_id)) {
eMember_log_debug("Error: " . $wp_user_id->get_error_message(), true);
return $wp_user_id;
}
$more['ID'] = $wp_user_id;
wp_update_user($more);
update_wp_user_Role($wp_user_id, $more['role']);
eMember_log_debug("Creating WP User using single site API. User ID: " . $wp_user_id, true);
return $wp_user_id;
}
}
示例14: wpmuLdapCreateWPUserFromLdap
/**
* Creates a WordPress user account from an LDAP response specified by
* $ldapUserData. Assumes that a user account $newUserName does not already
* exist.
*
* Code courtesy of dwang99 via post at
* <code>http://patcavit.com/2005/05/11/wordpress-ldap-and-playing-nicely/</code>
*
* @author - dwang99
*/
function wpmuLdapCreateWPUserFromLdap($opts)
{
global $base, $error, $wpdb, $current_site;
// Extract Inputs
extract($opts);
if (!isset($newUserName)) {
$newUserName = '';
}
if (!isset($newUserPassword)) {
$newUserPassword = '';
}
if (!isset($ldapUserData)) {
$ldapUserData = false;
}
if (!isset($createBlog)) {
$createBlog = true;
}
// Check to see if email is empty
if (empty($ldapUserData[LDAP_INDEX_EMAIL])) {
return new WP_Error('ldapcreate_emailempty', sprintf(__('<strong>ERROR</strong>: <strong>%s</strong> does not have an email address associated with the ldap record. All wordpress accounts must have a unique email address.'), $newUserName));
}
// Check to see if email already exists
if (email_exists($ldapUserData[LDAP_INDEX_EMAIL])) {
return new WP_Error('ldapcreate_emailconflict', sprintf(__('<strong>ERROR</strong>: <strong>%s</strong> (%s) is already associated with another account. All accounts (including the admin account) must have an unique email address.'), $ldapUserData[LDAP_INDEX_EMAIL], $newUserName));
}
// we don't actually care about the WP password (since it's LDAP), but we need one for WP database
$sPassword = generate_random_password();
$user_id = wpmu_create_user($newUserName, $sPassword, $ldapUserData[LDAP_INDEX_EMAIL]);
if ($user_id === false) {
return new WP_Error('ldapcreate_failed', __('<strong>ERROR</strong>: Account creation from LDAP failed.'));
}
//Update their first and last name from ldap
update_usermeta($user_id, 'first_name', $ldapUserData[LDAP_INDEX_GIVEN_NAME]);
update_usermeta($user_id, 'last_name', $ldapUserData[LDAP_INDEX_SURNAME]);
update_usermeta($user_id, 'ldap_login', 'true');
//Set Public Display Name
$displayName = get_site_option('ldapPublicDisplayName');
$display_name = '';
$ldapnick = $ldapUserData[LDAP_INDEX_NICKNAME];
if (!empty($ldapnick)) {
$display_name = $ldapnick;
} else {
if (!empty($displayName)) {
if ($displayName == 'username') {
$display_name = $newUserName;
}
if ($displayName == 'first') {
$display_name = $ldapUserData[LDAP_INDEX_GIVEN_NAME];
}
if ($displayName == 'firstlast') {
$display_name = $ldapUserData[LDAP_INDEX_GIVEN_NAME] . ' ' . $ldapUserData[LDAP_INDEX_SURNAME];
}
if ($displayName == 'lastfirst') {
$display_name = $ldapUserData[LDAP_INDEX_SURNAME] . ' ' . $ldapUserData[LDAP_INDEX_GIVEN_NAME];
}
} else {
$display_name = $newUserName;
}
}
if (!empty($display_name)) {
$wpdb->update($wpdb->users, compact('display_name'), array('ID' => $user_id));
}
//This is for plugin events
do_action('wpmu_activate_user', $user_id, $newUserPassword, false);
$uname = strtolower(wp_specialchars($newUserName));
# WPMU doesnot accept non-alphanumeric characters
$domain = preg_replace('/[^\\da-z]/i', '', $uname);
if (constant("VHOST") == 'yes') {
$newdomain = $domain . "." . $current_site->domain;
$path = $base;
} else {
$newdomain = $current_site->domain;
# prefix path with a /
$path = '/' . $base . $domain . '/';
}
// is it configured to create WP blogs from LDAP accounts?
$ldapCreateBlog = get_site_option("ldapCreateBlog");
if ($createBlog && $ldapCreateBlog) {
// Create and update the user's blog.
$meta = apply_filters('signup_create_blog_meta', array('lang_id' => 'en', 'public' => 0));
$blog_id = wpmu_create_blog($newdomain, $path, $newUserName . "'s blog", $user_id, $meta);
if (is_a($blog_id, "WP_Error")) {
return new WP_Error('blogcreate_failed', __('<strong>ERROR</strong>: Blog creation from LDAP failed.'));
}
do_action('wpmu_activate_blog', $blog_id, $user_id, $newUserPassword, $newUserName . "'s blog", $meta);
}
// Add user as subscriber to blog #1
wpmuUpdateBlogAccess($user_id);
return new WP_User($user_id);
}
示例15: 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
*
* @global wpdb $wpdb
*
* @param string $key The activation key provided to the user.
* @return array|WP_Error An array containing information about the activated user and/or blog
*/
function wpmu_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.' ) );
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 = maybe_unserialize($signup->meta);
$password = wp_generate_password( 12, false );
$user_id = username_exists($signup->user_login);
if ( ! $user_id )
$user_id = wpmu_create_user($signup->user_login, $password, $signup->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 );
/**
* Fires immediately after a new user is activated.
*
* @since MU
*
* @param int $user_id User ID.
* @param int $password User password.
* @param array $meta Signup meta data.
*/
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);
/**
* Fires immediately after a site is activated.
*
* @since MU
*
* @param int $blog_id Blog ID.
* @param int $user_id User ID.
* @param int $password User password.
* @param string $signup_title Site title.
* @param array $meta Signup meta data.
*/
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);
}