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

Add helper function to update an option #110

Merged
merged 2 commits into from
Dec 9, 2014

Conversation

mAAdhaTTah
Copy link
Contributor

Working on WP-CLI functionality for a plugin; would be helpful to use this to update options outside of the displayed form.

@jtsternberg
Copy link
Member

Looks like a good addition. Care to attempt a unit test to accompany this new function and complement the existing test?

@mAAdhaTTah
Copy link
Contributor Author

Will do that when I get home. You prefer a squashed commit or two commits?

Edit: Nevermind, I broke up the one unit test into 3, as you're testing 3 different functions. Hope that's ok!

*/
function cmb2_update_option( $option_key, $field_id, $value, $resave = false, $single = true ) {
if ( cmb2_options( $option_key )->update( $field_id, $value, $resave, $single ) ) {
return cmb2_options( $option_key )->set();
Copy link
Member

Choose a reason for hiding this comment

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

since you are using the set method, there is no reason to take in the $resave argument to this helper function (because using set, it will save it to the DB). I would remove it from the cmb2_update_option function and set it to 'false' for cmb2_options()->update.

@jtsternberg jtsternberg merged commit 1a6ea05 into CMB2:master Dec 9, 2014
@jtsternberg
Copy link
Member

I updated the function to remove $resave, so we're good to go. Thank you for your submission and for taking the time to add unit tests!

@mAAdhaTTah
Copy link
Contributor Author

No prob, happy to help.

@mAAdhaTTah mAAdhaTTah deleted the option-update-helper branch December 9, 2014 13:33
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.

2 participants