Skip to content

Allow models to pass schema for meta fields#51

Open
LC43 wants to merge 3 commits intodevfrom
fix/schema-when-registering-meta
Open

Allow models to pass schema for meta fields#51
LC43 wants to merge 3 commits intodevfrom
fix/schema-when-registering-meta

Conversation

@LC43
Copy link
Contributor

@LC43 LC43 commented Feb 22, 2026

Allow models to pass schema for meta fields

@gemini-code-assist
Copy link

Summary of Changes

Hello @LC43, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the registration of meta fields, particularly concerning their exposure through the WordPress REST API. It enhances the system's resilience by adding array type checks and increases configuration flexibility by allowing meta fields to be defined at different levels within the settings. Crucially, it empowers developers to specify custom schemas for REST API meta fields, leading to more robust data handling and better API documentation.

Highlights

  • Improved Robustness: Added is_array checks to ensure that 'sections' in metabox settings are valid arrays before attempting to iterate over them, preventing potential errors.
  • Enhanced Meta Field Registration Flexibility: Modified the meta field registration logic to support fields defined directly within box_settings in addition to those nested within sections, providing more flexible configuration options.
  • Custom REST API Schema Support: Introduced the ability to pass custom schema definitions for meta fields when registering them for the WordPress REST API, allowing for more precise data validation and representation.
  • Default Array Schema for REST API: Implemented a default schema for array-type meta fields exposed via the REST API, ensuring proper handling and documentation even when a custom schema is not explicitly provided.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/Features/Meta/CodestarMeta.php
    • Added is_array checks for box_settings['sections'] to prevent iteration errors.
    • Modified register_rest_api to handle meta fields defined directly in box_settings['fields'] or within box_settings['sections'].
    • Updated create_meta_fields_not_serialized to accept a full array of field arguments instead of just the meta type.
    • Implemented logic within create_meta_fields_not_serialized to use a custom schema from field_args for show_in_rest, or a default schema for array types.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces the ability to pass a custom schema for meta fields and adds support for top-level fields in REST API registration. While these are valuable improvements, there are a few issues: the default array schema is too restrictive for repeater fields, there's a potential type error when handling field arguments, and the removal of the preparation callback is a breaking change for the REST API output format. Additionally, some docblocks need updating to match the new function signatures.

@LC43
Copy link
Contributor Author

LC43 commented Feb 23, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully introduces the ability to define custom REST API schemas for meta fields, which significantly improves the flexibility and correctness of the REST API output, especially for complex fields like repeaters. The implementation for unserialized fields is solid, though I've suggested some minor updates to the documentation and type hinting to maintain consistency and clarity.

Comment on lines 174 to 177
* @param string $meta_type Type of the meta field
* @param string $post_type Post type to register the meta field for
*/
private function create_meta_fields_not_serialized( $meta_name, $meta_type, $post_type ) {
private function create_meta_fields_not_serialized( $meta_name, $field_args, $post_type ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The docblock and method signature for create_meta_fields_not_serialized should be updated to reflect that the second parameter is now an array of field arguments rather than just a string representing the meta type. Additionally, adding type hints improves code clarity and consistency with the rest of the class (e.g., the constructor).

	 * @param array  $field_args  Arguments for the field
	 * @param string $post_type   Post type to register the meta field for
	 */
	private function create_meta_fields_not_serialized( string $meta_name, array $field_args, string $post_type ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant