@@ -127,10 +127,12 @@ function register_meta_helper(
127127}
128128
129129/**
130- * Reads the post meta definitions from config and registers them.
130+ * Reads the meta definitions from config and registers them.
131+ *
132+ * @param 'post'|'term' $meta_context The context in which to register the definitions.
131133 */
132- function register_post_meta_from_defs ( ): void {
133- $ filepath = dirname ( __DIR__ ) . '/config/post -meta.json ' ;
134+ function register_meta_from_defs ( string $ meta_context = ' post ' ): void {
135+ $ filepath = dirname ( __DIR__ ) . '/config/ ' . $ meta_context . ' -meta.json ' ;
134136
135137 // Ensure the config file exists and is valid.
136138 if ( ! file_exists ( $ filepath ) || ! in_array ( validate_file ( $ filepath ), [ 0 , 2 ], true ) ) {
@@ -152,11 +154,12 @@ function register_post_meta_from_defs(): void {
152154 continue ;
153155 }
154156
155- // Extract post types.
156- $ post_types = $ definition ['post_types ' ] ?? [];
157+ // Extract post types or terms.
158+ $ definition_key = ( 'post ' === $ meta_context ) ? 'post_types ' : 'terms ' ;
159+ $ object_types = $ definition [ $ definition_key ] ?? [];
157160
158161 // Unset since $definition is passed as register_meta args.
159- unset( $ definition [' post_types ' ] );
162+ unset( $ definition [ $ definition_key ] );
160163
161164 // Relocate schema, if specified at the top level.
162165 if ( ! empty ( $ definition ['schema ' ] ) ) {
@@ -171,10 +174,24 @@ function register_post_meta_from_defs(): void {
171174
172175 // Register the meta.
173176 register_meta_helper (
174- ' post ' ,
175- $ post_types , // @phpstan-ignore-line array given
177+ $ meta_context ,
178+ $ object_types , // @phpstan-ignore-line array given
176179 $ meta_key ,
177- $ definition , // @phpstan-ignore-line array given
180+ $ definition , // @phpstan-ignore-line array given
178181 );
179182 }
180183}
184+
185+ /**
186+ * Reads the post meta definitions from config and registers them.
187+ */
188+ function register_post_meta_from_defs (): void {
189+ register_meta_from_defs ( 'post ' );
190+ }
191+
192+ /**
193+ * Reads the term meta definitions from config and registers them.
194+ */
195+ function register_term_meta_from_defs (): void {
196+ register_meta_from_defs ( 'term ' );
197+ }
0 commit comments