builtnorth / extended-cpts-extras
Additional functionality and features for johnbillion/extended-cpts
Requires
- php: >=8.1
- johnbillion/extended-cpts: ^5.0
README
Extended CPTs Extras is a companion package for the Extended CPTs library, providing additional functionality for managing post types in WordPress.
Features
-
Featured Image Column Width: Customize the width of the featured image column in the admin list view.
-
Remove Meta Boxes: Easily remove unwanted meta boxes from the post edit screen (useful for Gutenberg).
-
Register Meta: Register custom meta fields for your post types with support for the REST API.
-
Modify Existing Post Types: Add additional features to existing post types. Note that the the below features work correctly out of the box on the Extended CPTs package when registeting a new post type. It is only necessary to use the
extended_post_type_modify_existing()
function when modifying an existing post type. Theses features include:- Custom templates
- Template locking
- Menu position
- Menu icon
Installation
-
Require the package in your
composer.json
:{ "require": { "builtnorth/extended-cpts-extras": "^1.0" } }
-
Run
composer install
orcomposer update
.
Usage
Use the extended_post_type_extras()
function to apply extra configurations to post types:
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, ], ] ]);
Use function extended_post_type_modify_existing()
function to modify existing post types:
extended_post_type_modify_existing('post', [ 'menu_icon' => 'dashicons-index-card', 'menu_position' => 30, 'template' => [ ['core/image', []], ], ]);
Functions
extended_post_type_extras($post_types, $options)
Apply extra configurations to specified post types.
Parameters:
$post_types
: String or array of post type names$options
: Array of configuration optionsfeatured_image_column_width
: Set width for featured image columnremove_meta_boxes
: Array of meta box IDs to removeregister_meta
: Array of meta fields to register
extended_post_type_modify_existing($post_types, $options)
Modify existing post types with additional features that are not available in the original Extended CPTs package. This function allows you to apply certain options to existing post types that normally only work when registering a new post type with register_extended_post_type()
. Specifically, it enables you to modify the following attributes for existing post types:
$post_types
: String or array of post type names$options
: Array of configuration optionstemplate
: Custom template for the post typetemplate_lock
: Lock the template to prevent changesmenu_position
: Set the menu positionmenu_icon
: Set the menu icon
Contributing
Contributions are welcome. Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.