-
Notifications
You must be signed in to change notification settings - Fork 96
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 constant settings support #509
Conversation
04e7983
to
2a18d2c
Compare
@@ -150,7 +150,7 @@ public static function ready() { | |||
*/ | |||
public static function get_tenant_region( $domain ) { | |||
preg_match( '/^[\w\d\-_0-9]+\.([\w\d\-_0-9]*)[\.]*auth0\.com$/', $domain, $matches ); | |||
return !empty($matches[1]) ? $matches[1] : 'us'; | |||
return ! empty( $matches[1] ) ? $matches[1] : 'us'; |
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.
Formatting
@@ -7,7 +7,6 @@ | |||
|
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.
Code standards ruleset
1920b39
to
2f6afe9
Compare
lib/WP_Auth0_Options_Generic.php
Outdated
*/ | ||
public function get_constant_val( $key ) { | ||
$constant_name = $this->get_constant_name( $key ); | ||
return defined( $constant_name ) ? constant( $constant_name ) : null; |
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.
it sounds like this method is repeating the logic on the has_constant_val
method. Do you think this can be improved? i.e. if tomorrow the logic to check whether a constant exists or not changes, you'll need to change 2 methods instead of 1.
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.
I think the has_constant_val
was added after and I never went back to refactor this one. Good catch 👍
if ( $should_update ) { | ||
update_option( $this->_options_name, $options ); | ||
// No database update so process completed successfully. | ||
if ( ! $should_update ) { |
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.
is this update something you'll normally run after setting each key-value? Think of the case of setting a bunch of variables. I guess only the last call to this method would have this value as true
. Right? Since I guess is not going to perform well doing so after each call. If so, would it make sense to remove this parameter from this method and just expose the update_all
method for the user to call it directly on demand? You'll need to weight the most common use cases to make this decision.
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.
is this update something you'll normally run after setting each key-value?
It's run most of the time, yes.
Since I guess is not going to perform well doing so after each call.
Not excellent but we don't set
much except in the initial setup process and, in that case, there are a number of HTTP requests that will be the main slow-down. The main time settings are saved is when the page is saved and, in that case, it's a single update.
If so, would it make sense to remove this parameter from this method
BC there so I'll punt that to when we refactor this whole system.
lib/admin/WP_Auth0_Admin_Generic.php
Outdated
* @param string $input_name - Input name for the field, used as option key. | ||
*/ | ||
protected function render_const_notice( $input_name ) { | ||
if ( $this->options->has_constant_val( $input_name ) ) { |
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.
this check is already done on some of the render_const_notice
calls. Decide whether you'd like to do this here or outside, but don't check twice... it's an overkill. e.g. call
protected function render_radio_buttons( array $buttons, $id, $input_name, $curr_value ) {
if ( $field_is_const = $this->options->has_constant_val( $input_name ) ) {
$this->render_const_notice( $input_name );
}
@@ -13,5 +13,5 @@ | |||
} | |||
</style> | |||
<div id="extra-options"> | |||
<a href="?"><?php printf( _e( '← Back to %s login', 'wp-auth0' ), $title ); ?></a> | |||
<a href="?"><?php printf( __( '← Back to %s login', 'wp-auth0' ), $title ); ?></a> |
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.
what does this?
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.
_e()
echos the translated string, __()
returns it. Was passing an echo call to something that echos as well, causing the printf()
to be skipped.
tests/testConstantSettings.php
Outdated
|
||
// Make sure we have the right number of overrides. | ||
$opts = new WP_Auth0_Options(); | ||
$this->assertCount( 3, $opts->get_all_constant_keys() ); |
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.
you can go further and check the actual key values
tests/testConstantSettings.php
Outdated
|
||
$input = $this->getDomListFromTagName( $field_html, 'input' ); | ||
$this->assertTrue( $input->item( 0 )->hasAttribute( 'disabled' ) ); | ||
$this->assertNotFalse( strpos( $field_html, self::CONSTANT_NOTICE_TEXT ) ); |
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.
assertNotFalse
vs assertTrue
?
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.
strpos()
returns the position of the string as an integer (could be 0
) or FALSE
if it's not found. I want to check that the string is there so I want to assert that it's not false.
That said, there is an assertContains
that works better here so I switched to that.
2f6afe9
to
b30eb43
Compare
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.
🆗
Add support for defining settings in a constant. Closes #480. Replaces #488 (a review of most of this functionality was already complete there).
This will allow for sensitive data like the client secret, API token, and migration token to be stored in constants. The options class now looks for constants of a specific name being defined, like so:
The default constant name should be
AUTH0_ENV_
followed by the option name to override in all caps (the prefix can be modified with theauth0_settings_constant_prefix
filter). Option keys listed here can all be overridden.Note: the
migration_token
value is generated by the plugin when user migration is turned on. If there is already a value in the admin, make sure to set the constant to the same value. If that value needs to change, it also must be changed in the user migration script for the database connection being used.Once that is set,
WP_Auth0_Options_Generic::get_options()
will look for values before loading all options.WP_Auth0_Options_Generic::get()
will pull from this adjusted array.The settings field will change display based on this new value and show the constant being used:
Saving the settings page after setting a constant value will validate the constant-set values and delete them from the options array being saved to the database (important to mention that in upcoming docs).
All sites in a WordPress multi-site network will use the same constant value making this an easy way to setup a network using a single Application and DB Connection.