alleyinteractive/wp-block-audit-command

审计文章内容中WordPress块的使用。

v1.2.0 2024-06-18 02:24 UTC

This package is auto-updated.

Last update: 2024-09-18 02:59:22 UTC


README

这是一个用于审计文章内容中块使用的WP-CLI包,可以帮助在内容迁移或重新设计之前决定哪些块需要优先处理。

快速链接: 使用 | 安装 | 关于

使用

此包实现了以下命令

wp block-audit run

报告文章内容中每种类型块的数量,以及它们的汇总细节。

报告包括每个块的使用次数,使用它们的文章类型,以及以下细节

  • 对于所有块,'align'属性值的计数。
  • 对于'core/heading'块,每个标题级别的计数。
  • 对于'core/embed'块,每个嵌入提供者的计数。

您可以使用 alley_block_audit_block_type_detailsalley_block_audit_{$block_name}_block_type_details 过滤器向报告中添加更多细节

add_filter(
	'alley_block_audit_block_type_details',
	function ( $details, $block_name, $attrs, $inner_html, $block, $post ) {
		if ( isset( $attrs['fontSize'] ) && is_string( $attrs['fontSize'] ) ) {
			$details['fontSize'][ $attrs['fontSize'] ] ??= 0;
			$details['fontSize'][ $attrs['fontSize'] ]++;
		}

		return $details;
	},
	10,
	6,
);

add_filter(
	'alley_block_audit_core/image_block_type_details',
	function ( $details, $block_name, $attrs, $inner_html, $block, $post ) {
		if ( isset( $attrs['aspectRatio'] ) && is_string( $attrs['aspectRatio'] ) ) {
			$details['aspectRatio'][ $attrs['aspectRatio'] ] ??= 0;
			$details['aspectRatio'][ $attrs['aspectRatio'] ]++;
		}

		return $details;
	},
	10,
	6,
);
wp block-audit run  [--<field>=<value>] [--format=<format>] [--verbose] [--rewind]

选项

[--<field>=<value>]
    One or more args to pass to WP_Query except for 'order', 'orderby', or 'paged'.

[--format=<format>]
    Render output in a particular format.
    ---
    default: table
    options:
    - table
    - csv
    - json
    - count
    - yaml
    ---

[--verbose]
    Turn on verbose mode.

[--rewind]
    Resets the cursor so the next time the command is run it will start from the beginning.

示例

$ wp block-audit run --post_type=post,page
+-----------------------------------+-------+------------------------------------------------------------+-----------------+----------------------------------------------------------------------+
| Block Name                        | Count | Example URL                                                | Post Types      | Details                                                              |
+-----------------------------------+-------+------------------------------------------------------------+-----------------+----------------------------------------------------------------------+
| core/archives                     | 3     | https://www.example.com/2023/01/13/widgets-block-category/ | ["post"]        |                                                                      |
| core/button                       | 12    | https://www.example.com/2023/01/13/design-category-blocks/ | ["post"]        | {"align":{"left":2,"center":1,"right":1}}                            |
| core/code                         | 2     | https://www.example.com/2023/01/13/text-category-blocks/   | ["post"]        |                                                                      |
| core/column                       | 40    | https://www.example.com/2023/01/13/design-category-blocks/ | ["post"]        |                                                                      |
| core/columns                      | 13    | https://www.example.com/2023/01/13/design-category-blocks/ | ["post"]        | {"align":{"wide":2,"full":1}}                                        |
| core/cover                        | 21    | https://www.example.com/2023/01/13/media-category-blocks/  | ["post"]        | {"align":{"left":1,"center":2,"full":1,"wide":2}}                    |
| core/file                         | 3     | https://www.example.com/2023/01/13/media-category-blocks/  | ["post"]        |                                                                      |
| core/gallery                      | 10    | https://www.example.com/2023/01/13/media-category-blocks/  | ["post"]        |                                                                      |
| core/group                        | 25    | https://www.example.com/2023/01/13/design-category-blocks/ | ["post"]        |                                                                      |
| core/heading                      | 23    | https://www.example.com/2023/01/13/text-category-blocks/   | ["post","page"] | {"H1":2,"H2":11,"H3":4,"H4":2,"H5":2,"H6":2}                         |
| core/html                         | 2     | https://www.example.com/2023/01/13/widgets-block-category/ | ["post"]        |                                                                      |
| core/image                        | 19    | https://www.example.com/2023/01/13/media-category-blocks/  | ["post"]        | {"align":{"center":2,"left":2,"right":3,"none":1,"wide":1,"full":1}} |
| core/list                         | 9     | https://www.example.com/2023/01/13/text-category-blocks/   | ["post"]        |                                                                      |
| core/list-item                    | 6     | https://www.example.com/2023/01/13/text-category-blocks/   | ["post"]        |                                                                      |
| core/media-text                   | 6     | https://www.example.com/2023/01/13/media-category-blocks/  | ["post"]        | {"align":{"full":1}}                                                 |
| core/paragraph                    | 262   | https://www.example.com/2023/01/13/text-category-blocks/   | ["post","page"] | {"align":{"center":16,"right":1,"left":1}}                           |
| core/pullquote                    | 4     | https://www.example.com/2023/01/13/text-category-blocks/   | ["post"]        |                                                                      |
| core/spacer                       | 4     | https://www.example.com/2023/01/13/design-category-blocks/ | ["post"]        |                                                                      |
| core/table                        | 4     | https://www.example.com/2023/01/13/text-category-blocks/   | ["post"]        |                                                                      |
+-----------------------------------+-------+---------------------------------------------------------------+-----------------+----------------------------------------------------------------------+

安装

安装此包需要WP-CLI v1.3.0或更高版本。使用 wp cli update 更新到最新稳定版本。

完成此操作后,您可以使用以下命令安装此包的最新稳定版本

wp package install alleyinteractive/wp-block-audit-command:@stable

您还可以使用Composer安装此包

composer require alleyinteractive/wp-block-audit-command

关于

许可证

GPL-2.0-or-later

维护者

Alley Interactive