-
Notifications
You must be signed in to change notification settings - Fork 5
/
class.jetpack.php
6144 lines (5453 loc) · 202 KB
/
class.jetpack.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
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* The mega-class.
*
* This contains too much, so please think twice before adding more.
*
* @package automattic/jetpack
*/
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Boost_Speed_Score\Speed_Score;
use Automattic\Jetpack\Config;
use Automattic\Jetpack\Connection\Authorize_Json_Api;
use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Connection\Rest_Authentication as Connection_Rest_Authentication;
use Automattic\Jetpack\Connection\Secrets;
use Automattic\Jetpack\Connection\Tokens;
use Automattic\Jetpack\Connection\Webhooks\Authorize_Redirect;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\CookieState;
use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
use Automattic\Jetpack\Device_Detection\User_Agent_Info;
use Automattic\Jetpack\Errors;
use Automattic\Jetpack\Files;
use Automattic\Jetpack\Identity_Crisis;
use Automattic\Jetpack\Licensing;
use Automattic\Jetpack\Modules;
use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
use Automattic\Jetpack\Paths;
use Automattic\Jetpack\Plugin\Deprecate;
use Automattic\Jetpack\Plugin\Tracking as Plugin_Tracking;
use Automattic\Jetpack\Redirect;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
use Automattic\Jetpack\Status\Visitor;
use Automattic\Jetpack\Sync\Actions as Sync_Actions;
use Automattic\Jetpack\Sync\Health;
use Automattic\Jetpack\Sync\Sender;
use Automattic\Jetpack\Terms_Of_Service;
use Automattic\Jetpack\Tracking;
/*
Options:
jetpack_options (array)
An array of options.
@see Jetpack_Options::get_option_names()
jetpack_register (string)
Temporary verification secrets.
jetpack_activated (int)
1: the plugin was activated normally
2: the plugin was activated on this site because of a network-wide activation
3: the plugin was auto-installed
4: the plugin was manually disconnected (but is still installed)
jetpack_active_modules (array)
Array of active module slugs.
jetpack_do_activate (bool)
Flag for "activating" the plugin on sites where the activation hook never fired (auto-installs)
*/
require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.media.php';
/**
* The Jetpack class.
*/
class Jetpack {
/**
* XMLRPC server instance.
*
* @var null|Jetpack_XMLRPC_Server XMLRPC server used by Jetpack.
*/
public $xmlrpc_server = null;
/**
* Contains all assets that have had their URL rewritten to minified versions.
*
* @var array
*/
public static $min_assets = array();
/**
* Plugins to deactivate.
*
* @var array Plugins to deactivate by module.
*/
public $plugins_to_deactivate = array(
'contact-form' => array(
array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ),
array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ),
),
'gravatar-hovercards' => array(
array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ),
),
'latex' => array(
array( 'wp-latex/wp-latex.php', 'WP LaTeX' ),
),
'sharedaddy' => array(
array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ),
array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ),
),
'shortlinks' => array(
array( 'stats/stats.php', 'WordPress.com Stats' ),
),
'stats' => array(
array( 'stats/stats.php', 'WordPress.com Stats' ),
),
'twitter-widget' => array(
array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ),
),
'videopress' => array(
array( 'video/video.php', 'VideoPress' ),
),
'widget-visibility' => array(
array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ),
array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ),
),
);
/**
* Map of roles we care about, and their corresponding minimum capabilities.
*
* @deprecated 7.6 Use Automattic\Jetpack\Roles::$capability_translations instead.
*
* @access public
* @static
*
* @var array
*/
public static $capability_translations = array(
'administrator' => 'manage_options',
'editor' => 'edit_others_posts',
'author' => 'publish_posts',
'contributor' => 'edit_posts',
'subscriber' => 'read',
);
/**
* Map of modules that have conflicts with plugins and should not be auto-activated
* if the plugins are active. Used by filter_default_modules
*
* Plugin Authors: If you'd like to prevent a single module from auto-activating,
* change `module-slug` and add this to your plugin:
*
* add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' );
* function my_jetpack_get_default_modules( $modules ) {
* return array_diff( $modules, array( 'module-slug' ) );
* }
*
* @var array
*/
private $conflicting_plugins = array(
'comments' => array(
'Intense Debate' => 'intensedebate/intensedebate.php',
'Disqus' => 'disqus-comment-system/disqus.php',
'Livefyre' => 'livefyre-comments/livefyre.php',
'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php',
'Google+ Comments' => 'google-plus-comments/google-plus-comments.php',
'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php',
),
'comment-likes' => array(
'Epoch' => 'epoch/plugincore.php',
),
'latex' => array(
'LaTeX for WordPress' => 'latex/latex.php',
'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php',
'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php',
'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php',
'Enable Latex' => 'enable-latex/enable-latex.php',
'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php',
),
'protect' => array(
'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php',
'Captcha' => 'captcha/captcha.php',
'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php',
'Login Security Solution' => 'login-security-solution/login-security-solution.php',
'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php',
'BulletProof Security' => 'bulletproof-security/bulletproof-security.php',
'SiteGuard WP Plugin' => 'siteguard/siteguard.php',
'Security-protection' => 'security-protection/security-protection.php',
'Login Security' => 'login-security/login-security.php',
'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php',
'Wordfence Security' => 'wordfence/wordfence.php',
'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php',
'iThemes Security' => 'better-wp-security/better-wp-security.php',
),
'related-posts' => array(
'YARPP' => 'yet-another-related-posts-plugin/yarpp.php',
'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php',
'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php',
'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php',
'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php',
'outbrain' => 'outbrain/outbrain.php',
'Shareaholic' => 'shareaholic/shareaholic.php',
'Sexybookmarks' => 'sexybookmarks/shareaholic.php',
),
'sharedaddy' => array(
'AddThis' => 'addthis/addthis_social_widget.php',
'Add To Any' => 'add-to-any/add-to-any.php',
'ShareThis' => 'share-this/sharethis.php',
'Shareaholic' => 'shareaholic/shareaholic.php',
),
'seo-tools' => array(
'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php',
'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php',
'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php',
'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
'The SEO Framework' => 'autodescription/autodescription.php',
'Rank Math' => 'seo-by-rank-math/rank-math.php',
'Slim SEO' => 'slim-seo/slim-seo.php',
'SEOKEY' => 'seo-key/seo-key.php',
'SEOKEY Pro' => 'seo-key-pro/seo-key.php',
'SEOPress' => 'wp-seopress/seopress.php',
'SEOPress Pro' => 'wp-seopress-pro/seopress-pro.php',
),
'verification-tools' => array(
'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php',
'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php',
'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php',
'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
'The SEO Framework' => 'autodescription/autodescription.php',
'Rank Math' => 'seo-by-rank-math/rank-math.php',
'Slim SEO' => 'slim-seo/slim-seo.php',
),
'widget-visibility' => array(
'Widget Logic' => 'widget-logic/widget_logic.php',
'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php',
),
'sitemaps' => array(
'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php',
'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php',
'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php',
'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php',
'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php',
'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php',
'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php',
'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php',
'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
'The SEO Framework' => 'autodescription/autodescription.php',
'Sitemap' => 'sitemap/sitemap.php',
'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php',
'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php',
'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php',
'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php',
'Rank Math' => 'seo-by-rank-math/rank-math.php',
'Slim SEO' => 'slim-seo/slim-seo.php',
),
);
/**
* Plugins for which we turn off our Facebook OG Tags implementation.
*
* Note: the following plugins automatically deactivate Jetpack's Open
* Graph tags via filter when their Social Meta modules are active:
*
* - All in One SEO Pack, All in one SEO Pack Pro
* - WordPress SEO by Yoast, WordPress SEO Premium by Yoast
* - SEOPress, SEOPress Pro
*
* Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter:
* add_filter( 'jetpack_enable_open_graph', '__return_false' );
*
* @var array Array of plugin slugs.
*/
private $open_graph_conflicting_plugins = array(
'2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', // 2 Click Social Media Buttons.
'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook.
'add-meta-tags/add-meta-tags.php', // Add Meta Tags.
'complete-open-graph/complete-open-graph.php', // Complete Open Graph.
'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail.
'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', // Open Graph Meta Tags by Heateor.
'facebook/facebook.php', // Facebook (official plugin).
'facebook-awd/AWD_facebook.php', // Facebook AWD All in one.
'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', // Facebook Featured Image & OG Meta Tags.
'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags.
'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', // Facebook Open Graph Meta Tags for WordPress.
'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag.
'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer.
'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', // Fedmich's Facebook Open Graph Meta.
'network-publisher/networkpub.php', // Network Publisher.
'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG.
'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', // NextScripts SNAP.
'og-tags/og-tags.php', // OG Tags.
'opengraph/opengraph.php', // Open Graph.
'open-graph-protocol-framework/open-graph-protocol-framework.php', // Open Graph Protocol Framework.
'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments.
'seo-ultimate/seo-ultimate.php', // SEO Ultimate.
'sexybookmarks/sexy-bookmarks.php', // Shareaholic.
'shareaholic/sexy-bookmarks.php', // Shareaholic.
'sharepress/sharepress.php', // SharePress.
'simple-facebook-connect/sfc.php', // Simple Facebook Connect.
'social-discussions/social-discussions.php', // Social Discussions.
'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit.
'socialize/socialize.php', // Socialize.
'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™.
'only-tweet-like-share-and-google-1/tweet-like-plusone.php', // Tweet, Like, Google +1 and Share.
'wordbooker/wordbooker.php', // Wordbooker.
'wpsso/wpsso.php', // WordPress Social Sharing Optimization.
'wp-caregiver/wp-caregiver.php', // WP Caregiver.
'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', // WP Facebook Like Send & Open Graph Meta.
'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol.
'wp-ogp/wp-ogp.php', // WP-OGP.
'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin.
'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button.
'open-graph-metabox/open-graph-metabox.php', // Open Graph Metabox.
'seo-by-rank-math/rank-math.php', // Rank Math.
'slim-seo/slim-seo.php', // Slim SEO.
);
/**
* Plugins for which we turn off our Twitter Cards Tags implementation.
*
* @var array Plugins that conflict with Twitter cards.
*/
private $twitter_cards_conflicting_plugins = array(
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
// 'twitter/twitter.php', // The official one handles this on its own.
// https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php
'eewee-twitter-card/index.php', // Eewee Twitter Card.
'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards.
'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards.
'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', // Pure Web Brilliant's Social Graph Twitter Cards Extension.
'twitter-cards/twitter-cards.php', // Twitter Cards.
'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta.
'wp-to-twitter/wp-to-twitter.php', // WP to Twitter.
'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards.
'seo-by-rank-math/rank-math.php', // Rank Math.
'slim-seo/slim-seo.php', // Slim SEO.
);
/**
* Message to display in admin_notice
*
* @var string
*/
public $message = '';
/**
* Error to display in admin_notice
*
* @var string
*/
public $error = '';
/**
* Modules that need more privacy description.
*
* @var string
*/
public $privacy_checks = '';
/**
* Stats to record once the page loads
*
* @var array
*/
public $stats = array();
/**
* Jetpack_Sync object
*
* @todo This is also seemingly unused.
*
* @var object
*/
public $sync;
/**
* Verified data for JSON authorization request
*
* @deprecated 13.4
*
* @var array
*/
public $json_api_authorization_request = array();
/**
* Connection manager.
*
* @var Automattic\Jetpack\Connection\Manager
*/
protected $connection_manager;
/**
* Plugin lock key.
*
* @var string Transient key used to prevent multiple simultaneous plugin upgrades
*/
public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock';
/**
* Holds an instance of Automattic\Jetpack\A8c_Mc_Stats
*
* @var Automattic\Jetpack\A8c_Mc_Stats
*/
public $a8c_mc_stats_instance;
/**
* Constant for login redirect key.
*
* @var string
* @since 8.4.0
*/
public static $jetpack_redirect_login = 'jetpack_connect_login_redirect';
/**
* Holds the singleton instance of this class
*
* @since 2.3.3
* @var Jetpack
*/
public static $instance = false;
/**
* Singleton
*
* @static
*/
public static function init() {
if ( ! self::$instance ) {
self::$instance = new Jetpack();
add_action( 'plugins_loaded', array( self::$instance, 'plugin_upgrade' ) );
add_action( 'jetpack_idc_disconnect', array( __CLASS__, 'on_idc_disconnect' ) );
}
return self::$instance;
}
/**
* Must never be called statically
*/
public function plugin_upgrade() {
if ( self::is_connection_ready() ) {
list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) );
if ( JETPACK__VERSION !== $version ) {
// Prevent multiple upgrades at once - only a single process should trigger an upgrade to avoid stampedes.
if ( wp_using_ext_object_cache() ) {
if ( true !== wp_cache_add( self::$plugin_upgrade_lock_key, 1, 'transient', 10 ) ) {
return;
}
} else {
if ( false !== get_transient( self::$plugin_upgrade_lock_key ) ) {
return;
}
set_transient( self::$plugin_upgrade_lock_key, 1, 10 );
}
// check which active modules actually exist and remove others from active_modules list.
$unfiltered_modules = self::get_active_modules();
$modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) );
if ( array_diff( $unfiltered_modules, $modules ) ) {
self::update_active_modules( $modules );
}
add_action( 'init', array( __CLASS__, 'activate_new_modules' ) );
// Upgrade to 4.3.0.
if ( Jetpack_Options::get_option( 'identity_crisis_whitelist' ) ) {
Jetpack_Options::delete_option( 'identity_crisis_whitelist' );
}
// Make sure Markdown for posts gets turned back on.
if ( ! get_option( 'wpcom_publish_posts_with_markdown' ) ) {
update_option( 'wpcom_publish_posts_with_markdown', true );
}
/*
* Minileven deprecation. 8.3.0.
* Only delete options if not using
* the replacement standalone Minileven plugin.
*/
if (
! self::is_plugin_active( 'minileven-master/minileven.php' )
&& ! self::is_plugin_active( 'minileven/minileven.php' )
) {
if ( get_option( 'wp_mobile_custom_css' ) ) {
delete_option( 'wp_mobile_custom_css' );
}
if ( get_option( 'wp_mobile_excerpt' ) ) {
delete_option( 'wp_mobile_excerpt' );
}
if ( get_option( 'wp_mobile_featured_images' ) ) {
delete_option( 'wp_mobile_featured_images' );
}
if ( get_option( 'wp_mobile_app_promos' ) ) {
delete_option( 'wp_mobile_app_promos' );
}
}
// Upgrade to 8.4.0.
if ( Jetpack_Options::get_option( 'ab_connect_banner_green_bar' ) ) {
Jetpack_Options::delete_option( 'ab_connect_banner_green_bar' );
}
// Update to 8.8.x (WordPress 5.5 Compatibility).
if ( Jetpack_Options::get_option( 'autoupdate_plugins' ) ) {
$updated = update_site_option(
'auto_update_plugins',
array_unique(
array_merge(
(array) Jetpack_Options::get_option( 'autoupdate_plugins', array() ),
(array) get_site_option( 'auto_update_plugins', array() )
)
)
);
if ( $updated ) {
Jetpack_Options::delete_option( 'autoupdate_plugins' );
} // Should we have some type of fallback if something fails here?
}
if ( did_action( 'wp_loaded' ) ) {
self::upgrade_on_load();
} else {
add_action(
'wp_loaded',
array( __CLASS__, 'upgrade_on_load' )
);
}
}
}
}
/**
* Runs upgrade routines that need to have modules loaded.
*/
public static function upgrade_on_load() {
// Not attempting any upgrades if jetpack_modules_loaded did not fire.
// This can happen in case Jetpack has been just upgraded and is
// being initialized late during the page load. In this case we wait
// until the next proper admin page load with Jetpack active.
if ( ! did_action( 'jetpack_modules_loaded' ) ) {
delete_transient( self::$plugin_upgrade_lock_key );
return;
}
self::maybe_set_version_option();
if ( method_exists( 'Jetpack_Widget_Conditions', 'migrate_post_type_rules' ) ) {
Jetpack_Widget_Conditions::migrate_post_type_rules();
}
if (
class_exists( 'Jetpack_Sitemap_Manager' )
) {
do_action( 'jetpack_sitemaps_purge_data' );
}
// Delete old stats cache.
delete_option( 'jetpack_restapi_stats_cache' );
delete_transient( self::$plugin_upgrade_lock_key );
}
/**
* Saves all the currently active modules to options.
* Also fires Action hooks for each newly activated and deactivated module.
*
* @param array $modules Array of active modules to be saved in options.
*
* @return bool $success true for success, false for failure.
*/
public static function update_active_modules( $modules ) {
return ( new Modules() )->update_active( $modules );
}
/**
* Remove all active modules.
*
* @return void
*/
public static function delete_active_modules() {
self::update_active_modules( array() );
}
/**
* Adds a hook to plugins_loaded at a priority that's currently the earliest
* available.
*/
public function add_configure_hook() {
global $wp_filter;
$current_priority = has_filter( 'plugins_loaded', array( $this, 'configure' ) );
if ( false !== $current_priority ) {
remove_action( 'plugins_loaded', array( $this, 'configure' ), $current_priority );
}
$taken_priorities = array_map( 'intval', array_keys( $wp_filter['plugins_loaded']->callbacks ) );
sort( $taken_priorities );
$first_priority = array_shift( $taken_priorities );
if ( $first_priority <= PHP_INT_MIN ) {
$new_priority = PHP_INT_MIN;
} else {
$new_priority = $first_priority - 1;
}
add_action( 'plugins_loaded', array( $this, 'configure' ), $new_priority );
}
/**
* Constructor. Initializes WordPress hooks
*/
private function __construct() {
/*
* Check for and alert any deprecated hooks
*/
add_action( 'init', array( $this, 'deprecated_hooks' ) );
// Note how this runs at an earlier plugin_loaded hook intentionally to accomodate for other plugins.
add_action( 'plugin_loaded', array( $this, 'add_configure_hook' ), 90 );
add_action( 'network_plugin_loaded', array( $this, 'add_configure_hook' ), 90 );
add_action( 'mu_plugin_loaded', array( $this, 'add_configure_hook' ), 90 );
add_action( 'plugins_loaded', array( $this, 'late_initialization' ), 90 );
add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) );
/**
* Prepare Gutenberg Editor functionality
*/
require_once JETPACK__PLUGIN_DIR . 'class.jetpack-gutenberg.php';
add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_independent_blocks' ) );
add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'load_block_editor_extensions' ), 9 );
add_action( 'plugins_loaded', array( 'Jetpack_Gutenberg', 'register_block_metadata_collection' ) );
/**
* We've switched from enqueue_block_editor_assets to enqueue_block_assets in WP-Admin because the assets with the former are loaded on the main site-editor.php.
*
* With the latter, the assets are now loaded in the SE iframe; the implementation is now faster because Gutenberg doesn't need to inject the assets in the iframe on client-side.
*/
if ( is_admin() ) {
add_action( 'enqueue_block_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) );
} else {
add_action( 'enqueue_block_editor_assets', array( 'Jetpack_Gutenberg', 'enqueue_block_editor_assets' ) );
}
add_filter( 'render_block', array( 'Jetpack_Gutenberg', 'display_deprecated_block_message' ), 10, 2 );
add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 );
add_action( 'jetpack_event_log', array( 'Jetpack', 'log' ), 10, 2 );
add_filter( 'login_url', array( $this, 'login_url' ), 10, 2 );
add_action( 'login_init', array( $this, 'login_init' ) );
// Set up the REST authentication hooks.
Connection_Rest_Authentication::init();
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) );
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ), 20 );
// Filter the dashboard meta box order to swap the new one in in place of the old one.
add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) );
// WordPress dashboard widget.
require_once JETPACK__PLUGIN_DIR . 'class-jetpack-stats-dashboard-widget.php';
add_action( 'wp_dashboard_setup', array( new Jetpack_Stats_Dashboard_Widget(), 'init' ) );
// Returns HTTPS support status.
add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) );
add_action( 'wp_loaded', array( $this, 'register_assets' ) );
/**
* These actions run checks to load additional files.
* They check for external files or plugins, so they need to run as late as possible.
*/
add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 );
add_action( 'web_stories_story_head', array( $this, 'check_open_graph' ), 1 );
add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 );
add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 );
add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 );
add_action( 'style_loader_src', array( 'Jetpack', 'set_suffix_on_min' ), 10, 2 );
add_filter( 'profile_update', array( 'Jetpack', 'user_meta_cleanup' ) );
add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) );
add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 );
add_action(
'plugins_loaded',
function () {
if ( User_Agent_Info::is_mobile_app() ) {
add_filter( 'get_edit_post_link', '__return_empty_string' );
}
}
);
// Update the site's Jetpack plan and products from API on heartbeats.
add_action( 'jetpack_heartbeat', array( Jetpack_Plan::class, 'refresh_from_wpcom' ) );
// Actually push the stats on shutdown.
if ( ! has_action( 'shutdown', array( $this, 'push_stats' ) ) ) {
add_action( 'shutdown', array( $this, 'push_stats' ) );
}
// After a successful connection.
add_action( 'jetpack_site_registered', array( $this, 'activate_default_modules_on_site_register' ) );
add_action( 'jetpack_site_registered', array( $this, 'handle_unique_registrations_stats' ) );
// Actions for Manager::authorize().
add_action( 'jetpack_authorize_starting', array( $this, 'authorize_starting' ) );
add_action( 'jetpack_authorize_ending_linked', array( $this, 'authorize_ending_linked' ) );
add_action( 'jetpack_authorize_ending_authorized', array( $this, 'authorize_ending_authorized' ) );
Jetpack_Client_Server::init();
add_action( 'jetpack_client_authorize_error', array( Jetpack_Client_Server::class, 'client_authorize_error' ) );
add_filter( 'jetpack_client_authorize_already_authorized_url', array( Jetpack_Client_Server::class, 'client_authorize_already_authorized_url' ) );
add_action( 'jetpack_client_authorize_processing', array( Jetpack_Client_Server::class, 'client_authorize_processing' ) );
add_filter( 'jetpack_client_authorize_fallback_url', array( Jetpack_Client_Server::class, 'client_authorize_fallback_url' ) );
// Filters for the Manager::get_token() urls and request body.
add_filter( 'jetpack_token_redirect_url', array( Authorize_Redirect::class, 'filter_connect_redirect_url' ) );
add_filter( 'jetpack_token_request_body', array( __CLASS__, 'filter_token_request_body' ) );
// Filter for the `jetpack/v4/connection/data` API response.
add_filter( 'jetpack_current_user_connection_data', array( __CLASS__, 'filter_jetpack_current_user_connection_data' ) );
// Actions for successful reconnect.
add_action( 'jetpack_reconnection_completed', array( $this, 'reconnection_completed' ) );
// Actions for successful disconnect.
add_action( 'jetpack_site_disconnected', array( $this, 'jetpack_site_disconnected' ) );
// Actions for licensing.
Licensing::instance()->initialize();
// Filters for Sync Callables.
add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'filter_sync_callable_whitelist' ), 10, 1 );
add_filter( 'jetpack_sync_multisite_callable_whitelist', array( $this, 'filter_sync_multisite_callable_whitelist' ), 10, 1 );
// Make resources use static domain when possible.
add_filter( 'jetpack_static_url', array( 'Automattic\\Jetpack\\Assets', 'staticize_subdomain' ) );
// Validate the domain names in Jetpack development versions.
add_action( 'jetpack_pre_register', array( static::class, 'registration_check_domains' ) );
// Register product descriptions for partner coupon usage.
add_filter( 'jetpack_partner_coupon_products', array( $this, 'get_partner_coupon_product_descriptions' ) );
// Actions for conditional recommendations.
add_action( 'plugins_loaded', array( 'Jetpack_Recommendations', 'init_conditional_recommendation_actions' ) );
// Add 5-star
add_filter( 'plugin_row_meta', array( $this, 'add_5_star_review_link' ), 10, 2 );
add_action( 'init', array( Deprecate::class, 'instance' ) );
}
/**
* Before everything else starts getting initalized, we need to initialize Jetpack using the
* Config object.
*/
public function configure() {
$config = new Config();
foreach (
array(
'jitm',
'sync',
'waf',
'videopress',
'stats',
'stats_admin',
'import',
)
as $feature
) {
$config->ensure( $feature );
}
$config->ensure(
'connection',
array(
'slug' => 'jetpack',
'name' => 'Jetpack',
)
);
// Identity crisis package.
$config->ensure(
'identity_crisis',
array(
'slug' => 'jetpack',
'admin_page' => '/wp-admin/admin.php?page=jetpack',
)
);
$config->ensure( 'search' );
if ( defined( 'ENABLE_WORDADS_SHARED_UI' ) && ENABLE_WORDADS_SHARED_UI ) {
$config->ensure( 'wordads' );
}
if ( ! $this->connection_manager ) {
$this->connection_manager = new Connection_Manager( 'jetpack' );
}
$modules = new Automattic\Jetpack\Modules();
if ( $modules->is_active( 'publicize' ) && $this->connection_manager->has_connected_user() ) {
$config->ensure( 'publicize' );
}
add_action( 'jetpack_initialize_tracking', array( $this, 'initialize_tracking' ) );
/*
* Load things that should only be in Network Admin.
*
* For now blow away everything else until a more full
* understanding of what is needed at the network level is
* available
*/
if ( is_multisite() ) {
$network = Jetpack_Network::init();
$network->set_connection( $this->connection_manager );
}
$is_connection_ready = self::is_connection_ready();
if ( $is_connection_ready ) {
add_action( 'login_form_jetpack_json_api_authorization', array( $this, 'login_form_json_api_authorization' ) );
$this->run_initialize_tracking_action();
Jetpack_Heartbeat::init();
if ( self::is_module_active( 'stats' ) && self::is_module_active( 'search' ) ) {
require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php';
Jetpack_Search_Performance_Logger::init();
}
} else {
add_action( 'jetpack_agreed_to_terms_of_service', array( $this, 'run_initialize_tracking_action' ) );
add_action( 'rest_api_init', array( $this, 'run_initialize_tracking_action' ) );
add_filter(
'xmlrpc_methods',
function ( $methods ) {
$this->run_initialize_tracking_action();
return $methods;
},
1
);
}
// Initialize remote file upload request handlers.
$this->add_remote_request_handlers();
/*
* Enable enhanced handling of previewing sites in Calypso
*/
if ( $is_connection_ready ) {
require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-iframe-embed.php';
add_action( 'init', array( 'Jetpack_Iframe_Embed', 'init' ), 9, 0 );
require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-keyring-service-helper.php';
add_action( 'init', array( 'Jetpack_Keyring_Service_Helper', 'init' ), 9, 0 );
}
}
/**
* Runs on plugins_loaded. Use this to add code that needs to be executed later than other
* initialization code.
*
* @action plugins_loaded
*/
public function late_initialization() {
add_action( 'after_setup_theme', array( 'Jetpack', 'load_modules' ), -2 );
My_Jetpack_Initializer::init();
// Initialize Boost Speed Score
new Speed_Score( array(), 'jetpack-dashboard' );
/**
* Fires when Jetpack is fully loaded and ready. This is the point where it's safe
* to instantiate classes from packages and namespaces that are managed by the Jetpack Autoloader.
*
* @since 8.1.0
*
* @param Jetpack $jetpack the main plugin class object.
*/
do_action( 'jetpack_loaded', $this );
add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 2 );
}
/**
* This is ported over from the manage module, which has been deprecated and baked in here.
*/
public function add_wpcom_to_allowed_redirect_hosts() {
add_filter( 'allowed_redirect_hosts', array( $this, 'allow_wpcom_domain' ) );
}
/**
* Return $domains, with 'wordpress.com' appended.
* This is ported over from the manage module, which has been deprecated and baked in here.
*
* @param array $domains Array of domains allowed for redirect.
*
* @return array
*/
public function allow_wpcom_domain( $domains ) {
if ( empty( $domains ) ) {
$domains = array();
}
$domains[] = 'wordpress.com';
return array_unique( $domains );
}
/**
* Redirect edit post links to Calypso.
*
* @deprecated since 13.9
*
* @param string $default_url Post edit URL.
* @param int $post_id Post ID.
*
* @return string
*/
public function point_edit_post_links_to_calypso( $default_url, $post_id ) {
_deprecated_function( __METHOD__, '13.9' );
$post = get_post( $post_id );
if ( empty( $post ) ) {
return $default_url;
}
$post_type = $post->post_type;
// Mapping the allowed CPTs on WordPress.com to corresponding paths in Calypso.
// https://en.support.wordpress.com/custom-post-types/.
$allowed_post_types = array(
'post',
'page',
'jetpack-portfolio',
'jetpack-testimonial',
);
if ( ! in_array( $post_type, $allowed_post_types, true ) ) {
return $default_url;
}
return Redirect::get_url(
'calypso-edit-' . $post_type,
array(
'path' => $post_id,
)
);
}
/**
* Redirect edit comment links to Calypso.
*
* @deprecated since 13.9
*
* @param string $url Comment edit URL.
*
* @return string
*/
public function point_edit_comment_links_to_calypso( $url ) {
_deprecated_function( __METHOD__, '13.9' );
// Take the `query` key value from the URL, and parse its parts to the $query_args. `amp;c` matches the comment ID.
$query_args = null;
wp_parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $query_args );
return Redirect::get_url(
'calypso-edit-comment',
array(
'path' => $query_args['amp;c'],
)
);
}
/**
* Extend Sync callables with Jetpack Plugin functions.
*
* @param array $callables list of callables.
*
* @return array list of callables.
*/
public function filter_sync_callable_whitelist( $callables ) {
// Jetpack Functions.
$jetpack_callables = array(
'single_user_site' => array( 'Jetpack', 'is_single_user_site' ),
'updates' => array( 'Jetpack', 'get_updates' ),
'available_jetpack_blocks' => array( 'Jetpack_Gutenberg', 'get_availability' ), // Includes both Gutenberg blocks *and* plugins.
);
return array_merge( $callables, $jetpack_callables );
}
/**
* Extend Sync multisite callables with Jetpack Plugin functions.
*
* @param array $callables list of callables.
*
* @return array list of callables.