PluginProbe
IP Locator / trunk
IP Locator vtrunk
2.2.0 3.0.0 3.1.0 3.1.1 3.1.2 3.10.0 3.10.1 3.10.2 3.10.3 3.11.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.6.0 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.3.0 All 36 releases
ip-locator / includes / plugin / class-initializer.php

class-initializer.php in IP Locator trunk, at includes/plugin/class-initializer.php

91 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin initialization handling.
4 *
5 * @package Plugin
6 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
7 * @since 1.0.0
8 */
9
10 namespace IPLocator\Plugin;
11
12 use IPLocator\System\Cache;
13
14 use IPLocator\System\Option;
15
16 /**
17 * Fired after 'plugins_loaded' hook.
18 *
19 * This class defines all code necessary to run during the plugin's initialization.
20 *
21 * @package Plugin
22 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
23 * @since 1.0.0
24 */
25 class Initializer {
26
27 /**
28 * Initialize the class and set its properties.
29 *
30 * @since 1.0.0
31 */
32 public function __construct() {
33
34 }
35
36 /**
37 * Initialize the plugin.
38 *
39 * @since 1.0.0
40 */
41 public function initialize() {
42 \IPLocator\System\Sitehealth::init();
43 \IPLocator\System\APCu::init();
44 require_once IPLOCATOR_PLUGIN_DIR . 'includes/api/functions.php';
45 }
46
47 /**
48 * Initialize the plugin.
49 *
50 * @since 1.0.0
51 */
52 public function late_initialize() {
53 $this->action_schedule();
54 require_once IPLOCATOR_PLUGIN_DIR . 'perfopsone/init.php';
55 }
56
57 /**
58 * Initialize the shedulable actions.
59 *
60 * @since 1.0.0
61 */
62 public function action_schedule() {
63 add_action( 'ip-locator-update-v4', [ 'IPLocator\Plugin\Feature\IPData', 'update_v4' ], 10, 0 );
64 add_action( 'ip-locator-update-v6', [ 'IPLocator\Plugin\Feature\IPData', 'update_v6' ], 10, 0 );
65 if ( get_main_network_id() === get_current_blog_id() ) {
66 if ( false === as_next_scheduled_action( 'ip-locator-update-v4' ) && (bool) Option::network_get( 'autoupdate' ) ) {
67 $recur = IPLOCATOR_UPDATE_CYCLE * DAY_IN_SECONDS + random_int( -12, 12 ) * HOUR_IN_SECONDS + random_int( 1, 59 ) * MINUTE_IN_SECONDS;
68 as_schedule_recurring_action( time() + 20, $recur, 'ip-locator-update-v4', [], IPLOCATOR_SLUG );
69 }
70 if ( as_next_scheduled_action( 'ip-locator-update-v4' ) && ! (bool) Option::network_get( 'autoupdate' ) ) {
71 as_unschedule_all_actions( 'ip-locator-update-v4', [], IPLOCATOR_SLUG );
72 }
73 if ( false === as_next_scheduled_action( 'ip-locator-update-v6' ) && (bool) Option::network_get( 'autoupdate' ) ) {
74 $recur = IPLOCATOR_UPDATE_CYCLE * DAY_IN_SECONDS + random_int( -12, 12 ) * HOUR_IN_SECONDS + random_int( 1, 59 ) * MINUTE_IN_SECONDS;
75 as_schedule_recurring_action( time() + 20, $recur, 'ip-locator-update-v6', [], IPLOCATOR_SLUG );
76 }
77 if ( as_next_scheduled_action( 'ip-locator-update-v6' ) && ! (bool) Option::network_get( 'autoupdate' ) ) {
78 as_unschedule_all_actions( 'ip-locator-update-v6', [], IPLOCATOR_SLUG );
79 }
80 } else {
81 if ( as_next_scheduled_action( 'ip-locator-update-v4' ) ) {
82 as_unschedule_all_actions( 'ip-locator-update-v4', [], IPLOCATOR_SLUG );
83 }
84 if ( as_next_scheduled_action( 'ip-locator-update-v6' ) ) {
85 as_unschedule_all_actions( 'ip-locator-update-v6', [], IPLOCATOR_SLUG );
86 }
87 }
88 }
89
90 }
91