Skip to content

Commit 45bc868

Browse files
authored
Merge pull request #726 from ProgressPlanner/filip/register-branded-site-earlier
Register branded site earlier
2 parents 7ef39be + 476c5cd commit 45bc868

12 files changed

Lines changed: 29 additions & 20 deletions

classes/admin/widgets/class-challenge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function get_cache_key() {
9090
public function get_remote_api_url() {
9191
return \add_query_arg(
9292
[
93-
'license_key' => \get_option( 'progress_planner_license_key' ),
93+
'license_key' => \progress_planner()->get_license_key(),
9494
'site' => \get_site_url(),
9595
],
9696
\progress_planner()->get_remote_server_root_url() . '/wp-json/progress-planner-saas/v1/challenges'

classes/class-base.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ public function init() {
9898
$this->get_utils__playground();
9999
}
100100

101+
$prpl_license_key = $this->get_license_key();
102+
if ( ! $prpl_license_key && 0 !== (int) \progress_planner()->get_ui__branding()->get_branding_id() ) {
103+
$prpl_license_key = \progress_planner()->get_utils__onboard()->make_remote_onboarding_request();
104+
if ( '' !== $prpl_license_key ) {
105+
\update_option( 'progress_planner_license_key', $prpl_license_key, false );
106+
}
107+
}
108+
101109
// Basic classes.
102110
if ( \is_admin() && \current_user_can( 'edit_others_posts' ) ) {
103111
$this->get_admin__page();
@@ -301,7 +309,16 @@ public function get_activation_date() {
301309
* @return bool
302310
*/
303311
public function is_privacy_policy_accepted() {
304-
return false !== \get_option( 'progress_planner_license_key', false );
312+
return false !== $this->get_license_key();
313+
}
314+
315+
/**
316+
* Get the license key.
317+
*
318+
* @return string|false
319+
*/
320+
public function get_license_key() {
321+
return \get_option( 'progress_planner_license_key', false );
305322
}
306323

307324
/**

classes/class-lessons.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function get_remote_api_items() {
5757
$url = \add_query_arg(
5858
[
5959
'site' => \get_site_url(),
60-
'license_key' => \get_option( 'progress_planner_license_key' ),
60+
'license_key' => \progress_planner()->get_license_key(),
6161
],
6262
$url
6363
);

classes/rest/class-base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function validate_token( $token ) {
8686
return true;
8787
}
8888

89-
$license_key = \get_option( 'progress_planner_license_key', false );
89+
$license_key = \progress_planner()->get_license_key();
9090
if ( ! $license_key || 'no-license' === $license_key ) {
9191
// Increment failed attempts counter.
9292
\set_transient( $rate_limit_key, $failed_attempts + 1, HOUR_IN_SECONDS );

classes/utils/class-debug-tools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ protected function add_more_info_submenu_item( $admin_bar ) {
515515
);
516516

517517
// Free license info.
518-
$prpl_free_license_key = \get_option( 'progress_planner_license_key', false );
518+
$prpl_free_license_key = \progress_planner()->get_license_key();
519519
$admin_bar->add_node(
520520
[
521521
'id' => 'prpl-free-license',

classes/utils/class-onboard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct() {
2929
// Detect domain changes.
3030
\add_action( 'shutdown', [ $this, 'detect_site_url_changes' ] );
3131

32-
if ( \get_option( 'progress_planner_license_key' ) ) {
32+
if ( \progress_planner()->get_license_key() ) {
3333
return;
3434
}
3535

@@ -194,7 +194,7 @@ public function detect_site_url_changes() {
194194
return;
195195
}
196196

197-
$saved_license_key = \get_option( 'progress_planner_license_key', false );
197+
$saved_license_key = \progress_planner()->get_license_key();
198198

199199
// Bail early if the license key is not set, or if the site URL has not changed.
200200
if ( ! $saved_license_key || $saved_site_url === $current_site_url ) {

classes/utils/class-playground.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct() {
2828
* @return void
2929
*/
3030
public function register_hooks() {
31-
if ( ! \get_option( 'progress_planner_license_key', false ) && ! \get_option( 'progress_planner_demo_data_generated', false ) ) {
31+
if ( ! \progress_planner()->get_license_key() && ! \get_option( 'progress_planner_demo_data_generated', false ) ) {
3232
$this->generate_data();
3333
\update_option( 'progress_planner_license_key', \str_replace( ' ', '-', $this->create_random_string( 20 ) ) );
3434
\update_option( 'progress_planner_force_show_onboarding', false );

tests/phpunit/test-class-api-get-stats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function set_lessons_cache() {
7272
$url = \add_query_arg(
7373
[
7474
'site' => \get_site_url(),
75-
'license_key' => \get_option( 'progress_planner_license_key' ),
75+
'license_key' => \progress_planner()->get_license_key(),
7676
],
7777
$url
7878
);

tests/phpunit/test-class-page-types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function set_lessons_cache() {
7373
$url = \add_query_arg(
7474
[
7575
'site' => \get_site_url(),
76-
'license_key' => \get_option( 'progress_planner_license_key' ),
76+
'license_key' => \progress_planner()->get_license_key(),
7777
],
7878
$url
7979
);

views/admin-page-header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<?php
2626

2727
// Render the subscribe form button and popover if the license key is not set.
28-
if ( 'no-license' === \get_option( 'progress_planner_license_key', 'no-license' ) ) {
28+
if ( 'no-license' === \progress_planner()->get_license_key() ) {
2929
\progress_planner()->get_ui__popover()->the_popover( 'subscribe-form' )->render_button(
3030
'',
3131
\progress_planner()->get_asset( 'images/register_icon.svg' ) . '<span class="screen-reader-text">' . \esc_html__( 'Subscribe', 'progress-planner' ) . '</span>'

0 commit comments

Comments
 (0)