Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Fieldmanager media field to save 0 instead of null when no image set #806

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mslinnea
Copy link
Member

@mslinnea mslinnea commented Sep 15, 2021

We are encountering an issue with Fieldmanager Media field saving null instead of 0 when there is no image selected. The presave function PHPDoc indicates that an integer is always returned, but it is not.

The specific issue is when we need to make the field available in the REST API for use in the Gutenberg editor.
We have several instances where we need to integrate the value with a Gutenberg plugin and doing so requires us to add some code like

register_meta(
	'post',
	'index_featured_image',
	[
		'type'              => 'integer',
		'description'       => __( 'Index featured image ID.', 'alley' ),
		'show_in_rest'      => true,
		'single'            => true,
	]
);

In this case, index_featured_image is the name of the Fieldmanager Media field. We are specifying that the type is integer.

That code will cause the following error when null is the value:

Updating failed. The index_featured_image property has an invalid stored value, and cannot be updated to null.

This change resolves this issue.

@mslinnea
Copy link
Member Author

I anticipate this could be a breaking change if code is checking specifically for null instead of a more general empty() check.

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