Skip to content

Commit 1a3d1a6

Browse files
committed
Merge branch 'develop' into direct_links_support
2 parents 44f3dea + 30e5769 commit 1a3d1a6

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/Cron.php

Lines changed: 7 additions & 0 deletions
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/Plugin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ final class Plugin {
1616
* @return void
1717
*/
1818
public function register() {
19+
$this->setup();
20+
1921
// Register services used throughout the plugin. (WP Rocket runs at priority 10)
2022
add_action( 'plugins_loaded', [ $this, 'register_services' ], 9 );
2123

2224
// Load text domain.
2325
add_action( 'init', [ $this, 'load_plugin_textdomain' ], 1000 );
2426
}
2527

28+
public function setup() {
29+
new Setup();
30+
}
31+
2632
/**
2733
* Registers the individual services of the plugin.
2834
*
@@ -47,7 +53,6 @@ public function register_services() {
4753
new Compatibility();
4854
new Filters();
4955
new Proxy();
50-
new Setup();
5156
}
5257

5358
/**

src/Setup.php

Lines changed: 5 additions & 12 deletions
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)