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
Cast variable #993
Cast variable #993
Conversation
The method just return cast `$this->options` as array but actually `$this->options` assign before still a string in some case. Bugs will be show when I try empty cmb setting in `wp_options` table.
You will need to write unit tests to prove/test your scenario. |
Added unit tests |
I just ran the tests you wrote with and without the changes you made in |
Thank you for your PR. I have actually merged it to get your unit tests (and given you props), but I reverted the |
I miss forgot line in last commit: public function setUp() {
...
add_option( 'cmb_empty_option', '' );
} See the unit tests failures: The bug is because this $this->options = get_option( $this->key, $default );
...
return (array) $this->options; and on public function remove( $field_id, $resave = false ) {
$this->get_options();
if ( isset( $this->options[ $field_id ] ) ) {
unset( $this->options[ $field_id ] );
} If some reasons, I have a option with empty string (or nothing value). And call Because you only cast when return options. Actually |
…not just the return. Fixes #993
Ah, now I understand! ed2e58f should address that specific issue. Thank you for providing more info/clarification. |
The method just return cast
$this->options
as array but actually$this->options
assign before still a string in some case.Bugs will be show when I try empty cmb setting in
wp_options
table.