/** * Create a new WordPress website from scratch * * @Given /^\w+ have a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { global $wp_rewrite; $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $hash = $table->getHash(); $row = $hash[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); \PHPUnit_Framework_Assert::assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); //This is a bit of a hack, we don't care about the notification e-mails here so clear the inbox //we run the risk of deleting stuff we want! $this->inboxFactory->getInbox($email)->clearInbox(); $wp_rewrite->init(); $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); }
/** * Run wp_install. Assumes that wp-config.php is already in place. */ public function install($args, $assoc_args) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if (is_blog_installed()) { WP_CLI::error('WordPress is already installed.'); } extract(wp_parse_args($assoc_args, array('site_url' => defined('WP_SITEURL') ? WP_SITEURL : '', 'site_title' => '', 'admin_name' => 'admin', 'admin_email' => '', 'admin_password' => '')), EXTR_SKIP); $missing = false; foreach (array('site_url', 'site_title', 'admin_email', 'admin_password') as $required_arg) { if (empty(${$required_arg})) { WP_CLI::warning("missing --{$required_arg} parameter"); $missing = true; } } if ($site_url) { WP_CLI::set_url_params($site_url); } if ($missing) { exit(1); } $public = true; $result = wp_install($site_title, $admin_name, $admin_email, $public, '', $admin_password); if (is_wp_error($result)) { WP_CLI::error('Installation failed (' . WP_CLI::errorToString($result) . ').'); } else { WP_CLI::success('WordPress installed successfully.'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $env = Validators::validateEnv($input->getOption('env')); $_SERVER['DOCUMENT_ROOT'] = getcwd(); $_SERVER['SERVER_PROTOCOL'] = 'http'; $_SERVER['HTTP_HOST'] = $this->skeleton->get('deploy.%s.web.host', $env); define('WP_ROOT', $this->skeleton->getWebRoot() . '/'); define('WP_INSTALLING', true); require WP_ROOT . 'wp-load.php'; require WP_ROOT . 'wp-admin/includes/admin.php'; require WP_ROOT . 'wp-admin/includes/upgrade.php'; if (is_blog_installed()) { $output->writeln('<error>Already installed.</error>'); return 1; } $output->write('Installing...'); $result = wp_install($this->skeleton->get('name'), $this->skeleton->get('wordpress.%s.admin.user', $env), $this->skeleton->get('wordpress.%s.admin.email', $env), true, '', $this->skeleton->get('wordpress.%s.admin.password', $env)); if (is_wp_error($result)) { throw new \Exception($result); } update_option('db_version', $wp_db_version); update_option('db_upgraded', true); $output->writeln('<info>DONE</info>'); $output->writeln(sprintf("\nLogin as <info>%s</info> with the password <info>%s</info>", $this->skeleton->get('wordpress.%s.admin.user', $env), $this->skeleton->get('wordpress.%s.admin.password', $env))); }
public static function installDatabase(array $data, $directory, ConsoleLogger $logger) { // need for wordpress database functionality global $wpdb; if (!isset($data['blog_title'])) { $logger->log(LogLevel::NOTICE, 'Skipping step due to missing blog configuration'); return true; } define('WP_INSTALLING', true); require_once self::path($directory, 'wp-config.php'); // require_once self::path($directory, 'includes', 'wp-db.php'; require_once self::path($directory, 'wp-admin', 'upgrade-functions.php'); if (!function_exists('wp_install')) { $logger->log(LogLevel::WARNING, 'Could not find function "wp_install" in file "' . self::path($directory, 'wp-admin', 'includes', 'upgrade.php"')); } if (isset($data['password'])) { $logger->log(LogLevel::INFO, 'Using password: '******'password']); $result = wp_install($data['blog_title'], $data['admin'], $data['admin_email'], true, '', $data['password']); } else { $result = wp_install($data['blog_title'], $data['admin'], $data['admin_email'], true); } if ($result) { $logger->log(LogLevel::INFO, 'Wordpress successfully installed. Password is ' . $result['password']); } else { $logger->log(LogLevel::WARNING, 'Unexpected error occured during this step'); } return $result; }
/** * admin_init action hook operations * Checks for wordpress_reset post value and if there deletes all wp tables * and performs an install, populating the users previous password also */ public function admin_init() { global $current_user; $wordpress_reset = isset($_POST['wordpress_reset']) && $_POST['wordpress_reset'] == 'true' ? true : false; $wordpress_reset_confirm = isset($_POST['wordpress_reset_confirm']) && $_POST['wordpress_reset_confirm'] == 'reset' ? true : false; $valid_nonce = isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'wordpress_reset') ? true : false; if ($wordpress_reset && $wordpress_reset_confirm && $valid_nonce) { require_once ABSPATH . '/wp-admin/includes/upgrade.php'; $blogname = get_option('blogname'); $admin_email = get_option('admin_email'); $blog_public = get_option('blog_public'); if ($current_user->user_login != 'admin') { $user = get_user_by('login', 'admin'); } if (empty($user->user_level) || $user->user_level < 10) { $user = $current_user; } global $wpdb, $reactivate_wp_reset_additional; $prefix = str_replace('_', '\\_', $wpdb->prefix); $tables = $wpdb->get_col("SHOW TABLES LIKE '{$prefix}%'"); foreach ($tables as $table) { $wpdb->query("DROP TABLE {$table}"); } $result = wp_install($blogname, $user->user_login, $user->user_email, $blog_public); extract($result, EXTR_SKIP); $query = $wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user_id); $wpdb->query($query); $get_user_meta = function_exists('get_user_meta') ? 'get_user_meta' : 'get_usermeta'; $update_user_meta = function_exists('update_user_meta') ? 'update_user_meta' : 'update_usermeta'; if ($get_user_meta($user_id, 'default_password_nag')) { $update_user_meta($user_id, 'default_password_nag', false); } if ($get_user_meta($user_id, $wpdb->prefix . 'default_password_nag')) { $update_user_meta($user_id, $wpdb->prefix . 'default_password_nag', false); } if (defined('REACTIVATE_WP_RESET') && REACTIVATE_WP_RESET === true) { activate_plugin(plugin_basename(__FILE__)); } if (!empty($reactivate_wp_reset_additional)) { foreach ($reactivate_wp_reset_additional as $plugin) { $plugin = plugin_basename($plugin); if (!is_wp_error(validate_plugin($plugin))) { activate_plugin($plugin); } } } wp_clear_auth_cookie(); wp_set_auth_cookie($user_id); wp_redirect(admin_url() . '?reset'); exit; } if (array_key_exists('reset', $_GET) && stristr($_SERVER['HTTP_REFERER'], 'wordpress-reset')) { add_action('admin_notices', array(&$this, 'reset_notice')); } }
/** * Handles the admin page functionality * * @access public * @uses wp_install Located in includes/upgrade.php (line 22) */ function wp_reset_init() { global $wpdb, $current_user, $pagenow; // Grab the WordPress database tables $this->_wp_tables = $wpdb->tables(); // Check for valid input - goes ahead and drops / resets tables if (isset($_POST['wp-random-value'], $_POST['wp-reset-input']) && $_POST['wp-random-value'] == $_POST['wp-reset-input'] && check_admin_referer('wp-nonce-submit', $this->_nonce)) { require_once ABSPATH . '/wp-admin/includes/upgrade.php'; // No tables were selected if (!isset($_POST['tables']) && empty($_POST['tables'])) { wp_redirect(admin_url($pagenow) . '?page=wp-reset&reset=no-select'); exit; } // Get current options $blog_title = get_option('blogname'); $public = get_option('blog_public'); $admin_user = get_user_by('login', 'admin'); $user = !$admin_user || !user_can($admin_user->ID, 'update_core') ? $current_user : $admin_user; // Get the selected tables $tables = isset($_POST['tables']) ? array_flip($_POST['tables']) : array(); // Compare the selected tables against the ones in the database $this->_tables = array_diff_key($this->_wp_tables, $tables); // Preserve the data from the tables that are unique if (0 < count($this->_tables)) { $backup_tables = $this->_backup_tables($this->_tables); } // Grab the currently active plugins if (isset($_POST['wp-reset-check']) && 'true' == $_POST['wp-reset-check']) { $active_plugins = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", 'active_plugins')); } // Run through the database columns, drop all the tables and // install wp with previous settings if ($db_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'")) { foreach ($db_tables as $db_table) { $wpdb->query("DROP TABLE {$db_table}"); } $keys = wp_install($blog_title, $user->user_login, $user->user_email, $public); $this->_wp_update_user($user, $keys); } // Delete and replace tables with the backed up table data if ($backup_tables) { foreach ($this->_tables as $table) { $wpdb->query("DELETE FROM " . $table); } $this->_backup_tables($backup_tables, 'reset'); } if (!empty($active_plugins)) { $wpdb->update($wpdb->options, array('option_value' => $active_plugins), array('option_name' => 'active_plugins')); wp_redirect(admin_url($pagenow) . '?page=wp-reset&reset=success'); exit; } wp_redirect(admin_url()); exit; } }
/** * Run wp_install. Assumes that wp-config.php is already in place. */ public function install($args, $assoc_args) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if (is_blog_installed()) { WP_CLI::error('WordPress is already installed.'); } extract(wp_parse_args($assoc_args, array('title' => '', 'admin_name' => 'admin', 'admin_email' => '', 'admin_password' => '')), EXTR_SKIP); $public = true; $result = wp_install($title, $admin_name, $admin_email, $public, '', $admin_password); if (is_wp_error($result)) { WP_CLI::error('Installation failed (' . WP_CLI::error_to_string($result) . ').'); } else { WP_CLI::success('WordPress installed successfully.'); } }
/** preforms default wordpress install, which create database tables and add default values */ function ctl_wp_install() { define('WP_INSTALLING', true); $blog_title = BLOG_TITLE; $admin_name = CTL_USER; $admin_email = ADM_EMAIL; $public = true; $deprecated = ''; $admin_password = ADM_CREDS; $language = ''; wp_install($blog_title, $admin_name, $admin_email, (int) $public, $deprecated, $CTLUserData['password'], $language); update_option('template', WP_DEFAULT_THEME); update_option('stylesheet', WP_DEFAULT_THEME); define('WP_INSTALLING', false); }
/** * Create a new WordPress website from scratch * * @Given /^\w+ have|has a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $row = $table->getHash()[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); }
/** * Create a new WordPress website from scratch * * @Given /^\w+ have|has a vanilla wordpress installation$/ */ public function installWordPress(TableNode $table = null) { global $wp_rewrite; $name = "admin"; $email = "*****@*****.**"; $password = "******"; $username = "******"; if ($table) { $hash = $table->getHash(); $row = $hash[0]; $name = $row["name"]; $username = $row["username"]; $email = $row["email"]; $password = $row["password"]; } $mysqli = new \Mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $value = $mysqli->multi_query(implode("\n", array("DROP DATABASE IF EXISTS " . DB_NAME . ";", "CREATE DATABASE " . DB_NAME . ";"))); assertTrue($value); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install($name, $username, $email, true, '', $password); $wp_rewrite->init(); $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); }
/** * reset wp learn from plugin wordpress-reset * @param $args * @param $assoc_args */ public function resetwp($args, $assoc_args) { global $current_user, $user_id; require_once ABSPATH . '/wp-admin/includes/upgrade.php'; $blogname = get_option('blogname'); $admin_email = get_option('admin_email'); $blog_public = get_option('blog_public'); if ($current_user->user_login != 'admin') { $user = get_user_by('login', 'admin'); } if (empty($user->user_level) || $user->user_level < 10) { $user = $current_user; } global $wpdb, $reactivate_wp_reset_additional; $prefix = str_replace('_', '\\_', $wpdb->prefix); $tables = $wpdb->get_col("SHOW TABLES LIKE '{$prefix}%'"); foreach ($tables as $table) { $wpdb->query("DROP TABLE {$table}"); } $result = wp_install($blogname, $user->user_login, $user->user_email, $blog_public); extract($result, EXTR_SKIP); $query = $wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user_id); $wpdb->query($query); $get_user_meta = function_exists('get_user_meta') ? 'get_user_meta' : 'get_usermeta'; $update_user_meta = function_exists('update_user_meta') ? 'update_user_meta' : 'update_usermeta'; if ($get_user_meta($user_id, 'default_password_nag')) { $update_user_meta($user_id, 'default_password_nag', false); } if ($get_user_meta($user_id, $wpdb->prefix . 'default_password_nag')) { $update_user_meta($user_id, $wpdb->prefix . 'default_password_nag', false); } if (defined('REACTIVATE_WP_RESET') && REACTIVATE_WP_RESET === true) { @activate_plugin(plugin_basename(__FILE__)); } if (!empty($reactivate_wp_reset_additional)) { foreach ($reactivate_wp_reset_additional as $plugin) { $plugin = plugin_basename($plugin); if (!is_wp_error(validate_plugin($plugin))) { @activate_plugin($plugin); } } } wp_clear_auth_cookie(); wp_set_auth_cookie($user_id); wp_redirect(admin_url() . '?reset'); //exit(); $this->result('Reset WP successful.'); }
/** * Reset the database back to pristine condition * Reset the blog name / privacy setting * Reactivate our plugin, and whatever other plugins are caught in the filter * Save the db salts (to prevent loggint he user out) * Save the users (all non-subscribers) * Remove the default password nag (it isn't the default pw, it's just a clean DB) * Log the user back in * @filter gd_quick_setup_reactivate_plugins * @global mixed $wpdb * @global mixed $current_user */ function gd_quicksetup_reset_db() { global $wpdb, $current_user; require_once ABSPATH . '/wp-admin/includes/upgrade.php'; // Uncache wp_cache_flush(); if (function_exists('wp_cache_init')) { $GLOBALS['__wp_object_cache'] = $GLOBALS['wp_object_cache']; $GLOBALS['wp_object_cache'] = new GD_QuickSetup_ObjectCache(); } // Don't send out the "your new WordPress site" e-mail add_filter('wp_mail', 'gd_quicksetup_cancel_new_site_email'); // Save the blog options $blogname = get_option('blogname'); $blog_public = get_option('blog_public'); // Save the plugins $active_plugins = apply_filters('gd_quick_setup_reactivate_plugins', array()); $tmp = array(); foreach ($active_plugins as $plugin) { if (is_plugin_active($plugin)) { $tmp[] = $plugin; } } $active_plugins = $tmp; // Save the salts $logged_in_salt = get_site_option('logged_in_salt'); $auth_salt = get_site_option('auth_salt'); // Save the admin user if ($current_user->user_login != 'admin') { $user = get_user_by('login', 'admin'); } if (!isset($user) || $user->user_level < 10) { $user = $current_user; } // Save additional users $users = array(); foreach (get_users() as $_user) { if ($_user->ID == $user->ID) { continue; } if (user_can($_user, 'edit_posts')) { $users[] = $_user; } } // Nuke the DB $prefix = str_replace('_', '\\_', $wpdb->prefix); $tables = $wpdb->get_col("SHOW TABLES LIKE '{$prefix}%'"); foreach ($tables as $table) { $wpdb->query("DROP TABLE {$table}"); } // Reinstall $result = wp_install($blogname, $user->user_login, $user->user_email, $blog_public); extract($result, EXTR_SKIP); // Re-insert the admin user $query = $wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $user->user_pass, $user->ID); $wpdb->query($query); // Reset the salts update_site_option('logged_in_salt', $logged_in_salt); update_site_option('auth_salt', $auth_salt); // Disable the "you're using the default password" message if (get_user_meta($user->ID, 'default_password_nag')) { update_user_meta($user->ID, 'default_password_nag', false); } if (get_user_meta($user->ID, $wpdb->prefix . 'default_password_nag')) { update_user_meta($user->ID, $wpdb->prefix . 'default_password_nag', false); } // Re-insert the other users && disable the "you're using the default password" message foreach ($users as $_user) { $_user_id = wp_insert_user(array('user_login' => $_user->user_login, 'user_pass' => $_user->user_pass, 'user_email' => $_user->user_email)); if (is_wp_error($_user_id)) { continue; } $query = $wpdb->prepare("UPDATE {$wpdb->users} SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $_user->user_pass, $_user_id); $wpdb->query($query); update_user_meta($_user_id, $wpdb->prefix . 'capabilities', $_user->caps); update_user_meta($_user_id, $wpdb->prefix . 'user_level', gd_quicksetup_translate_role_level($_user)); if (get_user_meta($_user_id, 'default_password_nag')) { update_user_meta($_user_id, 'default_password_nag', false); } if (get_user_meta($_user_id, $wpdb->prefix . 'default_password_nag')) { update_user_meta($_user_id, $wpdb->prefix . 'default_password_nag', false); } } // Reset the salts update_site_option('logged_in_salt', $logged_in_salt); update_site_option('auth_salt', $auth_salt); // Remove sample content wp_delete_comment(1, true); wp_delete_post(1, true); wp_delete_post(2, true); // Log the user back in // wp_clear_auth_cookie(); wp_set_current_user($user->ID); // wp_set_auth_cookie( $user_id ); // Reactivate the plugins foreach ($active_plugins as $plugin) { activate_plugin($plugin); $tmp = explode('/', $plugin); do_action('gd_quicksetup_installed_plugin-' . $tmp[0]); } }
private function _install($assoc_args) { if (is_blog_installed()) { return false; } if (true === \WP_CLI\Utils\get_flag_value($assoc_args, 'skip-email') && !function_exists('wp_new_blog_notification')) { function wp_new_blog_notification() { // Silence is golden } } require_once ABSPATH . 'wp-admin/includes/upgrade.php'; extract(wp_parse_args($assoc_args, array('title' => '', 'admin_user' => '', 'admin_email' => '', 'admin_password' => '')), EXTR_SKIP); // Support prompting for the `--url=<url>`, // which is normally a runtime argument if (isset($assoc_args['url'])) { WP_CLI::set_url($assoc_args['url']); } $public = true; // @codingStandardsIgnoreStart if (!is_email($admin_email)) { WP_CLI::error("The '{$admin_email}' email address is invalid."); } $result = wp_install($title, $admin_user, $admin_email, $public, '', $admin_password); if (is_wp_error($result)) { WP_CLI::error('Installation failed (' . WP_CLI::error_to_string($result) . ').'); } // @codingStandardsIgnoreEnd if (!empty($GLOBALS['wpdb']->last_error)) { WP_CLI::error('Installation produced database errors, and may have partially or completely failed.'); } // Confirm the uploads directory exists $upload_dir = wp_upload_dir(); if (!empty($upload_dir['error'])) { WP_CLI::warning($upload_dir['error']); } return true; }
require_once ABSPATH . '/wp-admin/includes/upgrade.php'; require_once ABSPATH . '/wp-includes/wp-db.php'; define('WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version'); $wpdb->suppress_errors(); $wpdb->hide_errors(); $installed = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl'"); if ($installed && file_exists(WP_TESTS_VERSION_FILE)) { $installed_version_hash = file_get_contents(WP_TESTS_VERSION_FILE); if ($installed_version_hash == test_version_check_hash()) { return; } } $wpdb->query('SET storage_engine = INNODB;'); $wpdb->query('DROP DATABASE IF EXISTS ' . DB_NAME . ";"); $wpdb->query('CREATE DATABASE ' . DB_NAME . ";"); $wpdb->select(DB_NAME, $wpdb->dbh); echo "Installing Awesome Support…" . PHP_EOL; wp_install(WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, '', 'a'); if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE) { echo "Installing network…" . PHP_EOL; define('WP_INSTALLING_NETWORK', true); //wp_set_wpdb_vars(); // We need to create references to ms global tables to enable Network. foreach ($wpdb->tables('ms_global') as $table => $prefixed_table) { $wpdb->{$table} = $prefixed_table; } install_network(); $result = populate_network(1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, WP_TESTS_NETWORK_TITLE, '/', WP_TESTS_SUBDOMAIN_INSTALL); system(WP_PHP_BINARY . ' ' . escapeshellarg(dirname(__FILE__) . '/ms-install.php') . ' ' . escapeshellarg($config_file_path)); } file_put_contents(WP_TESTS_VERSION_FILE, test_version_check_hash());
function _install() { define('WP_INSTALLING', true); $this->load_wp_core(); $result = wp_install($this->data["config"]["site_title"], $this->data["config"]["username"], $this->data["config"]["email"], (int) $this->data["config"]["blog_public"], "", $this->data["config"]["password"]); if (!$result['password']) { $this->error[] = $result['password_message']; return; } }
/** * Handles the admin page functionality * * @access public * @uses wp_install Located in includes/upgrade.php (line 22) */ function wp_reset_init() { global $wpdb, $current_user, $pagenow; // Grab the WordPress database tables $this->_wp_tables = $wpdb->tables(); // Check for valid input - goes ahead and drops / resets tables if ( isset( $_POST['wp-random-value'], $_POST['wp-reset-input'] ) && $_POST['wp-random-value'] == $_POST['wp-reset-input'] && check_admin_referer( 'wp-nonce-submit', $this->_nonce ) ) { require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); // No tables were selected if ( empty( $_POST['tables'] ) ) { wp_redirect( admin_url( $pagenow ) . '?page=wp-reset&reset=no-select' ); exit(); } // Get current options $blog_title = get_option( 'blogname' ); $public = get_option( 'blog_public' ); $admin_user = get_user_by( 'login', 'admin' ); $user = ( ! $admin_user || ! user_can( $admin_user->ID, 'update_core' ) ) ? $current_user : $admin_user; // Get the selected tables $tables = ( isset( $_POST['tables'] ) ) ? array_flip( $_POST['tables'] ) : array(); // Compare the selected tables against the ones in the database $this->_tables = array_diff_key( $this->_wp_tables, $tables ); // Preserve the data from the tables that are unique if ( 0 < count( $this->_tables ) ) { $backup_tables = $this->_back_up_tables( $this->_tables ); } // Grab the currently active plugins and theme if ( ! empty($_POST['wp-reset-check']) ) { $current_data = array( 'active-plugins' => get_option( 'active_plugins' ), 'current-theme' => get_option( 'current_theme' ), 'template' => get_option( 'template' ), 'stylesheet' => get_option( 'stylesheet' ) ); } // Run through the database columns, drop all the tables and // install wp with previous settings if ( ! empty( $this->_wp_tables ) ) { foreach ( $this->_wp_tables as $wp_table ) { $wpdb->query( "DROP TABLE {$wp_table}" ); } $keys = wp_install( $blog_title, $user->user_login, $user->user_email, $public ); $this->_wp_update_user( $user, $keys ); } // Delete and replace tables with the backed up table data if ( ! empty( $backup_tables ) ) { foreach ( $this->_tables as $table ) { $wpdb->query( "DELETE FROM " . $table ); } $this->_restore_tables( $backup_tables ); } if ( get_user_meta( $current_user->ID, 'session_tokens' ) ) { delete_user_meta( $current_user->ID, 'session_tokens' ); } wp_clear_auth_cookie(); wp_set_auth_cookie( $current_user->ID ); if ( ! empty( $current_data ) ) { update_option( 'active_plugins', $current_data['active-plugins'] ); if ( ! empty( $current_data['current-theme'] ) ) { update_option( 'current_theme', $current_data['current-theme'] ); } update_option( 'template', $current_data['template'] ); update_option( 'stylesheet', $current_data['stylesheet'] ); wp_redirect( admin_url( $pagenow ) . '?page=wp-reset&reset=success' ); exit(); } wp_redirect( admin_url() ); exit(); } }
/** * Instale et configure WordPress sur le serveur local dans le dossier courant * * @param mixed[] $opts informations d'inscription du compte admin Wordpress * * @return bool true|false */ public function wp_install_wp($opts) { define('WP_INSTALLING', true); require_once 'wp-load.php'; require_once 'wp-admin/includes/upgrade.php'; require_once 'wp-includes/wp-db.php'; // WordPress installation wp_install($opts['weblog_title'], $opts['user_login'], $opts['admin_email'], (int) $opts['blog_public'], '', $opts['admin_password']); // We update the options with the right siteurl et homeurl value $newurl = 'http://' . $_SERVER['SERVER_NAME'] . rtrim(dirname($_SERVER['REQUEST_URI']), '/'); update_option('siteurl', $newurl); update_option('home', $newurl); update_option('permalink_structure', '/%postname%/'); return TRUE; }
display_setup_form(__('Your passwords do not match. Please try again.')); $error = true; } else { if (empty($admin_email)) { // TODO: poka-yoke display_setup_form(__('You must provide an email address.')); $error = true; } elseif (!is_email($admin_email)) { // TODO: poka-yoke display_setup_form(__('Sorry, that isn’t a valid email address. Email addresses look like <code>username@example.com</code>.')); $error = true; } } if ($error === false) { $wpdb->show_errors(); $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', wp_slash($admin_password), $loaded_language); ?> <h1><?php _e('Success!'); ?> </h1> <p><?php _e('WordPress has been installed. Were you expecting more steps? Sorry to disappoint.'); ?> </p> <table class="form-table install-success"> <tr> <th><?php
private function _install($assoc_args) { if (is_blog_installed()) { return false; } require_once ABSPATH . 'wp-admin/includes/upgrade.php'; extract(wp_parse_args($assoc_args, array('title' => '', 'admin_user' => '', 'admin_email' => '', 'admin_password' => '')), EXTR_SKIP); // Support prompting for the `--url=<url>`, // which is normally a runtime argument if (isset($assoc_args['url'])) { $url_parts = WP_CLI::set_url($assoc_args['url']); } $public = true; // @codingStandardsIgnoreStart if (!is_email($admin_email)) { WP_CLI::error("The '{$admin_email}' email address is invalid."); } $result = wp_install($title, $admin_user, $admin_email, $public, '', $admin_password); if (is_wp_error($result)) { WP_CLI::error('Installation failed (' . WP_CLI::error_to_string($result) . ').'); } // @codingStandardsIgnoreEnd // Confirm the uploads directory exists $upload_dir = wp_upload_dir(); if (!empty($upload_dir['error'])) { WP_CLI::warning($upload_dir['error']); } return true; }
foreach ( $wpdb->tables() as $table => $prefixed_table ) { $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); } foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) { $wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" ); // We need to create references to ms global tables. if ( $multisite ) $wpdb->$table = $prefixed_table; } // Prefill a permalink structure so that WP doesn't try to determine one itself. add_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' ); // Delete dummy permalink structure, as prefilled above. if ( ! is_multisite() ) { delete_option( 'permalink_structure' ); } remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); if ( $multisite ) { echo "Installing network..." . PHP_EOL; define( 'WP_INSTALLING_NETWORK', true ); $title = WP_TESTS_TITLE . ' Network'; $subdomain_install = false;
public function install() { global $table_prefix; error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT); define('WP_INSTALLING', true); $this->startHeadlessRequest(); if ($this->isMultisite) { echo "Running as multisite..." . PHP_EOL; define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); define('DOMAIN_CURRENT_SITE', WP_TESTS_DOMAIN); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); $GLOBALS['base'] = '/'; } else { echo "Running as single site..." . PHP_EOL; } // Preset WordPress options defined in bootstrap file. // Used to activate themes, plugins, as well as other settings. if (isset($GLOBALS['wp_tests_options'])) { function wp_tests_options($value) { $key = substr(current_filter(), strlen('pre_option_')); return $GLOBALS['wp_tests_options'][$key]; } foreach (array_keys($GLOBALS['wp_tests_options']) as $key) { tests_add_filter('pre_option_' . $key, 'wp_tests_options'); } } // Load WordPress require_once ABSPATH . 'wp-settings.php'; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; require_once ABSPATH . 'wp-includes/wp-db.php'; define('WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version'); $wpdb->suppress_errors(); $installed = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl'"); $wpdb->suppress_errors(false); $hash = get_option('db_version') . ' ' . (int) $multisite . ' ' . sha1(json_encode($this->settings)); if (!$this->alwaysReinstall && $installed && file_exists(WP_TESTS_VERSION_FILE) && file_get_contents(WP_TESTS_VERSION_FILE) == $hash) { return; } $wpdb->query('SET storage_engine = INNODB'); $wpdb->select(DB_NAME, $wpdb->dbh); echo "Installing..." . PHP_EOL; // Drop all tables foreach ($wpdb->get_col($wpdb->prepare("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='%s'", DB_NAME)) as $table) { $wpdb->query("DROP TABLE IF EXISTS {$table}"); } wp_install(WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, $this->adminPassword); if ($multisite) { echo "Installing network..." . PHP_EOL; define('WP_INSTALLING_NETWORK', true); $title = WP_TESTS_TITLE . ' Network'; $subdomain_install = false; install_network(); populate_network(1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install); } file_put_contents(WP_TESTS_VERSION_FILE, $hash); if ($this->events['after-install'] !== null) { $this->events['after-install'](); } }
<?php define('WP_INSTALLING', true); require_once 'wp-config.php'; require_once 'wp-admin/upgrade-functions.php'; // Let's check to make sure WP isn't already installed. if (is_blog_installed()) { die("Blog already installed; no-op"); } $weblog_title = "{${entity . weblogTitle}}"; $admin_email = "{${entity . weblogAdminEmail}}"; $public = ${entity . weblogPublic}; $password = ${entity . weblogAdminPassword}; $result = wp_install($weblog_title, __('admin'), $admin_email, $public, null, $password); extract($result); ?> Automated WordPress install <?php printf(__('Result is %1$s'), $result); exit;
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['HTTP_HOST'] = 'example.org'; $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; require_once $config_file_path; require_once ABSPATH . '/wp-settings.php'; require_once ABSPATH . '/wp-admin/includes/upgrade.php'; require_once ABSPATH . '/wp-includes/wp-db.php'; define('WP_TESTS_DB_VERSION_FILE', ABSPATH . '.wp-tests-db-version'); $wpdb->suppress_errors(); $wpdb->hide_errors(); $installed = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl'"); if ($installed && file_exists(WP_TESTS_DB_VERSION_FILE)) { $install_db_version = file_get_contents(WP_TESTS_DB_VERSION_FILE); $db_version = get_option('db_version'); if ($db_version == $install_db_version) { return; } } $wpdb->query('SET storage_engine = INNODB;'); $wpdb->query('DROP DATABASE IF EXISTS ' . DB_NAME . ";"); $wpdb->query('CREATE DATABASE ' . DB_NAME . ";"); $wpdb->select(DB_NAME, $wpdb->dbh); add_filter('dbdelta_create_queries', function ($queries) { foreach ($queries as &$query) { $query .= ' ENGINE=InnoDB'; } return $queries; }); echo "Installing…\n"; wp_install("Baba's blog", 'admin', '*****@*****.**', true, '', 'a'); file_put_contents(WP_TESTS_DB_VERSION_FILE, get_option('db_version'));
public function handleInstall($postInfo) { $this->_construct(); // We add ../ to directory $directory = !empty($postInfo['directory']) ? $postInfo['directory'] . '/' : ''; // Every directory should be an extension of a user's // public_html directory $directory = Setting::where('name', 'DEFAULT_HOME_DIRECTORY')->first()->setting . Auth::user()->uid . "/public_html/" . $directory; // try { // $db = new \PDO('mysql:host=127.0.0.1;dbname=tester_db_3496', 'tester_wp_3496', '9NQJ66gGN3XVDLm'); // } // catch (Exception $e) { // $this->data['db'] = "error etablishing connection"; // } // dd(); switch ($postInfo['action']) { case "check_before_upload": $this->data = array(); /*--------------------------*/ /* We verify if we can connect to DB or WP is not installed yet /*--------------------------*/ // WordPress test if (file_exists($directory . 'wp-config.php')) { $this->data['wp'] = "error directory"; } if (substr(sprintf('%o', fileperms($directory)), -4) != '0775') { $this->data['wp'] = "error directory-permissions"; } try { MySQLDatabase::where('db_name', $postInfo['dbname'])->firstOrfail(); } catch (ModelNotFoundException $e) { // Create a database and a user MySQLController::createDatabase($postInfo['dbname']); MySQLController::createSoleUser($postInfo['uname'], $postInfo['pwd'], $postInfo['dbname']); } // We send the response echo json_encode($this->data); break; case "download_wp": // Get WordPress language $language = substr($postInfo['language'], 0, 6); // Get WordPress data $wp = json_decode(file_get_contents($this->WP_API_CORE . $language))->offers[0]; /*--------------------------*/ /* We download the latest version of WordPress /*--------------------------*/ if (!file_exists($this->WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip')) { file_put_contents($this->WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip', file_get_contents($wp->download)); } break; case "unzip_wp": // Get WordPress language $language = substr($postInfo['language'], 0, 6); // Get WordPress data $wp = json_decode(file_get_contents($this->WP_API_CORE . $language))->offers[0]; /*--------------------------*/ /* We create the website folder with the files and the WordPress folder /*--------------------------*/ $zip = new \ZipArchive(); // We verify if we can use the archive if ($zip->open($this->WPQI_CACHE_CORE_PATH . 'wordpress-' . $wp->version . '-' . $language . '.zip') === true) { // Let's unzip $zip->extractTo('.'); $zip->close(); // We scan the folder $files = scandir('wordpress'); // We remove the "." and ".." from the current folder and its parent $files = array_diff($files, array('.', '..')); $this->recursive_copy('wordpress', $directory); $this->rrmdir('wordpress'); // We remove WordPress folder unlink($directory . '/license.txt'); // We remove licence.txt unlink($directory . '/readme.html'); // We remove readme.html unlink($directory . '/wp-content/plugins/hello.php'); // We remove Hello Dolly plugin } break; case "wp_config": /*--------------------------*/ /* Let's create the wp-config file /*--------------------------*/ // We retrieve each line as an array $config_file = file($directory . 'wp-config-sample.php'); // Managing the security keys $secret_keys = explode("\n", file_get_contents('https://api.wordpress.org/secret-key/1.1/salt/')); foreach ($secret_keys as $k => $v) { $secret_keys[$k] = substr($v, 28, 64); } // We change the data $key = 0; foreach ($config_file as &$line) { if ('$table_prefix =' == substr($line, 0, 16)) { $line = '$table_prefix = \'' . $this->sanit($postInfo['prefix']) . "';\r\n"; continue; } if (!preg_match('/^define\\(\'([A-Z_]+)\',([ ]+)/', $line, $match)) { continue; } $constant = $match[1]; switch ($constant) { case 'WP_DEBUG': // Debug mod if (isset($postInfo['debug']) && (int) $postInfo['debug'] == 1) { $line = "define('WP_DEBUG', 'true');\r\n"; // Display error if (isset($postInfo['debug_display']) && (int) $postInfo['debug_display'] == 1) { $line .= "\r\n\n " . "/** Affichage des erreurs à l'écran */" . "\r\n"; $line .= "define('WP_DEBUG_DISPLAY', 'true');\r\n"; } // To write error in a log files if (isset($postInfo['debug_log']) && (int) $postInfo['debug_log'] == 1) { $line .= "\r\n\n " . "/** Ecriture des erreurs dans un fichier log */" . "\r\n"; $line .= "define('WP_DEBUG_LOG', 'true');\r\n"; } } // We add the extras constant if (isset($postInfo['uploads']) && !empty($postInfo['uploads'])) { $line .= "\r\n\n " . "/** Dossier de destination des fichiers uploadés */" . "\r\n"; $line .= "define('UPLOADS', '" . $this->sanit($postInfo['uploads']) . "');"; } if (isset($postInfo['post_revisions']) && (int) $postInfo['post_revisions'] >= 0) { $line .= "\r\n\n " . "/** Désactivation des révisions d'articles */" . "\r\n"; $line .= "define('WP_POST_REVISIONS', " . (int) $postInfo['post_revisions'] . ");"; } if (isset($postInfo['disallow_file_edit']) && (int) $postInfo['disallow_file_edit'] == 1) { $line .= "\r\n\n " . "/** Désactivation de l'éditeur de thème et d'extension */" . "\r\n"; $line .= "define('DISALLOW_FILE_EDIT', true);"; } if (isset($postInfo['autosave_interval']) && (int) $postInfo['autosave_interval'] >= 60) { $line .= "\r\n\n " . "/** Intervalle des sauvegardes automatique */" . "\r\n"; $line .= "define('AUTOSAVE_INTERVAL', " . (int) $postInfo['autosave_interval'] . ");"; } if (isset($postInfo['wpcom_api_key']) && !empty($postInfo['wpcom_api_key'])) { $line .= "\r\n\n " . "/** WordPress.com API Key */" . "\r\n"; $line .= "define('WPCOM_API_KEY', '" . $postInfo['wpcom_api_key'] . "');"; } $line .= "\r\n\n " . "/** On augmente la mémoire limite */" . "\r\n"; $line .= "define('WP_MEMORY_LIMIT', '96M');" . "\r\n"; break; case 'DB_NAME': $line = "define('DB_NAME', '" . $this->sanit($postInfo['dbname']) . "');\r\n"; break; case 'DB_USER': $line = "define('DB_USER', '" . $this->sanit($postInfo['uname']) . "');\r\n"; break; case 'DB_PASSWORD': $line = "define('DB_PASSWORD', '" . $this->sanit($postInfo['pwd']) . "');\r\n"; break; case 'DB_HOST': $line = "define('DB_HOST', '" . $this->sanit($postInfo['dbhost']) . "');\r\n"; break; case 'AUTH_KEY': case 'SECURE_AUTH_KEY': case 'LOGGED_IN_KEY': case 'NONCE_KEY': case 'AUTH_SALT': case 'SECURE_AUTH_SALT': case 'LOGGED_IN_SALT': case 'NONCE_SALT': $line = "define('" . $constant . "', '" . $secret_keys[$key++] . "');\r\n"; break; case 'WPLANG': $line = "define('WPLANG', '" . $this->sanit($postInfo['language']) . "');\r\n"; break; } } unset($line); $handle = fopen($directory . 'wp-config.php', 'w'); foreach ($config_file as $line) { fwrite($handle, $line); } fwrite($handle, "define('FS_METHOD', 'direct');\r\n"); fclose($handle); chmod($directory . 'wp-config.php', 0775); chgrp($directory . 'wp-config.php', Setting::where('name', 'REGISTRATION_GROUP')->first()->setting); break; case "install_wp": /*--------------------------*/ /* Let's install WordPress database /*--------------------------*/ define('WP_INSTALLING', true); /** Load WordPress Bootstrap */ require_once $directory . 'wp-load.php'; /** Load WordPress Administration Upgrade API */ require_once $directory . 'wp-admin/includes/upgrade.php'; /** Load wpdb */ require_once $directory . 'wp-includes/wp-db.php'; // WordPress installation wp_install($postInfo['weblog_title'], $postInfo['user_login'], $postInfo['admin_email'], (int) $postInfo['blog_public'], '', $postInfo['admin_password']); update_option('siteurl', $postInfo['url']); update_option('home', $postInfo['url']); /*--------------------------*/ /* We remove the default content /*--------------------------*/ if (isset($postInfo['default_content']) && $postInfo['default_content'] == '1') { wp_delete_post(1, true); // We remove the article "Hello World" wp_delete_post(2, true); // We remove the "Exemple page" } /*--------------------------*/ /* We update permalinks /*--------------------------*/ if (isset($postInfo['permalink_structure']) && !empty($postInfo['permalink_structure'])) { update_option('permalink_structure', $postInfo['permalink_structure']); } /*--------------------------*/ /* We update the media settings /*--------------------------*/ if (isset($postInfo['thumbnail_size_w']) && !empty($postInfo['thumbnail_size_w']) || !empty($postInfo['thumbnail_size_h'])) { update_option('thumbnail_size_w', (int) $postInfo['thumbnail_size_w']); update_option('thumbnail_size_h', (int) $postInfo['thumbnail_size_h']); update_option('thumbnail_crop', (int) $postInfo['thumbnail_crop']); } if (isset($postInfo['medium_size_w']) && !empty($postInfo['medium_size_w']) || !empty($postInfo['medium_size_h'])) { update_option('medium_size_w', (int) $postInfo['medium_size_w']); update_option('medium_size_h', (int) $postInfo['medium_size_h']); } if (isset($postInfo['large_size_w']) && !empty($postInfo['large_size_w']) || !empty($postInfo['large_size_h'])) { update_option('large_size_w', (int) $postInfo['large_size_w']); update_option('large_size_h', (int) $postInfo['large_size_h']); } update_option('uploads_use_yearmonth_folders', (int) $postInfo['uploads_use_yearmonth_folders']); /*--------------------------*/ /* We add the pages we found in the wordpress/data.ini file /*--------------------------*/ // We check if wordpress/data.ini exists if (file_exists(app_path() . '/Http/Controllers/Software/wordpress/data.ini')) { // We parse the file and get the array $file = parse_ini_file(app_path() . '/Http/Controllers/Software/wordpress/data.ini'); // We verify if we have at least one page if (count($file['posts']) >= 1) { foreach ($file['posts'] as $post) { // We get the line of the page configuration $pre_config_post = explode("-", $post); $post = array(); foreach ($pre_config_post as $config_post) { // We retrieve the page title if (preg_match('#title::#', $config_post) == 1) { $post['title'] = str_replace('title::', '', $config_post); } // We retrieve the status (publish, draft, etc...) if (preg_match('#status::#', $config_post) == 1) { $post['status'] = str_replace('status::', '', $config_post); } // On retrieve the post type (post, page or custom post types ...) if (preg_match('#type::#', $config_post) == 1) { $post['type'] = str_replace('type::', '', $config_post); } // We retrieve the content if (preg_match('#content::#', $config_post) == 1) { $post['content'] = str_replace('content::', '', $config_post); } // We retrieve the slug if (preg_match('#slug::#', $config_post) == 1) { $post['slug'] = str_replace('slug::', '', $config_post); } // We retrieve the title of the parent if (preg_match('#parent::#', $config_post) == 1) { $post['parent'] = str_replace('parent::', '', $config_post); } } // foreach if (isset($post['title']) && !empty($post['title'])) { $parent = get_page_by_title(trim($post['parent'])); $parent = $parent ? $parent->ID : 0; // Let's create the page $args = array('post_title' => trim($post['title']), 'post_name' => $post['slug'], 'post_content' => trim($post['content']), 'post_status' => $post['status'], 'post_type' => $post['type'], 'post_parent' => $parent, 'post_author' => 1, 'post_date' => date('Y-m-d H:i:s'), 'post_date_gmt' => gmdate('Y-m-d H:i:s'), 'comment_status' => 'closed', 'ping_status' => 'closed'); wp_insert_post($args); } } } } break; case "install_theme": /** Load WordPress Bootstrap */ require_once $directory . 'wp-load.php'; /** Load WordPress Administration Upgrade API */ require_once $directory . 'wp-admin/includes/upgrade.php'; /*--------------------------*/ /* We install the new theme /*--------------------------*/ // We verify if theme.zip exists if (file_exists(app_path() . '/Http/Controllers/Software/wordpress/theme.zip')) { $zip = new \ZipArchive(); // We verify we can use it if ($zip->open(app_path() . '/Http/Controllers/Software/wordpress/theme.zip') === true) { // We retrieve the name of the folder $stat = $zip->statIndex(0); $theme_name = str_replace('/', '', $stat['name']); // We unzip the archive in the themes folder $zip->extractTo($directory . 'wp-content/themes/'); $zip->close(); // Let's activate the theme // Note : The theme is automatically activated if the user asked to remove the default theme if (isset($postInfo['activate_theme']) && $postInfo['activate_theme'] == 1 || $postInfo['delete_default_themes'] == 1) { switch_theme($theme_name, $theme_name); } // Let's remove the Tweenty family if (isset($postInfo['delete_default_themes']) && $postInfo['delete_default_themes'] == 1) { delete_theme('twentyfourteen'); delete_theme('twentythirteen'); delete_theme('twentytwelve'); delete_theme('twentyeleven'); delete_theme('twentyten'); } // We delete the _MACOSX folder (bug with a Mac) delete_theme('__MACOSX'); } } break; case "install_plugins": /*--------------------------*/ /* Let's retrieve the plugin folder /*--------------------------*/ if (isset($postInfo['plugins']) && !empty($postInfo['plugins'])) { $plugins = explode(";", $postInfo['plugins']); $plugins = array_map('trim', $plugins); $plugins_dir = $directory . 'wp-content/plugins/'; foreach ($plugins as $plugin) { // We retrieve the plugin XML file to get the link to downlad it $plugin_repo = file_get_contents("http://api.wordpress.org/plugins/info/1.0/{$plugin}.json"); if ($plugin_repo && ($plugin = json_decode($plugin_repo))) { $plugin_path = $this->WPQI_CACHE_PLUGINS_PATH . $plugin->slug . '-' . $plugin->version . '.zip'; if (!file_exists($plugin_path)) { // We download the lastest version if ($download_link = file_get_contents($plugin->download_link)) { file_put_contents($plugin_path, $download_link); } } // We unzip it $zip = new \ZipArchive(); if ($zip->open($plugin_path) === true) { $zip->extractTo($plugins_dir); $zip->close(); $this->chmod_r($plugins_dir . $plugin->slug); } } } } if ($postInfo['plugins_premium'] == 1) { // We scan the folder $plugins = scandir($directory . 'wp-content/plugins'); // We remove the "." and ".." corresponding to the current and parent folder $plugins = array_diff($plugins, array('.', '..')); // We move the archives and we unzip foreach ($plugins as $plugin) { // We verify if we have to retrive somes plugins via the WP Quick Install "plugins" folder if (preg_match('#(.*).zip$#', $plugin) == 1) { $zip = new \ZipArchive(); // We verify we can use the archive if ($zip->open($directory . 'wp-content/plugins/' . $plugin) === true) { // We unzip the archive in the plugin folder $zip->extractTo($plugins_dir); $zip->close(); } } } } /*--------------------------*/ /* We activate extensions /*--------------------------*/ if ($postInfo['activate_plugins'] == 1) { /** Load WordPress Bootstrap */ require_once $directory . 'wp-load.php'; /** Load WordPress Plugin API */ require_once $directory . 'wp-admin/includes/plugin.php'; // Activation activate_plugins(array_keys(get_plugins())); } break; case "success": /*--------------------------*/ /* If we have a success we add the link to the admin and the website /*--------------------------*/ /** Load WordPress Bootstrap */ require_once $directory . 'wp-load.php'; /** Load WordPress Administration Upgrade API */ require_once $directory . 'wp-admin/includes/upgrade.php'; /*--------------------------*/ /* We update permalinks /*--------------------------*/ if (!empty($postInfo['permalink_structure'])) { file_put_contents($directory . '.htaccess', null); chgrp($directory . '.htaccess', 'member'); chmod($directory . '.htaccess', 0755); flush_rewrite_rules(); } // Link to the admin echo '<a href="' . str_replace('https', 'http', admin_url()) . '" class="button" style="margin-right:5px;" target="_blank">' . _('Log In') . '</a>'; echo '<a href="' . str_replace('https', 'http', home_url()) . '" class="button" target="_blank">' . _('Go to website') . '</a>'; echo '<a href="' . \URL::route('home') . '" class="button" target="_blank">' . _('Go Back To Netsoc') . '</a>'; break; } }
die(__("<strong>ERROR</strong>: the e-mail address isn't correct")); } } ?> <h1><?php _e('Second Step'); ?> </h1> <p><?php _e('Now we’re going to create the database tables and fill them with some default data.'); ?> </p> <?php $result = wp_install($weblog_title, 'admin', $admin_email, $public); extract($result, EXTR_SKIP); ?> <p><em><?php _e('Finished!'); ?> </em></p> <p><?php printf(__('Now you can <a href="%1$s">log in</a> with the <strong>username</strong> "<code>admin</code>" and <strong>password</strong> "<code>%2$s</code>".'), '../wp-login.php', $password); ?> </p> <p><?php _e('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you. If you lose it, you will have to delete the tables from the database yourself, and re-install WordPress. So to review:'); ?>
require_once DIR_TESTROOT . '/wp-testlib/utils.php'; // configure wp require_once DIR_TESTROOT . '/wp-config.php'; define('ABSPATH', realpath(DIR_WP) . '/'); // install wp define('WP_BLOG_TITLE', rand_str()); define('WP_USER_NAME', rand_str()); define('WP_USER_EMAIL', rand_str() . '@example.com'); // initialize wp define('WP_INSTALLING', 1); $_SERVER['PATH_INFO'] = $_SERVER['SCRIPT_NAME']; // prevent a warning from some sloppy code in wp-settings.php require_once ABSPATH . 'wp-settings.php'; drop_tables(); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; wp_install(WP_BLOG_TITLE, WP_USER_NAME, WP_USER_EMAIL, true); // make sure we're installed assert(true == is_blog_installed()); define('PHPUnit_MAIN_METHOD', false); $original_wpdb = $GLOBALS['wpdb']; // hide warnings during testing, since that's the normal WP behaviour if (!WP_DEBUG) { error_reporting(E_ALL ^ E_NOTICE); } $to = "To <*****@*****.**>"; $from = "From <*****@*****.**>"; $cc = "CC <*****@*****.**>"; $bcc = "BCC <*****@*****.**>"; $subject = "RFC2822 Testing"; $message = "My RFC822 Test Message"; $headers[] = "From: {$from}";
display_setup_form(__('your passwords do not match. Please try again')); $error = true; } else { if (empty($admin_email)) { // TODO: poka-yoke display_setup_form(__('you must provide an e-mail address.')); $error = true; } elseif (!is_email($admin_email)) { // TODO: poka-yoke display_setup_form(__('that isn’t a valid e-mail address. E-mail addresses look like: <code>username@example.com</code>')); $error = true; } } if ($error === false) { $wpdb->show_errors(); $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password); extract($result, EXTR_SKIP); ?> <h1><?php _e('Success!'); ?> </h1> <p><?php _e('WordPress has been installed. Were you expecting more steps? Sorry to disappoint.'); ?> </p> <table class="form-table"> <tr>
protected function process(array $config) { global $wpdb; // We need to create references to ms global tables to enable Network. foreach ($this->singlesiteTables() as $table => $prefixed_table) { $wpdb->{$table} = $prefixed_table; } require_once wordpress_path('wp-admin/includes/upgrade.php'); $result = wp_install($config['site_title'], $config['admin_username'], $config['admin_email'], $config['site_public'], '', wp_slash($config['admin_password']), $config['language']); // var_dump($result); update_option('siteurl', $config['backend_url']); update_option('home', $config['site_url']); update_option('blogdescription', $config['site_description']); if ($config['language'] == 'ja') { // 週の初めは '日曜日' update_option('start_of_week', '0'); // 日付フォーマットは 'Y年n月j日' update_option('date_format', 'Y年n月j日'); // 時刻フォーマットは 'H:i' update_option('time_format', 'H:i'); } }
<?php $config_file = "<?php\n\ndefine('DB_NAME', 'test');\ndefine('DB_USER', 'root');\ndefine('DB_PASSWORD', '');\ndefine('DB_HOST', 'localhost');\ndefine('DB_CHARSET', 'utf8');\ndefine('DB_COLLATE', '');\n\ndefine('AUTH_KEY', 'sdfsdfdsf');\ndefine('SECURE_AUTH_KEY', 'sdfsdfsdf');\ndefine('LOGGED_IN_KEY', '2rwdfdsfdsf');\ndefine('NONCE_KEY', '25efgdfsdsaf');\ndefine('AUTH_SALT', '25werdfsfsdf');\ndefine('SECURE_AUTH_SALT', '536regdsfa');\ndefine('LOGGED_IN_SALT', '35trdsfa2te');\ndefine('NONCE_SALT', '23rwdfwfwdfwr');\n\n\$table_prefix = 'wp_';\n\nif ( !defined('ABSPATH') )\n\tdefine('ABSPATH', dirname(__FILE__) . '/');\n\nrequire_once(ABSPATH . 'wp-settings.php');\n\n"; file_put_contents('/temp/wp/wp-config.php', $config_file); define('WP_INSTALLING', true); $_SERVER['HTTP_HOST'] = 'test'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0'; $_SERVER['HTTP_USER_AGENT'] = ''; $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_URI'] = '/wp-admin/plugins.php'; require_once '/temp/wp/wp-load.php'; require_once '/temp/wp/wp-admin/includes/upgrade.php'; wp_install('Test', 'admin', '*****@*****.**', false, '', '12345');
<?php /***** * Wordpress automated setup * install.php * * Setup a WordPress instance and enable the network. * -d Delete default WordPress posts * *****/ define('WP_INSTALLING', true); # Should we delete the automatically created wordpress posts? $options = getopt("d"); require_once 'tools/cli-load.php'; /** Load WordPress Administration Upgrade API */ require_once ABSPATH . 'wp-admin/includes/upgrade.php'; global $settings; $wp_install_result = wp_install($settings['install']['weblog_title'], $settings['install']['user_name'], $settings['install']['admin_email'], $settings['install']['public'], '', $settings['install']['admin_password']); if (is_wp_error($wp_install_result)) { var_dump($wp_install_result); die("Wordpress install failed"); } if (!empty($options['d'])) { // Delete the first post wp_delete_post(1, true); // Delete the default about page wp_delete_post(2, true); } print "Wordpress install finished\n";