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
Options get_group() and get() return different values if using constants #35
Conversation
…_mailer_complete method, ie to use this->options instead of create new object and using $this-mailer instead of hard coded string.
…only returned database options. Updated to allows run apply_filters so developers can filter and return their own value when option is empty, because before filter only ran if group had database option. Updating the comment to match method. Reason for change was Options::init()->get( 'sendgrid', 'api_key' ) and Options::init()->get_group( 'sendgrid' )[ 'api_key' ] returned different values if you were using constants. So the method is_mailer_complete on SendGrid/Mailer would return false even though api_key was setup with constant.
The approach in So inside |
Also, thank you for fixing copy-paste error in |
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.
Minor changes required to not directly modify the class property _options
.
…ptions and instead use local variable $options to match style of get_all(), and passing $options to filter so filters cannot modify class property. Change isset check of map to if statement for readability.
@slaFFik I wanted to check in and see if we can get this pull request closed. |
@spenserhale |
This will be included into the next WP Mail SMTP release. Thank you for your contribution! |
Reason for change was Options::init()->get( 'sendgrid', 'api_key' ) and Options::init()->get_group( 'sendgrid' )[ 'api_key' ] returned different values if you were using constants.
So for our instant:
Options::init()->get( 'sendgrid', 'api_key' ) would return the string.
Options::init()->get_group( 'sendgrid' )[ 'api_key' ] would return null and throw undefined index.
So Sendgrid\Mailer::is_mailer_complete would return false even though api_key was setup with constant, since it used the get_group method.
I updated get_group to return defaults and constants, where before it only returned database options.
I also updated to always run apply_filters so developers can filter and return their own value when option is empty, because before filter only ran if group had database option.
Testing procedure
Tested saving admin.
Tested sending mail with external plugin.
Tested sending test mail with plugin.
Types of changes
Checklist:
Important notes on the breaking change, ideally should have no affects if developers are checking values. Only problem is if developers were checking the get_group array. Before would return empty array(), now always has some value.
Example:
Also another important note:
There was a local variable, $options, that was being set in foreach but not used anywhere. The get_all() method above passes $options into apply_filters(), but this method instead passes $this->_options[ $group ] into apply_fitlers(). I wanted to know if the goal of plugin was to always update and use $_options instead of local $options. Because either get_all() should be updated to match this style or get_group() should be updated to match get_all()'s style.