PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.4 3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 All 262 releases
wpfunnels / packages / action-scheduler / classes / abstracts / ActionScheduler.php

ActionScheduler.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at packages/action-scheduler/classes/abstracts/ActionScheduler.php

313 lines 8.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Action_Scheduler\WP_CLI\Migration_Command;
4 use Action_Scheduler\Migration\Controller;
5
6 /**
7 * Class ActionScheduler
8 *
9 * @codeCoverageIgnore
10 */
11 abstract class ActionScheduler {
12 private static $plugin_file = '';
13 /**
14 * @var ActionScheduler_ActionFactory
15 */
16 private static $factory = NULL;
17 /**
18 * @var bool
19 */
20 private static $data_store_initialized = false;
21
22 public static function factory() {
23 if ( !isset(self::$factory) ) {
24 self::$factory = new ActionScheduler_ActionFactory();
25 }
26 return self::$factory;
27 }
28
29 public static function store() {
30 return ActionScheduler_Store::instance();
31 }
32
33 public static function lock() {
34 return ActionScheduler_Lock::instance();
35 }
36
37 public static function logger() {
38 return ActionScheduler_Logger::instance();
39 }
40
41 public static function runner() {
42 return ActionScheduler_QueueRunner::instance();
43 }
44
45 public static function admin_view() {
46 return ActionScheduler_AdminView::instance();
47 }
48
49 /**
50 * Get the absolute system path to the plugin directory, or a file therein
51 *
52 * @static
53 * @param string $path
54 * @return string
55 */
56 public static function plugin_path( $path ) {
57 $base = dirname(self::$plugin_file);
58 if ( $path ) {
59 return trailingslashit($base).$path;
60 } else {
61 return untrailingslashit($base);
62 }
63 }
64
65 /**
66 * Get the absolute URL to the plugin directory, or a file therein
67 *
68 * @static
69 * @param string $path
70 * @return string
71 */
72 public static function plugin_url( $path ) {
73 return plugins_url($path, self::$plugin_file);
74 }
75
76 public static function autoload( $class ) {
77 $d = DIRECTORY_SEPARATOR;
78 $classes_dir = self::plugin_path( 'classes' . $d );
79 $separator = strrpos( $class, '\\' );
80 if ( false !== $separator ) {
81 if ( 0 !== strpos( $class, 'Action_Scheduler' ) ) {
82 return;
83 }
84 $class = substr( $class, $separator + 1 );
85 }
86
87 if ( 'Deprecated' === substr( $class, -10 ) ) {
88 $dir = self::plugin_path( 'deprecated' . $d );
89 } elseif ( self::is_class_abstract( $class ) ) {
90 $dir = $classes_dir . 'abstracts' . $d;
91 } elseif ( self::is_class_migration( $class ) ) {
92 $dir = $classes_dir . 'migration' . $d;
93 } elseif ( 'Schedule' === substr( $class, -8 ) ) {
94 $dir = $classes_dir . 'schedules' . $d;
95 } elseif ( 'Action' === substr( $class, -6 ) ) {
96 $dir = $classes_dir . 'actions' . $d;
97 } elseif ( 'Schema' === substr( $class, -6 ) ) {
98 $dir = $classes_dir . 'schema' . $d;
99 } elseif ( strpos( $class, 'ActionScheduler' ) === 0 ) {
100 $segments = explode( '_', $class );
101 $type = isset( $segments[ 1 ] ) ? $segments[ 1 ] : '';
102
103 switch ( $type ) {
104 case 'WPCLI':
105 $dir = $classes_dir . 'WP_CLI' . $d;
106 break;
107 case 'DBLogger':
108 case 'DBStore':
109 case 'HybridStore':
110 case 'wpPostStore':
111 case 'wpCommentLogger':
112 $dir = $classes_dir . 'data-stores' . $d;
113 break;
114 default:
115 $dir = $classes_dir;
116 break;
117 }
118 } elseif ( self::is_class_cli( $class ) ) {
119 $dir = $classes_dir . 'WP_CLI' . $d;
120 } elseif ( strpos( $class, 'CronExpression' ) === 0 ) {
121 $dir = self::plugin_path( 'lib' . $d . 'cron-expression' . $d );
122 } elseif ( strpos( $class, 'WP_Async_Request' ) === 0 ) {
123 $dir = self::plugin_path( 'lib' . $d );
124 } else {
125 return;
126 }
127
128 if ( file_exists( "{$dir}{$class}.php" ) ) {
129 include( "{$dir}{$class}.php" );
130 return;
131 }
132 }
133
134 /**
135 * Initialize the plugin
136 *
137 * @static
138 * @param string $plugin_file
139 */
140 public static function init( $plugin_file ) {
141 self::$plugin_file = $plugin_file;
142 spl_autoload_register( array( __CLASS__, 'autoload' ) );
143
144 /**
145 * Fires in the early stages of Action Scheduler init hook.
146 */
147 do_action( 'action_scheduler_pre_init' );
148
149 require_once( self::plugin_path( 'functions.php' ) );
150 ActionScheduler_DataController::init();
151
152 $store = self::store();
153 $logger = self::logger();
154 $runner = self::runner();
155 $admin_view = self::admin_view();
156
157 // Ensure initialization on plugin activation.
158 if ( ! did_action( 'init' ) ) {
159 add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init()
160 add_action( 'init', array( $store, 'init' ), 1, 0 );
161 add_action( 'init', array( $logger, 'init' ), 1, 0 );
162 add_action( 'init', array( $runner, 'init' ), 1, 0 );
163 } else {
164 $admin_view->init();
165 $store->init();
166 $logger->init();
167 $runner->init();
168 }
169
170 if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) {
171 require_once( self::plugin_path( 'deprecated/functions.php' ) );
172 }
173
174 if ( defined( 'WP_CLI' ) && WP_CLI ) {
175 WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' );
176 if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) {
177 $command = new Migration_Command();
178 $command->register();
179 }
180 }
181
182 self::$data_store_initialized = true;
183
184 /**
185 * Handle WP comment cleanup after migration.
186 */
187 if ( is_a( $logger, 'ActionScheduler_DBLogger' ) && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs() ) {
188 ActionScheduler_WPCommentCleaner::init();
189 }
190
191 add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' );
192 }
193
194 /**
195 * Check whether the AS data store has been initialized.
196 *
197 * @param string $function_name The name of the function being called. Optional. Default `null`.
198 * @return bool
199 */
200 public static function is_initialized( $function_name = null ) {
201 if ( ! self::$data_store_initialized && ! empty( $function_name ) ) {
202 $message = sprintf( __( '%s() was called before the Action Scheduler data store was initialized', 'woocommerce' ), esc_attr( $function_name ) );
203 }
204
205 return self::$data_store_initialized;
206 }
207
208 /**
209 * Determine if the class is one of our abstract classes.
210 *
211 * @since 3.0.0
212 *
213 * @param string $class The class name.
214 *
215 * @return bool
216 */
217 protected static function is_class_abstract( $class ) {
218 static $abstracts = array(
219 'ActionScheduler' => true,
220 'ActionScheduler_Abstract_ListTable' => true,
221 'ActionScheduler_Abstract_QueueRunner' => true,
222 'ActionScheduler_Abstract_Schedule' => true,
223 'ActionScheduler_Abstract_RecurringSchedule' => true,
224 'ActionScheduler_Lock' => true,
225 'ActionScheduler_Logger' => true,
226 'ActionScheduler_Abstract_Schema' => true,
227 'ActionScheduler_Store' => true,
228 'ActionScheduler_TimezoneHelper' => true,
229 );
230
231 return isset( $abstracts[ $class ] ) && $abstracts[ $class ];
232 }
233
234 /**
235 * Determine if the class is one of our migration classes.
236 *
237 * @since 3.0.0
238 *
239 * @param string $class The class name.
240 *
241 * @return bool
242 */
243 protected static function is_class_migration( $class ) {
244 static $migration_segments = array(
245 'ActionMigrator' => true,
246 'BatchFetcher' => true,
247 'DBStoreMigrator' => true,
248 'DryRun' => true,
249 'LogMigrator' => true,
250 'Config' => true,
251 'Controller' => true,
252 'Runner' => true,
253 'Scheduler' => true,
254 );
255
256 $segments = explode( '_', $class );
257 $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class;
258
259 return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ];
260 }
261
262 /**
263 * Determine if the class is one of our WP CLI classes.
264 *
265 * @since 3.0.0
266 *
267 * @param string $class The class name.
268 *
269 * @return bool
270 */
271 protected static function is_class_cli( $class ) {
272 static $cli_segments = array(
273 'QueueRunner' => true,
274 'Command' => true,
275 'ProgressBar' => true,
276 );
277
278 $segments = explode( '_', $class );
279 $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class;
280
281 return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ];
282 }
283
284 final public function __clone() {
285 trigger_error("Singleton. No cloning allowed!", E_USER_ERROR);
286 }
287
288 final public function __wakeup() {
289 trigger_error("Singleton. No serialization allowed!", E_USER_ERROR);
290 }
291
292 final private function __construct() {}
293
294 /**
295 * Deprecated
296 **/
297
298 public static function get_datetime_object( $when = null, $timezone = 'UTC' ) {
299 _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' );
300 return as_get_datetime_object( $when, $timezone );
301 }
302
303 /**
304 * Issue deprecated warning if an Action Scheduler function is called in the shutdown hook.
305 *
306 * @param string $function_name The name of the function being called.
307 * @deprecated 3.1.6.
308 */
309 public static function check_shutdown_hook( $function_name ) {
310 _deprecated_function( __FUNCTION__, '3.1.6' );
311 }
312 }
313