alexrah / wp-admin-custom-post-types
需要Wordpress安装。用于创建Wordpress自定义文章类型、文章元数据和自定义分类的辅助类
3.0.0
2024-04-03 14:31 UTC
Requires
- php: >=7.0.0
README
辅助类,用于在Wordpress中注册自定义文章类型和相关的文章元数据
使用composer安装
composer require alexrah/wp-admin-custom-post-types
发布于Packagist:https://packagist.org.cn/packages/alexrah/wp-admin-custom-post-types
使用方法
use WpAdminCPT\RegisterTypes; use WpAdminCPT\MetaFieldsManager; use WpAdminCPT\MetaFieldsAdmin; const META_BOX_NONCE = 'meta_box_nonce'; new RegisterTypes('user-paid-content', [ 'label_singular' => "My Post", 'label_plural' => "My Posts" ], true, [ 'label_singular' => "Categoria Contenuto", 'label_plural' => "Categorie Contenuto" ] ); function vn_fields(): MetaFieldsManager { $sPrefix = 'user-paid-'; $aFields = [ [ "Name" => "type", "Label" => "Tipo Contenuto", "LabelPublic" => "", "Placeholder" => "Seleziona Tipo", "Type" => "select", "Validation" => '', "Value" => ['job-listing','event'], 'Group' => 'global' ], [ "Name" => "candidati_comunali", "Label" => "Candidati Consiglieri", "LabelPublic" => "", "Placeholder" => "", "Type" => "data-grid", "Validation" => '', "Group" => 'global', "Value" => [ [ 'type' => 'text', 'name' => 'nome', 'label' => "Nome" ], [ 'type' => 'text', 'name' => 'cognome', 'label' => "Cognome" ], [ 'type' => 'text', 'name' => 'voti', 'label' => "Voti" ], [ 'type' => 'checkbox', 'name' => 'isEletto', 'label' => "Eletto" ] ] ] ]; return new MetaFieldsManager($sPrefix,$aFields); } $oUserPaidContent = new MetaFieldsAdmin(vn_fields()->getFields(),META_BOX_NONCE,['user-paid-content'],'Dati'); $oUserPaidContent->init();
注册类型选项
string $screen
文章类型屏幕IDarray $args_post
注册文章类型时要传递的参数label_singular
用于标签和定义能力的字符串label_plural
用于标签和定义能力的字符串menu_icon
用于菜单图标的dashicons类slug
用于自定义重写规则的字符串taxonomies
分类别名的数组show_in_menu
bool|string,例如:edit.php?post_type=eventosupports
数组,例如:'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'has_archive
bool|string - 是否应该有文章类型存档,或者如果是一个字符串,则使用该存档别名。如果启用了$rewrite,将生成适当的重写规则。默认为falsebool $register_tax
是否使用屏幕ID来注册分类array $args_tax
注册分类时要传递的参数label_singular
用于标签的字符串label_plural
用于标签的字符串cat_name
用于注册分类的字符串,如果没有指定,则使用cat-$screenslinked_types
(array|string) 与分类相关联的对象类型,默认为$screenhierarchical
bool 是否分类是层次结构的。默认为trueslug
string 自定义永久链接别名。默认为cat-$screen
bool $register_tax
是否使用屏幕ID来注册分类array $args_tax
注册分类时要传递的参数label_singular
用于标签的字符串label_plural
用于标签的字符串cat_name
用于注册分类的字符串,如果没有指定,则使用cat-$screenslinked_types
(array|string) 与分类相关联的对象类型,默认为$screenhierarchical
bool 是否分类是层次结构的。默认为trueslug
string 自定义永久链接别名。默认为cat-$screen
元字段管理器选项
array $aMetaFields
元字段的数组,由MetaFieldsManager::getFields()
返回string $sNonce
用于验证请求的唯一字符串array $aScreens
要注册的帖子类型ID的数组string $sBoxTitle
元框的标签
注意:请转到 /wp-admin/users.php?page=users-user-role-editor.php 更新权限
变更日志
版本 1.0.0
- 注册文章类型的辅助类
- 支持创建自定义分类
- 支持创建文章元数据
版本 2.0.0
将PHP类的根目录从src更改为backend
版本 2.1.0
添加对Rest API的支持
版本 3.0
新的文章元数据类型 = data-grid -> React UX 用于在单个文章元数据中管理多维数组数据