handpressed/wp-multitenancy-add-site

将 WordPress 站点添加到 handpressed/wp-multitenancy-boilerplate。

dev-main 2022-01-18 19:02 UTC

This package is auto-updated.

Last update: 2024-09-19 00:42:02 UTC


README

将 WordPress 站点添加到 WP 多站点模板

功能

  • 改进的目录结构
  • 使用环境和常量文件轻松配置 WordPress
  • 使用 PHP dotenv 环境变量
  • 增强安全性(使用 roots/wp-password-bcrypt 分离网站根目录和安全的密码)
  • WordPress 多站点(一个 WordPress 核心实例、主题和插件为多个站点提供服务)

需求

  • PHP 7.4+
  • Composer

先决条件

已安装带有 WP 多站点模板 的 WordPress 实例。

安装

$ composer create-project handpressed/wp-multitenancy-add-site {directory}

$ cd {directory}

{directory} 替换为新 WordPress 项目的名称,例如其域名。

Composer 将将使用 WP 多站点模板添加到 /var/opt/wp 中的现有 WordPress 实例符号链接到 web/wp(见 目录结构)。

Composer 还会将 /var/opt/wp/wp-content/themes 符号链接到 web/app/themes/var/opt/wp/wp-content/plugins 符号链接到 web/app/plugins,并将 /var/opt/wp/wp-content/mu-plugins 符号链接到 web/app/mu-plugins

配置

打开 conf/.env 文件并添加新站点的首页 URL(WP_HOME)和数据库凭据(DB_NAMEDB_USERDB_PASSWORD)。如果需要,您还可以定义数据库 $table_prefix(默认为 wp_)。

将网站的 vhost 根目录设置为 /path/to/{directory}/web

主题

如正常 WordPress 安装一样,在 web/app/themes 中添加主题。您可以使用 WordPress 管理员更新它们。

插件

WordPress Packagist 已在 composer.json 文件中注册,因此可以从 WordPress 插件目录 轻松地要求任何插件。

要添加插件,请在命令行中使用 composer require <namespace>/<packagename>。如果它是来自 WordPress Packagist 的,则命名空间始终为 wpackagist-plugin,例如。

$ composer require wpackagist-plugin/wp-optimize

每次添加新插件或更新 WordPress 核心时,请运行 composer update 以安装新包。

主题和插件安装在与符号链接的 themesplugins 目录在 /var/opt/wp/wp-content 中,并将对所有多站点站点可用。

注意:某些插件可能会修改核心 wp-config.php 文件。需要由单个站点使用的任何 wp-config.php 修改应移动到站点的 conf/wp-constants.php 文件。

常量

将自定义核心、主题和插件常量放在 conf/wp-constants.php 中。

目录结构

├── composer.json             → Manage versions of WordPress, plugins and dependencies
├── conf                      → WordPress configuration files
│   ├── .env       	      → WordPress environment variables (WP_HOME, DB_NAME, DB_USER, DB_PASSWORD required)
│   ├── wp-constants.php      → Custom core, theme and plugin constants
│   ├── wp-env-config.php     → Primary WordPress config file (wp-config.php equivalent)
│   └── wp-salts.php          → Authentication unique keys and salts (auto generated)
├── vendor                    → Composer packages (never edit)
└── web                       → Web root (vhost document root)
    ├── app                   → wp-content equivalent
    │   ├── mu-plugins        ↔ Must-use plugins symlinked to /var/opt/wp/wp-content/mu-plugins
    │   ├── plugins           ↔ Plugins symlinked to /var/opt/wp/wp-content/plugins
    │   ├── themes            ↔ Themes symlinked to /var/opt/wp/wp-content/themes
    │   └── uploads           → Uploads
    ├── index.php             → Loads the WordPress environment and template (never edit)
    └── wp                    ↔ WordPress core symlinked to /var/opt/wp (never edit)
    	└── wp-config.php     → Required by WordPress - loads conf/wp-env-config.php (never edit)

表示符号链接。

另请参阅

WordPress Substratum

致谢

roots/bedrockwpscholar/wp-skeleton 启发。