/** * 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']); }
public static function createSubDirectorySite($dir = '/mysite/', $title = 'Multisite Subdir Test') { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $blog_id = wpmu_create_blog('example.org', $dir, $title, 1); switch_to_blog($blog_id); return $blog_id; }
function createSubDirectorySite() { $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $blog_id = wpmu_create_blog('example.org', '/mysite/', 'Multisite Test', 1); $this->assertGreaterThan(1, $blog_id); switch_to_blog($blog_id); return $blog_id; }
function create_object($args) { global $wpdb; $meta = isset($args['meta']) ? $args['meta'] : array('public' => 1); $user_id = isset($args['user_id']) ? $args['user_id'] : get_current_user_id(); // temp tables will trigger db errors when we attempt to reference them as new temp tables $suppress = $wpdb->suppress_errors(); $blog = wpmu_create_blog($args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id']); $wpdb->suppress_errors($suppress); // Tell WP we're done installing. wp_installing(false); return $blog; }
function create_object($args) { /** * @var \wpdb $wpdb */ global $wpdb; $meta = isset($args['meta']) ? $args['meta'] : array(); $user_id = isset($args['user_id']) ? $args['user_id'] : get_current_user_id(); // temp tables will trigger db errors when we attempt to reference them as new temp tables $suppress = $wpdb->suppress_errors(); $blog = wpmu_create_blog($args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id']); $wpdb->suppress_errors($suppress); return $blog; }
function jb_create_blog($domain, $title) { global $wpdb; // $wpdb->db_connect(); $domain = $domain . "." . HOST; $n = wpmu_create_blog($domain, '/', $title, '1', array('public' => 1), '1'); if (!is_int($n)) { if (DEBUG) { printf("Could not create blog " . $domain . "!"); } return -1; } if (DEBUG) { printf("Created blog number: %d\n", $n); } return $n; }
/** * Generates a new blog. * * @since 1.0.0 * * @access protected * @global \wpdb $wpdb The database connection. * @param array $args The array of arguments to use during a new blog creation. * @return int|\WP_Error The newly created blog's ID on success, otherwise a WP_Error object. */ protected function _createObject($args) { global $wpdb; $meta = isset($args['meta']) ? $args['meta'] : array(); $user_id = isset($args['user_id']) ? $args['user_id'] : get_current_user_id(); // temp tables will trigger db errors when we attempt to reference them as new temp tables $suppress = $wpdb->suppress_errors(); $blog = wpmu_create_blog($args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id']); $wpdb->suppress_errors($suppress); if ($blog && !is_wp_error($blog)) { $this->_debug('Generated blog ID: ' . $blog); } elseif (is_wp_error($blog)) { $this->_debug('Blog generation failed with message [%s] %s', $blog->get_error_code(), $blog->get_error_messages()); } else { $this->_debug('Blog generation failed'); } return $blog; }
/** * Creates new MLP site for the provided language * * @param string $language * * @return int */ public function create_site($language) { if ($this->site_exists($language)) { return -1; } $active = (int) $language['active']; $lng_code = $language['language_code']; $is_multisite_on_subdomain = $this->check_is_subdomain_multisite_running(); $current_site = get_current_site(); $domain = $is_multisite_on_subdomain ? $lng_code . $current_site->domain : $current_site->domain; $path = $is_multisite_on_subdomain ? "/" : "/" . $lng_code; $user_id = get_current_user_id(); $this->set_or_update_post_obj($language, $current_site); $blog_id = wpmu_create_blog($domain, $path, "My " . $language['translated_name'] . " site", $user_id, array('public' => $active, 'lang_id' => $language['id']), $current_site->id); if (0 < $blog_id) { $this->set_after_blog_created_vars($language, $current_site, $blog_id); //$this->network_new_site_controler->update( $blog_id ); Wpml2mlp_Helper::update_flag($blog_id, $language['country_flag_url']); } return $blog_id; }
/** * Create site */ function ns_wp_create_site($site_name, $site_title, $logfile) { $user = apply_filters('ns_wp_create_site_admin', wp_get_current_user()); $site_meta = apply_filters('ns_wp_create_site_meta', array("public" => 1)); // use wp's built in wpmu_validate_blog_signup validation for all new site vars // also, use a test on a known valid name/title to filter out any validation errors added by other plugins via the wpmu_validate_blog_signup filter $baseline_validation = wpmu_validate_blog_signup('1000000', 'NS Cloner Test'); $site_data = wpmu_validate_blog_signup($site_name, $site_title, $user); $site_errors = array_diff($baseline_validation['errors']->get_error_messages(), $site_data['errors']->get_error_messages()); if (!empty($site_errors) && false) { ns_log_write(array("Error creating site with name '{$site_name}' and title '{$site_title}'. One or more problems errors detected by WP:", $site_errors), $logfile); return false; } $site_id = wpmu_create_blog($site_data["domain"], $site_data["path"], $site_title, $site_data["user"]->ID, $site_meta, get_current_site()->id); if (!is_wp_error($site_id)) { ns_log_write("New site with name '{$site_name}' and title '{$site_title}' (" . get_site_url($site_id) . ") successfully created!", $logfile); return $site_id; } else { ns_log_write("Error creating site with domain '{$site_name}' and path '{$site_title}' - " . $site_id->get_error_message(), $logfile); return false; } }
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'])); }
/** * Process a blog registration submission. * * Passes submitted values to {@link wpmu_create_blog()}. * * @return bool True on success, false on failure. */ function bp_blogs_validate_blog_signup() { global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path, $current_site; if (!check_admin_referer('bp_blog_signup_form')) { return false; } $current_user = wp_get_current_user(); if (!is_user_logged_in()) { die; } $result = bp_blogs_validate_blog_form(); extract($result); if ($errors->get_error_code()) { unset($_POST['submit']); bp_show_blog_signup_form($blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $meta = apply_filters('signup_create_blog_meta', array('lang_id' => 1, 'public' => $public)); // depreciated /** * Filters the default values for Blog meta. * * @since BuddyPress (1.0.0) * * @param array $meta { * string $value Default blog language ID. * string $public Default public status. * } */ $meta = apply_filters('add_signup_meta', $meta); // If this is a subdomain install, set up the site inside the root domain. if (is_subdomain_install()) { $domain = $blogname . '.' . preg_replace('|^www\\.|', '', $current_site->domain); } wpmu_create_blog($domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid); bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta); return true; }
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%/'); } update_blog_option(1, 'rewrite_rules', ''); $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> <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 <?php reset($dirs); foreach ((array) $dirs as $dir) { echo "{$dir} "; } ?> </code> </p> <h2>Further reading</h2> <p> <ul> <li>If you run into problems, please search the <a href='http://mu.wordpress.org/forums/'>WordPress µ Forums</a> where you will most likely find a solution. Please don't post there before searching. It's not polite.</li> <li>There is also the <a href='http://trac.mu.wordpress.org/'>WordPress µ Trac</a>. That's our bug tracker.</li> </ul> </p> <p>Thanks for installing WordPress µ!<br /><br />Donncha<br /><code>wpmu version: <?php echo $wpmu_version; ?> </code></p> <?php }
function lti_parse_request_OLD($wp) { if (!is_basic_lti_request()) { $good_message_type = $_REQUEST[LTI_MESSAGE_TYPE] == LTI_MESSAGE_TYPE_VALUE; $good_lti_version = $_REQUEST[LTI_VERSION] == LTI_VERSION_VALUE; $resource_link_id = $_REQUEST[RESOURCE_LINK_ID]; if ($good_message_type && $good_lti_version && !isset($resource_link_id)) { $launch_presentation_return_url = $_REQUEST[LAUNCH_PRESENTATION_URL]; if (isset($launch_presentation_return_url)) { header('Location: ' . $launch_presentation_return_url); exit; } } return; } // See if we get a context, do not set session, do not redirect $secret = lti_get_secret_from_consumer_key(); $context = new bltiUocWrapper(false, false, null, $secret); if (!$context->valid) { //var_dump($_POST); echo "<hr>OAuthUtil::urldecode_rfc3986('%2B') " . OAuthUtil::urldecode_rfc3986('%2B') . "<br>"; echo "<hr>OAuthUtil::urldecode_rfc3986('%5C') " . OAuthUtil::urldecode_rfc3986('%5C') . "<br>"; wp_die("BASIC LTI Authentication Failed, not valid request (make sure that consumer is authorized and secret is correct) " . $context->message); return; } $error = is_lti_error_data($context); if ($error !== FALSE) { $launch_presentation_return_url = $_REQUEST[LAUNCH_PRESENTATION_URL]; if (isset($launch_presentation_return_url)) { $error = '<p>' . $error . '</p><p>Return to site <a href="' . $launch_presentation_return_url . '">' . $launch_presentation_return_url . '</a></p>'; } wp_die($error, ''); } $blogType = new blogTypeLoader($context); if ($blogType->error < 0) { wp_die("BASIC LTI loading Types Aula Failed " . $blogType->error_miss); return; } // Set up the user... $userkey = getUserkeyLTI($context); $userkey = apply_filters('pre_user_login', $userkey); $userkey = trim($userkey); if (empty($userkey)) { wp_die('<p>Empty username</p><p>Cannot create a user without username</p>'); } $uinfo = get_user_by('login', $userkey); if (isset($uinfo) && $uinfo != false) { // og LTI: set the user_login and user_nicename to the same value, // , because we want the wordpress-login cookie to have the username // otherwise caching won't work properly! $ret_id = wp_insert_user(array('ID' => $uinfo->ID, 'user_login' => $userkey, 'user_nicename' => $userkey, 'first_name' => $context->getUserFirstName(), 'last_name' => $context->getUserLastName(), 'user_email' => $context->getUserEmail(), 'user_url' => 'http://b', 'display_name' => $context->getUserName(), 'role' => get_option('default_role'))); //error_log("og old role is set"); if (is_object($ret_id) && isset($ret_id->errors)) { $msg = ''; foreach ($ret_id->errors as $key => $error) { $msg .= "<p><b>{$key}</b> "; foreach ($error as $erroMsg) { $msg .= "<p> {$erroMsg}</p>"; } $msg .= "</p>"; } wp_die($msg); } } else { // new user!!!! $ret_id = wp_insert_user(array('user_login' => $userkey, 'user_nicename' => $context->getUserName(), 'first_name' => $context->getUserFirstName(), 'last_name' => $context->getUserLastName(), 'user_email' => $context->getUserEmail(), 'user_url' => 'http://c', 'display_name' => $context->getUserName())); if (is_object($ret_id) && isset($ret_id->errors)) { $msg = ''; foreach ($ret_id->errors as $key => $error) { $msg .= "<p><b>{$key}</b> "; foreach ($error as $erroMsg) { $msg .= "<p> {$erroMsg}</p>"; } $msg .= "</p>"; } wp_die($msg); } $uinfo = get_user_by('login', $userkey); } //Eliminem del blog Principal (si no es admin) http://jira.uoc.edu/jira/browse/BLOGA-218 if (!$is_admin) { $user = new WP_User($uinfo->ID); $user->remove_all_caps(); } $_SERVER['REMOTE_USER'] = $userkey; $password = md5($uinfo->user_pass); // User is now authorized; force WordPress to use the generated password //login, set cookies, and set current user wp_authenticate($userkey, $password); wp_set_auth_cookie($user->ID, false); wp_set_current_user($user->ID, $userkey); $siteUrl = substr(get_option("siteurl"), 7); // - "http://" $siteUrlArray = explode("/", $siteUrl); $domain = $siteUrlArray[0]; unset($siteUrlArray[0]); //error_log("og LTI domain: ". $domain); $course = $blogType->getCoursePath($context, $siteUrlArray, $domain); if (isset($context->info[RESOURCE_LINK_ID]) && $context->info[RESOURCE_LINK_ID]) { $course .= '-' . $context->info[RESOURCE_LINK_ID]; } $course = sanitize_user($course, true); //Bug wordpress doesn't get stye sheet if has a dot $course = str_replace('.', '_', $course); $path_base = "/" . implode("/", $siteUrlArray) . "/" . $course; $path_base = str_replace('//', '/', $path_base); $path = $path_base . "/"; $path = str_replace('//', '/', $path); $blog_created = false; $overwrite_plugins_theme = isset($context->info[OVERWRITE_PLUGINS_THEME]) ? $context->info[OVERWRITE_PLUGINS_THEME] == 1 : false; $overwrite_roles = isset($context->info[OVERWRITE_ROLES]) ? $context->info[OVERWRITE_ROLES] == 1 : false; $blog_id = domain_exists($domain, $path); $blog_is_new = false; if (!isset($blog_id)) { $title = __("Blog ") . $blogType->getCourseName($context); $blog_is_new = true; $meta = $blogType->getMetaBlog($context); $old_site_language = get_site_option('WPLANG'); $blogType->setLanguage($context); $blog_id = wpmu_create_blog($domain, $path, $title, $user_id, $meta); update_site_option('WPLANG', $old_site_language); $blogType->checkErrorCreatingBlog($blog_id, $path); $blog_created = true; } // Connect the user to the blog if (isset($blog_id)) { switch_to_blog($blog_id); ob_start(); if ($overwrite_plugins_theme || $blog_created) { $blogType->loadPlugins(); $blogType->changeTheme(); } //Agafem el rol anterior $old_role = null; if (!$blog_created && !$overwrite_roles) { $old_role_array = get_usermeta($user->id, 'wp_' . $blog_id . '_capabilities'); if (count($old_role_array) > 0) { foreach ($old_role_array as $key => $value) { if ($value == true) { $old_role = $key; } } } } remove_user_from_blog($uinfo->ID, $blog_id); $obj = new stdClass(); $obj->blog_id = $blog_id; $obj->userkey = $userkey; $obj->path_base = $path_base; $obj->domain = $domain; $obj->context = $context; $obj->uinfoID = $uinfo->ID; $obj->blog_is_new = $blog_is_new; if ($overwrite_roles || $old_role == null) { $obj->role = $blogType->roleMapping($context->info[FIELD_ROLE_UOC_CAMPUS], $context->info); } else { $obj->role = $old_role; } $blogType->postActions($obj); add_user_to_blog($blog_id, $uinfo->ID, $obj->role); //Si posem el restore_current_blog ens va al principi // restore_current_blog(); ob_end_clean(); } $redirecturl = get_option("siteurl"); //error_log("og LTI redirect URL: ".$redirecturl); $redirecturl = str_replace("http://", "https://", $redirecturl); //error_log("og LTI new redirect URL: ".$redirecturl); wp_redirect($redirecturl); exit; }
/** * Validate a new blog signup * * @since MU * * @return null|boolean True if blog signup was validated, false if error. * The function halts all execution if the user is not logged in. */ function validate_another_blog_signup() { global $wpdb, $blogname, $blog_title, $errors, $domain, $path; $current_user = wp_get_current_user(); if ( ! is_user_logged_in() ) { die(); } $result = validate_blog_form(); // Extracted values set/overwrite globals. $domain = $result['domain']; $path = $result['path']; $blogname = $result['blogname']; $blog_title = $result['blog_title']; $errors = $result['errors']; if ( $errors->get_error_code() ) { signup_another_blog($blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $blog_meta_defaults = array( 'lang_id' => 1, 'public' => $public ); /** * Filter the new site meta variables. * * @since MU * @deprecated 3.0.0 Use the 'add_signup_meta' filter instead. * * @param array $blog_meta_defaults An array of default blog meta variables. */ $meta_defaults = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults ); /** * Filter the new default site meta variables. * * @since 3.0.0 * * @param array $meta { * An array of default site meta variables. * * @type int $lang_id The language ID. * @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false. * } */ $meta = apply_filters( 'add_signup_meta', $meta_defaults ); wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, $wpdb->siteid ); confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta); return true; }
public static function create_new_multisite($user_id, $config, $lead, $password) { global $current_site; $form = RGFormsModel::get_form_meta($lead['form_id']); $ms_options = rgars($config, 'meta/multisite_options'); $is_update_feed = rgars($config, 'meta/feed_type') == 'update'; $user = new WP_User($user_id); $password_field = rgars($config, 'meta/password'); $set_password = $password_field && rgar($lead, $password_field); $password = $password ? $password : rgar($lead, $password_field); // @review, verify what this is doing and notate here if (!$set_password) { remove_filter('update_welcome_email', 'bp_core_filter_blog_welcome_email'); } // is create site option enabled? if (!rgar($ms_options, 'create_site')) { return false; } $site_data = self::get_site_data($lead, $form, $config, $is_update_feed); if (!$site_data) { return false; } // create the new site! $meta = apply_filters('gform_user_registration_new_site_meta', array('public' => 1), $form, $lead, $config, $user_id, $is_update_feed); $blog_id = wpmu_create_blog($site_data['domain'], $site_data['path'], $site_data['title'], $user_id, $meta, $current_site->id); if (is_wp_error($blog_id)) { return false; } // add entry ID to site meta for new site GFUserData::update_site_meta($blog_id, 'entry_id', $lead['id']); if (!is_super_admin($user_id) && get_user_option('primary_blog', $user_id) == $current_site->blog_id) { update_user_option($user_id, 'primary_blog', $blog_id, true); } if (rgar($ms_options, 'site_role')) { $user = new WP_User($user_id, null, $blog_id); $user->set_role(rgar($ms_options, 'site_role')); } $root_role = rgar($ms_options, 'root_role'); // if no root role, remove user from current site if (!$root_role) { remove_user_from_blog($user_id); } else { if ($root_role == 'gfur_preserve_role') { } else { $user = new WP_User($user_id); $user->set_role($root_role); } } self::log_debug("Calling wpmu_welcome_notification to send multisite welcome - blog_id: {$blog_id} user_id: {$user_id}"); wpmu_welcome_notification($blog_id, $user_id, $password, $site_data['title'], array('public' => 1)); self::log_debug("Done with wpmu_welcome_notification"); do_action('gform_site_created', $blog_id, $user_id, $lead, $config, $password); // return new blog ID return $blog_id; }
$path = $base; } } else { $newdomain = $current_blog->domain; $path = $base . $domain . '/'; } $blog_id = 0; if (domain_exists($newdomain, $path, $current_blog->blog_id)) { $blog_id = domain_exists($newdomain, $path, $current_blog->blog_id); $messages['errors'][] = __('This site address already exists. Please choose another name or delete the existing site first.', 'it-l10n-backupbuddy'); } else { if (count($messages['errors']) <= 0) { flush(); // Creation can take a second. $messages['updates'][] = __('The site has been created. Click `Continue` to use this site.', 'it-l10n-backupbuddy'); $blog_id = wpmu_create_blog($newdomain, $path, 'temp title', $current_user->ID, array('public' => 1)); } } // PARSE ADVANCED OPTIONS foreach ($_POST['advanced_options'] as $advanced_option_name => $advanced_option_value) { $this->advanced_options[$advanced_option_name] = $advanced_option_value; } //Output alerts foreach ($messages['updates'] as $update) { pb_backupbuddy::alert($update); } foreach ($messages['errors'] as $error) { pb_backupbuddy::alert($error, true); } if (count($messages['errors']) > 0) { $errors = true;
function create_object($args) { $meta = isset($args['meta']) ? $args['meta'] : array(); $user_id = isset($args['user_id']) ? $args['user_id'] : get_current_user_id(); return wpmu_create_blog($args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id']); }
/** * 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 { WP_CLI::error($id->get_error_message()); } if (\WP_CLI\Utils\get_flag_value($assoc_args, 'porcelain')) { WP_CLI::line($id); } else { WP_CLI::success("Site {$id} created: {$url}"); } }
$password = wp_generate_password(12, false); $user_id = wpmu_create_user($domain, $password, $email); if (false === $user_id) { wp_die(__('There was an error creating the user.')); } /** * Fires after a new user has been created via the network site-new.php page. * * @since 4.4.0 * * @param int $user_id ID of the newly created user. */ do_action('network_site_new_created_user', $user_id); } $wpdb->hide_errors(); $id = wpmu_create_blog($newdomain, $path, $title, $user_id, $meta, $current_site->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); } $content_mail = sprintf(__('New site created by %1$s Address: %2$s Name: %3$s'), $current_user->user_login, get_site_url($id), wp_unslash($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') . '>'); wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); wp_redirect(add_query_arg(array('update' => 'added', 'id' => $id), 'site-new.php')); exit; } else { wp_die($id->get_error_message());
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 = '*****@*****.**'; $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() }
/** * Add a new network * * @since 1.3 * * @param string $domain Domain name for new network - for VHOST=no, this * should be FQDN, otherwise domain only * @param string $path Path to root of network hierarchy - should be '/' unless * WP is cohabiting with another product on a domain * @param string $site_name Name of the root blog to be created on the new * network * @param integer $clone_network ID of network whose networkmeta values are * to be copied - default NULL * @param array $options_to_clone Override default network meta options to copy * when cloning - default NULL * @return integer ID of newly created network */ function add_network($domain, $path, $site_name = false, $clone_network = false, $options_to_clone = false) { global $wpdb, $sites; // Set a default site name if one isn't set if (false == $site_name) { $site_name = __('New Network Root', 'wp-multi-network'); } // If no options, fallback on defaults if (empty($options_to_clone)) { $options_to_clone = array_keys(network_options_to_copy()); } // Check for existing network $sql = "SELECT * FROM {$wpdb->site} WHERE domain = %s AND path = %s LIMIT 1"; $query = $wpdb->prepare($sql, $domain, $path); $network = $wpdb->get_row($query); if (!empty($network)) { return new WP_Error('network_exists', __('Network already exists.', 'wp-multi-network')); } // Insert new network $wpdb->insert($wpdb->site, array('domain' => $domain, 'path' => $path)); $new_network_id = $wpdb->insert_id; // Update global network list $sites = $wpdb->get_results("SELECT * FROM {$wpdb->site}"); // If network was created, create a blog for it too if (!empty($new_network_id)) { if (!defined('WP_INSTALLING')) { define('WP_INSTALLING', true); } // there's an ongoing error with wpmu_create_blog that throws a warning if meta is not defined: // http://core.trac.wordpress.org/ticket/20793 // temporary fix -- set from current blog's value // Looks like a fix is in for 3.7 $new_blog_id = wpmu_create_blog($domain, $path, $site_name, get_current_user_id(), array('public' => get_option('blog_public', false)), (int) $new_network_id); // Bail if blog could not be created if (is_a($new_blog_id, 'WP_Error')) { return $new_blog_id; } /** * Fix upload_path for main sites on secondary networks * This applies only to new installs (WP 3.5+) */ // Switch to main network (if it exists) if (defined('SITE_ID_CURRENT_SITE') && network_exists(SITE_ID_CURRENT_SITE)) { switch_to_network(SITE_ID_CURRENT_SITE); $use_files_rewriting = get_site_option('ms_files_rewriting'); restore_current_network(); } else { $use_files_rewriting = get_site_option('ms_files_rewriting'); } global $wp_version; // Create the upload_path and upload_url_path values if (!$use_files_rewriting && version_compare($wp_version, '3.7', '<')) { // WP_CONTENT_URL is locked to the current site and can't be overridden, // so we have to replace the hostname the hard way $current_siteurl = get_option('siteurl'); $new_siteurl = untrailingslashit(get_blogaddress_by_id($new_blog_id)); $upload_url = str_replace($current_siteurl, $new_siteurl, WP_CONTENT_URL); $upload_url = $upload_url . '/uploads'; $upload_dir = WP_CONTENT_DIR; if (0 === strpos($upload_dir, ABSPATH)) { $upload_dir = substr($upload_dir, strlen(ABSPATH)); } $upload_dir .= '/uploads'; if (defined('MULTISITE')) { $ms_dir = '/sites/' . $new_blog_id; } else { $ms_dir = '/' . $new_blog_id; } $upload_dir .= $ms_dir; $upload_url .= $ms_dir; update_blog_option($new_blog_id, 'upload_path', $upload_dir); update_blog_option($new_blog_id, 'upload_url_path', $upload_url); } } // Clone the network meta from an existing network if (!empty($clone_network) && network_exists($clone_network)) { $options_cache = array(); $clone_network = (int) $clone_network; switch_to_network($clone_network); foreach ($options_to_clone as $option) { $options_cache[$option] = get_site_option($option); } restore_current_network(); switch_to_network($new_network_id); foreach ($options_to_clone as $option) { if (isset($options_cache[$option])) { // Fix for strange bug that prevents writing the ms_files_rewriting value for new networks if ($option === 'ms_files_rewriting') { $wpdb->insert($wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $options_cache[$option])); } else { add_site_option($option, $options_cache[$option]); } } } unset($options_cache); restore_current_network(); } do_action('add_network', $new_network_id); return $new_network_id; }
function createNetworkBlog(Am_Record $record, User $user) { $current_site = get_current_site(); $blog = array('domain' => $user->login, 'email' => $user->email, 'title' => sprintf("%s %s's Blog", $user->name_f, $user->name_l)); $domain = strtolower($blog['domain']); // If not a subdomain install, make sure the domain isn't a reserved word if (!is_subdomain_install()) { $subdirectory_reserved_names = array('page', 'comments', 'blog', 'files', 'feed'); if (in_array($domain, $subdirectory_reserved_names)) { throw new Am_Exception_InputError(sprintf(___('The following words are reserved : <code>%s</code>'), implode('</code>, <code>', $subdirectory_reserved_names))); } } if (is_subdomain_install()) { $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain); $path = $current_site->path; } else { $newdomain = $current_site->domain; $path = $current_site->path . $domain . '/'; } $user_id = $record->pk(); $id = wpmu_create_blog($newdomain, $path, $blog['title'], $user_id, array('public' => 1), $current_site->id); 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); } wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); } else { throw new Am_Exception_InputError($id->get_error_message()); } }
function validate_another_blog_signup() { global $wpdb, $blogname, $blog_title, $errors, $domain, $path; $current_user = wp_get_current_user(); if (!is_user_logged_in()) { die; } $result = validate_blog_form(); extract($result); if ($errors->get_error_code()) { signup_another_blog($blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $meta = apply_filters('signup_create_blog_meta', array('lang_id' => 1, 'public' => $public)); // deprecated $meta = apply_filters('add_signup_meta', $meta); wpmu_create_blog($domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid); confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta); return true; }
public function test_syncs_users_added_to_multisite() { global $wpdb; if (!is_multisite()) { $this->markTestSkipped('Run it in multi site mode'); } $original_blog_id = get_current_blog_id(); // create a different blog $suppress = $wpdb->suppress_errors(); $other_blog_id = wpmu_create_blog('foo.com', '', "My Blog", $this->user_id); $wpdb->suppress_errors($suppress); // create a user from within that blog (won't be synced) switch_to_blog($other_blog_id); $mu_blog_user_id = $this->factory->user->create(); restore_current_blog(); $this->sender->do_sync(); $this->assertNull($this->server_replica_storage->get_user($mu_blog_user_id)); add_user_to_blog($original_blog_id, $mu_blog_user_id, 'administrator'); $this->sender->do_sync(); $this->assertNotNull($this->server_replica_storage->get_user($mu_blog_user_id)); }
/** * Copy the blog * * @param string $domain url of the new blog * @param string $title title of the new blog * @param int $from_blog_id ID of the blog being copied from. * @param bool $copy_files true if files should be copied * @return string status message */ private function copy_blog($domain, $title, $from_blog_id = 0, $copy_files = true) { global $wpdb, $current_site, $base; $email = get_blog_option($from_blog_id, 'admin_email'); $user_id = email_exists(sanitize_email($email)); if (!$user_id) { // Use current user instead $user_id = get_current_user_id(); } // The user id of the user that will become the blog admin of the new blog. $user_id = apply_filters('copy_blog_user_id', $user_id, $from_blog_id); if (is_subdomain_install()) { $newdomain = $domain . "." . $current_site->domain; $path = $base; } else { $newdomain = $current_site->domain; $path = trailingslashit($base . $domain); } // The new domain that will be created for the destination blog. $newdomain = apply_filters('copy_blog_domain', $newdomain, $domain); // The new path that will be created for the destination blog. $path = apply_filters('copy_blog_path', $path, $domain); $wpdb->hide_errors(); $to_blog_id = wpmu_create_blog($newdomain, $path, $title, $user_id, array("public" => 1), $current_site->id); $wpdb->show_errors(); if (!is_wp_error($to_blog_id)) { $dashboard_blog = get_dashboard_blog(); if (!is_super_admin() && get_user_option('primary_blog', $user_id) == $dashboard_blog->blog_id) { update_user_option($user_id, 'primary_blog', $to_blog_id, true); } // now copy if ($from_blog_id) { $this->copy_blog_data($from_blog_id, $to_blog_id); if ($copy_files) { $this->copy_blog_files($from_blog_id, $to_blog_id); $this->replace_content_urls($from_blog_id, $to_blog_id); } $msg = sprintf(__('Copied: %s in %s seconds', $this->_domain), '<a href="http://' . $newdomain . '" target="_blank">' . $title . '</a>', number_format_i18n(timer_stop())); do_action('log', __('Copy Complete!', $this->_domain), $this->_domain, $msg); } } else { $msg = $to_blog_id->get_error_message(); } return $msg; }
$password = wp_generate_password(12, false); $user_id = wpmu_create_user($domain, $password, $email); if (false === $user_id) { wp_die(__('There was an error creating the user.')); } /** * Fires after a new user has been created via the network site-new.php page. * * @since 4.4.0 * * @param int $user_id ID of the newly created user. */ do_action('network_site_new_created_user', $user_id); } $wpdb->hide_errors(); $id = wpmu_create_blog($newdomain, $path, $title, $user_id, $meta, get_current_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); } wp_mail(get_site_option('admin_email'), sprintf(__('[%s] New Site Created'), get_network()->site_name), sprintf(__('New site created by %1$s Address: %2$s Name: %3$s'), $current_user->user_login, get_site_url($id), wp_unslash($title)), sprintf('From: "%1$s" <%2$s>', _x('Site Admin', 'email "From" field'), get_site_option('admin_email'))); wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); wp_redirect(add_query_arg(array('update' => 'added', 'id' => $id), 'site-new.php')); exit; } else { wp_die($id->get_error_message()); }
$path = $base . $domain . '/'; } $password = '******'; $user_id = email_exists($email); if (!$user_id) { // Create a new user with a random password $password = wp_generate_password(); $user_id = wpmu_create_user($domain, $password, $email); if (false == $user_id) { wp_die(__('There was an error creating the user.')); } else { wp_new_user_notification($user_id, $password); } } $wpdb->hide_errors(); $id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id); $wpdb->show_errors(); if (!is_wp_error($id)) { $dashboard_blog = get_dashboard_blog(); if (get_user_option('primary_blog', $user_id) == $dashboard_blog->blog_id) { update_user_option($user_id, 'primary_blog', $id, true); } $content_mail = sprintf(__("New site created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login, $newdomain . $path, 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') . '>'); wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); wp_redirect(add_query_arg(array('updated' => 'true', 'action' => 'add-blog'), wp_get_referer())); exit; } else { wp_die($id->get_error_message()); } break;
/** * @ticket 33620 * @dataProvider data_new_blog_url_schemes */ function test_new_blog_url_schemes($home_scheme, $siteurl_scheme, $force_ssl_admin) { $current_site = get_current_site(); $home = get_option('home'); $siteurl = get_site_option('siteurl'); $admin = force_ssl_admin(); // Setup: update_option('home', set_url_scheme($home, $home_scheme)); update_site_option('siteurl', set_url_scheme($siteurl, $siteurl_scheme)); force_ssl_admin($force_ssl_admin); // Install: $new = wpmu_create_blog($current_site->domain, '/new-blog/', 'New Blog', get_current_user_id()); // Reset: update_option('home', $home); update_site_option('siteurl', $siteurl); force_ssl_admin($admin); // Assert: $this->assertNotWPError($new); $this->assertSame($home_scheme, parse_url(get_blog_option($new, 'home'), PHP_URL_SCHEME)); $this->assertSame($siteurl_scheme, parse_url(get_blog_option($new, 'siteurl'), PHP_URL_SCHEME)); }
/** * 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); }
function create_microweb() { global $_POST, $current_site, $current_user; if (!is_array($_POST['blog'])) { wp_die(__('Can’t create an empty site.')); } $blog = $_POST['blog']; $email = sanitize_email($blog['email']); $title = $blog['title']; $domain = $blog['domain']; if (empty($domain)) { print_r(__('Missing or invalid site address.')); } if (empty($email)) { print_r(__('Missing email address.')); } if (!is_email($email)) { print_r(__('Invalid email address.')); } if (is_subdomain_install()) { $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain); $path = $current_site->path; } else { $newdomain = $current_site->domain; $path = $current_site->path . $domain . '/'; } $password = '******'; $user_id = email_exists($email); if ($user_id) { $password = wp_generate_password(12, false); $user_id = wp_update_user(array("ID" => $user_id, "user_pass" => $password)); if (false == $user_id) { print_r(__('There was an error updating the user.')); } else { wp_new_user_notification($user_id, $password); } } $id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id); if (!is_wp_error($id)) { update_user_meta($user_id, "agent-web", $path); if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) { update_user_option($user_id, 'primary_blog', $id, true); } $content_mail = sprintf(__('New site created by %1$s Address: %2$s Name: %3$s'), $current_user->user_login, 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') . '>'); wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); // wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) ); // exit; } else { wp_die($id->get_error_message()); } }