-
Notifications
You must be signed in to change notification settings - Fork 286
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 RRM module settings. #8965
Add RRM module settings. #8965
Changes from all commits
5dac654
ab372d7
1b08b38
87130a1
17cf5c0
96da6c4
b812e42
2cca448
3e697aa
a4c180d
b38c5d6
707b912
5a9d8a3
635194a
cc87ccd
168b113
d879772
51d7836
40da58d
f6d4c9a
c956629
063a2e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
/** | ||
* Class Google\Site_Kit\Modules\Reader_Revenue_Manager\Settings | ||
* | ||
* @package Google\Site_Kit\Modules\Reader_Revenue_Manager | ||
* @copyright 2021 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
* @link https://sitekit.withgoogle.com | ||
*/ | ||
|
||
namespace Google\Site_Kit\Modules\Reader_Revenue_Manager; | ||
|
||
use Google\Site_Kit\Core\Modules\Module_Settings; | ||
use Google\Site_Kit\Core\Storage\Setting_With_Owned_Keys_Interface; | ||
use Google\Site_Kit\Core\Storage\Setting_With_Owned_Keys_Trait; | ||
use Google\Site_Kit\Core\Storage\Setting_With_ViewOnly_Keys_Interface; | ||
use Google\Site_Kit\Core\Util\Method_Proxy_Trait; | ||
|
||
/** | ||
* Class for RRM settings. | ||
* | ||
* @since n.e.x.t | ||
* @access private | ||
* @ignore | ||
*/ | ||
class Settings extends Module_Settings implements Setting_With_Owned_Keys_Interface, Setting_With_ViewOnly_Keys_Interface { | ||
|
||
use Setting_With_Owned_Keys_Trait; | ||
use Method_Proxy_Trait; | ||
|
||
const OPTION = 'googlesitekit_reader-revenue-manager_settings'; | ||
|
||
/** | ||
* Various Reader Revenue Manager onboarding statuses. | ||
*/ | ||
const ONBOARDING_STATE_UNSPECIFIED = 'ONBOARDING_STATE_UNSPECIFIED'; | ||
const ONBOARDING_STATE_ACTION_REQUIRED = 'ONBOARDING_ACTION_REQUIRED'; | ||
const ONBOARDING_STATE_PENDING_VERIFICATION = 'PENDING_VERIFICATION'; | ||
const ONBOARDING_STATE_COMPLETE = 'ONBOARDING_COMPLETE'; | ||
|
||
/** | ||
* Registers the setting in WordPress. | ||
* | ||
* @since n.e.x.t | ||
*/ | ||
public function register() { | ||
parent::register(); | ||
|
||
$this->register_owned_keys(); | ||
} | ||
|
||
/** | ||
* Returns keys for owned settings. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return array An array of keys for owned settings. | ||
*/ | ||
public function get_owned_keys() { | ||
return array( 'publicationID' ); | ||
} | ||
|
||
/** | ||
* Gets the default value. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return array | ||
*/ | ||
protected function get_default() { | ||
return array( | ||
'publicationID' => '', | ||
'publicationOnboardingState' => '', | ||
'publicationOnboardingStateLastSyncedAtMs' => 0, | ||
); | ||
} | ||
|
||
/** | ||
* Returns keys for view-only settings. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return array An array of keys for view-only settings. | ||
*/ | ||
public function get_view_only_keys() { | ||
return array(); | ||
} | ||
|
||
/** | ||
* Gets the callback for sanitizing the setting's value before saving. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @return callable|null | ||
*/ | ||
protected function get_sanitize_callback() { | ||
return function ( $option ) { | ||
if ( isset( $option['publicationID'] ) ) { | ||
if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $option['publicationID'] ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ankitrox This is inconsistent with the related check we have in JS and does not allow for a valid ID that I am trying to test with. See #8948 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for spotting this @aaemnnosttv, sorry I missed it during CR. As mentioned on Slack, I've got a followup PR ready if we want to reopen this issue, otherwise I'll create a separate issue for the fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: The above PR has now been merged. |
||
$option['publicationID'] = ''; | ||
} | ||
} | ||
|
||
if ( isset( $option['publicationOnboardingStateLastSyncedAtMs'] ) ) { | ||
if ( ! is_int( $option['publicationOnboardingStateLastSyncedAtMs'] ) ) { | ||
$option['publicationOnboardingStateLastSyncedAtMs'] = 0; | ||
} | ||
} | ||
|
||
if ( isset( $option['publicationOnboardingState'] ) ) { | ||
$valid_onboarding_states = array( | ||
self::ONBOARDING_STATE_UNSPECIFIED, | ||
self::ONBOARDING_STATE_ACTION_REQUIRED, | ||
self::ONBOARDING_STATE_PENDING_VERIFICATION, | ||
self::ONBOARDING_STATE_COMPLETE, | ||
); | ||
|
||
if ( ! in_array( $option['publicationOnboardingState'], $valid_onboarding_states, true ) ) { | ||
$option['publicationOnboardingState'] = ''; | ||
} | ||
} | ||
|
||
return $option; | ||
}; | ||
} | ||
} |
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 Reader Revenue Manager module, as it currently stands, does not have any data to work with, hence, it should neither use the
Module_With_Data_Available_State_Trait
trait, nor call thereset_data_available
function.Is there a specific reason this was added? If not, I'm happy to remove this as part of one of my upcoming PRs.
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.
Good spot @nfmohit 🦅 👁️! I missed this in CR. I believe this should indeed be removed, if you can do it via one of your forthcoming PRs that would be great.