wordpress流程

tech2022-10-27  105

wordpress流程

Composer is a fantastic tool that is widely used in modern PHP development to handle your project dependencies. It helps to install and update all related packages or dependencies of your project. Although it is not primarily used in WordPress core yet, as developers we can still take advantage of Composer to bootstrap our WordPress applications.

Composer是一个出色的工具,已广泛用于现代PHP开发中以处理项目依赖项。 它有助于安装和更新项目的所有相关软件包或依赖项。 尽管它并不是主要用于WordPress核心,但作为开发人员,我们仍然可以利用Composer引导我们的WordPress应用程序。

For references and documentation on using Composer alongside WordPress, I cannot recommend highly enough Rarst’s Composer site. It is a great resource to learn how Composer can be integrated to WordPress in many different ways. Recently, there has also been a few projects that aim to simplify the WordPress setup using Composer such as WP Starter and WordPlate.

对于与WordPress一起使用Composer的参考和文档,我不能推荐足够高的Rarst的Composer网站 。 这是学习Composer如何以多种不同方式集成到WordPress的绝佳资源。 最近,也有一些旨在使用Composer简化WordPress设置的项目,例如WP Starter和WordPlate 。

According to the official WordPlate website, WordPlate is described as a:

根据WordPlate官方网站,WordPlate被描述为:

WordPress framework built with Laravel and Symfony components. With a familiar setup for every Laravel enthusiast. Following the don’t repeat yourself principle.

使用Laravel和Symfony组件构建的WordPress框架。 为每个Laravel爱好者提供熟悉的设置。 遵循“不要重复自己”的原则。

WordPlate is a WordPress boilerplate that takes the idea of managing your WordPress site completely with Composer, and eases up various parts of the development with popular packages from Packagist such as PHP dotenv and Symfony components. The rest of the article will focus on WordPlate, specifically the latest release version of 3.1.0 at the time of writing.

WordPlate是一种WordPress样板,它采用通过Composer完全管理WordPress网站的想法,并使用Packagist的流行软件包(例如PHP dotenv和Symfony组件)简化了开发的各个部分。 本文的其余部分将重点放在WordPlate上,尤其是撰写本文时的最新发行版3.1.0。

This tutorial assumes that you have a working web server, either locally or remotely with SSH access to use the command line. You are also expected to be comfortable working on command line to follow the tutorial.

本教程假定您拥有本地或远程工作的Web服务器,并具有SSH访问权限以使用命令行。 您还应该习惯在命令行上按照本教程进行操作。

先决条件 (Prerequisites)

WordPlate requires at least PHP version 5.5.9 with mbstring extension, so for older PHP installation, an update is required. To check on your installed PHP version, simply run the command:

WordPlate至少需要具有mbstring扩展名PHP 5.5.9版本,因此对于较旧PHP安装,需要进行更新。 要检查已安装PHP版本,只需运行以下命令:

php -v

and it will show whatever version of PHP you currently have.

它将显示您当前拥有的任何版本PHP。

There are also few other things that need to be installed beforehand which are:

事先还需要安装其他一些东西:

Composer

作曲家 Node.js and gulp.js

Node.js和gulp.js

安装作曲家 (Installing Composer)

To install Composer on Linux or Unix system, simply type the command

要在Linux或Unix系统上安装Composer,只需键入以下命令

curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer

The second line is optional, so that you can simply reference composer in your terminal instead of php composer.phar when using Composer. For other systems, please refer to Composer documentation.

第二行是可选的,因此使用Composer时,您可以在终端中简单地引用composer而不是php composer.phar 。 对于其他系统,请参考Composer文档 。

To verify you have installed Composer correctly, type in this command in your terminal, and you should be able to see the installed version of Composer with all available commands.

要验证您是否已正确安装Composer,请在终端中键入此命令,然后您将能够使用所有可用命令查看Composer的安装版本。

composer -v

安装Node.js和gulp.js (Installing Node.js and gulp.js)

Node.js can be downloaded, or installed from the source code depending on your operating system by visiting the Node.js download page while gulp.js can be installed by simply running this command:

可以通过访问Node.js下载页面来下载或从源代码安装Node.js,具体取决于您的操作系统,而只需通过运行以下命令即可安装gulp.js:

npm install --global gulp

npm should be available to use once you have Node.js successfully installed. You can find more info on installing gulp.js on their documentation page.

成功安装Node.js后,应该可以使用npm 。 您可以在其文档页面上找到有关安装gulp.js的更多信息。

Now, typing in node -v should return the correct version of installed Node.js if everything goes well.

现在,如果一切顺利,输入node -v应该返回正确版本的已安装Node.js。

安装 (Installation)

Now that you have got all the required dependencies out of your way, let’s take a look at actually installing and using the WordPlate itself. Type in the command:

现在您已经摆脱了所有必需的依赖关系,让我们看一下实际安装和使用WordPlate本身的情况。 输入命令:

composer create-project wordplate/wordplate

This will tell Composer to download WordPlate into the current directory. You should see the output similar to this:

这将告诉Composer将WordPlate下载到当前目录中。 您应该看到类似于以下的输出:

Installing wordplate/wordplate (3.1.0) - Installing wordplate/wordplate (3.1.0) Downloading: 100% Created project in /srv/www/wordplate > php -r "copy('.env.example', '.env');" Loading composer repositories with package information Installing dependencies (including require-dev) - Installing johnpbloch/wordpress-core-installer (0.2.1) Loading from cache - Installing composer/installers (v1.0.22) Loading from cache - Installing vlucas/phpdotenv (v2.2.0) Loading from cache - Installing symfony/polyfill-mbstring (v1.0.1) Downloading: 100% - Installing symfony/var-dumper (v3.0.1) Downloading: 100% - Installing symfony/finder (v3.0.1) Downloading: 100% - Installing psr/log (1.0.0) Loading from cache - Installing symfony/debug (v3.0.1) Downloading: 100% - Installing symfony/console (v3.0.1) Downloading: 100% - Installing johnpbloch/wordpress (4.4.1) Downloading: 100% - Installing doctrine/inflector (v1.1.0) Loading from cache - Installing illuminate/contracts (v5.2.7) Downloading: 100% - Installing illuminate/support (v5.2.7) Downloading: 100% - Installing illuminate/container (v5.2.7) Downloading: 100% - Installing illuminate/filesystem (v5.2.7) Downloading: 100% - Installing illuminate/config (v5.2.7) Downloading: 100% - Installing filp/whoops (2.0.0) Downloading: 100% - Installing wordplate/framework (3.1.0) Downloading: 100% - Installing roots/soil (3.6.2) Loading from cache symfony/var-dumper suggests installing ext-symfony_debug () symfony/console suggests installing symfony/event-dispatcher () symfony/console suggests installing symfony/process () illuminate/support suggests installing jeremeamia/superclosure (Required to be able to serialize closures (~2.2).) illuminate/support suggests installing paragonie/random_compat (Provides a compatible interface like PHP7's random_bytes() in PHP 5 projects (~1.1).) illuminate/support suggests installing symfony/polyfill-php56 (Required to use the hash_equals function on PHP 5.5 (~1.0).) illuminate/support suggests installing symfony/process (Required to use the composer class (2.8.*|3.0.*).) illuminate/filesystem suggests installing league/flysystem (Required to use the Flysystem local and FTP drivers (~1.0).) illuminate/filesystem suggests installing league/flysystem-aws-s3-v3 (Required to use the Flysystem S3 driver (~1.0).) illuminate/filesystem suggests installing league/flysystem-rackspace (Required to use the Flysystem Rackspace driver (~1.0).) filp/whoops suggests installing whoops/soap (Formats errors as SOAP responses) Writing lock file Generating autoload files > php plate salts:generate WordPress security salts set successfully.

With a single command, various tasks have been done including downloading the latest version of WordPress, downloading all required packages such as Soil, PHP dotenv and a bunch of Symfony and Laravel packages.

通过一个命令,完成了各种任务,包括下载最新版本的WordPress,下载所有必需的软件包,例如Soil , PHP dotenv以及一堆Symfony和Laravel软件包。

Since WordPlate uses Elixir for frontend assets compilation, all dependencies in the package.json need to be installed as well. Run this command in the terminal, within the directory of WordPlate, to tell npm to install all dependencies.

由于WordPlate使用Elixir进行前端资产编译,因此也需要安装package.json所有依赖项。 在终端的WordPlate目录中运行此命令,以告诉npm安装所有依赖项。

cd wordplate npm install

When that is done, you should have all required dependencies, both from Composer and Node.js downloaded into the vendor and node_modules directories respectively.

完成后,您应该拥有所有必需的依赖项,分别来自Composer和Node.js,分别从它们下载到vendor和node_modules目录中。

目录结构 (Directory Structure)

It is a good idea to familiarise yourself with the directory structure within WordPlate since you won’t find the default wp-content, wp-admin, wp-includes and all the other related wp- file in the root directory of your project.

熟悉WordPlate中的目录结构是个好主意,因为在项目的根目录中找不到默认的wp-content , wp-admin , wp-includes和所有其他相关的wp-文件。

If your installation works correctly, this is what you should be seeing inside the main working directory.

如果您的安装可以正常工作,这就是您在主工作目录中看到的内容。

- bootstrap/ - config/ - node_modules/ - public/ - resources/ - vendor/ - .editorconfig - .env - .env.example - .gitignore - composer.json - composer.lock - gulpfile.babel.js - LICENSE - package.json - plate - README.md

Let’s go through each folders and files, and see how each of them is related to WordPlate.

让我们浏览每个文件夹和文件,看看它们与WordPlate的关系。

bootstrap – Contains autoload.php that does the autoloading of Composer package, as well as instantiating the WordPlate app.

bootstrap –包含autoload.php ,该文件可自动加载Composer程序包并实例化WordPlate应用程序。

config – Contains several files that affect how the WordPress site works, which will be discussed more in next section.

config –包含几个影响WordPress网站工作方式的文件,这将在下一部分中详细讨论。

node_modules – Automatically created directory by npm that contains all Node.js dependencies.

node_modules –由npm自动创建的目录,其中包含所有Node.js依赖项。

public – The actual site, which contains files that you would expect from a normal installation of WordPress, with a slight tweak due to Composer usage. Themes defined in composer.json will be installed to public/themes/ directory, and plugins will go into public/plugins directory as per the configuration in composer.json. WordPress is contained in a separate directory of public/wordpress.

public –实际站点,其中包含正常安装WordPress所需的文件,由于Composer的使用情况而略有调整。 根据composer.json的配置, composer.json定义的主题将被安装到public/themes/目录,插件将进入public/plugins目录。 WordPress包含在public/wordpress的单独目录中。

resources – Contains all the scripts, styles and images that will be processed by Elixir into a specified output folder, usually the theme assets folder.

资源 –包含Elixir将处理到指定输出文件夹(通常是主题资产文件夹)的所有脚本,样式和图像。

vendor – Automatically created directory by Composer, that stores all dependencies defined in composer.json.

vendor –由Composer自动创建的目录,用于存储composer.json定义的所有依赖项。

.editorconfig – Standard editor config file that can be loaded into your favourite text editor. Learn more at editorconfig.org.

.editorconfig –标准编辑器配置文件,可以将其加载到您喜欢的文本编辑器中。 在editorconfig.org上了解更多信息 。

.env – Used by phpdotenv to store all general site configuration. Here you can define the WordPress database access, mailer settings and salt keys.

.env –由phpdotenv用于存储所有常规站点配置。 在这里,您可以定义WordPress数据库访问权限,邮件程序设置和盐键。

.env.example – Provide a sample .env of expected configurations in case we need to create another .env file based on a different environment.

.env.example –如果需要基于不同的环境创建另一个.env文件,请提供预期配置的示例.env 。

.gitignore – Standard .gitignore file. By default, it ignores node_modules, vendor and few other files that have sensitive information like .env file. Note that the public plugin, theme and WordPress folder are also excluded from being tracked by Git since they are all managed via Composer.

.gitignore –标准.gitignore文件。 默认情况下,它会忽略node_modules , vendor和其他一些具有敏感信息的文件,例如.env文件。 注意,公共插件,主题和WordPress文件夹也被Git排除在外,因为它们都是通过Composer管理的。

composer.json – Standard composer.json with a few settings adapted to WordPress configuration. All themes and plugins should be defined here in order to be installed.

composer.json –标准composer.json ,其中一些设置适用于WordPress配置。 所有主题和插件都应在此处定义才能安装。

composer.lock – Used internally by Composer to keep track of the dependencies.

composer.lock –由Composer内部使用以跟踪依赖性。

gulpfile.babel.js – Provides configuration for Elixir to manage the assets compilation inside the resources folder.

gulpfile.babel.js –为Elixir提供配置以管理resources文件夹中的资产编译。

LICENSE – A copy of MIT license.

许可证 – MIT许可证的副本。

package.json – Node.js dependencies are defined here, mostly gulp related packages that are used by Elixir.

package.json –这里定义了Node.js依赖项,主要是Elixir使用的与gulp相关的软件包。

plate – Provide basic command to manage WordPlate via CLI.

plate –提供基本命令以通过CLI管理WordPlate。

README.md – Project README file.

README.md –项目自述文件。

组态 (Configuration)

At this point, you will have WordPress and all other dependencies downloaded, but the WordPress site is not installed yet. Before configuring it, we will need to:

此时,您将下载WordPress和所有其他依赖项,但是尚未安装WordPress网站。 在配置它之前,我们需要:

Point the document root of your http server (nginx, apache or others) to the WordPlate public folder.

将您的http服务器(nginx,apache或其他服务器)的文档根目录指向WordPlate公用文件夹。 Create a database for WordPress to use with user that has privilege to said database.

为WordPress创建一个数据库,以供对该数据库具有特权的用户使用。

Once you’ve done both, change the database access appropriately located in the .env file. You wouldn’t need to touch the wp-config.php file since it will all be managed inside this single file instead. You can then proceed to the usual process of WordPress installation by selecting the preferred language, and few other site details in the installation wizard.

两者都完成后,请更改.env文件中适当的数据库访问权限。 您无需触摸wp-config.php文件,因为它将全部在该单个文件内进行管理。 然后,您可以通过选择首选语言以及安装向导中的其他一些站点详细信息来进行WordPress的常规安装过程。

Upon logging in into the WordPress dashboard, you will notice that the dashboard has been stripped down to bare essentials.

登录WordPress仪表板后,您会注意到该仪表板已被简化为基本组件。

Here are some screenshots of what you’re supposed to see in WordPress dashboard out of the box.

以下是一些开箱即用的屏幕快照,它们应该显示在WordPress仪表板中。

主题页面: (Theme page:)

仪表板: (Dashboard:)

已安装的插件: (Installed plugins:)

添加新帖子: (Add new post:)

通过.env文件配置 (Configuration via .env File)

.env file located in the root directory provides a site-wide configuration specific to your installation. As you saw before, this is the place where we can put in the database access details. The WordPress salts should also have been configured for you and stored. Things that can be configured inside the .env file are not limited to what is stated in the .env.example, as you can always introduce your own configuration key inside it.

位于根目录中的.env文件提供特定于您的安装的站点范围的配置。 如您所见,这是我们可以放入数据库访问详细信息的地方。 WordPress盐也应该已经为您配置并存储。 在.env文件中可以配置的.env不限于.env.example中指定的.env.example ,因为您始终可以在其中引入自己的配置密钥。

I will not go into detail about how phpdotenv works, but essentially, you can access the configuration settings via env function, or the $_ENV and $_SERVER superglobals. There are a few examples in the wp-config.php file on how the configuration is loaded.

我不会详细介绍phpdotenv的工作原理,但是从本质上讲 ,您可以通过env函数或$_ENV和$_SERVER超全局变量访问配置设置。 wp-config.php文件中有一些有关如何加载配置的示例。

使用config文件夹进行额外配置 (Extra Configuration Using the config Folder)

There are 10 files located inside the config folder that determines how your site works. Each of them already contains helpful comments as to what they control, but it is a good idea to go through them one by one for clarification.

config文件夹中有10个文件,这些文件确定站点的工作方式。 它们中的每一个都已包含有关其控制内容的有用注释,但是最好逐个进行详细说明。

dashboard.php – Controls which widgets are enabled on the dashboard. Comment the specific line to enable the widget (disabled by default).

dashboard.php –控制在仪表板上启用哪些窗口小部件。 注释特定行以启用窗口小部件(默认情况下禁用)。

editor.php – Controls how the new post screen looks. You can customize the TinyMCE toolbar, media compression settings as well as which metaboxes that should appear on this screen.

editor.php –控制新帖子屏幕的外观。 您可以自定义TinyMCE工具栏,媒体压缩设置以及应在此屏幕上显示的元框。

footer.php – Controls the text at the footer.

footer.php –控制页脚处的文本。

login.php – Can be used to change the logo on login page, as well as error message on failed login.

login.php –可用于更改登录页面上的徽标以及登录失败时的错误消息。

mail.php – Configures how WordPress sends out your mail, by default it is configured to send all mail via mailtrap.

mail.php –配置WordPress发送邮件的方式,默认情况下,它配置为通过mailtrap发送所有邮件。

menus.php – Controls both the admin sidebar and admin menu bar links, as well as disabling Help and Screen Options tab by default. Comment to re-enable preferred links.

menus.php –默认情况下,控制admin侧边栏和admin菜单栏链接,以及禁用“帮助”和“屏幕选项”选项卡。 评论以重新启用首选链接。

options.php – Only controls one option for now, which is permalink structure of the site.

options.php –现在仅控制一个选项,即站点的永久链接结构。

plugins.php – Set auto activation of plugin when installed by default, and can be changed accordingly.

plugins.php –设置默认情况下安装时自动激活插件,可以进行相应更改。

themes.php – Usually the main file that you will need to configure. Controls the site description, timezone and other useful settings.

themes.php –通常需要配置的主文件。 控制网站说明,时区和其他有用的设置。

widgets.php – Contains list of built-in widgets that are disabled by default by WordPlate. Comment specific line to re-enable the widget.

widgets.php –包含默认由WordPlate禁用的内置窗口小部件列表。 注释特定行以重新启用窗口小部件。

All files in config directory are well documented, and should be sufficent to understand how it works.

config目录中的所有文件都有详细的文档说明,应该足以理解其工作原理。

插件和主题 (Plugins and Themes)

By default, WordPlate requires roots/soil package that is used in the default WordPlate theme for various frontend cleanup tasks. Other than that, you are free to install any other plugin as usual, via Composer since WordPlate already configures WordPress Packagist for you.

默认情况下,WordPlate需要在默认WordPlate主题中使用的roots / soil软件包来执行各种前端清理任务。 除此之外,由于WordPlate已经为您配置了WordPress Packagist ,因此您可以像往常一样通过Composer自由安装任何其他插件。

For the uninitiated, WordPress Packagist is a mirror for the official plugins and themes directory, with the difference being that all plugins and themes from WordPress Packagist contain composer.json file which means, all of them are available to be installed normally via Composer.

对于初学者来说,WordPress Packagist是官方插件和主题目录的镜像,不同之处在于WordPress Packagist中的所有插件和主题都包含composer.json文件,这意味着它们都可以通过Composer正常安装。

Managing plugins and themes installations and updates via Composer means that the backend administration for managing themes and plugins won’t be used anymore.

通过Composer管理插件和主题的安装和更新意味着不再使用用于管理主题和插件的后端管理。

安装插件和主题 (Installing Plugins and Themes)

All you need to do is to define your desired plugins/themes to be installed inside the require section of the composer.json. There is already an example of roots/soil being included which is installed by default.

您需要做的就是定义要安装在composer.json的require部分内的所需插件/主题。 默认情况下已经安装了一个包含roots/soil的示例。

For example, to install Yoast WordPress SEO plugin, simply append the require section with the name of plugin and specific version to install.

例如,要安装Yoast WordPress SEO插件,只需在require部分附加插件名称和要安装的特定版本。

... "require": { "php": "^5.5.9 || ^7.0", "wordplate/framework": "3.1.*", "roots/soil": "^3.6", "wpackagist-plugin/wordpress-seo": "3.0.7" //new addition } ...

Note that composer.json needs to be a valid json, so the comment in the example above is only to illustrate the change that needs to be done. Then, in your terminal, simply run composer update and Composer will fetch the plugin for you.

请注意, composer.json必须是有效的json,因此上面示例中的注释只是为了说明需要进行的更改。 然后,在您的终端中,只需运行composer update ,Composer就会为您获取插件。

The same concept is applied for installing and updating themes. For example, to install the latest version of Twenty Sixteen, add this line into your require section of composer.json and run composer update again.

相同的概念适用于主题的安装和更新。 例如,要安装最新版本的《 二十一岁》 ,请将此行添加到composer.json的require部分,然后再次运行composer update 。

... "require": { "php": "^5.5.9 || ^7.0", "wordplate/framework": "3.1.*", "roots/soil": "^3.6", "wpackagist-plugin/wordpress-seo": "3.0.7", "wpackagist-theme/twentysixteen": "1.1" //add new theme } ...

WordPlate默认主题 (WordPlate Default Theme)

In addition to that, WordPlate also ships with a custom themes. There is nothing much out of the box, with no styling at all. It is because the theme serves a purpose as a starting point that you can use to develop your theme from, with nice defaults. It also demonstrates the use of roots/soil package inside the theme’s functions.php file.

除此之外,WordPlate还附带自定义主题。 开箱即用,没有任何样式。 这是因为主题的目的是作为起点,您可以使用它以很好的默认值来开发主题。 它还演示了在主题的functions.php文件中使用roots/soil软件包。

板CLI (Plates CLI)

Plates CLI offers another way to manage some aspects of your site via command line. At the time of writing, it is quite limited but surely the list of available commands will grow in the future.

Plates CLI提供了另一种通过命令行管理站点某些方面的方法。 在撰写本文时,它是非常有限的,但是将来可用命令的列表肯定会增加。

Here are three commands available to be used.

这是三个可用的命令。

php plate list – Lists all available commands, and few other options also come with it.

php plate list –列出所有可用的命令,并且还附带了一些其他选项。

php plate help <command-name – Displays helpful information for a given command.

php plate help <command-name –显示给定命令的有用信息。

php salts:generate – Generates WordPress security salt keys which are defined inside the .env file.

php salts:generate –生成在.env文件中定义的WordPress安全盐密钥。

结论 (Conclusion)

Composer is a useful tool that has been adopted by developers for many years now to develop modern PHP applications. Although it is not supported natively by WordPress core yet, there is no reason to not start using it as it offers a powerful development workflow with thousand of packages available to be used alongside WordPress itself.

Composer是一个有用的工具,已被开发人员使用多年,以开发现代PHP应用程序。 尽管WordPress核心本身还不支持它,但没有理由不开始使用它,因为它提供了强大的开发工作流,并且可以与WordPress本身一起使用数千个软件包 。

Integrating Composer with WordPress requires a bit of work, but WordPlate has already provided a nice starting point without too much hassle to get you started.

将Composer与WordPress集成需要一些工作,但是WordPlate已经提供了一个不错的起点,而没有太多麻烦让您入门。

翻译自: https://www.sitepoint.com/wordplate/

wordpress流程

最新回复(0)