forked from WPCloudDeploy/wp-cloud-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpcd.php
796 lines (680 loc) · 35.9 KB
/
wpcd.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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
<?php
/**
Plugin Name: WPCloudDeploy
Plugin URI: https://wpclouddeploy.com
Description: Deploy and manage cloud servers and apps from inside the WordPress Admin dashboard.
Version: 4.16.7
Requires at least: 5.4
Requires PHP: 7.4
Item Id: 1493
Author: WPCloudDeploy
Author URI: https://wpclouddeploy.com
Domain Path: /languages
*/
require_once ABSPATH . 'wp-admin/includes/plugin.php';
/**
* Class WPCD_Init.
*/
class WPCD_Init {
/**
* Construct function.
*/
public function __construct() {
$plugin_data = get_plugin_data( __FILE__ );
$extra_plugin_data = get_file_data( __FILE__, array( 'ItemId' => 'Item Id' ) );
if ( ! defined( 'wpcd_url' ) ) {
// Deprecated constants - lowercased.
define( 'wpcd_url', plugin_dir_url( __FILE__ ) );
define( 'wpcd_path', plugin_dir_path( __FILE__ ) );
define( 'wpcd_root', dirname( plugin_basename( __FILE__ ) ) );
define( 'wpcd_plugin', plugin_basename( __FILE__ ) );
define( 'wpcd_extension', $plugin_data['Name'] );
define( 'wpcd_version', $plugin_data['Version'] );
define( 'wpcd_textdomain', 'wpcd' );
define( 'wpcd_requires', '2.0.3' );
define( 'wpcd_rest_version', '1' );
define( 'wpcd_db_version', '1' );
// Redefine again as upper-case since we're going to be moving all constants to uppercase going forward.
// Note that there are additional constants here vs above since we added new ones. But we're only
// adding new UPPERCASE ones.
define( 'WPCD_URL', plugin_dir_url( __FILE__ ) );
define( 'WPCD_PATH', plugin_dir_path( __FILE__ ) );
define( 'WPCD_ROOT', dirname( plugin_basename( __FILE__ ) ) );
define( 'WPCD_PLUGIN', plugin_basename( __FILE__ ) );
define( 'WPCD_BASE_FILE', __FILE__ );
define( 'WPCD_EXTENSION', $plugin_data['Name'] );
define( 'WPCD_VERSION', $plugin_data['Version'] );
define( 'WPCD_ITEM_ID', $extra_plugin_data['ItemId'] );
define( 'WPCD_TEXTDOMAIN', 'wpcd' );
define( 'WPCD_REQUIRES', '2.0.3' );
define( 'WPCD_REST_VERSION', '1' );
define( 'WPCD_DB_VERSION', '1' );
// Define the default brand colors.
define( 'WPCD_PRIMARY_BRAND_COLOR', '#E91E63' );
define( 'WPCD_SECONDARY_BRAND_COLOR', '#FF5722' );
define( 'WPCD_TERTIARY_BRAND_COLOR', '#03114A' );
define( 'WPCD_ACCENT_BG_COLOR', '#3F4C5F' );
define( 'WPCD_MEDIUM_BG_COLOR', '#FAFAFA' );
define( 'WPCD_LIGHT_BG_COLOR', '#FDFDFD' );
define( 'WPCD_ALTERNATE_ACCENT_BG_COLOR', '#CFD8DC' );
// Define a variable that can be used for versioning scripts - required to force multisite to use different version numbers for each site.
if ( is_multisite() ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
define( 'wpcd_scripts_version', (string) get_current_blog_id() . '_' . (string) time() );
define( 'WPCD_SCRIPTS_VERSION', (string) get_current_blog_id() . '_' . (string) time() );
} else {
define( 'wpcd_scripts_version', (string) get_current_blog_id() . '_' . (string) wpcd_version );
define( 'WPCD_SCRIPTS_VERSION', (string) get_current_blog_id() . '_' . (string) wpcd_version );
}
} else {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
define( 'wpcd_scripts_version', (string) time() );
define( 'WPCD_SCRIPTS_VERSION', (string) time() );
} else {
define( 'wpcd_scripts_version', (string) wpcd_version );
define( 'WPCD_SCRIPTS_VERSION', (string) wpcd_version );
}
}
}
/* Use init hook to load up required files */
add_action( 'init', array( $this, 'required_files' ), -20 );
/* Use admin_init hook to run things that should only be run when the admin is logged in. */
add_action( 'admin_init', array( $this, 'admin_init' ) );
/* Create a custom schedule for 1 minute */
add_filter( 'cron_schedules', array( $this, 'custom_cron_schedule' ) );
/* Activation and deactivation hooks */
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
/* Show some notices as required */
add_action( 'admin_notices', array( $this, 'wpcd_global_admin_notice' ) );
/* Show documentation and quick-start links in the plugin list. */
add_filter( 'plugin_row_meta', array( $this, 'wpcd_append_support_and_faq_links' ), 10, 4 );
/* Attempt to get and show any upgrade notice for the next version of the plugin - @see https://wisdomplugin.com/add-inline-plugin-update-message/ */
add_action( 'in_plugin_update_message-wp-cloud-deploy/wpcd.php', array( $this, 'wpcd_plugin_update_message' ), 10, 2 );
/* Load languages files */
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
/* Send email to admin if critical crons aren't running. */
add_action( 'init', array( $this, 'send_email_for_absent_crons' ), 20 );
}
/**
* Create cron timers for use by other wpcd functions.
* Three timers - 1 min, 2 min and 15 min.
*
* @param Array $schedules schedules.
*/
public function custom_cron_schedule( $schedules ) {
// if this schedule is not already defined by someone else...
if ( ! isset( $schedules['every_minute'] ) ) {
$schedules['every_minute'] = array(
'interval' => MINUTE_IN_SECONDS,
'display' => __( 'Every minute', 'wpcd' ),
);
}
if ( ! isset( $schedules['every_two_minute'] ) ) {
$schedules['every_two_minute'] = array(
'interval' => 120,
'display' => __( 'Every 2 minutes', 'wpcd' ),
);
}
if ( ! isset( $schedules['every_fifteen_minute'] ) ) {
$schedules['every_fifteen_minute'] = array(
'interval' => 900,
'display' => __( 'Every 15 minutes', 'wpcd' ),
);
}
return $schedules;
}
/**
* Fires on activation of plugin.
*
* @param String $network_wide network_wide.
*/
public function activate( $network_wide ) {
require_once wpcd_path . 'includes/core/class-wpcd-base.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-base.php';
require_once wpcd_path . 'includes/core/apps/class-wpcd-app.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-permission-type.php';
require_once wpcd_path . 'includes/core/class-wpcd-dns.php';
require_once wpcd_path . 'includes/core/functions.php';
if ( defined( 'WPCD_LOAD_VPN_APP' ) && ( true === WPCD_LOAD_VPN_APP ) ) {
require_once wpcd_path . 'includes/core/apps/vpn/class-vpn-app.php';
}
if ( defined( 'WPCD_LOAD_BASIC_SERVER_APP' ) && ( true === WPCD_LOAD_BASIC_SERVER_APP ) ) {
require_once wpcd_path . 'includes/core/apps/basic-server/class-basic-server-app.php';
}
// @TODO: Have to make these static till autoloading is implemented
// @TODO: This is also poor because N crons will be registered for N providers even if only one provider is actually active and has credentials
if ( defined( 'WPCD_LOAD_VPN_APP' ) && ( true === WPCD_LOAD_VPN_APP ) ) {
WPCD_VPN_APP::activate( $network_wide );
}
if ( defined( 'WPCD_LOAD_BASIC_SERVER_APP' ) && ( true === WPCD_LOAD_BASIC_SERVER_APP ) ) {
WPCD_BASIC_SERVER_APP::activate( $network_wide );
}
$this->wpcd_load_wpapp_traits();
require_once wpcd_path . 'includes/core/apps/wordpress-app/class-wordpress-app.php';
WPCD_WORDPRESS_APP::activate( $network_wide );
WPCD_POSTS_PERMISSION_TYPE::activate( $network_wide );
require_once wpcd_path . 'includes/core/class-wpcd-sync.php';
WPCD_Sync::activate( $network_wide );
require_once wpcd_path . 'includes/core/class-wpcd-roles-capabilities.php';
WPCD_ROLES_CAPABILITIES::activate( $network_wide );
$this->wpcd_load_core_traits();
require_once wpcd_path . 'includes/core/class-wpcd-posts-app-server.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-app.php';
WPCD_POSTS_APP_SERVER::activate( $network_wide );
WPCD_POSTS_APP::activate( $network_wide );
require_once wpcd_path . 'includes/core/class-wpcd-posts-notify-user.php';
WPCD_NOTIFY_USER::activate( $network_wide );
if ( defined( 'WPCD_DISABLE_EMAIL_NOTIFICATIONS' ) && ( false === WPCD_DISABLE_EMAIL_NOTIFICATIONS ) ) {
require_once wpcd_path . 'includes/core/class-wpcd-email-notifications.php';
WPCD_EMAIL_NOTIFICATIONS::activate( $network_wide );
}
// Set transient for not showing the cron check message immediately as soon as plugin is activated.
// It will be shown after 2 minutes if crons are not scheduled and loaded.
set_transient( 'wpcd_loaded_timeout', 1, 2 * MINUTE_IN_SECONDS );
require_once wpcd_path . 'includes/core/class-wpcd-posts-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-pending-tasks-log.php';
WPCD_PENDING_TASKS_LOG::activate( $network_wide );
// Set cron for set some options that the Wisdom plugin will pick up.
if ( ! wp_next_scheduled( 'wpcd_wisdom_custom_options' ) ) {
wp_schedule_event( time(), 'twicedaily', 'wpcd_wisdom_custom_options' );
}
flush_rewrite_rules();
}
/**
* Fires on deactivation of plugin.
*
* @param String $network_wide network_wide.
*/
public function deactivate( $network_wide ) {
require_once wpcd_path . 'includes/core/apps/class-wpcd-app.php';
if ( defined( 'WPCD_LOAD_VPN_APP' ) && ( true === WPCD_LOAD_VPN_APP ) ) {
require_once wpcd_path . 'includes/core/apps/vpn/class-vpn-app.php';
}
if ( defined( 'WPCD_LOAD_BASIC_SERVER_APP' ) && ( true === WPCD_LOAD_BASIC_SERVER_APP ) ) {
require_once wpcd_path . 'includes/core/apps/basic-server/class-basic-server-app.php';
}
require_once wpcd_path . 'includes/core/apps/wordpress-app/class-wordpress-app.php';
if ( defined( 'WPCD_LOAD_VPN_APP' ) && ( true === WPCD_LOAD_VPN_APP ) ) {
WPCD_VPN_APP::deactivate( $network_wide );
}
if ( defined( 'WPCD_LOAD_BASIC_SERVER_APP' ) && ( true === WPCD_LOAD_BASIC_SERVER_APP ) ) {
WPCD_BASIC_SERVER_APP::deactivate( $network_wide );
}
WPCD_WORDPRESS_APP::deactivate( $network_wide );
require_once wpcd_path . 'includes/core/class-wpcd-sync.php';
WPCD_Sync::deactivate( $network_wide );
require_once wpcd_path . 'includes/core/class-wpcd-posts-notify-user.php';
WPCD_NOTIFY_USER::deactivate( $network_wide );
if ( wpcd_email_notifications_allowed() ) {
require_once wpcd_path . 'includes/core/class-wpcd-email-notifications.php';
WPCD_EMAIL_NOTIFICATIONS::deactivate( $network_wide );
}
require_once wpcd_path . 'includes/core/class-wpcd-posts-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-pending-tasks-log.php';
WPCD_PENDING_TASKS_LOG::deactivate( $network_wide );
// Clear old cron.
wp_unschedule_hook( 'wpcd_wisdom_custom_options' );
// Clear long-lived transients.
delete_transient( 'wpcd_wisdom_custom_options_first_run_done' );
}
/**
* Include additional files as needed
*/
public function required_files() {
/* These two files ensure that certain third party plugins are available - primarily METABOX.IO */
require_once wpcd_path . 'required_plugins/class-tgm-plugin-activation.php';
require_once wpcd_path . 'required_plugins/wpcd-required-plugins.php';
/* End ensure third party plugins are available */
/* Include the SETTINGS PAGE and other related metabox.io extension files */
require_once wpcd_path . 'required_plugins/mb-settings-page/mb-settings-page.php';
if ( is_admin() ) {
require_once wpcd_path . '/required_plugins/mb-admin-columns/mb-admin-columns.php';
require_once wpcd_path . '/required_plugins/meta-box-tabs/meta-box-tabs.php';
require_once wpcd_path . '/required_plugins/meta-box-tooltip/meta-box-tooltip.php';
require_once wpcd_path . '/required_plugins/mb-term-meta/mb-term-meta.php';
require_once wpcd_path . '/required_plugins/meta-box-columns/meta-box-columns.php';
require_once wpcd_path . '/required_plugins/meta-box-group/meta-box-group.php';
require_once wpcd_path . '/required_plugins/mb-user-meta/mb-user-meta.php';
}
/* Load up some licensing files. */
if ( true === is_admin() ) {
require_once WPCD_PATH . '/includes/vendor/WPCD_EDD_SL_Plugin_Updater.php';
require_once WPCD_PATH . '/includes/core/class-wpcd-license.php';
}
/* Load up our files */
require_once wpcd_path . 'includes/core/functions.php';
require_once wpcd_path . 'includes/core/class-wpcd-custom-fields.php';
require_once wpcd_path . 'includes/core/class-wpcd-roles-capabilities.php';
require_once wpcd_path . 'includes/core/class-wpcd-data-sync-rest.php';
require_once wpcd_path . 'includes/core/class-wpcd-server-statistics.php';
$this->wpcd_load_core_traits();
require_once wpcd_path . 'includes/core/class-wpcd-base.php';
require_once wpcd_path . 'includes/core/class-wpcd-dns.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-base.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-app.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-app-server.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-cloud-provider.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-notify-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-notify-user.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-notify-sent-log.php';
if ( wpcd_email_notifications_allowed() ) {
require_once wpcd_path . 'includes/core/class-wpcd-email-notifications.php';
}
require_once wpcd_path . 'includes/core/class-wpcd-posts-ssh-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-error-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-command-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-pending-tasks-log.php';
require_once wpcd_path . 'includes/core/class-wpcd-server.php';
require_once wpcd_path . 'includes/core/class-wpcd-settings.php';
if ( wpcd_data_sync_allowed() ) {
require_once wpcd_path . 'includes/core/class-wpcd-sync.php';
}
require_once wpcd_path . 'includes/core/class-wpcd-setup.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-team.php';
require_once wpcd_path . 'includes/core/class-wpcd-posts-permission-type.php';
require_once wpcd_path . 'includes/core/providers/class-cloud-provider-api.php';
require_once wpcd_path . 'includes/core/providers/class-digital-ocean-parent.php';
require_once wpcd_path . 'includes/core/providers/class-digital-ocean.php';
if ( defined( 'WPCD_LOAD_BACKUP_DO_PROVIDER' ) && ( true === WPCD_LOAD_BACKUP_DO_PROVIDER ) ) {
require_once wpcd_path . 'includes/core/providers/class-digital-ocean-alternate.php';
}
require_once wpcd_path . 'includes/core/providers/class-custom-server-parent.php';
require_once wpcd_path . 'includes/core/apps/class-wpcd-app.php';
require_once wpcd_path . 'includes/core/apps/class-wpcd-app-settings.php';
require_once wpcd_path . 'includes/core/apps/class-wpcd-ssh.php';
require_once wpcd_path . 'includes/core/apps/class-wpcd-woocommerce.php';
if ( is_admin() ) {
require_once wpcd_path . 'includes/core/functions-handle-admin-notices.php';
}
/**
* For the VPN App
*/
/* @TODO: Need to find a more dynamic way to load these by letting apps register themselves at the right time and having them load up their own files */
if ( defined( 'WPCD_LOAD_VPN_APP' ) && ( true === WPCD_LOAD_VPN_APP ) ) {
require_once wpcd_path . 'includes/core/apps/vpn/class-vpn-app.php';
require_once wpcd_path . 'includes/core/apps/vpn/class-vpn-app-settings.php';
require_once wpcd_path . 'includes/core/apps/vpn/class-vpn-ssh.php';
require_once wpcd_path . 'includes/core/apps/vpn/class-vpn-woocommerce.php';
}
/**
* For the BASIC SERVER App
*/
/* @TODO: Need to find a more dynamic way to load these by letting apps register themselves at the right time and having them load up their own files */
if ( defined( 'WPCD_LOAD_BASIC_SERVER_APP' ) && ( true === WPCD_LOAD_BASIC_SERVER_APP ) ) {
require_once wpcd_path . 'includes/core/apps/basic-server/class-basic-server-app.php';
require_once wpcd_path . 'includes/core/apps/basic-server/class-basic-server-app-settings.php';
require_once wpcd_path . 'includes/core/apps/basic-server/class-basic-server-ssh.php';
require_once wpcd_path . 'includes/core/apps/basic-server/class-basic-server-woocommerce.php';
}
/**
* For the WP App
*/
/* @TODO: Need to find a more dynamic way to load these by letting apps register themselves at the right time and having them load up their own files */
$this->wpcd_load_wpapp_traits();
require_once wpcd_path . 'includes/core/apps/wordpress-app/class-wordpress-app.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/class-wordpress-app-settings.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/class-wordpress-ssh.php';
require_once wpcd_path . 'includes/core/wp-cloud-deploy.php';
require_once wpcd_path . 'includes/core/class-wpcd-server.php';
require_once wpcd_path . 'includes/core/functions-classes.php';
/**
* Now fire up the main class
* The constructor should place
* a reference to itself inside the
* $GLOBAL variable.
*
* @TODO: There's likely a better way to do this - maybe an action hook such as plugins-loaded or init
* that calls the constructor function directly?
*/
$wpcd_throwaaway_var = new WP_CLOUD_DEPLOY();
}
/**
* Load CORE Trait Files
*/
public function wpcd_load_core_traits() {
require_once wpcd_path . 'includes/core/traits/get_set_post_type.php';
require_once wpcd_path . 'includes/core/traits/metaboxes_for_taxonomies_for_servers_and_apps.php';
require_once wpcd_path . 'includes/core/traits/metaboxes_for_teams_for_servers_and_apps.php';
require_once wpcd_path . 'includes/core/traits/metaboxes_for_labels_notes_for_servers_and_apps.php';
}
/**
* Load WP APP Trait Files
*/
public function wpcd_load_wpapp_traits() {
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/tabs-security.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/metaboxes-app.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/metaboxes-server.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/commands-and-logs.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/after-prepare-server.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/push-commands.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/admin-columns.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/backup.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/woocommerce_support.php';
require_once wpcd_path . 'includes/core/apps/wordpress-app/traits/traits-for-class-wordpress-app/upgrade.php';
}
/**
* Warn user of a number of issues that could affect the clean running of wpcd:
* 1. If encryption key in wp-config is not defined.
* 2. Permalink structure is incorrect.
* 3. Certain files cannot be read.
* 4. Certain crons are not running on a regular basis.
*/
public function wpcd_global_admin_notice() {
// Only show messages to admins.
if ( ! wpcd_is_admin() ) {
return;
}
if ( in_array( isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : '', array( '127.0.0.1', '::1' ), true ) ) {
if ( ! wpcd_get_early_option( 'hide-local-host-warning' ) ) {
$class = 'notice notice-error';
$message = __( '<strong>You cannot run the WPCloudDeploy plugin on a localhost server or a server that cannot be reached from the internet.</strong>', 'wpcd' );
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}
}
if ( ! defined( 'WPCD_ENCRYPTION_KEY' ) ) {
$class = 'notice notice-error is-dismissible';
/* translators: %s read more */
$message = sprintf( __( '<strong>WPCD_ENCRYPTION_KEY</strong> is not defined in wp-config.php. We STRONGLY recommend that you define an encryption key in that file so that your passwords and private ssh key data can be more securely stored in the database! In the meantime we have created a temporary key and stored it in your database. %s', 'wpcd' ), '<a href="https://wpclouddeploy.com/documentation/wpcloud-deploy-admin/wp-config-entries/" target=”_blank”>' . __( 'Read More', 'wpcd' ) . '</a>' );
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}
if ( defined( 'WPCD_ENCRYPTION_KEY' ) && ( 'your very long encryption key goes here' === WPCD_ENCRYPTION_KEY ) ) {
$class = 'notice notice-error is-dismissible';
/* translators: %s read more */
$message = sprintf( __( '<strong>WPCD_ENCRYPTION_KEY</strong> is defined in wp-config.php but is using the example key from our documentation. This is still insecure so we STRONGLY recommend that you set a new encryption key. %s', 'wpcd' ), '<a href="https://wpclouddeploy.com/documentation/wpcloud-deploy-admin/wp-config-entries/" target=”_blank”>' . __( 'Read More', 'wpcd' ) . '</a>' );
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}
// Check to make sure we're not using the default permalink structure.
$structure = get_option( 'permalink_structure' );
if ( empty( $structure ) ) {
// means that default structure is in use which is no good for callbacks.
$class = 'notice notice-error';
$message = __( 'Warning: WPCloudDeploy cannot use the WordPress default permalink. Please change the permalinks option to something other than <em>plain.</em> This can be done under the WordPress <strong>SETTINGS->Permalinks</strong> menu option.', 'wpcd' );
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}
$screen = get_current_screen();
$post_types = array( 'wpcd_app_server', 'wpcd_app', 'wpcd_team', 'wpcd_permission_type', 'wpcd_command_log', 'wpcd_ssh_log', 'wpcd_error_log', 'wpcd_pending_log' );
// Checks to see if "text files are readable" transient is set or not. If not set then show an admin notice.
if ( ! get_transient( 'wpcd_readable_check' ) && is_object( $screen ) && in_array( $screen->post_type, $post_types, true ) ) {
$class = 'notice notice-error is-dismissible wpcd-readability-check';
$message = __( '<strong>WPCD: Warning</strong> - The <em>includes/core/apps/wordpress-app/scripts/v1/raw/ </em> folder on your WordPress server does not allow text files to be read by browsers and other outside viewers. This folder contains the script files that we execute on your WordPress server. Please modify your web server configuration to allow .txt files in this folder to be readable. Otherwise, The WPCD plugin will not be able to manage your servers and sites. <br /><br /> Note that you CANNOT run this plugin on a local machine - it must be run on a server that is reachable from the public internet. <br /><br /> If you dismiss this message but do not resolve the issue, it will appear again in 12 hours. <br /><br /> <a href="" id="wpcd-check-again">Check Again</a>', 'wpcd' );
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}
// Make sure all our CRONS are running or, if not, that the user has seen and dismissed the warning notice.
$not_loaded_crons = $this->get_list_of_absent_crons();
// Checks to see if "cron check" transient is set or not. If not set then show an admin notice.
if ( ! get_transient( 'wpcd_loaded_timeout' ) && ! get_transient( 'wpcd_cron_check' ) && is_object( $screen ) && in_array( $screen->post_type, $post_types, true ) ) {
$class = 'notice notice-error is-dismissible wpcd-cron-check';
$not_loaded_crons = implode( ', ', $not_loaded_crons );
$message = __( '<strong>WPCD: Warning</strong> - ' . $not_loaded_crons . ' cron(s) are not running.', 'wpcd' );
printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
}
}
/**
* If critical crons aren't running, send email to admin.
*
* Action Hook: Init.
*/
public function send_email_for_absent_crons() {
// Exit if option to suppress sending these emails is turned on.
if ( true === (bool) wpcd_get_early_option( 'wpcd_do_not_send_cron_warning_emails' ) ) {
return;
}
// Get list of crons that aren't running.
$not_loaded_crons = $this->get_list_of_absent_crons();
// Send email to site administrator if we have some crons that are not running.
if ( ! empty( $not_loaded_crons ) ) {
$str_crons = implode( ', ', $not_loaded_crons );
$to = get_site_option( 'admin_email' );
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$subject = sprintf(
/* translators: %s: Site title. */
__( '[%s] - One or more critical crons are not running...', 'wpcd' ),
wp_specialchars_decode( get_option( 'blogname' ) )
);
$body = array();
$body[] = __( 'Hello Admin,', 'wpcd' );
$body[] = '';
$body[] = __( '<strong>WPCD: Warning</strong> - certain critical CRONS are not running on your site. Below are the ones that appear to be missing:', 'wpcd' );
$body[] = '';
$body[] = $str_crons;
$body[] = '';
$body[] = __( 'Before contacting support, please try to disable and renable the plugin to reactivate crons. Additionally, please verify that your WP CRON is firing every 1 minute - either from enough frequent site traffic or, better yet, from a native LINUX cron process.', 'wpcd' );
$body[] = '';
$body[] = __( '--------', 'wpcd' );
$body[] = '';
$body[] = __( 'If you do not want to receive these emails you can turn them off in the settings area under the MISC tab.', 'wpcd' );
$body[] = '';
$body[] = __( 'Thanks,', 'wpcd' );
$body[] = '';
$body[] = __( '- Your WP Management Dashboard BOT.', 'wpcd' );
// Apply filters to each var for the outgoing email.
$headers = apply_filters( 'wpcd_send_email_for_absent_crons_to', $headers );
$to = apply_filters( 'wpcd_send_email_for_absent_crons_to', $to );
$subject = apply_filters( 'wpcd_send_email_for_absent_crons_subject', $subject );
$body = apply_filters( 'wpcd_send_email_for_absent_crons_body', $body );
$email = array(
'to' => $to,
'subject' => $subject,
'body' => implode( "\n" . PHP_EOL . '<br />', $body ),
'headers' => $headers,
);
if ( defined( 'WPCD_CRONS_NOT_RUNNING_EMAIL_TEST' ) && WPCD_CRONS_NOT_RUNNING_EMAIL_TEST ) {
// When this constant is set, we're always going to send an email - useful for TESTING.
wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );
} else {
// Send an email every 8 hours. Start by getting the current date and time.
$current_datetime = gmdate( 'Y-m-d H:i:s' );
$str_current_datetime = strtotime( $current_datetime );
// Calculate the next date/time to send an alert email. The option wpcd_crons_not_running_email_next_send_date is where we store the next time we have to send an email if all our crons aren't running.
$next_email_send_date = get_option( 'wpcd_crons_not_running_email_next_send_date' );
$str_next_email_send_date = strtotime( $next_email_send_date );
if ( $str_current_datetime >= $str_next_email_send_date ) {
$next_send_time = gmdate( 'Y-m-d H:i:s', strtotime( '+8 hours' ) );
update_option( 'wpcd_crons_not_running_email_next_send_date', $next_send_time );
wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] );
}
}
}
}
/**
* Returns a list of critical crons that aren't running.
*
* Only returns the list if the user has not dismissed the notification at the top of the screen.
*/
public function get_list_of_absent_crons() {
$not_loaded_crons = array();
if ( ! get_transient( 'wpcd_cron_check' ) ) {
$wpcd_crons = array( 'do_deferred_actions_for_server', 'do_deferred_actions_for_app', 'wordpress_file_watcher_delete_temp_files', 'scan_new_notifications_to_send', 'clean_up_pending_logs' );
$wpcd_crons = apply_filters( 'wpcd_crons_needing_active_check', $wpcd_crons );
if ( defined( 'WPCD_LOAD_VPN_APP' ) && ( true === WPCD_LOAD_VPN_APP ) ) {
$wpcd_crons[] = 'file_watcher_delete_temp_files';
$wpcd_crons[] = 'do_deferred_actions_for_vpn';
}
if ( defined( 'WPCD_LOAD_BASIC_SERVER_APP' ) && ( true === WPCD_LOAD_BASIC_SERVER_APP ) ) {
$wpcd_crons[] = 'do_deferred_actions_for_basic_server';
}
foreach ( $wpcd_crons as $cron ) {
$cron_transient = "wpcd_{$cron}_is_active";
if ( ! get_transient( $cron_transient ) ) {
$not_loaded_crons[] = $cron;
}
}
// If empty means all crons are loaded properly, then set the transient so that we can recheck once per hour.
// This transient will also be set if the user dismisses the notice they get at the top of the screen.
// Here we will set it so that we'll recheck in 1 hour. If it gets set when the user dismisses the notice it will be set for 12 hours.
// See the function set_cron_check() in file class-wordpress-app.php.
if ( count( $not_loaded_crons ) === 0 ) {
set_transient( 'wpcd_cron_check', 1, 1 * HOUR_IN_SECONDS );
}
} else {
// Transient is set. But the time remaining can sometimes be negative. While we're not sure why that happens, if it is, delete it!
$time_left = (int) wpcd_get_transient_remaining_time_in_mins( 'wpcd_cron_check' );
if ( $time_left < 0 ) {
delete_transient( 'wpcd_cron_check' );
}
}
return $not_loaded_crons;
}
/**
* Filters the array of row meta for each/specific plugin in the Plugins list table.
* Appends additional links below each/specific plugin on the plugins page.
*
* Action Hook: plugin_row_meta
*
* @since 4.15.1
*
* @access public
* @param array $links_array An array of the plugin's metadata.
* @param string $plugin_file_name Path to the plugin file.
* @param array $plugin_data An array of plugin data.
* @param string $status Status of the plugin.
*
* @return array $links_array New links to be added to the plugin list.
*/
public function wpcd_append_support_and_faq_links( $links_array, $plugin_file_name, $plugin_data, $status ) {
if ( strpos( $plugin_file_name, basename( __FILE__ ) ) ) {
// You can still use `array_unshift()` to add links at the beginning.
$links_array[] = '<a href="https://wpclouddeploy.com/documentation/wpcloud-deploy/introduction-to-wpcloud-deploy/" target="_blank">Quick Start</a>';
$links_array[] = '<a href="https://wpclouddeploy.com/doc-landing/" target="_blank">Documentation</a>';
$links_array[] = '<a href="https://wpclouddeploy.com/documentation/wpcloud-deploy-admin/bootstrapping-a-wordpress-server-with-our-scripts/" target="_blank">Bootstrap Your Own Server</a>';
$settings_link = admin_url( 'edit.php?post_type=wpcd_app_server&page=wpcd_settings' );
$links_array[] = '<a href="' . $settings_link . '">Settings</a>';
$links_array[] = '<a href="https://wpclouddeploy.com/pricing/" target="_blank">Premium Options</a>';
$links_array[] = '<a href="https://wpclouddeploy.com/support/" target="_blank">Support</a>';
}
return $links_array;
}
/**
* Attempt to get and show any upgrade notice for the next version of the plugin.
*
* @see https://wisdomplugin.com/add-inline-plugin-update-message/
* @see https://developer.wordpress.org/reference/hooks/in_plugin_update_message-file/
*
* Action Hook: in_plugin_update_message-{$file} | in_plugin_update_message-wpcd/wpcd.php
*
* @since 4.15.1
*
* @param array $data The array of plugin metadata.
* @param object $response An object of metadata about the available plugin update.
*
* @return void
*/
public function wpcd_plugin_update_message( $data, $response ) {
if ( ! defined( 'WPCD_HIDE_CHANGELOG_IN_PLUGIN_LIST' ) || ( defined( 'WPCD_HIDE_CHANGELOG_IN_PLUGIN_LIST' ) && ! WPCD_HIDE_CHANGELOG_IN_PLUGIN_LIST ) ) {
if ( isset( $data['upgrade_notice'] ) ) {
printf(
'<div class="update-message">%s</div>',
wp_kses_post( wpautop( $data['upgrade_notice'] ) )
);
} else {
$release_notes = wpcd_get_string_between( $data['sections']->changelog, '<p>', '<p>' ); // Grab data between two paragraph tags - this gives us the raw release notes for the most recent release.
$release_notes = wpcd_get_string_between( $data['sections']->changelog, '<ul>', '</ul>' ); // Just grab the list and remove everthing above and below it.
$release_notes_link = '<br /><a href="https://wpclouddeploy.com/category/release-notes/" target="_blank">' . __( 'View friendly release notes to learn about any breaking changes that might affect you.', 'wpcd' ) . '</a>';
printf(
'<div class="update-message">%s</div>',
'<br />' . wp_kses_post( $release_notes ) . wp_kses_post( $release_notes_link )
);
}
}
}
/**
* Load the plugin text domain for translation.
*
* With the introduction of plugins language packs in WordPress loading the textdomain is slightly more complex.
*
* We now have 3 steps:
*
* 1. Check for the language pack in the WordPress core directory
* 2. Check for the translation file in the plugin's language directory
* 3. Fallback to loading the textdomain the classic way
*
* @since 2.8.0
* @return boolean True if the language file was loaded, false otherwise
*/
public function load_plugin_textdomain() {
$lang_dir = trailingslashit( wpcd_root ) . 'languages/';
$lang_path = trailingslashit( wpcd_path ) . 'languages/';
$locale = apply_filters( 'plugin_locale', get_locale(), 'wpcd' );
$mofile = "wpcd-$locale.mo";
$glotpress_file = WP_LANG_DIR . '/plugins/wpcd/' . $mofile;
// Look for the GlotPress language pack first of all.
if ( file_exists( $glotpress_file ) ) {
$language = load_textdomain( 'wpcd', $glotpress_file );
} elseif ( file_exists( $lang_path . $mofile ) ) {
$language = load_textdomain( 'wpcd', $lang_path . $mofile );
} else {
$language = load_plugin_textdomain( 'wpcd', false, $lang_dir );
}
return $language;
}
/**
* Activation hook
*
* ** Not currently called or used. Saving for later.
*/
public function activation_hook() {
// first install.
$version = get_option( 'wpcd_version' );
if ( ! $version ) {
update_option( 'wpcd_last_version_upgrade', wpcd_version );
}
if ( wpcd_version !== $version ) {
update_option( 'wpcd_version', wpcd_version );
}
// run setup.
if ( ! class_exists( 'WPCD_Setup' ) ) {
require_once wpcd_path . 'includes/core/class-wpcd-setup.php';
}
$wpcd_setup = new WPCD_Setup();
$wpcd_setup->run_setup();
}
/**
* Processes that run only when in the wp-admin area.
*
* Action Hook: admin_init
*/
public function admin_init() {
// Setup the Wisdom custom options on first run.
if ( function_exists( 'wpcd_start_plugin_tracking' ) ) {
if ( ! (bool) get_transient( 'wpcd_wisdom_custom_options_first_run_done' ) ) {
do_action( 'wpcd_wisdom_custom_options' ); // Trigger our custom calculations.
$wisdom = wpcd_start_plugin_tracking();
$wisdom->schedule_tracking(); // Setup the wisdom cron. Normally this is done automatically by the wisdom code upon plugin activation but we end up bypassing it because we delay things a bit so we can setup custom vars. So have to set it up manually.
set_transient( 'wpcd_wisdom_custom_options_first_run_done', 1, ( 60 * 24 * 7 ) * MINUTE_IN_SECONDS );
}
}
}
}
/**
* Get WPCD running.
*/
$wpcd_throwaway = new WPCD_Init();
/**
* Statistics Collection
*/
if ( ! class_exists( 'Plugin_Usage_Tracker' ) ) {
require_once dirname( __FILE__ ) . '/vendor/wisdom_plugin/class-plugin-usage-tracker.php';
}
if ( ! function_exists( 'wpcd_start_plugin_tracking' ) ) {
function wpcd_start_plugin_tracking() {
$wisdom = new Plugin_Usage_Tracker(
__FILE__,
'https://statistics.wpclouddeploy.com',
array( 'wisdom_opt_out', 'wisdom_wpcd_server_count', 'wisdom_wpcd_app_count' ),
false,
false,
3
);
return $wisdom;
}
// Start Wisdom but only if the custom options have been calculated at least once.
// The initial calculation only happens if the admin area has been accessed at least once after the plugin was activated.
// (See the admin_init() function in the main plugin class above.)
// After that the calculations occur on a cron hook.
// (See the function set_wisdom_custom_options() in file includes/core/wp-cloud-deploy.php)
if ( true === (bool) get_transient( 'wpcd_wisdom_custom_options_first_run_done' ) ) {
wpcd_start_plugin_tracking();
}
}