WP-CLI是2011年诞生和开发的一个功能。使用WP-CLI,您只需通过命令行界面即可轻松管理您的WordPress网站。通常,当您需要安装插件、主题或进行与 WordPress 相关的编辑时,您需要访问 WordPress 管理后台并通过单击鼠标进行操作,这有时会有点麻烦和耗时,对吗?
这就是为什么 WP-CLI 被开发来帮助您处理上述问题,我们不需要单独访问 WordPress 管理后台,仍然能够更快地管理我们的网站并节省大量时间。
WP-CLI 安装条件
- 您需要拥有服务器的 root 访问权限
安装说明
第 1 步:安装 WP-CLI
要安装WP-CLI,您需要通过 SSH 连接到您的 VPS/服务器并运行以下安装命令:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar php wp-cli.phar --info chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp
上述命令的解释:
- 命令1:从Github主页下载WP-CLI工具。
- 命令2:查看下载的WP-CLI信息
- 命令 3:委派执行下载的文件的权限
- 命令 4:将wp-cli.phar重命名为wp并将文件移动到/usr/local/bin(您可以在 VPS/服务器上的任何位置使用 wp 命令)
如果您想更快地安装,只需复制下面的命令并将其粘贴到您的服务器中即可完成。
wget https://tool.damtrungkien.info/cli/cli.sh && chmod +x cli.sh && bash cli.sh
第 2 步:如何使用 WP-CLI
注意:当您在服务器/VPS 服务器上安装 WP-CLI 并以 root 身份使用时,使用 WP-CLI 命令时,您需要 在 CLI 命令行后添加 –allow-root选项。此外,要使用WP-CLI,您需要移动到您需要操作的WordPress网站的正确文档根文件夹。
下面是一些基本的 WP-CLI 命令,您可以看一下
- 检查 WP-CLI 版本
wp --info
- 列出 WP-CLI 支持的功能。
wp help --allow-root
NAME
wp
DESCRIPTION
Manage WordPress through the command-line.
SYNOPSIS
wp
SUBCOMMANDS
cache Adds, removes, fetches, and flushes the WP Object Cache object.
cap Adds, removes, and lists capabilities of a user role.
cli Reviews current WP-CLI info, checks for updates, or views defined aliases.
comment Creates, updates, deletes, and moderates comments.
config Generates and reads the wp-config.php file.
core Downloads, installs, updates, and manages a WordPress installation.
cron Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
db Performs basic database operations using credentials stored in wp-config.php.
embed Inspects oEmbed providers, clears embed cache, and more.
eval Executes arbitrary PHP code.
eval-file Loads and executes a PHP file.
export Exports WordPress content to a WXR file.
help Gets help on WP-CLI, or on a specific command.
i18n Provides internationalization tools for WordPress projects.
import Imports content from a given WXR file.
language Installs, activates, and manages language packs.
maintenance-mode Activates, deactivates or checks the status of the maintenance mode of a site.
media Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
menu Lists, creates, assigns, and deletes the active theme's navigation menus.
network Perform network-wide operations.
option Retrieves and sets site options, including plugin and WordPress settings.
package Lists, installs, and removes WP-CLI packages.
plugin Manages plugins, including installs, activations, and updates.
post Manages posts, content, and meta.
post-type Retrieves details on the site's registered post types.
rewrite Lists or flushes the site's rewrite rules, updates the permalink structure.
role Manages user roles, including creating new roles and resetting to defaults.
scaffold Generates code for post types, taxonomies, plugins, child themes, etc.
search-replace Searches/replaces strings in the database.
server Launches PHP's built-in web server for a specific WordPress installation.
shell Opens an interactive PHP console for running and testing PHP code.
sidebar Lists registered sidebars.
site Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation.
super-admin Lists, adds, or removes super admin users on a multisite installation.
taxonomy Retrieves information about registered taxonomies.
term Manages taxonomy terms and term meta, with create, delete, and list commands.
theme Manages themes, including installs, activations, and updates.
transient Adds, gets, and deletes entries in the WordPress Transient Cache.
user Manages users, along with their roles, capabilities, and meta.
widget Manages widgets, including adding and moving them within sidebars.
例如,这里如果需要操作插件,可以使用以下命令:
wp plugin --allow-root
接下来,WP-CLI 将向您展示在 WP-CLI 上操作插件的详细说明。
[root@da1 ~]# wp plugin --allow-root
usage: wp plugin activate [...] [--all] [--network]
or: wp plugin auto-updates
or: wp plugin deactivate [...] [--uninstall] [--all] [--network]
or: wp plugin delete [...] [--all]
or: wp plugin get [--field=] [--fields=] [--format=]
or: wp plugin install <plugin|zip|url>... [--version=] [--force] [--activate] [--activate-network] [--insecure]
or: wp plugin is-active [--network]
or: wp plugin is-installed
or: wp plugin list [--=] [--field=] [--fields=] [--format=] [--status=] [--skip-update-check]
or: wp plugin path [] [--dir]
or: wp plugin search [--page=] [--per-page=] [--field=] [--fields=] [--format=]
or: wp plugin status []
or: wp plugin toggle ... [--network]
or: wp plugin uninstall [...] [--deactivate] [--skip-delete] [--all]
or: wp plugin update [...] [--all] [--exclude=] [--minor] [--patch] [--format=] [--version=] [--dry-run] [--insecure]
or: wp plugin verify-checksums [...] [--all] [--strict] [--format=] [--insecure]
See 'wp help plugin
[root@da1 ~]#
下面是插件管理的具体示例,包括列表/激活/停用/删除插件操作。
本站资源来源于网络,仅限用于学习和研究目的,请勿用于其他用途。如有侵权请发送邮件至vizenaujmaslak9@hotmail.com删除。:FGJ博客 » 在 Linux 服务器上轻松安装 WP-CLI