builtnorth/extended-cpts-extras

为 johnbillion/extended-cpts 提供额外功能和特性

dev-main 2024-09-10 04:12 UTC

This package is auto-updated.

Last update: 2024-09-10 04:13:12 UTC


README

Extended CPTs Extras 是 Extended CPTs 库的配套包,为管理 WordPress 中的文章类型提供额外功能。

特性

  1. 特色图片列宽:自定义管理列表视图中特色图片列的宽度。
  2. 移除元框:轻松从文章编辑屏幕中移除不需要的元框(对 Gutenberg 有用)。
  3. 注册元:为您的文章类型注册自定义元字段,支持 REST API。
  4. 修改现有文章类型:向现有文章类型添加额外功能,包括
    • 自定义模板
    • 模板锁定
    • 菜单位置
    • 菜单图标

安装

  1. 在您的 composer.json 中要求此包

    {
        "require": {
            "builtnorth/extended-cpts-extras": "^1.0"
        }
    }
  2. 运行 composer installcomposer update

用法

使用 extended_post_type_extras() 函数将额外配置应用于文章类型

extended_post_type_extras(['post', 'page'], [
	'featured_image_column_width' => 80,
	'remove_meta_boxes' => ['postcustom', 'commentstatusdiv'],
	'register_meta' => [
		'my_custom_field' => [
			'type' => 'string',
			'description' => 'A custom field for this post type',
			'single' => true,
			'show_in_rest' => true,
		],
	]
]);

使用 extended_post_type_modify_existing() 函数修改现有文章类型

extended_post_type_modify_existing('post', [
	'menu_icon' => 'dashicons-index-card',
	'menu_position' => 30,
	'template' => [
		['core/image', []],
	],

]);

函数

extended_post_type_extras($post_types, $options)

将额外配置应用于指定的文章类型。

参数

  • $post_types:字符串或文章类型名称数组
  • $options:配置选项数组
    • featured_image_column_width:设置特色图片列的宽度
    • remove_meta_boxes:要移除的元框 ID 数组
    • register_meta:要注册的元字段数组

extended_post_type_modify_existing($post_types, $options)

使用额外功能修改现有文章类型,这些功能在原始 Extended CPTs 包中不可用。此函数允许您将某些选项应用于现有文章类型,通常仅在注册新的文章类型时使用 register_extended_post_type() 才有效。具体来说,它允许您修改以下属性

  • $post_types:字符串或文章类型名称数组
  • $options:配置选项数组
    • template:文章类型的自定义模板
    • template_lock:锁定模板以防止更改
    • menu_position:设置菜单位置
    • menu_icon:设置菜单图标

贡献

欢迎贡献。请随时提交拉取请求。

许可

此软件包是开源软件,受 MIT 许可证 的许可。