-
Notifications
You must be signed in to change notification settings - Fork 98
Cast scalar meta values as string #650
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
Conversation
Replaces #617
dlh01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The similar logic seems to suggest a shared method on Fieldmanager_Context_Storable might be useful, like sanitize_scalar_value(). Up to you, though.
| protected function update_data( $post_id, $meta_key, $meta_value, $data_prev_value = '' ) { | ||
| // Meta is always stored as a string, so if this is a scalar value, cast | ||
| // it as a string to ensure that `update_metadata()` is able to correctly | ||
| // compare the current value against the previous value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps should follow docs standards for inline comments: https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#5-2-multi-line-comments (applies throughout)?
| */ | ||
| protected function update_data( $data_id, $option_name, $option_value, $option_prev_value = '' ) { | ||
| // Meta is always stored as a string, so if this is a scalar value, cast | ||
| // it as a string to ensure that `update_metadata()` is able to correctly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be *_option() instead of _metadata, and the earlier reference to "Meta is" be "Options are"?
|
Thanks for the suggestion @dlh01. Not sure why I didn't consider that, it seems so obvious in retrospect. That also made it more testable, of course. |
Replaces #617, props @david-binda