diff --git a/composer.json b/composer.json index bd3ac32..0ef23da 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Post/BaseObject.php b/src/Post/BaseObject.php index 7425fea..8a1ff01 100644 --- a/src/Post/BaseObject.php +++ b/src/Post/BaseObject.php @@ -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. * @@ -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 ) { @@ -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 ); + } } } }