'string', 'single' => true, 'default' => '', 'sanitize_callback' => array( PostData::class, 'sanitize_meta_value' ), 'show_in_rest' => array( 'schema' => array( 'type' => 'string', 'context' => array( 'view', 'edit' ), ), ), 'auth_callback' => static function (): bool { return current_user_can( 'edit_posts' ); }, ) ); } /** * Register a single string meta key. * * @param string $post_type Post type name. * @param string $meta_key Meta key identifier. * * @return void */ private static function register_string_meta( string $post_type, string $meta_key ): void { register_post_meta( $post_type, $meta_key, array( 'type' => 'string', 'single' => true, 'default' => '', 'sanitize_callback' => 'sanitize_text_field', 'show_in_rest' => array( 'schema' => array( 'type' => 'string', 'context' => array( 'view', 'edit' ), ), ), 'auth_callback' => static function (): bool { return current_user_can( 'edit_posts' ); }, ) ); } /** * Determine the post types that should expose the metadata. * * @return array */ private static function target_post_types(): array { $post_types = get_post_types( array( 'show_ui' => true, ), 'names' ); return array_values( array_diff( $post_types, array( 'attachment', 'revision', 'nav_menu_item', 'wp_block' ) ) ); } }