wp-cli/scaffold-command

生成用于帖子类型、分类法、块、插件、子主题等的代码。

安装数量: 4,934,126

依赖项: 13

建议者: 0

安全性: 0

星标: 165

关注者: 12

分支: 86

开放问题: 32

语言:Gherkin

类型:wp-cli-package

v2.3.0 2024-04-26 21:05 UTC

README

生成用于帖子类型、分类法、块、插件、子主题等的代码。

Testing

快速链接: 使用 | 安装 | 贡献 | 支持

使用

本软件包实现了以下命令

wp scaffold

为帖子类型、分类法、插件、子主题等生成代码。

wp scaffold

示例

# Generate a new plugin with unit tests.
$ wp scaffold plugin sample-plugin
Success: Created plugin files.
Success: Created test files.

# Generate theme based on _s.
$ wp scaffold _s sample-theme --theme_name="Sample Theme" --author="John Doe"
Success: Created theme 'Sample Theme'.

# Generate code for post type registration in given theme.
$ wp scaffold post-type movie --label=Movie --theme=simple-life
Success: Created '/var/www/example.com/public_html/wp-content/themes/simple-life/post-types/movie.php'.

wp scaffold underscores

生成基于 _s 的主题的初始代码。

wp scaffold underscores <slug> [--activate] [--enable-network] [--theme_name=<title>] [--author=<full-name>] [--author_uri=<uri>] [--sassify] [--woocommerce] [--force]

有关更多详细信息,请访问 Underscores 网站

选项

<slug>
	The slug for the new theme, used for prefixing functions.

[--activate]
	Activate the newly downloaded theme.

[--enable-network]
	Enable the newly downloaded theme for the entire network.

[--theme_name=<title>]
	What to put in the 'Theme Name:' header in 'style.css'.

[--author=<full-name>]
	What to put in the 'Author:' header in 'style.css'.

[--author_uri=<uri>]
	What to put in the 'Author URI:' header in 'style.css'.

[--sassify]
	Include stylesheets as SASS.

[--woocommerce]
	Include WooCommerce boilerplate files.

[--force]
	Overwrite files that already exist.

示例

# Generate a theme with name "Sample Theme" and author "John Doe"
$ wp scaffold _s sample-theme --theme_name="Sample Theme" --author="John Doe"
Success: Created theme 'Sample Theme'.

wp scaffold block

为插件或主题生成注册 Gutenberg 块的 PHP、JS 和 CSS 代码。

wp scaffold block <slug> [--title=<title>] [--dashicon=<dashicon>] [--category=<category>] [--theme] [--plugin=<plugin>] [--force]

警告:wp scaffold block 已弃用。

生成块的官方脚本是 @wordpress/create-block 软件包。

有关完整教程,请参阅 创建块教程

选项

<slug>
	The internal name of the block.

[--title=<title>]
	The display title for your block.

[--dashicon=<dashicon>]
	The dashicon to make it easier to identify your block.

[--category=<category>]
	The category name to help users browse and discover your block.
	---
	default: widgets
	options:
	  - common
	  - embed
	  - formatting
	  - layout
	  - widgets
	---

[--theme]
	Create files in the active theme directory. Specify a theme with `--theme=<theme>` to have the file placed in that theme.

[--plugin=<plugin>]
	Create files in the given plugin's directory.

[--force]
	Overwrite files that already exist.

wp scaffold child-theme

基于现有主题生成子主题。

wp scaffold child-theme <slug> --parent_theme=<slug> [--theme_name=<title>] [--author=<full-name>] [--author_uri=<uri>] [--theme_uri=<uri>] [--activate] [--enable-network] [--force]

创建一个包含 functions.phpstyle.css 文件的子主题文件夹。

选项

<slug>
	The slug for the new child theme.

--parent_theme=<slug>
	What to put in the 'Template:' header in 'style.css'.

[--theme_name=<title>]
	What to put in the 'Theme Name:' header in 'style.css'.

[--author=<full-name>]
	What to put in the 'Author:' header in 'style.css'.

[--author_uri=<uri>]
	What to put in the 'Author URI:' header in 'style.css'.

[--theme_uri=<uri>]
	What to put in the 'Theme URI:' header in 'style.css'.

[--activate]
	Activate the newly created child theme.

[--enable-network]
	Enable the newly created child theme for the entire network.

[--force]
	Overwrite files that already exist.

示例

# Generate a 'sample-theme' child theme based on TwentySixteen
$ wp scaffold child-theme sample-theme --parent_theme=twentysixteen
Success: Created '/var/www/example.com/public_html/wp-content/themes/sample-theme'.

wp scaffold plugin

为插件生成初始代码。

wp scaffold plugin <slug> [--dir=<dirname>] [--plugin_name=<title>] [--plugin_description=<description>] [--plugin_author=<author>] [--plugin_author_uri=<url>] [--plugin_uri=<url>] [--skip-tests] [--ci=<provider>] [--activate] [--activate-network] [--force]

以下文件始终生成

  • plugin-slug.php 是主要的 PHP 插件文件。
  • readme.txt 是插件的说明文件。
  • package.json 是 NPM 所需的,包含与项目相关的各种元数据。软件包:gruntgrunt-wp-i18ngrunt-wp-readme-to-markdown。脚本:startreadmei18n
  • Gruntfile.js 是包含 Grunt 任务的 JS 文件。任务:i18n 包含 addtextdomainmakepotreadme 包含 wp_readme_to_markdown
  • .editorconfig 是 Editor 的配置文件。
  • .gitignore 指定 git 应忽略哪些文件(或模式)。
  • .distignore 指定在分发中应忽略哪些文件和文件夹。

除非使用 --skip-tests,否则以下文件也将包括在内

  • phpunit.xml.dist 是 PHPUnit 的配置文件。
  • .circleci/config.yml 是 CircleCI 的配置文件。使用 --ci=<provider> 选择不同的服务。
  • bin/install-wp-tests.sh 配置 WordPress 测试套件和测试数据库。
  • tests/bootstrap.php 是在运行测试套件时使当前插件生效的文件。
  • tests/test-sample.php 是包含测试用例的示例文件。
  • .phpcs.xml.dist 是 PHP_CodeSniffer 规则的集合。

选项

<slug>
	The internal name of the plugin.

[--dir=<dirname>]
	Put the new plugin in some arbitrary directory path. Plugin directory will be path plus supplied slug.

[--plugin_name=<title>]
	What to put in the 'Plugin Name:' header.

[--plugin_description=<description>]
	What to put in the 'Description:' header.

[--plugin_author=<author>]
	What to put in the 'Author:' header.

[--plugin_author_uri=<url>]
	What to put in the 'Author URI:' header.

[--plugin_uri=<url>]
	What to put in the 'Plugin URI:' header.

[--skip-tests]
	Don't generate files for unit testing.

[--ci=<provider>]
	Choose a configuration file for a continuous integration provider.
	---
	default: circle
	options:
	  - circle
	  - gitlab
	  - bitbucket
	  - github
	---

[--activate]
	Activate the newly generated plugin.

[--activate-network]
	Network activate the newly generated plugin.

[--force]
	Overwrite files that already exist.

示例

$ wp scaffold plugin sample-plugin
Success: Created plugin files.
Success: Created test files.

wp scaffold plugin-tests

生成在插件中运行 PHPUnit 测试所需的文件。

wp scaffold plugin-tests [<plugin>] [--dir=<dirname>] [--ci=<provider>] [--force]

以下文件默认生成

  • phpunit.xml.dist 是 PHPUnit 的配置文件。
  • .circleci/config.yml 是 CircleCI 的配置文件。使用 --ci=<provider> 选择不同的服务。
  • bin/install-wp-tests.sh 配置 WordPress 测试套件和测试数据库。
  • tests/bootstrap.php 是在运行测试套件时使当前插件生效的文件。
  • tests/test-sample.php 是包含实际测试的示例文件。
  • .phpcs.xml.dist 是 PHP_CodeSniffer 规则的集合。

有关更多信息,请参阅 插件单元测试文档

环境

tests/bootstrap.php 文件查找 WP_TESTS_DIR 环境变量。

选项

[<plugin>]
	The name of the plugin to generate test files for.

[--dir=<dirname>]
	Generate test files for a non-standard plugin path. If no plugin slug is specified, the directory name is used.

[--ci=<provider>]
	Choose a configuration file for a continuous integration provider.
	---
	default: circle
	options:
	  - circle
	  - gitlab
	  - bitbucket
	  - github
	---

[--force]
	Overwrite files that already exist.

示例

# Generate unit test files for plugin 'sample-plugin'.
$ wp scaffold plugin-tests sample-plugin
Success: Created test files.

wp scaffold post-type

生成用于注册自定义帖子类型的 PHP 代码。

wp scaffold post-type <slug> [--label=<label>] [--textdomain=<textdomain>] [--dashicon=<dashicon>] [--theme] [--plugin=<plugin>] [--raw] [--force]

选项

<slug>
	The internal name of the post type.

[--label=<label>]
	The text used to translate the update messages.

[--textdomain=<textdomain>]
	The textdomain to use for the labels.

[--dashicon=<dashicon>]
	The dashicon to use in the menu.

[--theme]
	Create a file in the active theme directory, instead of sending to
	STDOUT. Specify a theme with `--theme=<theme>` to have the file placed in that theme.

[--plugin=<plugin>]
	Create a file in the given plugin's directory, instead of sending to STDOUT.

[--raw]
	Just generate the `register_post_type()` call and nothing else.

[--force]
	Overwrite files that already exist.

示例

# Generate a 'movie' post type for the 'simple-life' theme
$ wp scaffold post-type movie --label=Movie --theme=simple-life
Success: Created '/var/www/example.com/public_html/wp-content/themes/simple-life/post-types/movie.php'.

wp scaffold taxonomy

生成用于注册自定义分类法的 PHP 代码。

wp scaffold taxonomy <slug> [--post_types=<post-types>] [--label=<label>] [--textdomain=<textdomain>] [--theme] [--plugin=<plugin>] [--raw] [--force]

选项

<slug>
	The internal name of the taxonomy.

[--post_types=<post-types>]
	Post types to register for use with the taxonomy.

[--label=<label>]
	The text used to translate the update messages.

[--textdomain=<textdomain>]
	The textdomain to use for the labels.

[--theme]
	Create a file in the active theme directory, instead of sending to
	STDOUT. Specify a theme with `--theme=<theme>` to have the file placed in that theme.

[--plugin=<plugin>]
	Create a file in the given plugin's directory, instead of sending to STDOUT.

[--raw]
	Just generate the `register_taxonomy()` call and nothing else.

[--force]
	Overwrite files that already exist.

示例

# Generate PHP code for registering a custom taxonomy and save in a file
$ wp scaffold taxonomy venue --post_types=event,presentation > taxonomy.php

wp scaffold theme-tests

生成运行主题中PHPUnit测试所需文件。

wp scaffold theme-tests [<theme>] [--dir=<dirname>] [--ci=<provider>] [--force]

以下文件默认生成

  • phpunit.xml.dist 是 PHPUnit 的配置文件。
  • .circleci/config.yml 是 CircleCI 的配置文件。使用 --ci=<provider> 选择不同的服务。
  • bin/install-wp-tests.sh 配置 WordPress 测试套件和测试数据库。
  • tests/bootstrap.php 是在运行测试套件时使当前主题生效的文件。
  • tests/test-sample.php 是包含实际测试的示例文件。
  • .phpcs.xml.dist 是 PHP_CodeSniffer 规则的集合。

有关更多信息,请参阅 插件单元测试文档

环境

tests/bootstrap.php 文件查找 WP_TESTS_DIR 环境变量。

选项

[<theme>]
	The name of the theme to generate test files for.

[--dir=<dirname>]
	Generate test files for a non-standard theme path. If no theme slug is specified, the directory name is used.

[--ci=<provider>]
	Choose a configuration file for a continuous integration provider.
	---
	default: circle
	options:
	  - circle
	  - gitlab
	  - bitbucket
	  - github
	---

[--force]
	Overwrite files that already exist.

示例

# Generate unit test files for theme 'twentysixteenchild'.
$ wp scaffold theme-tests twentysixteenchild
Success: Created test files.

安装

此软件包已包含在WP-CLI中,无需额外安装。

要安装此软件包的最新版本,覆盖WP-CLI中包含的版本,请运行

wp package install [email protected]:wp-cli/scaffold-command.git

贡献

我们感谢您主动为这个项目做出贡献。

贡献不仅限于代码。我们鼓励您以最适合您能力的方式做出贡献,比如撰写教程、在当地聚会中演示、帮助其他用户解答支持问题或修订我们的文档。

要了解更多信息,请查看WP-CLI贡献指南。此软件包遵循那些政策和指南。

报告一个bug

认为找到了一个bug?我们非常希望您能帮助我们修复它。

在创建新问题之前,您应该搜索现有问题,看看是否有现成的解决方案,或者它是否已经被最新版本修复。

在搜索之后发现,您的bug没有未解决或已修复的问题,请创建一个新问题。尽可能提供详细信息,并尽可能提供重现步骤。更多指导,请查看我们的bug报告文档

创建一个pull request

想要贡献一个新功能?请首先打开一个新问题,讨论该功能是否适合本项目。

一旦您决定投入时间提交pull request,请遵循我们创建pull request的指南,确保这是一个愉快的体验。有关在本软件包本地工作的详细信息,请参阅"设置"。

支持

GitHub问题不是用于一般支持问题的地方,但您还可以尝试其他途径: https://wp-cli.org/#support

此README.md是从项目的代码库中动态生成的,使用wp scaffold package-readme (文档)。要建议更改,请提交针对代码库相应部分的pull request。