Skip to content

Commit

Permalink
feature: Support registering meta fields
Browse files Browse the repository at this point in the history
build: [skip-ci]
  • Loading branch information
lots0logs committed Oct 5, 2020
1 parent eb7c2ee commit 975c8b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "WordPress Database Objects - Work with posts and taxonomies, including queries and custom type registration, using OOP style.",
"type": "library",
"license": "GPL-v2-or-later",
"version": "1.1.3",
"version": "1.2.0",
"authors": [
{
"name": "Elegant Themes",
Expand Down
15 changes: 15 additions & 0 deletions src/Post/BaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ protected function _beforeRegister(): void {}
*/
abstract protected function _labels(): array;

/**
* Returns meta field definitions for the instance. See {@see register_post_meta()} or {@see register_term_meta()}.
*
* @since 1.2.0
*/
abstract protected function _meta(): array;

/**
* Checks for required properties and existing instances.
*
Expand Down Expand Up @@ -177,6 +184,10 @@ public static function registerAll(): void {

$instance->_wp_object = $wp_taxonomies[ $instance::$name ];
$instance->_is_registered = true;

foreach ( $instance->_meta() as $field => $definition ) {
register_term_meta( $instance::$name, $field, $definition );
}
}

foreach ( self::$_instances['cpt'] as $instance ) {
Expand All @@ -188,6 +199,10 @@ public static function registerAll(): void {

$instance->_wp_object = register_post_type( $instance::$name, $instance->_args );
$instance->_is_registered = true;

foreach ( $instance->_meta() as $field => $definition ) {
register_post_meta( $instance::$name, $field, $definition );
}
}
}
}

0 comments on commit 975c8b4

Please sign in to comment.