https://github.com/makeitworkpress/wp-register
Makes registering custom post types, taxonomies, sidebars, menus and widgets pretty easy.
https://github.com/makeitworkpress/wp-register
wordpress wordpress-development wordpress-library wordpress-php-library wordpress-plugin-development wordpress-post-type wordpress-theme-development
Last synced: 7 months ago
JSON representation
Makes registering custom post types, taxonomies, sidebars, menus and widgets pretty easy.
- Host: GitHub
- URL: https://github.com/makeitworkpress/wp-register
- Owner: makeitworkpress
- License: gpl-3.0
- Created: 2017-01-17T11:09:16.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-26T12:35:29.000Z (over 2 years ago)
- Last Synced: 2025-04-07T00:27:36.555Z (10 months ago)
- Topics: wordpress, wordpress-development, wordpress-library, wordpress-php-library, wordpress-plugin-development, wordpress-post-type, wordpress-theme-development
- Language: PHP
- Homepage: https://makeitwork.press/scripts/wp-register/
- Size: 30.3 KB
- Stars: 20
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wp-register
WordPress has many registration tasks. WP Register makes registering custom blocks, image sizes, menus, post types, taxonomies, sidebars and widgets easy.
WP Register is maintained by [Make it WorkPress](https://makeitwork.press/scripts/wp-register/).
## Usage
Include the WP_Register class in your plugin, theme or child theme file. Require it in your file, use an autoloader or include it using composer. You can read more about autoloading in [the readme of wp-autoload](https://github.com/makeitworkpress/wp-autoload).
### Build your array with registrations
You can add the types you want to register through an multidimensional array, as explained in the example below
```php
$registrations = [
'blocks' => [
[
'type' => 'custom/block-type', // The type, object or json path for the custom gutenberg block
'args' => ['style' => 'custom-block-type-style'] // The arguments for registering a block, following the arguments in the codex
]
]
'image_sizes' => [
[
'name' => 'fhd',
'height' => 1080,
'width' => 1920,
'crop' => true
]
],
'menus' => [
'menu-location' => __('Custom Menu Location', 'textdomain'),
'another-location' => __('AnotherCustom Menu Location', 'textdomain')
],
'post_types' => [
[
'name' => 'beer',
'plural' => __('Beers', 'textdomain'),
'singular' => __('Beer', 'textdomain'),
'args' => ['public' => true] // Contains the arguments as they are supported by register_post_type. (optional)
'taxonomies' => ['category'] // Connects existing taxonomies to this post type. Should be an array. (optional)
'slug' => 'slug' // Sets a custom slug, fastforward for the rewrite slug setting in arguments
'icon' => 'dashicon-beer' // Sets a custom wp-admin menu icon, fastforward for the menu_icon setting in arguments
]
],
'sidebars' => [
[
'id' => 'custom-sidebar',
'name' => __('Custom Sidebar', 'textdomain'),
'description' => __('Description for this sidebar', 'textdomain'),
'before_widget' => '', // The opening element for the widget (optional)
'after_widget' => '', // The closing element for the widget (optional)
'before_title' => '
', // The opening title tag for the widget (optional)
'after_title' => '
' // The closing title tag for the widget (optional)
]
],
'taxonomies' => [
[
'name' => 'type',
'object' => 'beer',
'plural' => __('Types', 'textdomain'),
'singular' => __('Type', 'textdomain'),
'args' => ['hierarchical' => true] // Contains the arguments as they are supported by register_post_type. (optional)
]
],
'widgets' => [
'WidgetClass' // The name of your custom widget class, namespeced if using autoload
],
];
```
### Create instance
Create a new instance of the WP_Register class with your registration array and textdomain string as arguments in the following manner.
```php
$register = new MakeitWorkPress\WP_Register\Register( $registrations, 'textdomain' );
```
The Register class accepts two arguments, namely an ``Array $registrations`` and ``String $textdomain``.