/var/www/html_uk/wp-content/plugins/automatewoo/includes/AutomateWoo.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<?php

use AutomateWoo\ActionScheduler\ActionScheduler;
use 
AutomateWoo\ActionScheduler\ActionSchedulerInterface;
use 
AutomateWoo\ActionScheduler\AW_AsyncRequest_QueueRunner;
use 
AutomateWoo\Addons;
use 
AutomateWoo\ActionScheduler\AsyncActionRunner;
use 
AutomateWoo\Proxies\Bookings as BookingsProxy;
use 
AutomateWoo\Frontend_Endpoints\Login_Redirect;
use 
AutomateWoo\Jobs\JobRegistry;
use 
AutomateWoo\Jobs\JobService;
use 
AutomateWoo\Options;
use 
AutomateWoo\OptionsStore;
use 
AutomateWoo\Tools\ToolsService;
use 
AutomateWoo\Usage_Tracking\Initializer as UsageTrackingInitializer;
use 
AutomateWoo\Workflows\Presets\PresetService;
use 
AutomateWoo\Workflows\Presets\Storage\PHPFileStorage;
use 
AutomateWoo\Workflows\Presets\Parser\PresetParser;
use 
ActionScheduler as ActionSchedulerCore;

defined'ABSPATH' ) || exit;

/**
 * AutomateWoo plugin singleton.
 *
 * @class   AutomateWoo
 * @package AutomateWoo
 */
final class AutomateWoo extends AutomateWoo_Legacy {

    
/**
     * The plugin version.
     *
     * @var string
     */
    
public $version;

    
/**
     * The plugin slug 'automatewoo'.
     *
     * @var string
     */
    
public $plugin_slug;

    
/**
     * The plugin basename 'automatewoo/automatewoo.php'.
     *
     * @var string
     */
    
public $plugin_basename;

    
/**
     * The plugin website URL.
     *
     * @var string
     */
    
public $website_url 'https://automatewoo.com/';

    
/**
     * Order helper class.
     *
     * @var AutomateWoo\Order_Helper
     */
    
public $order_helper;

    
/**
     * Options class.
     *
     * @var AutomateWoo\Options
     */
    
private $options;

    
/**
     * ActionScheduler instance.
     *
     * @var ActionSchedulerInterface
     */
    
private $action_scheduler;

    
/**
     * PresetService class.
     *
     * @var PresetService
     */
    
private $preset_service;

    
/**
     * JobService class.
     *
     * @var JobService
     */
    
private $job_service;

    
/**
     * OptionsStore class.
     *
     * @var OptionsStore
     */
    
private $options_store;

    
/**
     * Tools registry class.
     *
     * @var ToolsService
     */
    
private $tools_service;

    
/**
     * Instance of singleton.
     *
     * @var AutomateWoo
     */
    
private static $instance null;

    
/**
     * Constructor
     */
    
private function __construct() {
        
$this->version         AUTOMATEWOO_VERSION;
        
$this->plugin_basename plugin_basenameAUTOMATEWOO_FILE );
        
$this->plugin_slug     AUTOMATEWOO_SLUG;
        require_once 
$this->path() . '/includes/helpers.php';
        
add_action'woocommerce_init', [ $this'init' ], 20 );
    }

    
/**
     * Init
     */
    
public function init() {
        
$this->includes();

        
AutomateWoo\Constants::init();
        
AutomateWoo\Post_Types::init();
        
AutomateWoo\Ajax::init();

        if ( 
$this->is_installed() ) {
            
// Todo: Remove in 6.2.0
            
AutomateWoo\Cron::init();
            ( new 
AutomateWoo\Rest_Api() )->init();
            
AutomateWoo\Session_Tracker::init();
            
AutomateWoo\Customers::init();
            ( new 
AutomateWoo\Orders\Observers\CustomerLastPurchasedDateUpdaterAW()->action_scheduler() ) )->register();
            ( new 
AutomateWoo\Orders\Observers\GuestMostRecentOrderUpdater() )->register();
        }

        
// legacy access to session tracker class
        
$this->session_tracker = new AutomateWoo\Session_Tracker();
        
$this->order_helper    = new AutomateWoo\Order_Helper();

        
do_action'automatewoo_init_addons' );

        
// Init all triggers
        // Actions don't load until required by admin interface or when a workflow runs
        
AutomateWoo\Triggers::init();

        if ( 
is_admin() ) {
            
$this->admin = new AutomateWoo\Admin();
            
AutomateWoo\Admin::init();
            
AutomateWoo\AdminNotices\WelcomeNoticeManager::init();
            
AutomateWoo\AdminNotices\UpdateNoticeManager::init();
            
AutomateWoo\AdminNotices\NewWorkflowHelperManager::init();
            ( new 
AutomateWoo\AdminNotices\WcAdminDisabled() )->init();

            foreach ( 
Addons::get_all() as $addon ) {
                ( new 
AutomateWoo\AdminNotices\AddonWelcome$addon ) )->init();
            }

            if ( 
WC()->is_wc_admin_active() ) {
                
AutomateWoo\ActivityPanelInbox\UpdateNote::init();
                ( new 
AutomateWoo\ActivityPanelInbox\SubscriptionsAddonDeactivatedNote() )->init();
            }

            
AutomateWoo\Installer::init();
        }

        
do_action'automatewoo_init' );

        
AutomateWoo\Event_Helpers\User_Registration::init();
        
AutomateWoo\Event_Helpers\Review_Posted::init();

        if ( 
AutomateWoo\Integrations::is_subscriptions_active() ) {
            
AutomateWoo\Event_Helpers\Subscription_Status_Changed::init();
        }

        if ( 
AutomateWoo\Integrations::is_mailpoet_api_active() ) {
            
AutomateWoo\Integrations::mailpoet()->init_hooks();
        }

        
AutomateWoo\Active_Triggers_Cache::init();
        
AutomateWoo\Async_Events::init_required_events();

        ( new 
AutomateWoo\Notifications\NotificationsInitializerAW()->action_scheduler() ) )->init();

        
/**
         * Check if Points and Rewards is active
         *
         * @since 4.5.0
         */
        
if ( AutomateWoo\Integrations::is_points_rewards_active() ) {
            new 
\AutomateWoo\Points_Rewards_Integration();
        }

        if ( 
$this->is_request'ajax' ) || $this->is_request'cron' ) || ( defined'WP_CLI' ) && WP_CLI ) || is_admin() ) {
            
// Load all background processes
            
$this->job_service()->init_jobs();
        }

        if ( 
$this->is_request'frontend' ) ) {
            ( new 
Login_Redirect() )->init();
        }

        
// Load the usage tracker.
        
UsageTrackingInitializer::init();

        if ( 
AutomateWoo\Options::abandoned_cart_enabled() ) {
            
AutomateWoo\Carts::init();
        }

        
AutomateWoo\Communication_Account_Tab::init();
        
AutomateWoo\Workflows::init();

        if ( 
$this->is_installed() ) {
            
AutomateWoo\Hooks::init();
        }

        new 
AutomateWoo\Privacy();
        ( new 
\AutomateWoo\LegacyAddonHandler() )->init();

        
/**
         * Check if WooCommerce blocks are active and if the opt-in checkbox should be displayed during checkout.
         *
         * @since 5.6.0
         */
        
if ( \AutomateWoo\Integrations::is_woocommerce_blocks_active() && Options::optin_enabled() && ( is_admin() || Options::checkout_optin_enabled() ) ) {
            new 
\AutomateWoo\WooCommerce_Blocks_Integration();
        }

        
/**
         * Check if WooCommerce Payments is active
         *
         * @since 5.5.12
         */
        
if ( class_exists'\WC_Payments' ) ) {
            new 
\AutomateWoo\WooCommerce_Payments_Integration();
        }

        
do_action'automatewoo_loaded' );
    }

    
/**
     * File includes.
     */
    
public function includes() {
        require_once 
$this->path() . '/includes/customer-functions.php';
        require_once 
$this->path() . '/includes/product-functions.php';

        if ( ! 
class_exists'Easy_User_Tags' ) ) {
            new 
AutomateWoo\User_Tags();
        }
    }

    
/**
     * Plugin options.
     *
     * @return AutomateWoo\Options
     */
    
public function options() {
        if ( ! isset( 
$this->options ) ) {
            
$this->options = new AutomateWoo\Options();
        }
        return 
$this->options;
    }

    
/**
     * What type of request is this?
     *
     * @param string $type Ajax, frontend or admin.
     *
     * @return bool
     */
    
public function is_request$type ) {
        switch ( 
$type ) {
            case 
'admin':
                return 
is_admin();
            case 
'ajax':
                return 
defined'DOING_AJAX' );
            case 
'cron':
                return 
defined'DOING_CRON' );
            case 
'frontend':
                return ( ! 
is_admin() || defined'DOING_AJAX' ) ) && ! defined'DOING_CRON' ) && ! $this->is_rest_api_request();
        }
        return 
false;
    }


    
/**
     * Returns true if the request is a non-legacy REST API request.
     *
     * Legacy REST requests should still run some extra code for backwards compatibility.
     *
     * Copy of \WooCommerce::is_rest_api_request() which was added around 3.6
     *
     * @since 4.5.4
     *
     * @todo: replace this function once core WP function is available: https://core.trac.wordpress.org/ticket/42061.
     *
     * @return bool
     */
    
public function is_rest_api_request() {
        if ( empty( 
$_SERVER['REQUEST_URI'] ) ) {
            return 
false;
        }

        
$rest_prefix         trailingslashitrest_get_url_prefix() );
        
$is_rest_api_request = ( false !== strpos$_SERVER['REQUEST_URI'], $rest_prefix ) ); // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

        
return apply_filters'woocommerce_is_rest_api_request'$is_rest_api_request );
    }

    
/**
     * Get the URL to something in the plugin dir.
     *
     * @param string $end End of the URL.
     *
     * @return string
     */
    
public function url$end '' ) {
        return 
untrailingslashitplugin_dir_url$this->plugin_basename ) ) . $end;
    }

    
/**
     * Get the URL to something in the plugin admin assets dir.
     *
     * @param string $end End of the URL.
     *
     * @return string
     */
    
public function admin_assets_url$end '' ) {
        return 
$this->url'/admin/assets' $end );
    }

    
/**
     * Get the path to something in the plugin dir.
     *
     * @param string $end End of the path.
     *
     * @return string
     */
    
public function path$end '' ) {
        return 
untrailingslashitdirnameAUTOMATEWOO_FILE ) ) . $end;
    }

    
/**
     * Get the path to something in the plugin admin dir.
     *
     * @param string $end End of the path.
     *
     * @return string
     */
    
public function admin_path$end '' ) {
        return 
$this->path'/admin' $end );
    }

    
/**
     * Return true if AutomateWoo is installed.
     *
     * @since 4.9.2
     *
     * @return bool
     */
    
public function is_installed() {
        
// The database version is only added after install is complete
        
return (bool) Options::database_version();
    }

    
/**
     * Get ActionScheduler.
     *
     * @return ActionSchedulerInterface
     */
    
public function action_scheduler() {
        if ( ! isset( 
$this->action_scheduler ) ) {
            
$async_runner           = new AsyncActionRunner(
                new 
AW_AsyncRequest_QueueRunnerActionSchedulerCore::store() ),
                
ActionSchedulerCore::lock()
            );
            
$this->action_scheduler = new ActionScheduler$async_runner );
        }
        return 
$this->action_scheduler;
    }

    
/**
     * Returns the PresetService
     *
     * @return PresetService
     */
    
public function preset_service() {
        if ( ! isset( 
$this->preset_service ) ) {
            
$preset_storage       = new PHPFileStorage$this->path'/presets' ) );
            
$preset_parser        = new PresetParser();
            
$this->preset_service = new PresetService$preset_storage$preset_parser );
        }

        return 
$this->preset_service;
    }

    
/**
     * Get job service class.
     *
     * @return JobService
     */
    
public function job_service() {
        if ( ! isset( 
$this->job_service ) ) {
            
$job_registry      = new JobRegistry(
                
$this->action_scheduler(),
                
$this->options_store(),
                
$this->tools_service()
            );
            
$this->job_service = new JobService$job_registry );
        }

        return 
$this->job_service;
    }

    
/**
     * Get job service class.
     *
     * @return OptionsStore
     */
    
public function options_store() {
        if ( ! isset( 
$this->options_store ) ) {
            
$this->options_store = new OptionsStore();
        }

        return 
$this->options_store;
    }

    
/**
     * Get tools registry class.
     *
     * @return ToolsService
     */
    
public function tools_service() {
        if ( ! isset( 
$this->tools_service ) ) {
            
$this->tools_service = new ToolsService$this->options_store() );
        }

        return 
$this->tools_service;
    }

    
/**
     * Get bookings proxy class.
     *
     * @return BookingsProxy
     */
    
public function bookings_proxy(): BookingsProxy {
        return new 
BookingsProxy();
    }

    
/**
     * Return the singleton instance.
     *
     * @return AutomateWoo
     */
    
public static function instance() {
        if ( 
is_nullself::$instance ) ) {
            
self::$instance = new self();
        }
        return 
self::$instance;
    }
}

// phpcs:disable WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed

/**
 * For backwards compatible.
 *
 * @deprecated
 *
 * @return AutomateWoo
 */
function AutomateWoo() {
    
wc_deprecated_function__FUNCTION__'5.2.0''AW' );

    return 
AW();
}

/**
 * Access the plugin singleton with this.
 *
 * @return AutomateWoo
 */
function AW() {
    return 
AutomateWoo::instance();
}