Skip to content

Commit 6ceaf40

Browse files
committed
Minor re-factor to Cron label.
1 parent 9cfa977 commit 6ceaf40

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/Cron.php

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
use Exception;
1414

1515
class Cron {
16+
/**
17+
* Cron job handle
18+
*
19+
* @var string
20+
*/
21+
const TASK_NAME = 'plausible_analytics_update_js';
22+
1623
/**
1724
* Build class
1825
*

src/Setup.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
namespace Plausible\Analytics\WP;
1111

1212
class Setup {
13-
/**
14-
* Cron job handle
15-
*
16-
* @var string
17-
*/
18-
private $cron = 'plausible_analytics_update_js';
19-
2013
/**
2114
* Filters and Hooks.
2215
*
@@ -28,7 +21,7 @@ public function __construct() {
2821
register_deactivation_hook( PLAUSIBLE_ANALYTICS_PLUGIN_FILE, [ $this, 'deactivate_cron' ] );
2922

3023
// Attach the cron script to the cron action.
31-
add_action( $this->cron, [ $this, 'load_cron_script' ] );
24+
add_action( Cron::TASK_NAME, [ $this, 'load_cron_script' ] );
3225

3326
// This assures that the local file is downloaded/updated when settings are saved.
3427
add_action( 'plausible_analytics_settings_saved', [ $this, 'load_cron_script' ] );
@@ -51,8 +44,8 @@ public function create_cache_dir() {
5144
* @codeCoverageIgnore
5245
*/
5346
public function activate_cron() {
54-
if ( ! wp_next_scheduled( $this->cron ) ) {
55-
wp_schedule_event( time(), 'daily', $this->cron );
47+
if ( ! wp_next_scheduled( Cron::TASK_NAME ) ) {
48+
wp_schedule_event( time(), 'daily', Cron::TASK_NAME );
5649
}
5750
}
5851

@@ -62,8 +55,8 @@ public function activate_cron() {
6255
* @codeCoverageIgnore
6356
*/
6457
public function deactivate_cron() {
65-
if ( wp_next_scheduled( $this->cron ) ) {
66-
wp_clear_scheduled_hook( $this->cron );
58+
if ( wp_next_scheduled( Cron::TASK_NAME ) ) {
59+
wp_clear_scheduled_hook( Cron::TASK_NAME );
6760
}
6861
}
6962

0 commit comments

Comments
 (0)