alexrah / wp-admin-custom-post-types
Requires a Wordpress installation. Helper Classes to create Wordpress Custom Post Types, Post Meta, Custom Taxonomies
3.0.0
2024-04-03 14:31 UTC
Requires
- php: >=7.0.0
README
Helper class to register custom post_types and relative post_metas to Wordpress
Install using composer:
composer require alexrah/wp-admin-custom-post-types
published on packagist at: https://packagist.org/packages/alexrah/wp-admin-custom-post-types
Usage
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();
RegisterTypes options
string $screen
post_type screen IDsarray $args_post
arguments to pass for registering post_typeslabel_singular
string used for labels and define capabilitylabel_plural
string used for labels and define capabilitymenu_icon
string dashicons classslug
string for custom rewrite ruletaxonomies
array of taxonomy slugsshow_in_menu
bool|string ie. edit.php?post_type=eventosupports
array ie. 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'has_archive
bool|string - Whether there should be post type archives, or if a string, the archive slug to use. Will generate the proper rewrite rules if $rewrite is enabled. Default falsebool $register_tax
whether use screens IDs to register taxonomyarray $args_tax
arguments to pass for registering taxonomylabel_singular
string used for labelslabel_plural
string used for labelscat_name
string used to register taxonomy, if not specified use cat-$screenslinked_types
(array|string) object types with which the taxonomy should be associated, Default to $screenhierarchical
bool Whether the taxonomy is hierarchical. Default trueslug
string Customize the permalink slug. Default to cat-$screen
bool $register_tax
whether use screens IDs to register taxonomyarray $args_tax
arguments to pass for registering taxonomylabel_singular
string used for labelslabel_plural
string used for labelscat_name
string used to register taxonomy, if not specified use cat-$screenslinked_types
(array|string) object types with which the taxonomy should be associated, Default to $screenhierarchical
bool Whether the taxonomy is hierarchical. Default trueslug
string Customize the permalink slug. Default to cat-$screen
MetaFieldsAdmin options
array $aMetaFields
array of meta_fields as returned byMetaFieldsManager::getFields()
string $sNonce
a unique string used to validate requestsarray $aScreens
an array of post_type IDs to register withstring $sBoxTitle
a label for the meta_box
NB: go to /wp-admin/users.php?page=users-user-role-editor.php to update permissions
Changelog
version 1.0.0
- helper classes to register post_types
- supports creating custom taxonomies
- support creating post_metas
version 2.0.0
change root dir for PHP classes from src to backend
version 2.1.0
add support to Rest API
Version 3.0
new post_meta type = data-grid -> React UX to manage multi-dimensional array data in a single post_meta