@@ -127,10 +127,12 @@ function register_meta_helper(
127
127
}
128
128
129
129
/**
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.
131
133
*/
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 ' ;
134
136
135
137
// Ensure the config file exists and is valid.
136
138
if ( ! file_exists ( $ filepath ) || ! in_array ( validate_file ( $ filepath ), [ 0 , 2 ], true ) ) {
@@ -152,11 +154,12 @@ function register_post_meta_from_defs(): void {
152
154
continue ;
153
155
}
154
156
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 ] ?? [];
157
160
158
161
// Unset since $definition is passed as register_meta args.
159
- unset( $ definition [' post_types ' ] );
162
+ unset( $ definition [ $ definition_key ] );
160
163
161
164
// Relocate schema, if specified at the top level.
162
165
if ( ! empty ( $ definition ['schema ' ] ) ) {
@@ -171,10 +174,24 @@ function register_post_meta_from_defs(): void {
171
174
172
175
// Register the meta.
173
176
register_meta_helper (
174
- ' post ' ,
175
- $ post_types , // @phpstan-ignore-line array given
177
+ $ meta_context ,
178
+ $ object_types , // @phpstan-ignore-line array given
176
179
$ meta_key ,
177
- $ definition , // @phpstan-ignore-line array given
180
+ $ definition , // @phpstan-ignore-line array given
178
181
);
179
182
}
180
183
}
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