Skip to content

Commit a8d2c9d

Browse files
authored
Merge pull request #593 from ProgressPlanner/172
v1.7.2
2 parents e09e23f + 1f2e56f commit a8d2c9d

28 files changed

+120
-347
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
= 1.7.2 =
3+
4+
* Backported some features from the Progress Planner Pro plugin.
5+
16
= 1.7.1 =
27

38
Bugs we fixed:

assets/images/logo_progress_planner_pro.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

classes/admin/class-editor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function enqueue_editor_script() {
3030
if ( ! $request && isset( $_SERVER['REQUEST_URI'] ) ) {
3131
$request = \sanitize_text_field( \wp_unslash( $_SERVER['REQUEST_URI'] ) );
3232
}
33-
if ( $request && str_contains( $request, 'site-editor.php' ) ) {
33+
if ( $request && \str_contains( $request, 'site-editor.php' ) ) {
3434
return;
3535
}
3636

classes/admin/class-enqueue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function get_localized_strings() {
410410
* @return void
411411
*/
412412
public function maybe_empty_session_storage() {
413-
$screen = get_current_screen();
413+
$screen = \get_current_screen();
414414

415415
if ( ! $screen ) {
416416
return;

classes/admin/class-page-settings.php

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public function store_settings_form_options() {
172172

173173
$this->save_settings();
174174
$this->save_post_types();
175-
$this->save_license();
176175

177176
\do_action( 'progress_planner_settings_form_options_stored' );
178177

@@ -211,109 +210,4 @@ public function save_post_types() {
211210

212211
\progress_planner()->get_settings()->set( 'include_post_types', $include_post_types );
213212
}
214-
215-
/**
216-
* Save the license key.
217-
*
218-
* @return void
219-
*/
220-
public function save_license() {
221-
// Check the nonce.
222-
\check_admin_referer( 'progress_planner' );
223-
224-
$license = isset( $_POST['prpl-pro-license-key'] )
225-
? \sanitize_text_field( \wp_unslash( $_POST['prpl-pro-license-key'] ) )
226-
: '';
227-
228-
$previous = \get_option( 'progress_planner_pro_license_key' );
229-
$is_new = $previous !== $license;
230-
231-
if ( ! $is_new ) {
232-
return;
233-
}
234-
235-
\update_option( 'progress_planner_pro_license_key', $license );
236-
\update_option( 'progress_planner_pro_license_status', null );
237-
238-
// Do nothing if user just cleared the license.
239-
if ( empty( $license ) ) {
240-
return;
241-
}
242-
243-
// Call the custom API.
244-
$response = \wp_remote_post(
245-
\progress_planner()->get_remote_server_root_url(),
246-
[
247-
'timeout' => 15,
248-
'sslverify' => false,
249-
'body' => [
250-
'edd_action' => 'activate_license',
251-
'license' => $license,
252-
'item_id' => 1136,
253-
'item_name' => \rawurlencode( 'Progress Planner Pro' ),
254-
'url' => \home_url(),
255-
'environment' => \function_exists( 'wp_get_environment_type' ) ? \wp_get_environment_type() : 'production',
256-
],
257-
]
258-
);
259-
260-
// Make sure the response came back okay.
261-
if ( \is_wp_error( $response ) || 200 !== \wp_remote_retrieve_response_code( $response ) ) {
262-
if ( \is_wp_error( $response ) ) {
263-
\wp_send_json_error( $response->get_error_message() );
264-
}
265-
\wp_send_json_error( \esc_html__( 'An error occurred, please try again.', 'progress-planner' ) );
266-
}
267-
$license_data = \json_decode( \wp_remote_retrieve_body( $response ), true );
268-
if ( ! $license_data || ! \is_array( $license_data ) ) {
269-
\wp_send_json_error( \esc_html__( 'An error occurred, please try again.', 'progress-planner' ) );
270-
}
271-
272-
\update_option( 'progress_planner_pro_license_status', $license_data['license'] );
273-
274-
if ( true === $license_data['success'] ) {
275-
return;
276-
}
277-
278-
if ( false !== $license_data['success'] ) {
279-
\wp_send_json_error( \esc_html__( 'An error occurred, please try again.', 'progress-planner' ) );
280-
}
281-
282-
if ( ! isset( $license_data['error'] ) ) {
283-
\wp_send_json_error( \esc_html__( 'An error occurred, please try again.', 'progress-planner' ) );
284-
}
285-
286-
// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
287-
switch ( $license_data['error'] ) {
288-
case 'expired':
289-
\wp_send_json_error( \esc_html__( 'Your license key has expired.', 'progress-planner' ) );
290-
291-
case 'disabled':
292-
case 'revoked':
293-
\wp_send_json_error( \esc_html__( 'Your license key has been disabled.', 'progress-planner' ) );
294-
295-
case 'missing':
296-
\wp_send_json_error( \esc_html__( 'Invalid license.', 'progress-planner' ) );
297-
298-
case 'invalid':
299-
case 'site_inactive':
300-
\wp_send_json_error( \esc_html__( 'Your license is not active for this URL.', 'progress-planner' ) );
301-
302-
case 'item_name_mismatch':
303-
\wp_send_json_error(
304-
\sprintf(
305-
/* translators: the plugin name */
306-
\esc_html__( 'This appears to be an invalid license key for %s.', 'progress-planner' ),
307-
'Progress Planner Pro'
308-
)
309-
);
310-
311-
case 'no_activations_left':
312-
\wp_send_json_error( \esc_html__( 'Your license key has reached its activation limit.', 'progress-planner' ) );
313-
314-
default:
315-
\wp_send_json_error( \esc_html__( 'An error occurred, please try again.', 'progress-planner' ) );
316-
}
317-
// phpcs:enable
318-
}
319213
}

classes/admin/widgets/class-challenge.php

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ final class Challenge extends Widget {
2222
/**
2323
* Get the feed from the blog.
2424
*
25-
* @param bool $force_free Whether to force the free version.
26-
*
2725
* @return array
2826
*/
29-
public function get_challenge( $force_free = false ) {
30-
$cache_key = $this->get_cache_key( $force_free );
27+
public function get_challenge() {
28+
$cache_key = $this->get_cache_key();
3129
$feed_data = \progress_planner()->get_utils__cache()->get( $cache_key );
3230

3331
// Transient not set.
@@ -41,14 +39,9 @@ public function get_challenge( $force_free = false ) {
4139
// Transient expired, fetch new feed.
4240
if ( $feed_data['expires'] < \time() ) {
4341
// Get the feed using the REST API.
44-
$response = \wp_remote_get( $this->get_remote_api_url( $force_free ) );
42+
$response = \wp_remote_get( $this->get_remote_api_url() );
4543

4644
if ( 200 !== \wp_remote_retrieve_response_code( $response ) ) {
47-
// Fallback to free response if PRO but the license is invalid.
48-
if ( ! $force_free && \progress_planner()->is_pro_site() ) {
49-
return $this->get_challenge( true );
50-
}
51-
5245
// If we cant fetch the feed, we will try again later.
5346
$feed_data['expires'] = \time() + 5 * MINUTE_IN_SECONDS;
5447
} else {
@@ -83,33 +76,24 @@ public function render() {
8376
/**
8477
* Get the cache key.
8578
*
86-
* @param bool $force_free Whether to force the free version.
87-
*
8879
* @return string
8980
*/
90-
public function get_cache_key( $force_free = false ) {
91-
return \md5( $this->get_remote_api_url( $force_free ) );
81+
public function get_cache_key() {
82+
return \md5( $this->get_remote_api_url() );
9283
}
9384

9485
/**
9586
* Get the remote-API URL.
9687
*
97-
* @param bool $force_free Whether to force the free version.
98-
*
9988
* @return string
10089
*/
101-
public function get_remote_api_url( $force_free = false ) {
102-
$url = \progress_planner()->get_remote_server_root_url() . '/wp-json/progress-planner-saas/v1/challenges';
103-
$url = ( ! $force_free && \progress_planner()->is_pro_site() )
104-
? \add_query_arg(
105-
[
106-
'license_key' => \get_option( 'progress_planner_pro_license_key' ),
107-
'site' => \get_site_url(),
108-
],
109-
$url
110-
)
111-
: \add_query_arg( [ 'site' => \get_site_url() ], $url );
112-
113-
return $url;
90+
public function get_remote_api_url() {
91+
return \add_query_arg(
92+
[
93+
'license_key' => \get_option( 'progress_planner_license_key' ),
94+
'site' => \get_site_url(),
95+
],
96+
\progress_planner()->get_remote_server_root_url() . '/wp-json/progress-planner-saas/v1/challenges'
97+
);
11498
}
11599
}

classes/class-base.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ public function init() {
113113
$this->get_todo();
114114

115115
// Post-meta.
116-
if ( $this->is_pro_site() ) {
117-
$this->get_page_todos();
118-
}
116+
$this->get_page_todos();
119117

120118
\add_filter( 'plugin_action_links_' . \plugin_basename( PROGRESS_PLANNER_FILE ), [ $this, 'add_action_links' ] );
121119

@@ -433,16 +431,6 @@ public function is_local_site() {
433431
return false;
434432
}
435433

436-
/**
437-
* Check if this is a PRO site.
438-
*
439-
* @return bool
440-
*/
441-
public function is_pro_site() {
442-
return \get_option( 'progress_planner_pro_license_key' )
443-
&& 'valid' === \get_option( 'progress_planner_pro_license_status' );
444-
}
445-
446434
/**
447435
* Redirect on login.
448436
*

classes/class-lessons.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ public function get_items() {
3737
*/
3838
public function get_remote_api_items() {
3939
$url = \progress_planner()->get_remote_server_root_url() . '/wp-json/progress-planner-saas/v1/lessons';
40-
$url = ( \progress_planner()->is_pro_site() )
41-
? \add_query_arg(
42-
[
43-
'site' => \get_site_url(),
44-
'license_key' => \get_option( 'progress_planner_pro_license_key' ),
45-
],
46-
$url
47-
)
48-
: \add_query_arg( [ 'site' => \get_site_url() ], $url );
40+
$url = \add_query_arg(
41+
[
42+
'site' => \get_site_url(),
43+
'license_key' => \get_option( 'progress_planner_license_key' ),
44+
],
45+
$url
46+
);
4947

5048
$cache_key = \md5( $url );
5149

classes/class-plugin-installer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function is_plugin_activated( $plugin_slug ) {
259259
}
260260

261261
// If the is_plugin_active function does not exist, include the necessary file.
262-
if ( ! function_exists( 'is_plugin_active' ) ) {
262+
if ( ! \function_exists( 'is_plugin_active' ) ) {
263263
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore-line
264264
}
265265

@@ -281,7 +281,7 @@ private function get_plugin_path( $plugin_slug ) {
281281
}
282282

283283
// If the get_plugins function does not exist, include the necessary file.
284-
if ( ! function_exists( 'get_plugins' ) ) {
284+
if ( ! \function_exists( 'get_plugins' ) ) {
285285
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore-line
286286
}
287287

classes/rest/class-stats.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ public function get_stats() {
7272
* @return bool
7373
*/
7474
public function validate_token( $token ) {
75-
$token = \str_replace( 'token/', '', $token );
76-
if ( \progress_planner()->is_pro_site() && $token === \get_option( 'progress_planner_pro_license_key' ) ) {
77-
return true;
78-
}
75+
$token = \str_replace( 'token/', '', $token );
7976
$license_key = \get_option( 'progress_planner_license_key', false );
8077
if ( ! $license_key || 'no-license' === $license_key ) {
8178
return false;

0 commit comments

Comments
 (0)