我制作了很多wordpress站点,所以我决定在本地主机上开始编写一个简单的自动脚本,在这里我只需填写一个表单,它就可以构建wordpress站点。
<label>MagicWord<br /><input type="text" name="magicword"></label>
<label>Email Address<br /><input type="text" name="email" ></label>
<label>Site Title<br /><input type="text" name="title"></label>
<label>Wp-Admin User<br /><input type="text" name="username" ></label>
<label>Wp-Admin Password<br /><input type="password" name="password" ></label>
<input type="submit" class="submit" value="Let Get Wordpressing!">
表格张贴到安装程序.php.
安装脚本创建数据库,创建文件夹,下载最新的wordpress zip,解压并将其放在已创建的文件夹中。
但我正在努力研究如何安装wordpress,但使用表单输入。有很多客户端,但我不知道如何去做网络。
$magicword = $_POST["magicword"];
$email = $_POST["email"];
$sitetitle = $_POST["title"];
$wpadminuser = $_POST["username"];
$wpadminpass = $_POST["password"];
define('ABSPATH', $WEBROOT);
define('WP_CONTENT_DIR', 'wp-content/');
define('WPINC', 'wp-includes');
define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
define('WP_USE_THEMES', true);
define('DB_NAME', $MYSQLDB);
define('DB_USER', $MYSQLUSER);
define('DB_PASSWORD', $MYSQLPWD);
define('DB_HOST', $MYSQLHOST);
$_GET['step'] = 2;
$_POST['weblog_title'] = $sitetitle;
$_POST['user_name'] = $wpadminuser;
$_POST['admin_email'] = $email;
$_POST['blog_public'] = true;
$_POST['admin_password'] = $wpadminpass;
require_once(ABSPATH . 'wp-admin/install.php');
require_once(ABSPATH . 'wp-load.php');
require_once(ABSPATH . WPINC . '/class-wp-walker.php');
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
这是上面代码i参考的链接:
https://www.markomedia.com.au/install-wordpress-in-less-than-a-minute/
总结一下我要做的事
使用表单条目和php脚本自动完成wordpress的设置和安装。
我已经看过WP CLI,但我不能百分之百确定如何将其集成到本地主机中,或者我是否真的可以?
非常感谢你提前
编辑
我设法制作了配置文件。
$file = "../". $magicword ."/wp-config.php";
$current = file_put_contents($file);
$current .= "<?php\n";
$current .= "// @link https://codex.wordpress.org/Editing_wp-config.php";
$current .= "// @package WordPress";
$current .= "\ndefine( 'DB_NAME', 'wordpres_". $magicword ."' );";
$current .= "\ndefine( 'DB_USER', 'wordpres' );";
$current .= "\ndefine( 'DB_PASSWORD', 'D9td2yp7' );";
$current .= "\ndefine( 'DB_HOST', 'localhost' );";
$current .= "\ndefine( 'DB_CHARSET', 'utf8mb4' );";
$current .= "\ndefine( 'DB_COLLATE', '' );\n\n\n";
$explode = explode("\n", $secretkeys);
$current .= "\n". $explode[0];
$current .= "\n". $explode[1];
$current .= "\n". $explode[2];
$current .= "\n". $explode[3];
$current .= "\n". $explode[4];
$current .= "\n". $explode[5];
$current .= "\n". $explode[6];
$current .= "\n". $explode[7];
$current .= "\n\n\n\$table_prefix = 'wordpres_';";
$current .= "\n\ndefine( 'WP_DEBUG', false );";
$current .= "\n\nif ( ! defined( 'ABSPATH' ) ) {";
$current .= "\n define( 'ABSPATH', dirname( __FILE__ ) . '/' );";
$current .= "\n}\n\nrequire_once( ABSPATH . 'wp-settings.php' );";
$current .= "?>";
file_put_contents($file, $current);
chmod("../". $magicword ."/wp-config.php", 0666);
define( 'WP_INSTALLING', true );
require_once("../". $magicword ."/wp-load.php" );
require_once("../". $magicword ."/wp-admin/includes/upgrade.php" );
require_once("../". $magicword ."/wp-includes/wp-db.php" );
wp_install( $sitetitle, $wpadminuser, $email, "1", '', $wpadminpass, "en_GB");
$directory = "http://www.designerdev.co.uk/~wordpres/". $magicword . "/";
$protocol = ! is_ssl() ? 'http' : 'https';
$get = basename( dirname( __FILE__ ) ) . '/index.php/wp-admin/install.php?action=install_wp';
$dir = str_replace( '../', '', $directory );
$link = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url = str_replace( $get, $dir, $link );
$url = trim( $url, '/' );
update_option( 'siteurl', $url );
update_option( 'home', $url );
要设置db install,在子文件夹wordpress外部的根目录中安装wordpress时会导致一个奇怪的错误