From 975c8b4e6f4b48ce859af5d369004d06af1193b0 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Mon, 5 Oct 2020 15:06:34 -0500 Subject: [PATCH] feature: Support registering meta fields build: [skip-ci] --- composer.json | 2 +- src/Post/BaseObject.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 ); + } } } }