forked from Automattic/jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.jetpack.php
6746 lines (5827 loc) · 227 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
/*
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)
*/
class Jetpack {
public $xmlrpc_server = null;
private $xmlrpc_verification = null;
public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA']
/**
* @var array The handles of styles that are concatenated into jetpack.css
*/
public $concatenated_style_handles = array(
'jetpack-carousel',
'grunion.css',
'the-neverending-homepage',
'jetpack_likes',
'jetpack_related-posts',
'sharedaddy',
'jetpack-slideshow',
'presentations',
'jetpack-subscriptions',
'tiled-gallery',
'widget-conditions',
'jetpack_display_posts_widget',
'gravatar-profile-widget',
'widget-grid-and-list',
'jetpack-widgets',
'goodreads-widget',
);
public $plugins_to_deactivate = array(
'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ),
'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ),
'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ),
'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ),
'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ),
'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ),
'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ),
'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ),
'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ),
'videopress' => array( 'video/video.php', 'VideoPress' ),
'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ),
'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ),
'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ),
'omnisearch' => array( 'jetpack-omnisearch/omnisearch.php', 'Jetpack Omnisearch' ),
'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ),
'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' )
);
public $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',
),
'contact-form' => array(
'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php',
'Gravity Forms' => 'gravityforms/gravityforms.php',
'Contact Form Plugin' => 'contact-form-plugin/contact_form.php',
'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php',
'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php',
),
'minileven' => array(
'WPtouch' => 'wptouch/wptouch.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',
),
'random-redirect' => array(
'Random Redirect 2' => 'random-redirect-2/random-redirect.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',
),
'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',
),
'widget-visibility' => array(
'Widget Logic' => 'widget-logic/widget_logic.php',
'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php',
),
);
/**
* Plugins for which we turn off our Facebook OG Tags implementation.
*
* Note: WordPress SEO by Yoast and WordPress SEO Premium by Yoast automatically deactivate
* Jetpack's Open Graph tags via filter when their Social Meta modules are active.
*
* 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' );
*/
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
'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail
'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
'header-footer/plugin.php', // Header and Footer
'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
'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
'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
);
/**
* Plugins for which we turn off our Twitter Cards Tags implementation.
*/
private $twitter_cards_conflicting_plugins = array(
// '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-twitter-cards/twitter_cards.php', // WP Twitter Cards
);
/**
* 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();
/**
* Allows us to build a temporary security report
*
* @var array
*/
static $security_report = array();
/**
* Jetpack_Sync object
*/
public $sync;
/**
* Verified data for JSON authorization request
*/
public $json_api_authorization_request = array();
/**
* Holds the singleton instance of this class
* @since 2.3.3
* @var Jetpack
*/
static $instance = false;
/**
* Singleton
* @static
*/
public static function init() {
if ( ! self::$instance ) {
if ( did_action( 'plugins_loaded' ) )
self::plugin_textdomain();
else
add_action( 'plugins_loaded', array( __CLASS__, 'plugin_textdomain' ), 99 );
self::$instance = new Jetpack;
self::$instance->plugin_upgrade();
add_action( 'init', array( __CLASS__, 'perform_security_reporting' ) );
}
return self::$instance;
}
/**
* Must never be called statically
*/
function plugin_upgrade() {
// Upgrade: 1.1 -> 1.2
if ( get_option( 'jetpack_id' ) ) {
// Move individual jetpack options to single array of options
$options = array();
foreach ( Jetpack_Options::get_option_names() as $option ) {
if ( false !== $value = get_option( "jetpack_$option" ) ) {
$options[$option] = $value;
}
}
if ( $options ) {
Jetpack_Options::update_options( $options );
foreach ( array_keys( $options ) as $option ) {
delete_option( "jetpack_$option" );
}
}
// Add missing version and old_version options
if ( ! $version = Jetpack_Options::get_option( 'version' ) ) {
$version = $old_version = '1.1:' . time();
/**
* Fires on update, before bumping version numbers up to a new version.
*
* @since 3.4.0
*
* @param string $version Jetpack version number.
* @param bool false Does an old version exist. Default is false.
*/
do_action( 'updating_jetpack_version', $version, false );
Jetpack_Options::update_options( compact( 'version', 'old_version' ) );
}
}
// Upgrade from a single user token to a user_id-indexed array and a master_user ID
if ( ! Jetpack_Options::get_option( 'user_tokens' ) ) {
if ( $user_token = Jetpack_Options::get_option( 'user_token' ) ) {
$token_parts = explode( '.', $user_token );
if ( isset( $token_parts[2] ) ) {
$master_user = $token_parts[2];
$user_tokens = array( $master_user => $user_token );
Jetpack_Options::update_options( compact( 'master_user', 'user_tokens' ) );
Jetpack_Options::delete_option( 'user_token' );
} else {
// @todo: is this even possible?
trigger_error( sprintf( 'Jetpack::plugin_upgrade found no user_id in user_token "%s"', $user_token ), E_USER_WARNING );
}
}
}
// Clean up legacy G+ Authorship data.
if ( get_option( 'gplus_authors' ) ) {
delete_option( 'gplus_authors' );
delete_option( 'hide_gplus' );
delete_metadata( 'post', 0, 'gplus_authorship_disabled', null, true );
}
if ( ! get_option( 'jetpack_private_options' ) ) {
$jetpack_options = get_option( 'jetpack_options', array() );
foreach( Jetpack_Options::get_option_names( 'private' ) as $option_name ) {
if ( isset( $jetpack_options[ $option_name ] ) ) {
Jetpack_Options::update_option( $option_name, $jetpack_options[ $option_name ] );
unset( $jetpack_options[ $option_name ] );
}
}
update_option( 'jetpack_options', $jetpack_options );
}
if ( Jetpack::is_active() ) {
list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) );
if ( JETPACK__VERSION != $version ) {
add_action( 'init', array( __CLASS__, 'activate_new_modules' ) );
/**
* Fires when synchronizing all registered options and constants.
*
* @since 3.3.0
*/
do_action( 'jetpack_sync_all_registered_options' );
}
//if Jetpack is connected check if jetpack_unique_connection exists and if not then set it
$jetpack_unique_connection = get_option( 'jetpack_unique_connection' );
$is_unique_connection = $jetpack_unique_connection && array_key_exists( 'version', $jetpack_unique_connection );
if ( ! $is_unique_connection ) {
$jetpack_unique_connection = array(
'connected' => 1,
'disconnected' => -1,
'version' => '3.6.1'
);
update_option( 'jetpack_unique_connection', $jetpack_unique_connection );
}
}
if ( get_option( 'jetpack_json_api_full_management' ) ) {
delete_option( 'jetpack_json_api_full_management' );
self::activate_manage();
}
}
static function activate_manage( ) {
if ( did_action( 'init' ) || current_filter() == 'init' ) {
self::activate_module( 'manage', false, false );
} else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) {
add_action( 'init', array( __CLASS__, 'activate_manage' ) );
}
}
/**
* Constructor. Initializes WordPress hooks
*/
private function __construct() {
/*
* Check for and alert any deprecated hooks
*/
add_action( 'init', array( $this, 'deprecated_hooks' ) );
/*
* Do things that should run even in the network admin
* here, before we potentially fail out.
*/
add_filter( 'jetpack_require_lib_dir', array( $this, 'require_lib_dir' ) );
/**
* We need sync object even in Multisite mode
*/
$this->sync = new Jetpack_Sync;
/**
* Trigger a wp_version sync when updating WP versions
**/
add_action( 'upgrader_process_complete', array( 'Jetpack', 'update_get_wp_version' ), 10, 2 );
$this->sync->mock_option( 'wp_version', array( 'Jetpack', 'get_wp_version' ) );
add_action( 'init', array( $this, 'sync_update_data') );
/*
* 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() ) {
Jetpack_Network::init();
// Only sync this info if we are on a multi site
// @since 3.7
$this->sync->mock_option( 'network_name', array( 'Jetpack', 'network_name' ) );
$this->sync->mock_option( 'network_allow_new_registrations', array( 'Jetpack', 'network_allow_new_registrations' ) );
$this->sync->mock_option( 'network_add_new_users', array( 'Jetpack', 'network_add_new_users' ) );
$this->sync->mock_option( 'network_site_upload_space', array( 'Jetpack', 'network_site_upload_space' ) );
$this->sync->mock_option( 'network_upload_file_types', array( 'Jetpack', 'network_upload_file_types' ) );
$this->sync->mock_option( 'network_enable_administration_menus', array( 'Jetpack', 'network_enable_administration_menus' ) );
if( is_network_admin() ) {
// Sync network site data if it is updated or not.
add_action( 'update_wpmu_options', array( $this, 'update_jetpack_network_settings' ) );
return; // End here to prevent single site actions from firing
}
}
$theme_slug = get_option( 'stylesheet' );
// Modules should do Jetpack_Sync::sync_options( __FILE__, $option, ... ); instead
// We access the "internal" method here only because the Jetpack object isn't instantiated yet
$this->sync->options(
JETPACK__PLUGIN_DIR . 'jetpack.php',
'home',
'siteurl',
'blogname',
'gmt_offset',
'timezone_string',
'security_report',
'stylesheet',
"theme_mods_{$theme_slug}",
'jetpack_sync_non_public_post_stati',
'jetpack_options',
'site_icon' // (int) - ID of core's Site Icon attachment ID
);
foreach( Jetpack_Options::get_option_names( 'non-compact' ) as $option ) {
$this->sync->options( __FILE__, 'jetpack_' . $option );
}
/**
* Sometimes you want to sync data to .com without adding options to .org sites.
* The mock option allows you to do just that.
*/
$this->sync->mock_option( 'is_main_network', array( $this, 'is_main_network_option' ) );
$this->sync->mock_option( 'is_multi_site', array( $this, 'is_multisite' ) );
$this->sync->mock_option( 'main_network_site', array( $this, 'jetpack_main_network_site_option' ) );
$this->sync->mock_option( 'single_user_site', array( 'Jetpack', 'is_single_user_site' ) );
$this->sync->mock_option( 'has_file_system_write_access', array( 'Jetpack', 'file_system_write_access' ) );
$this->sync->mock_option( 'is_version_controlled', array( 'Jetpack', 'is_version_controlled' ) );
/**
* Trigger an update to the main_network_site when we update the blogname of a site.
*
*/
add_action( 'update_option_siteurl', array( $this, 'update_jetpack_main_network_site_option' ) );
add_action( 'update_option', array( $this, 'log_settings_change' ), 10, 3 );
// Update the settings everytime the we register a new user to the site or we delete a user.
add_action( 'user_register', array( $this, 'is_single_user_site_invalidate' ) );
add_action( 'deleted_user', array( $this, 'is_single_user_site_invalidate' ) );
// Unlink user before deleting the user from .com
add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 );
add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 );
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) {
@ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed.
require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php';
$this->xmlrpc_server = new Jetpack_XMLRPC_Server();
$this->require_jetpack_authentication();
if ( Jetpack::is_active() ) {
// Hack to preserve $HTTP_RAW_POST_DATA
add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) );
$signed = $this->verify_xml_rpc_signature();
if ( $signed && ! is_wp_error( $signed ) ) {
// The actual API methods.
add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) );
} else {
add_filter( 'xmlrpc_methods', '__return_empty_array' );
}
} else {
// The bootstrap API methods.
add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) );
}
// Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on.
add_filter( 'pre_option_enable_xmlrpc', '__return_true' );
} elseif ( is_admin() && isset( $_POST['action'] ) && 'jetpack_upload_file' == $_POST['action'] ) {
$this->require_jetpack_authentication();
$this->add_remote_request_handlers();
} else {
if ( Jetpack::is_active() ) {
add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) );
add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) );
}
}
if ( Jetpack::is_active() ) {
Jetpack_Heartbeat::init();
}
add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) );
if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) {
wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' );
}
add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) );
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' ) );
add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) );
// 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' ) );
add_action( 'wp_ajax_jetpack-sync-reindex-trigger', array( $this, 'sync_reindex_trigger' ) );
add_action( 'wp_ajax_jetpack-sync-reindex-status', array( $this, 'sync_reindex_status' ) );
// Jump Start AJAX callback function
add_action( 'wp_ajax_jetpack_jumpstart_ajax', array( $this, 'jetpack_jumpstart_ajax_callback' ) );
add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) );
// Identity Crisis AJAX callback function
add_action( 'wp_ajax_jetpack_resolve_identity_crisis', array( $this, 'resolve_identity_crisis_ajax_callback' ) );
// JITM AJAX callback function
add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) );
add_action( 'wp_ajax_jetpack_admin_ajax', array( $this, 'jetpack_admin_ajax_callback' ) );
add_action( 'wp_ajax_jetpack_admin_ajax_refresh', array( $this, 'jetpack_admin_ajax_refresh_data' ) );
add_action( 'wp_loaded', array( $this, 'register_assets' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) );
add_action( 'jetpack_activate_module', array( $this, 'activate_module_actions' ) );
add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 );
add_action( 'jetpack_notices', array( $this, 'show_development_mode_notice' ) );
/**
* 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( '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_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 );
add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 );
add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) );
add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 );
// A filter to control all just in time messages
add_filter( 'jetpack_just_in_time_msgs', '__return_true' );
/**
* This is the hack to concatinate all css files into one.
* For description and reasoning see the implode_frontend_css method
*
* Super late priority so we catch all the registered styles
*/
if( !is_admin() ) {
add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first
add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles`
}
// Sync Core Icon: Detect changes in Core's Site Icon and make it syncable.
add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) );
add_action( 'jetpack_heartbeat', array( $this, 'jetpack_sync_core_icon' ) );
}
/*
* Make sure any site icon added to core can get
* synced back to dotcom, so we can display it there.
*/
function jetpack_sync_core_icon() {
if ( function_exists( 'get_site_icon_url' ) ) {
$url = get_site_icon_url();
} else {
return;
}
require_once( JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php' );
// If there's a core icon, maybe update the option. If not, fall back to Jetpack's.
if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) {
// This is the option that is synced with dotcom
Jetpack_Options::update_option( 'site_icon_url', $url );
} else if ( empty( $url ) && did_action( 'delete_option_site_icon' ) ) {
Jetpack_Options::delete_option( 'site_icon_url' );
}
}
function jetpack_admin_ajax_callback() {
// Check for nonce
if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) || ! current_user_can( 'jetpack_manage_modules' ) ) {
wp_die( 'permissions check failed' );
}
if ( isset( $_REQUEST['toggleModule'] ) && 'nux-toggle-module' == $_REQUEST['toggleModule'] ) {
$slug = $_REQUEST['thisModuleSlug'];
if ( ! in_array( $slug, Jetpack::get_available_modules() ) ) {
wp_die( 'That is not a Jetpack module slug' );
}
if ( Jetpack::is_module_active( $slug ) ) {
Jetpack::deactivate_module( $slug );
} else {
Jetpack::activate_module( $slug, false, false );
}
$modules = Jetpack_Admin::init()->get_modules();
echo json_encode( $modules[ $slug ] );
exit;
}
wp_die();
}
/*
* Sometimes we need to refresh the data,
* especially if the page is visited via a 'history'
* event like back/forward
*/
function jetpack_admin_ajax_refresh_data() {
// Check for nonce
if ( ! isset( $_REQUEST['adminNonce'] ) || ! wp_verify_nonce( $_REQUEST['adminNonce'], 'jetpack-admin-nonce' ) ) {
wp_die( 'permissions check failed' );
}
if ( isset( $_REQUEST['refreshData'] ) && 'refresh' == $_REQUEST['refreshData'] ) {
$modules = Jetpack_Admin::init()->get_modules();
echo json_encode( $modules );
exit;
}
wp_die();
}
/**
* The callback for the Jump Start ajax requests.
*/
function jetpack_jumpstart_ajax_callback() {
// Check for nonce
if ( ! isset( $_REQUEST['jumpstartNonce'] ) || ! wp_verify_nonce( $_REQUEST['jumpstartNonce'], 'jetpack-jumpstart-nonce' ) )
wp_die( 'permissions check failed' );
if ( isset( $_REQUEST['jumpStartActivate'] ) && 'jump-start-activate' == $_REQUEST['jumpStartActivate'] ) {
// Update the jumpstart option
if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) {
Jetpack_Options::update_option( 'jumpstart', 'jumpstart_activated' );
}
// Loops through the requested "Jump Start" modules, and activates them.
// Custom 'no_message' state, so that no message will be shown on reload.
$modules = $_REQUEST['jumpstartModSlug'];
$module_slugs = array();
foreach( $modules as $module => $value ) {
$module_slugs[] = $value['module_slug'];
}
// Check for possible conflicting plugins
$module_slugs_filtered = $this->filter_default_modules( $module_slugs );
foreach ( $module_slugs_filtered as $module_slug ) {
Jetpack::log( 'activate', $module_slug );
Jetpack::activate_module( $module_slug, false, false );
Jetpack::state( 'message', 'no_message' );
}
// Set the default sharing buttons and set to display on posts if none have been set.
$sharing_services = get_option( 'sharing-services' );
$sharing_options = get_option( 'sharing-options' );
if ( empty( $sharing_services['visible'] ) ) {
// Default buttons to set
$visible = array(
'twitter',
'facebook',
'google-plus-1',
);
$hidden = array();
// Set some sharing settings
$sharing = new Sharing_Service();
$sharing_options['global'] = array(
'button_style' => 'icon',
'sharing_label' => $sharing->default_sharing_label,
'open_links' => 'same',
'show' => array( 'post' ),
'custom' => isset( $sharing_options['global']['custom'] ) ? $sharing_options['global']['custom'] : array()
);
update_option( 'sharing-options', $sharing_options );
// Send a success response so that we can display an error message.
$success = update_option( 'sharing-services', array( 'visible' => $visible, 'hidden' => $hidden ) );
echo json_encode( $success );
exit;
}
} elseif ( isset( $_REQUEST['disableJumpStart'] ) && true == $_REQUEST['disableJumpStart'] ) {
// If dismissed, flag the jumpstart option as such.
// Send a success response so that we can display an error message.
if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) {
$success = Jetpack_Options::update_option( 'jumpstart', 'jumpstart_dismissed' );
echo json_encode( $success );
exit;
}
} elseif ( isset( $_REQUEST['jumpStartDeactivate'] ) && 'jump-start-deactivate' == $_REQUEST['jumpStartDeactivate'] ) {
// FOR TESTING ONLY
// @todo remove
$modules = (array) $_REQUEST['jumpstartModSlug'];
foreach( $modules as $module => $value ) {
if ( !in_array( $value['module_slug'], Jetpack::get_default_modules() ) ) {
Jetpack::log( 'deactivate', $value['module_slug'] );
Jetpack::deactivate_module( $value['module_slug'] );
Jetpack::state( 'message', 'no_message' );
} else {
Jetpack::log( 'activate', $value['module_slug'] );
Jetpack::activate_module( $value['module_slug'], false, false );
Jetpack::state( 'message', 'no_message' );
}
}
Jetpack_Options::update_option( 'jumpstart', 'new_connection' );
echo "reload the page";
}
wp_die();
}
/**
* The callback for the JITM ajax requests.
*/
function jetpack_jitm_ajax_callback() {
// Check for nonce
if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) {
wp_die( 'Module activation failed due to lack of appropriate permissions' );
}
if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) {
$module_slug = $_REQUEST['jitmModule'];
Jetpack::log( 'activate', $module_slug );
Jetpack::activate_module( $module_slug, false, false );
Jetpack::state( 'message', 'no_message' );
//A Jetpack module is being activated through a JITM, track it
$this->stat( 'jitm', $module_slug.'-activated' );
$this->do_stats( 'server_side' );
wp_send_json_success();
}
if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) {
// get the hide_jitm options array
$jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' );
$module_slug = $_REQUEST['jitmModule'];
if( ! $jetpack_hide_jitm ) {
$jetpack_hide_jitm = array(
$module_slug => 'hide'
);
} else {
$jetpack_hide_jitm[$module_slug] = 'hide';
}
Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm );
//jitm is being dismissed forever, track it
$this->stat( 'jitm', $module_slug.'-dismissed' );
$this->do_stats( 'server_side' );
wp_send_json_success();
}
}
/**
* If there are any stats that need to be pushed, but haven't been, push them now.
*/
function __destruct() {
if ( ! empty( $this->stats ) ) {
$this->do_stats( 'server_side' );
}
}
function jetpack_custom_caps( $caps, $cap, $user_id, $args ) {
switch( $cap ) {
case 'jetpack_connect' :
case 'jetpack_reconnect' :
if ( Jetpack::is_development_mode() ) {
$caps = array( 'do_not_allow' );
break;
}
/**
* Pass through. If it's not development mode, these should match disconnect.
* Let users disconnect if it's development mode, just in case things glitch.
*/
case 'jetpack_disconnect' :
/**
* In multisite, can individual site admins manage their own connection?
*
* Ideally, this should be extracted out to a separate filter in the Jetpack_Network class.
*/
if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) {
if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) {
/**
* We need to update the option name -- it's terribly unclear which
* direction the override goes.
*
* @todo: Update the option name to `sub-sites-can-manage-own-connections`
*/
$caps = array( 'do_not_allow' );
break;
}
}
$caps = array( 'manage_options' );
break;
case 'jetpack_manage_modules' :
case 'jetpack_activate_modules' :
case 'jetpack_deactivate_modules' :
$caps = array( 'manage_options' );
break;
case 'jetpack_configure_modules' :
$caps = array( 'manage_options' );
break;
case 'jetpack_admin_page' :
if ( Jetpack::is_development_mode() ) {
$caps = array( 'manage_options' );
break;
}
// Don't ever show to subscribers, but allow access to the page if they're trying to unlink.
if ( ! current_user_can( 'edit_posts' ) ) {
if ( isset( $_GET['redirect'] ) && 'sub-unlink' == $_GET['redirect'] ) {
// We need this in order to unlink the user.
$this->admin_page_load();
}
if ( ! wp_verify_nonce( 'jetpack-unlink' ) ) {
$caps = array( 'do_not_allow' );
break;
}
}
if ( ! self::is_active() && ! current_user_can( 'jetpack_connect' ) ) {
$caps = array( 'do_not_allow' );
break;
}
/**
* Pass through. If it's not development mode, these should match the admin page.
* Let users disconnect if it's development mode, just in case things glitch.
*/
case 'jetpack_connect_user' :
if ( Jetpack::is_development_mode() ) {
$caps = array( 'do_not_allow' );
break;
}
$caps = array( 'read' );
break;
}
return $caps;
}
function require_jetpack_authentication() {
// Don't let anyone authenticate
$_COOKIE = array();
remove_all_filters( 'authenticate' );
/**
* For the moment, remove Limit Login Attempts if its xmlrpc for Jetpack.
* If Limit Login Attempts is installed as a mu-plugin, it can occasionally
* generate false-positives.
*/
remove_filter( 'wp_login_failed', 'limit_login_failed' );
if ( Jetpack::is_active() ) {
// Allow Jetpack authentication
add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 );
}
}
/**
* Load language files
*/
public static function plugin_textdomain() {
// Note to self, the third argument must not be hardcoded, to account for relocated folders.
load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' );
}
/**
* Register assets for use in various modules and the Jetpack admin page.
*
* @uses wp_script_is, wp_register_script, plugins_url
* @action wp_loaded
* @return null
*/
public function register_assets() {
if ( ! wp_script_is( 'spin', 'registered' ) ) {
wp_register_script( 'spin', plugins_url( '_inc/spin.js', JETPACK__PLUGIN_FILE ), false, '1.3' );
}
if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) {
wp_register_script( 'jquery.spin', plugins_url( '_inc/jquery.spin.js', JETPACK__PLUGIN_FILE ) , array( 'jquery', 'spin' ), '1.3' );
}
if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) {
wp_register_script( 'jetpack-gallery-settings', plugins_url( '_inc/gallery-settings.js', JETPACK__PLUGIN_FILE ), array( 'media-views' ), '20121225' );
}
/**
* As jetpack_register_genericons is by default fired off a hook,
* the hook may have already fired by this point.
* So, let's just trigger it manually.
*/
require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' );
jetpack_register_genericons();
if ( ! wp_style_is( 'jetpack-icons', 'registered' ) )
wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION );
}