concept-image/wp-make-cpt 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

concept-image/wp-make-cpt

Composer 安装命令:

composer require --dev concept-image/wp-make-cpt

包简介

Add a command to generate custom post types and taxonomies.

关键字:

README 文档

README

Requirements

  • PHP >= 8.0
  • WordPress >= 6.5
  • Roots Bedrock >= 1.26
  • Roots Acorn >= 4.3

Installation

You can install this package with Composer:

composer require concept-image/wp-make-cpt --dev

Purpose

This package provides commands to generate custom post types and taxonomies in WordPress projects using Acorn.

Available Commands

make:cpt

Create a new Custom Post Type class file. (Before creating a new CPT, check if a preset is available for the one you wish to create.)

Options:

  • name (required): The name of the custom post type.
  • --lang: Language for the custom post type.
  • --singular: Singular name for the custom post type.
  • --plural: Plural name for the custom post type.
  • --is_feminine: Indicates if the custom post type is feminine.
  • --dashicon: Dashicon for the custom post type.
  • --public: Indicates if the custom post type is public.
  • --has_archive: Indicates if the custom post type has an archive.
  • --hierarchical: Indicates if the custom post type is hierarchical.
  • --supports: Features supported by the custom post type.
  • --taxonomies: Taxonomies associated with the custom post type.
  • --rewrite: Indicates if the custom post type should be rewritten.
  • --slug: Slug for the custom post type.
  • --show_ui: Indicates if the custom post type should be shown in the UI.
  • --position: Position of the custom post type in the menu.
  • --show_in_rest: Indicates if the custom post type should be shown in the REST API.
  • --delete_with_user: Indicates if the custom post type should be deleted with the user.

make:tax

Create a new Taxonomy class file.

Options:

  • name (required): The name of the taxonomy.
  • --lang: Language for the taxonomy.
  • --singular: Singular name for the taxonomy.
  • --plural: Plural name for the taxonomy.
  • --is_feminine: Indicates if the taxonomy is feminine.
  • --object_type: Object type for the taxonomy.
  • --public: Indicates if the taxonomy is public.
  • --hierarchical: Indicates if the taxonomy is hierarchical.
  • --rewrite: Indicates if the taxonomy should be rewritten.
  • --rewrite_hierarchical: Indicates if the taxonomy should be rewritten hierarchically.
  • --slug: Slug for the taxonomy.
  • --show_ui: Indicates if the taxonomy should be shown in the UI.
  • --show_in_rest: Indicates if the taxonomy should be shown in the REST API.
  • --show_in_nav_menus: Indicates if the taxonomy should be shown in navigation menus.

Examples

Create a custom post type named "project":

wp acorn make:cpt project

Create a taxonomy named "project_cat":

wp acorn make:tax project_cat

Command Prompts and Choices

When you run the make:cpt or make:tax commands, you will be prompted to provide various details about the custom post type or taxonomy. Here are the steps and choices you will encounter:

  1. Language: You will be asked to select the language code (e.g., en or fr).
  2. Singular Name: Enter the singular name of the custom post type or taxonomy.
  3. Plural Name: Enter the plural name of the custom post type or taxonomy.
  4. Feminine (French only): Indicate if the name is feminine or masculine.
  5. Dashicon (Custom Post Type only): Enter the dashicon for the custom post type.
  6. More Options: Indicate if you want to add more options.
  7. Public: Indicate if the custom post type or taxonomy is public.
  8. Has Archive (Custom Post Type only): Indicate if the custom post type has an archive.
  9. Hierarchical: Indicate if the custom post type or taxonomy is hierarchical.
  10. Supports (Custom Post Type only): Select the features supported by the custom post type.
  11. Taxonomies (Custom Post Type only): Select the taxonomies associated with the custom post type.
  12. Rewrite: Indicate if the custom post type or taxonomy should be rewritten.
  13. Slug: Enter the slug for the custom post type or taxonomy.
  14. Show UI: Indicate if the custom post type or taxonomy should be shown in the UI.
  15. Position (Custom Post Type only): Enter the position of the custom post type in the menu.
  16. Show in REST API: Indicate if the custom post type or taxonomy should be shown in the REST API.
  17. Delete with User (Custom Post Type only): Indicate if the custom post type should be deleted with the user.
  18. Show in Navigation Menus (Taxonomy only): Indicate if the taxonomy should be shown in navigation menus.
  19. Object Type (Taxonomy only): Select the post types to link the taxonomy to.

These prompts ensure that you provide all necessary information to generate the custom post type or taxonomy with the desired configuration.

Generated Files

Custom Post Type

When you run the make:cpt command, the following files are generated:

  • Custom Post Type Class: Located in App\CustomPostTypes\{{ className }}.php, this file defines the custom post type and its arguments.
  • Views: Blade templates for the custom post type views, such as archive, single, and card.
  • Styles: SCSS files for the custom post type styles.
  • ACF Fields: PHP files defining ACF fields for the custom post type.

Taxonomy

When you run the make:tax command, the following files are generated:

  • Taxonomy Class: Located in App\Taxonomies\{{ className }}.php, this file defines the taxonomy and its arguments.
  • Views: Blade templates for the taxonomy views, such as taxonomy-view.
  • ACF Fields: PHP files defining ACF fields for the taxonomy.

Available Presets for Custom Post Types

The following presets are available for custom post types: news and event. A preset contains all basic files for a difine CPT.

Available Commands

cpt-preset

Generate dummy Custom Post Type data with Faker. If the name of the preset is not provided, the command will list all available presets.

Options:
  • name: The name of the preset you want to publish.
  • --force: Force to republish the preset files.

Usage of the Seed Command

The seed command allows you to generate dummy data for custom post types and taxonomies using Faker.

Available Commands

seed:cpt

Generate dummy Custom Post Type data with Faker.

Options:
  • name (required): The name of the custom post type.
  • count: The number of dummy posts to generate (default: 24).

seed:tax

Generate dummy Taxonomy data with Faker.

Options:
  • name (required): The name of the taxonomy.
  • --count: The number of dummy terms to generate (default: 4).

seed:event

Generate dummy Events data with faker.

Options:
  • --count: The number of dummy terms to generate (default: 4).

Examples

Generate 10 dummy posts for the custom post type "project":

wp acorn seed:cpt project --count=10

Generate 5 dummy terms for the taxonomy "project_cat":

wp acorn seed:tax project_cat --count=5

Results

When you run the seed:cpt command, the following actions are performed:

  • Dummy Posts: Generates the specified number of dummy posts for the custom post type.
  • Taxonomies: Assigns random terms from associated taxonomies to the dummy posts.
  • ACF Fields: Populates ACF fields with random data if defined for the custom post type.

When you run the seed:tax command, the following actions are performed:

  • Dummy Terms: Generates the specified number of dummy terms for the taxonomy.

Custom Seeder

To build a custom seeder, you can create a new Command Class that extends CustomPostTypeSeedCommand and override the getValueForFieldName function in the CustomPostTypeSeedCommand class. This allows you to provide custom Faker data for specific fields.

Define Custom Post Type for the seeder

// filepath: /App/Commands/Seeders/ExampleSeederCommand
protected string $objectName = 'example'

Example

Suppose you have a custom field named address and you want to generate a random sentence for this field. You can override the getValueForFieldName function as follows:

// filepath: /App/Commands/ExampleSeederCommand
protected function getValueForFieldName(string $name, Generator $faker)
{
    return match ($name) {
        'address' => $faker->locale('fr_FR')->address;,
        default => null,
    };
}

In this example, the address will be populated with a random address generated by Faker. You can add more cases to the match statement to handle other custom fields as needed.

Changelog

Please refer to CHANGELOG for more information.

Contributing

Please refer to CONTRIBUTING for more information.

License

Please refer to LICENSE for more information.

concept-image/wp-make-cpt 适用场景与选型建议

concept-image/wp-make-cpt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 225 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「dev」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 concept-image/wp-make-cpt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 concept-image/wp-make-cpt 我们能提供哪些服务?
定制开发 / 二次开发

基于 concept-image/wp-make-cpt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 225
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 2

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-19