Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class Jetpack { |
||
28 | public $xmlrpc_server = null; |
||
29 | |||
30 | private $xmlrpc_verification = null; |
||
31 | private $rest_authentication_status = null; |
||
32 | |||
33 | public $HTTP_RAW_POST_DATA = null; // copy of $GLOBALS['HTTP_RAW_POST_DATA'] |
||
34 | |||
35 | /** |
||
36 | * @var array The handles of styles that are concatenated into jetpack.css |
||
37 | */ |
||
38 | public $concatenated_style_handles = array( |
||
39 | 'jetpack-carousel', |
||
40 | 'grunion.css', |
||
41 | 'the-neverending-homepage', |
||
42 | 'jetpack_likes', |
||
43 | 'jetpack_related-posts', |
||
44 | 'sharedaddy', |
||
45 | 'jetpack-slideshow', |
||
46 | 'presentations', |
||
47 | 'jetpack-subscriptions', |
||
48 | 'jetpack-responsive-videos-style', |
||
49 | 'jetpack-social-menu', |
||
50 | 'tiled-gallery', |
||
51 | 'jetpack_display_posts_widget', |
||
52 | 'gravatar-profile-widget', |
||
53 | 'goodreads-widget', |
||
54 | 'jetpack_social_media_icons_widget', |
||
55 | 'jetpack-top-posts-widget', |
||
56 | 'jetpack_image_widget', |
||
57 | 'jetpack-my-community-widget', |
||
58 | 'wordads', |
||
59 | 'eu-cookie-law-style', |
||
60 | 'flickr-widget-style', |
||
61 | 'jetpack-search-widget' |
||
62 | ); |
||
63 | |||
64 | /** |
||
65 | * Contains all assets that have had their URL rewritten to minified versions. |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | static $min_assets = array(); |
||
|
|||
70 | |||
71 | public $plugins_to_deactivate = array( |
||
72 | 'stats' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
73 | 'shortlinks' => array( 'stats/stats.php', 'WordPress.com Stats' ), |
||
74 | 'sharedaddy' => array( 'sharedaddy/sharedaddy.php', 'Sharedaddy' ), |
||
75 | 'twitter-widget' => array( 'wickett-twitter-widget/wickett-twitter-widget.php', 'Wickett Twitter Widget' ), |
||
76 | 'after-the-deadline' => array( 'after-the-deadline/after-the-deadline.php', 'After The Deadline' ), |
||
77 | 'contact-form' => array( 'grunion-contact-form/grunion-contact-form.php', 'Grunion Contact Form' ), |
||
78 | 'contact-form' => array( 'mullet/mullet-contact-form.php', 'Mullet Contact Form' ), |
||
79 | 'custom-css' => array( 'safecss/safecss.php', 'WordPress.com Custom CSS' ), |
||
80 | 'random-redirect' => array( 'random-redirect/random-redirect.php', 'Random Redirect' ), |
||
81 | 'videopress' => array( 'video/video.php', 'VideoPress' ), |
||
82 | 'widget-visibility' => array( 'jetpack-widget-visibility/widget-visibility.php', 'Jetpack Widget Visibility' ), |
||
83 | 'widget-visibility' => array( 'widget-visibility-without-jetpack/widget-visibility-without-jetpack.php', 'Widget Visibility Without Jetpack' ), |
||
84 | 'sharedaddy' => array( 'jetpack-sharing/sharedaddy.php', 'Jetpack Sharing' ), |
||
85 | 'gravatar-hovercards' => array( 'jetpack-gravatar-hovercards/gravatar-hovercards.php', 'Jetpack Gravatar Hovercards' ), |
||
86 | 'latex' => array( 'wp-latex/wp-latex.php', 'WP LaTeX' ) |
||
87 | ); |
||
88 | |||
89 | static $capability_translations = array( |
||
90 | 'administrator' => 'manage_options', |
||
91 | 'editor' => 'edit_others_posts', |
||
92 | 'author' => 'publish_posts', |
||
93 | 'contributor' => 'edit_posts', |
||
94 | 'subscriber' => 'read', |
||
95 | ); |
||
96 | |||
97 | /** |
||
98 | * Map of modules that have conflicts with plugins and should not be auto-activated |
||
99 | * if the plugins are active. Used by filter_default_modules |
||
100 | * |
||
101 | * Plugin Authors: If you'd like to prevent a single module from auto-activating, |
||
102 | * change `module-slug` and add this to your plugin: |
||
103 | * |
||
104 | * add_filter( 'jetpack_get_default_modules', 'my_jetpack_get_default_modules' ); |
||
105 | * function my_jetpack_get_default_modules( $modules ) { |
||
106 | * return array_diff( $modules, array( 'module-slug' ) ); |
||
107 | * } |
||
108 | * |
||
109 | * @var array |
||
110 | */ |
||
111 | private $conflicting_plugins = array( |
||
112 | 'comments' => array( |
||
113 | 'Intense Debate' => 'intensedebate/intensedebate.php', |
||
114 | 'Disqus' => 'disqus-comment-system/disqus.php', |
||
115 | 'Livefyre' => 'livefyre-comments/livefyre.php', |
||
116 | 'Comments Evolved for WordPress' => 'gplus-comments/comments-evolved.php', |
||
117 | 'Google+ Comments' => 'google-plus-comments/google-plus-comments.php', |
||
118 | 'WP-SpamShield Anti-Spam' => 'wp-spamshield/wp-spamshield.php', |
||
119 | ), |
||
120 | 'comment-likes' => array( |
||
121 | 'Epoch' => 'epoch/plugincore.php', |
||
122 | ), |
||
123 | 'contact-form' => array( |
||
124 | 'Contact Form 7' => 'contact-form-7/wp-contact-form-7.php', |
||
125 | 'Gravity Forms' => 'gravityforms/gravityforms.php', |
||
126 | 'Contact Form Plugin' => 'contact-form-plugin/contact_form.php', |
||
127 | 'Easy Contact Forms' => 'easy-contact-forms/easy-contact-forms.php', |
||
128 | 'Fast Secure Contact Form' => 'si-contact-form/si-contact-form.php', |
||
129 | 'Ninja Forms' => 'ninja-forms/ninja-forms.php', |
||
130 | ), |
||
131 | 'minileven' => array( |
||
132 | 'WPtouch' => 'wptouch/wptouch.php', |
||
133 | ), |
||
134 | 'latex' => array( |
||
135 | 'LaTeX for WordPress' => 'latex/latex.php', |
||
136 | 'Youngwhans Simple Latex' => 'youngwhans-simple-latex/yw-latex.php', |
||
137 | 'Easy WP LaTeX' => 'easy-wp-latex-lite/easy-wp-latex-lite.php', |
||
138 | 'MathJax-LaTeX' => 'mathjax-latex/mathjax-latex.php', |
||
139 | 'Enable Latex' => 'enable-latex/enable-latex.php', |
||
140 | 'WP QuickLaTeX' => 'wp-quicklatex/wp-quicklatex.php', |
||
141 | ), |
||
142 | 'protect' => array( |
||
143 | 'Limit Login Attempts' => 'limit-login-attempts/limit-login-attempts.php', |
||
144 | 'Captcha' => 'captcha/captcha.php', |
||
145 | 'Brute Force Login Protection' => 'brute-force-login-protection/brute-force-login-protection.php', |
||
146 | 'Login Security Solution' => 'login-security-solution/login-security-solution.php', |
||
147 | 'WPSecureOps Brute Force Protect' => 'wpsecureops-bruteforce-protect/wpsecureops-bruteforce-protect.php', |
||
148 | 'BulletProof Security' => 'bulletproof-security/bulletproof-security.php', |
||
149 | 'SiteGuard WP Plugin' => 'siteguard/siteguard.php', |
||
150 | 'Security-protection' => 'security-protection/security-protection.php', |
||
151 | 'Login Security' => 'login-security/login-security.php', |
||
152 | 'Botnet Attack Blocker' => 'botnet-attack-blocker/botnet-attack-blocker.php', |
||
153 | 'Wordfence Security' => 'wordfence/wordfence.php', |
||
154 | 'All In One WP Security & Firewall' => 'all-in-one-wp-security-and-firewall/wp-security.php', |
||
155 | 'iThemes Security' => 'better-wp-security/better-wp-security.php', |
||
156 | ), |
||
157 | 'random-redirect' => array( |
||
158 | 'Random Redirect 2' => 'random-redirect-2/random-redirect.php', |
||
159 | ), |
||
160 | 'related-posts' => array( |
||
161 | 'YARPP' => 'yet-another-related-posts-plugin/yarpp.php', |
||
162 | 'WordPress Related Posts' => 'wordpress-23-related-posts-plugin/wp_related_posts.php', |
||
163 | 'nrelate Related Content' => 'nrelate-related-content/nrelate-related.php', |
||
164 | 'Contextual Related Posts' => 'contextual-related-posts/contextual-related-posts.php', |
||
165 | 'Related Posts for WordPress' => 'microkids-related-posts/microkids-related-posts.php', |
||
166 | 'outbrain' => 'outbrain/outbrain.php', |
||
167 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
168 | 'Sexybookmarks' => 'sexybookmarks/shareaholic.php', |
||
169 | ), |
||
170 | 'sharedaddy' => array( |
||
171 | 'AddThis' => 'addthis/addthis_social_widget.php', |
||
172 | 'Add To Any' => 'add-to-any/add-to-any.php', |
||
173 | 'ShareThis' => 'share-this/sharethis.php', |
||
174 | 'Shareaholic' => 'shareaholic/shareaholic.php', |
||
175 | ), |
||
176 | 'seo-tools' => array( |
||
177 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
178 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
179 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
180 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
181 | ), |
||
182 | 'verification-tools' => array( |
||
183 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
184 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
185 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
186 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
187 | ), |
||
188 | 'widget-visibility' => array( |
||
189 | 'Widget Logic' => 'widget-logic/widget_logic.php', |
||
190 | 'Dynamic Widgets' => 'dynamic-widgets/dynamic-widgets.php', |
||
191 | ), |
||
192 | 'sitemaps' => array( |
||
193 | 'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php', |
||
194 | 'Better WordPress Google XML Sitemaps' => 'bwp-google-xml-sitemaps/bwp-simple-gxs.php', |
||
195 | 'Google XML Sitemaps for qTranslate' => 'google-xml-sitemaps-v3-for-qtranslate/sitemap.php', |
||
196 | 'XML Sitemap & Google News feeds' => 'xml-sitemap-feed/xml-sitemap.php', |
||
197 | 'Google Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php', |
||
198 | 'WordPress SEO by Yoast' => 'wordpress-seo/wp-seo.php', |
||
199 | 'WordPress SEO Premium by Yoast' => 'wordpress-seo-premium/wp-seo-premium.php', |
||
200 | 'All in One SEO Pack' => 'all-in-one-seo-pack/all_in_one_seo_pack.php', |
||
201 | 'All in One SEO Pack Pro' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', |
||
202 | 'Sitemap' => 'sitemap/sitemap.php', |
||
203 | 'Simple Wp Sitemap' => 'simple-wp-sitemap/simple-wp-sitemap.php', |
||
204 | 'Simple Sitemap' => 'simple-sitemap/simple-sitemap.php', |
||
205 | 'XML Sitemaps' => 'xml-sitemaps/xml-sitemaps.php', |
||
206 | 'MSM Sitemaps' => 'msm-sitemap/msm-sitemap.php', |
||
207 | ), |
||
208 | 'lazy-images' => array( |
||
209 | 'Lazy Load' => 'lazy-load/lazy-load.php', |
||
210 | 'BJ Lazy Load' => 'bj-lazy-load/bj-lazy-load.php', |
||
211 | 'Lazy Load by WP Rocket' => 'rocket-lazy-load/rocket-lazy-load.php', |
||
212 | ), |
||
213 | ); |
||
214 | |||
215 | /** |
||
216 | * Plugins for which we turn off our Facebook OG Tags implementation. |
||
217 | * |
||
218 | * Note: All in One SEO Pack, All in one SEO Pack Pro, WordPress SEO by Yoast, and WordPress SEO Premium by Yoast automatically deactivate |
||
219 | * Jetpack's Open Graph tags via filter when their Social Meta modules are active. |
||
220 | * |
||
221 | * Plugin authors: If you'd like to prevent Jetpack's Open Graph tag generation in your plugin, you can do so via this filter: |
||
222 | * add_filter( 'jetpack_enable_open_graph', '__return_false' ); |
||
223 | */ |
||
224 | private $open_graph_conflicting_plugins = array( |
||
225 | '2-click-socialmedia-buttons/2-click-socialmedia-buttons.php', |
||
226 | // 2 Click Social Media Buttons |
||
227 | 'add-link-to-facebook/add-link-to-facebook.php', // Add Link to Facebook |
||
228 | 'add-meta-tags/add-meta-tags.php', // Add Meta Tags |
||
229 | 'autodescription/autodescription.php', // The SEO Framework |
||
230 | 'easy-facebook-share-thumbnails/esft.php', // Easy Facebook Share Thumbnail |
||
231 | 'heateor-open-graph-meta-tags/heateor-open-graph-meta-tags.php', |
||
232 | // Open Graph Meta Tags by Heateor |
||
233 | 'facebook/facebook.php', // Facebook (official plugin) |
||
234 | 'facebook-awd/AWD_facebook.php', // Facebook AWD All in one |
||
235 | 'facebook-featured-image-and-open-graph-meta-tags/fb-featured-image.php', |
||
236 | // Facebook Featured Image & OG Meta Tags |
||
237 | 'facebook-meta-tags/facebook-metatags.php', // Facebook Meta Tags |
||
238 | 'wonderm00ns-simple-facebook-open-graph-tags/wonderm00n-open-graph.php', |
||
239 | // Facebook Open Graph Meta Tags for WordPress |
||
240 | 'facebook-revised-open-graph-meta-tag/index.php', // Facebook Revised Open Graph Meta Tag |
||
241 | 'facebook-thumb-fixer/_facebook-thumb-fixer.php', // Facebook Thumb Fixer |
||
242 | 'facebook-and-digg-thumbnail-generator/facebook-and-digg-thumbnail-generator.php', |
||
243 | // Fedmich's Facebook Open Graph Meta |
||
244 | 'network-publisher/networkpub.php', // Network Publisher |
||
245 | 'nextgen-facebook/nextgen-facebook.php', // NextGEN Facebook OG |
||
246 | 'social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php', |
||
247 | // NextScripts SNAP |
||
248 | 'og-tags/og-tags.php', // OG Tags |
||
249 | 'opengraph/opengraph.php', // Open Graph |
||
250 | 'open-graph-protocol-framework/open-graph-protocol-framework.php', |
||
251 | // Open Graph Protocol Framework |
||
252 | 'seo-facebook-comments/seofacebook.php', // SEO Facebook Comments |
||
253 | 'seo-ultimate/seo-ultimate.php', // SEO Ultimate |
||
254 | 'sexybookmarks/sexy-bookmarks.php', // Shareaholic |
||
255 | 'shareaholic/sexy-bookmarks.php', // Shareaholic |
||
256 | 'sharepress/sharepress.php', // SharePress |
||
257 | 'simple-facebook-connect/sfc.php', // Simple Facebook Connect |
||
258 | 'social-discussions/social-discussions.php', // Social Discussions |
||
259 | 'social-sharing-toolkit/social_sharing_toolkit.php', // Social Sharing Toolkit |
||
260 | 'socialize/socialize.php', // Socialize |
||
261 | 'squirrly-seo/squirrly.php', // SEO by SQUIRRLY™ |
||
262 | 'only-tweet-like-share-and-google-1/tweet-like-plusone.php', |
||
263 | // Tweet, Like, Google +1 and Share |
||
264 | 'wordbooker/wordbooker.php', // Wordbooker |
||
265 | 'wpsso/wpsso.php', // WordPress Social Sharing Optimization |
||
266 | 'wp-caregiver/wp-caregiver.php', // WP Caregiver |
||
267 | 'wp-facebook-like-send-open-graph-meta/wp-facebook-like-send-open-graph-meta.php', |
||
268 | // WP Facebook Like Send & Open Graph Meta |
||
269 | 'wp-facebook-open-graph-protocol/wp-facebook-ogp.php', // WP Facebook Open Graph protocol |
||
270 | 'wp-ogp/wp-ogp.php', // WP-OGP |
||
271 | 'zoltonorg-social-plugin/zosp.php', // Zolton.org Social Plugin |
||
272 | 'wp-fb-share-like-button/wp_fb_share-like_widget.php', // WP Facebook Like Button |
||
273 | 'open-graph-metabox/open-graph-metabox.php' // Open Graph Metabox |
||
274 | ); |
||
275 | |||
276 | /** |
||
277 | * Plugins for which we turn off our Twitter Cards Tags implementation. |
||
278 | */ |
||
279 | private $twitter_cards_conflicting_plugins = array( |
||
280 | // 'twitter/twitter.php', // The official one handles this on its own. |
||
281 | // // https://github.com/twitter/wordpress/blob/master/src/Twitter/WordPress/Cards/Compatibility.php |
||
282 | 'eewee-twitter-card/index.php', // Eewee Twitter Card |
||
283 | 'ig-twitter-cards/ig-twitter-cards.php', // IG:Twitter Cards |
||
284 | 'jm-twitter-cards/jm-twitter-cards.php', // JM Twitter Cards |
||
285 | 'kevinjohn-gallagher-pure-web-brilliants-social-graph-twitter-cards-extention/kevinjohn_gallagher___social_graph_twitter_output.php', |
||
286 | // Pure Web Brilliant's Social Graph Twitter Cards Extension |
||
287 | 'twitter-cards/twitter-cards.php', // Twitter Cards |
||
288 | 'twitter-cards-meta/twitter-cards-meta.php', // Twitter Cards Meta |
||
289 | 'wp-twitter-cards/twitter_cards.php', // WP Twitter Cards |
||
290 | ); |
||
291 | |||
292 | /** |
||
293 | * Message to display in admin_notice |
||
294 | * @var string |
||
295 | */ |
||
296 | public $message = ''; |
||
297 | |||
298 | /** |
||
299 | * Error to display in admin_notice |
||
300 | * @var string |
||
301 | */ |
||
302 | public $error = ''; |
||
303 | |||
304 | /** |
||
305 | * Modules that need more privacy description. |
||
306 | * @var string |
||
307 | */ |
||
308 | public $privacy_checks = ''; |
||
309 | |||
310 | /** |
||
311 | * Stats to record once the page loads |
||
312 | * |
||
313 | * @var array |
||
314 | */ |
||
315 | public $stats = array(); |
||
316 | |||
317 | /** |
||
318 | * Jetpack_Sync object |
||
319 | */ |
||
320 | public $sync; |
||
321 | |||
322 | /** |
||
323 | * Verified data for JSON authorization request |
||
324 | */ |
||
325 | public $json_api_authorization_request = array(); |
||
326 | |||
327 | /** |
||
328 | * @var string Transient key used to prevent multiple simultaneous plugin upgrades |
||
329 | */ |
||
330 | public static $plugin_upgrade_lock_key = 'jetpack_upgrade_lock'; |
||
331 | |||
332 | /** |
||
333 | * Holds the singleton instance of this class |
||
334 | * @since 2.3.3 |
||
335 | * @var Jetpack |
||
336 | */ |
||
337 | static $instance = false; |
||
338 | |||
339 | /** |
||
340 | * Singleton |
||
341 | * @static |
||
342 | */ |
||
343 | public static function init() { |
||
344 | if ( ! self::$instance ) { |
||
345 | self::$instance = new Jetpack; |
||
346 | |||
347 | self::$instance->plugin_upgrade(); |
||
348 | } |
||
349 | |||
350 | return self::$instance; |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * Must never be called statically |
||
355 | */ |
||
356 | function plugin_upgrade() { |
||
357 | if ( Jetpack::is_active() ) { |
||
358 | list( $version ) = explode( ':', Jetpack_Options::get_option( 'version' ) ); |
||
359 | if ( JETPACK__VERSION != $version ) { |
||
360 | // Prevent multiple upgrades at once - only a single process should trigger |
||
361 | // an upgrade to avoid stampedes |
||
362 | if ( false !== get_transient( self::$plugin_upgrade_lock_key ) ) { |
||
363 | return; |
||
364 | } |
||
365 | |||
366 | // Set a short lock to prevent multiple instances of the upgrade |
||
367 | set_transient( self::$plugin_upgrade_lock_key, 1, 10 ); |
||
368 | |||
369 | // check which active modules actually exist and remove others from active_modules list |
||
370 | $unfiltered_modules = Jetpack::get_active_modules(); |
||
371 | $modules = array_filter( $unfiltered_modules, array( 'Jetpack', 'is_module' ) ); |
||
372 | if ( array_diff( $unfiltered_modules, $modules ) ) { |
||
373 | Jetpack::update_active_modules( $modules ); |
||
374 | } |
||
375 | |||
376 | add_action( 'init', array( __CLASS__, 'activate_new_modules' ) ); |
||
377 | |||
378 | // Upgrade to 4.3.0 |
||
379 | if ( Jetpack_Options::get_option( 'identity_crisis_whitelist' ) ) { |
||
380 | Jetpack_Options::delete_option( 'identity_crisis_whitelist' ); |
||
381 | } |
||
382 | |||
383 | // Make sure Markdown for posts gets turned back on |
||
384 | if ( ! get_option( 'wpcom_publish_posts_with_markdown' ) ) { |
||
385 | update_option( 'wpcom_publish_posts_with_markdown', true ); |
||
386 | } |
||
387 | |||
388 | if ( did_action( 'wp_loaded' ) ) { |
||
389 | self::upgrade_on_load(); |
||
390 | } else { |
||
391 | add_action( |
||
392 | 'wp_loaded', |
||
393 | array( __CLASS__, 'upgrade_on_load' ) |
||
394 | ); |
||
395 | } |
||
396 | } |
||
397 | } |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * Runs upgrade routines that need to have modules loaded. |
||
402 | */ |
||
403 | static function upgrade_on_load() { |
||
404 | |||
405 | // Not attempting any upgrades if jetpack_modules_loaded did not fire. |
||
406 | // This can happen in case Jetpack has been just upgraded and is |
||
407 | // being initialized late during the page load. In this case we wait |
||
408 | // until the next proper admin page load with Jetpack active. |
||
409 | if ( ! did_action( 'jetpack_modules_loaded' ) ) { |
||
410 | delete_transient( self::$plugin_upgrade_lock_key ); |
||
411 | |||
412 | return; |
||
413 | } |
||
414 | |||
415 | Jetpack::maybe_set_version_option(); |
||
416 | |||
417 | if ( class_exists( 'Jetpack_Widget_Conditions' ) ) { |
||
418 | Jetpack_Widget_Conditions::migrate_post_type_rules(); |
||
419 | } |
||
420 | |||
421 | if ( |
||
422 | class_exists( 'Jetpack_Sitemap_Manager' ) |
||
423 | && version_compare( JETPACK__VERSION, '5.3', '>=' ) |
||
424 | ) { |
||
425 | do_action( 'jetpack_sitemaps_purge_data' ); |
||
426 | } |
||
427 | |||
428 | delete_transient( self::$plugin_upgrade_lock_key ); |
||
429 | } |
||
430 | |||
431 | static function activate_manage( ) { |
||
432 | if ( did_action( 'init' ) || current_filter() == 'init' ) { |
||
433 | self::activate_module( 'manage', false, false ); |
||
434 | } else if ( ! has_action( 'init' , array( __CLASS__, 'activate_manage' ) ) ) { |
||
435 | add_action( 'init', array( __CLASS__, 'activate_manage' ) ); |
||
436 | } |
||
437 | } |
||
438 | |||
439 | static function update_active_modules( $modules ) { |
||
440 | $current_modules = Jetpack_Options::get_option( 'active_modules', array() ); |
||
441 | |||
442 | $success = Jetpack_Options::update_option( 'active_modules', array_unique( $modules ) ); |
||
443 | |||
444 | if ( is_array( $modules ) && is_array( $current_modules ) ) { |
||
445 | $new_active_modules = array_diff( $modules, $current_modules ); |
||
446 | foreach( $new_active_modules as $module ) { |
||
447 | /** |
||
448 | * Fires when a specific module is activated. |
||
449 | * |
||
450 | * @since 1.9.0 |
||
451 | * |
||
452 | * @param string $module Module slug. |
||
453 | * @param boolean $success whether the module was activated. @since 4.2 |
||
454 | */ |
||
455 | do_action( 'jetpack_activate_module', $module, $success ); |
||
456 | |||
457 | /** |
||
458 | * Fires when a module is activated. |
||
459 | * The dynamic part of the filter, $module, is the module slug. |
||
460 | * |
||
461 | * @since 1.9.0 |
||
462 | * |
||
463 | * @param string $module Module slug. |
||
464 | */ |
||
465 | do_action( "jetpack_activate_module_$module", $module ); |
||
466 | } |
||
467 | |||
468 | $new_deactive_modules = array_diff( $current_modules, $modules ); |
||
469 | foreach( $new_deactive_modules as $module ) { |
||
470 | /** |
||
471 | * Fired after a module has been deactivated. |
||
472 | * |
||
473 | * @since 4.2.0 |
||
474 | * |
||
475 | * @param string $module Module slug. |
||
476 | * @param boolean $success whether the module was deactivated. |
||
477 | */ |
||
478 | do_action( 'jetpack_deactivate_module', $module, $success ); |
||
479 | /** |
||
480 | * Fires when a module is deactivated. |
||
481 | * The dynamic part of the filter, $module, is the module slug. |
||
482 | * |
||
483 | * @since 1.9.0 |
||
484 | * |
||
485 | * @param string $module Module slug. |
||
486 | */ |
||
487 | do_action( "jetpack_deactivate_module_$module", $module ); |
||
488 | } |
||
489 | } |
||
490 | |||
491 | return $success; |
||
492 | } |
||
493 | |||
494 | static function delete_active_modules() { |
||
495 | self::update_active_modules( array() ); |
||
496 | } |
||
497 | |||
498 | /** |
||
499 | * Constructor. Initializes WordPress hooks |
||
500 | */ |
||
501 | private function __construct() { |
||
502 | /* |
||
503 | * Check for and alert any deprecated hooks |
||
504 | */ |
||
505 | add_action( 'init', array( $this, 'deprecated_hooks' ) ); |
||
506 | |||
507 | /* |
||
508 | * Enable enhanced handling of previewing sites in Calypso |
||
509 | */ |
||
510 | if ( Jetpack::is_active() ) { |
||
511 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-iframe-embed.php'; |
||
512 | add_action( 'init', array( 'Jetpack_Iframe_Embed', 'init' ), 9, 0 ); |
||
513 | } |
||
514 | |||
515 | /* |
||
516 | * Load things that should only be in Network Admin. |
||
517 | * |
||
518 | * For now blow away everything else until a more full |
||
519 | * understanding of what is needed at the network level is |
||
520 | * available |
||
521 | */ |
||
522 | if( is_multisite() ) { |
||
523 | Jetpack_Network::init(); |
||
524 | } |
||
525 | |||
526 | add_action( 'set_user_role', array( $this, 'maybe_clear_other_linked_admins_transient' ), 10, 3 ); |
||
527 | |||
528 | // Unlink user before deleting the user from .com |
||
529 | add_action( 'deleted_user', array( $this, 'unlink_user' ), 10, 1 ); |
||
530 | add_action( 'remove_user_from_blog', array( $this, 'unlink_user' ), 10, 1 ); |
||
531 | |||
532 | if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST && isset( $_GET['for'] ) && 'jetpack' == $_GET['for'] ) { |
||
533 | @ini_set( 'display_errors', false ); // Display errors can cause the XML to be not well formed. |
||
534 | |||
535 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; |
||
536 | $this->xmlrpc_server = new Jetpack_XMLRPC_Server(); |
||
537 | |||
538 | $this->require_jetpack_authentication(); |
||
539 | |||
540 | if ( Jetpack::is_active() ) { |
||
541 | // Hack to preserve $HTTP_RAW_POST_DATA |
||
542 | add_filter( 'xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); |
||
543 | |||
544 | $signed = $this->verify_xml_rpc_signature(); |
||
545 | View Code Duplication | if ( $signed && ! is_wp_error( $signed ) ) { |
|
546 | // The actual API methods. |
||
547 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'xmlrpc_methods' ) ); |
||
548 | } else { |
||
549 | // The jetpack.authorize method should be available for unauthenticated users on a site with an |
||
550 | // active Jetpack connection, so that additional users can link their account. |
||
551 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'authorize_xmlrpc_methods' ) ); |
||
552 | } |
||
553 | View Code Duplication | } else { |
|
554 | // The bootstrap API methods. |
||
555 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'bootstrap_xmlrpc_methods' ) ); |
||
556 | $signed = $this->verify_xml_rpc_signature(); |
||
557 | if ( $signed && ! is_wp_error( $signed ) ) { |
||
558 | // the jetpack Provision method is available for blog-token-signed requests |
||
559 | add_filter( 'xmlrpc_methods', array( $this->xmlrpc_server, 'provision_xmlrpc_methods' ) ); |
||
560 | } |
||
561 | } |
||
562 | |||
563 | // Now that no one can authenticate, and we're whitelisting all XML-RPC methods, force enable_xmlrpc on. |
||
564 | add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); |
||
565 | } elseif ( |
||
566 | is_admin() && |
||
567 | isset( $_POST['action'] ) && ( |
||
568 | 'jetpack_upload_file' == $_POST['action'] || |
||
569 | 'jetpack_update_file' == $_POST['action'] |
||
570 | ) |
||
571 | ) { |
||
572 | $this->require_jetpack_authentication(); |
||
573 | $this->add_remote_request_handlers(); |
||
574 | } else { |
||
575 | if ( Jetpack::is_active() ) { |
||
576 | add_action( 'login_form_jetpack_json_api_authorization', array( &$this, 'login_form_json_api_authorization' ) ); |
||
577 | add_filter( 'xmlrpc_methods', array( $this, 'public_xmlrpc_methods' ) ); |
||
578 | } |
||
579 | } |
||
580 | |||
581 | if ( Jetpack::is_active() ) { |
||
582 | Jetpack_Heartbeat::init(); |
||
583 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.jetpack-search-performance-logger.php'; |
||
584 | Jetpack_Search_Performance_Logger::init(); |
||
585 | } |
||
586 | |||
587 | add_filter( 'determine_current_user', array( $this, 'wp_rest_authenticate' ) ); |
||
588 | add_filter( 'rest_authentication_errors', array( $this, 'wp_rest_authentication_errors' ) ); |
||
589 | |||
590 | add_action( 'jetpack_clean_nonces', array( 'Jetpack', 'clean_nonces' ) ); |
||
591 | if ( ! wp_next_scheduled( 'jetpack_clean_nonces' ) ) { |
||
592 | wp_schedule_event( time(), 'hourly', 'jetpack_clean_nonces' ); |
||
593 | } |
||
594 | |||
595 | add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ) ); |
||
596 | |||
597 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
||
598 | add_action( 'admin_init', array( $this, 'dismiss_jetpack_notice' ) ); |
||
599 | |||
600 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
||
601 | |||
602 | add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) ); |
||
603 | // Filter the dashboard meta box order to swap the new one in in place of the old one. |
||
604 | add_filter( 'get_user_option_meta-box-order_dashboard', array( $this, 'get_user_option_meta_box_order_dashboard' ) ); |
||
605 | |||
606 | // returns HTTPS support status |
||
607 | add_action( 'wp_ajax_jetpack-recheck-ssl', array( $this, 'ajax_recheck_ssl' ) ); |
||
608 | |||
609 | // If any module option is updated before Jump Start is dismissed, hide Jump Start. |
||
610 | add_action( 'update_option', array( $this, 'jumpstart_has_updated_module_option' ) ); |
||
611 | |||
612 | // JITM AJAX callback function |
||
613 | add_action( 'wp_ajax_jitm_ajax', array( $this, 'jetpack_jitm_ajax_callback' ) ); |
||
614 | |||
615 | // Universal ajax callback for all tracking events triggered via js |
||
616 | add_action( 'wp_ajax_jetpack_tracks', array( $this, 'jetpack_admin_ajax_tracks_callback' ) ); |
||
617 | |||
618 | add_action( 'wp_ajax_jetpack_connection_banner', array( $this, 'jetpack_connection_banner_callback' ) ); |
||
619 | |||
620 | add_action( 'wp_loaded', array( $this, 'register_assets' ) ); |
||
621 | add_action( 'wp_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
622 | add_action( 'customize_controls_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
623 | add_action( 'admin_enqueue_scripts', array( $this, 'devicepx' ) ); |
||
624 | |||
625 | // gutenberg locale |
||
626 | add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_gutenberg_locale' ) ); |
||
627 | |||
628 | add_action( 'plugins_loaded', array( $this, 'extra_oembed_providers' ), 100 ); |
||
629 | |||
630 | /** |
||
631 | * These actions run checks to load additional files. |
||
632 | * They check for external files or plugins, so they need to run as late as possible. |
||
633 | */ |
||
634 | add_action( 'wp_head', array( $this, 'check_open_graph' ), 1 ); |
||
635 | add_action( 'plugins_loaded', array( $this, 'check_twitter_tags' ), 999 ); |
||
636 | add_action( 'plugins_loaded', array( $this, 'check_rest_api_compat' ), 1000 ); |
||
637 | |||
638 | add_filter( 'plugins_url', array( 'Jetpack', 'maybe_min_asset' ), 1, 3 ); |
||
639 | add_action( 'style_loader_src', array( 'Jetpack', 'set_suffix_on_min' ), 10, 2 ); |
||
640 | add_filter( 'style_loader_tag', array( 'Jetpack', 'maybe_inline_style' ), 10, 2 ); |
||
641 | |||
642 | add_filter( 'map_meta_cap', array( $this, 'jetpack_custom_caps' ), 1, 4 ); |
||
643 | |||
644 | add_filter( 'jetpack_get_default_modules', array( $this, 'filter_default_modules' ) ); |
||
645 | add_filter( 'jetpack_get_default_modules', array( $this, 'handle_deprecated_modules' ), 99 ); |
||
646 | |||
647 | // A filter to control all just in time messages |
||
648 | add_filter( 'jetpack_just_in_time_msgs', '__return_true', 9 ); |
||
649 | add_filter( 'jetpack_just_in_time_msg_cache', '__return_true', 9); |
||
650 | |||
651 | // If enabled, point edit post, page, and comment links to Calypso instead of WP-Admin. |
||
652 | // We should make sure to only do this for front end links. |
||
653 | if ( Jetpack::get_option( 'edit_links_calypso_redirect' ) && ! is_admin() ) { |
||
654 | add_filter( 'get_edit_post_link', array( $this, 'point_edit_post_links_to_calypso' ), 1, 2 ); |
||
655 | add_filter( 'get_edit_comment_link', array( $this, 'point_edit_comment_links_to_calypso' ), 1 ); |
||
656 | |||
657 | //we'll override wp_notify_postauthor and wp_notify_moderator pluggable functions |
||
658 | //so they point moderation links on emails to Calypso |
||
659 | jetpack_require_lib( 'functions.wp-notify' ); |
||
660 | } |
||
661 | |||
662 | // Update the Jetpack plan from API on heartbeats |
||
663 | add_action( 'jetpack_heartbeat', array( $this, 'refresh_active_plan_from_wpcom' ) ); |
||
664 | |||
665 | /** |
||
666 | * This is the hack to concatenate all css files into one. |
||
667 | * For description and reasoning see the implode_frontend_css method |
||
668 | * |
||
669 | * Super late priority so we catch all the registered styles |
||
670 | */ |
||
671 | if( !is_admin() ) { |
||
672 | add_action( 'wp_print_styles', array( $this, 'implode_frontend_css' ), -1 ); // Run first |
||
673 | add_action( 'wp_print_footer_scripts', array( $this, 'implode_frontend_css' ), -1 ); // Run first to trigger before `print_late_styles` |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * These are sync actions that we need to keep track of for jitms |
||
678 | */ |
||
679 | add_filter( 'jetpack_sync_before_send_updated_option', array( $this, 'jetpack_track_last_sync_callback' ), 99 ); |
||
680 | |||
681 | // Actually push the stats on shutdown. |
||
682 | if ( ! has_action( 'shutdown', array( $this, 'push_stats' ) ) ) { |
||
683 | add_action( 'shutdown', array( $this, 'push_stats' ) ); |
||
684 | } |
||
685 | } |
||
686 | |||
687 | function point_edit_post_links_to_calypso( $default_url, $post_id ) { |
||
688 | $post = get_post( $post_id ); |
||
689 | |||
690 | if ( empty( $post ) ) { |
||
691 | return $default_url; |
||
692 | } |
||
693 | |||
694 | $post_type = $post->post_type; |
||
695 | |||
696 | // Mapping the allowed CPTs on WordPress.com to corresponding paths in Calypso. |
||
697 | // https://en.support.wordpress.com/custom-post-types/ |
||
698 | $allowed_post_types = array( |
||
699 | 'post' => 'post', |
||
700 | 'page' => 'page', |
||
701 | 'jetpack-portfolio' => 'edit/jetpack-portfolio', |
||
702 | 'jetpack-testimonial' => 'edit/jetpack-testimonial', |
||
703 | ); |
||
704 | |||
705 | if ( ! in_array( $post_type, array_keys( $allowed_post_types ) ) ) { |
||
706 | return $default_url; |
||
707 | } |
||
708 | |||
709 | $path_prefix = $allowed_post_types[ $post_type ]; |
||
710 | |||
711 | $site_slug = Jetpack::build_raw_urls( get_home_url() ); |
||
712 | |||
713 | return esc_url( sprintf( 'https://wordpress.com/%s/%s/%d', $path_prefix, $site_slug, $post_id ) ); |
||
714 | } |
||
715 | |||
716 | function point_edit_comment_links_to_calypso( $url ) { |
||
717 | // Take the `query` key value from the URL, and parse its parts to the $query_args. `amp;c` matches the comment ID. |
||
718 | wp_parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $query_args ); |
||
719 | return esc_url( sprintf( 'https://wordpress.com/comment/%s/%d', |
||
720 | Jetpack::build_raw_urls( get_home_url() ), |
||
721 | $query_args['amp;c'] |
||
722 | ) ); |
||
723 | } |
||
724 | |||
725 | function jetpack_track_last_sync_callback( $params ) { |
||
726 | /** |
||
727 | * Filter to turn off jitm caching |
||
728 | * |
||
729 | * @since 5.4.0 |
||
730 | * |
||
731 | * @param bool false Whether to cache just in time messages |
||
732 | */ |
||
733 | if ( ! apply_filters( 'jetpack_just_in_time_msg_cache', false ) ) { |
||
734 | return $params; |
||
735 | } |
||
736 | |||
737 | if ( is_array( $params ) && isset( $params[0] ) ) { |
||
738 | $option = $params[0]; |
||
739 | if ( 'active_plugins' === $option ) { |
||
740 | // use the cache if we can, but not terribly important if it gets evicted |
||
741 | set_transient( 'jetpack_last_plugin_sync', time(), HOUR_IN_SECONDS ); |
||
742 | } |
||
743 | } |
||
744 | |||
745 | return $params; |
||
746 | } |
||
747 | |||
748 | function jetpack_connection_banner_callback() { |
||
749 | check_ajax_referer( 'jp-connection-banner-nonce', 'nonce' ); |
||
750 | |||
751 | if ( isset( $_REQUEST['dismissBanner'] ) ) { |
||
752 | Jetpack_Options::update_option( 'dismissed_connection_banner', 1 ); |
||
753 | wp_send_json_success(); |
||
754 | } |
||
755 | |||
756 | wp_die(); |
||
757 | } |
||
758 | |||
759 | function jetpack_admin_ajax_tracks_callback() { |
||
760 | // Check for nonce |
||
761 | if ( ! isset( $_REQUEST['tracksNonce'] ) || ! wp_verify_nonce( $_REQUEST['tracksNonce'], 'jp-tracks-ajax-nonce' ) ) { |
||
762 | wp_die( 'Permissions check failed.' ); |
||
763 | } |
||
764 | |||
765 | if ( ! isset( $_REQUEST['tracksEventName'] ) || ! isset( $_REQUEST['tracksEventType'] ) ) { |
||
766 | wp_die( 'No valid event name or type.' ); |
||
767 | } |
||
768 | |||
769 | $tracks_data = array(); |
||
770 | if ( 'click' === $_REQUEST['tracksEventType'] && isset( $_REQUEST['tracksEventProp'] ) ) { |
||
771 | if ( is_array( $_REQUEST['tracksEventProp'] ) ) { |
||
772 | $tracks_data = $_REQUEST['tracksEventProp']; |
||
773 | } else { |
||
774 | $tracks_data = array( 'clicked' => $_REQUEST['tracksEventProp'] ); |
||
775 | } |
||
776 | } |
||
777 | |||
778 | JetpackTracking::record_user_event( $_REQUEST['tracksEventName'], $tracks_data ); |
||
779 | wp_send_json_success(); |
||
780 | wp_die(); |
||
781 | } |
||
782 | |||
783 | /** |
||
784 | * The callback for the JITM ajax requests. |
||
785 | */ |
||
786 | function jetpack_jitm_ajax_callback() { |
||
787 | // Check for nonce |
||
788 | if ( ! isset( $_REQUEST['jitmNonce'] ) || ! wp_verify_nonce( $_REQUEST['jitmNonce'], 'jetpack-jitm-nonce' ) ) { |
||
789 | wp_die( 'Module activation failed due to lack of appropriate permissions' ); |
||
790 | } |
||
791 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'activate' == $_REQUEST['jitmActionToTake'] ) { |
||
792 | $module_slug = $_REQUEST['jitmModule']; |
||
793 | Jetpack::log( 'activate', $module_slug ); |
||
794 | Jetpack::activate_module( $module_slug, false, false ); |
||
795 | Jetpack::state( 'message', 'no_message' ); |
||
796 | |||
797 | //A Jetpack module is being activated through a JITM, track it |
||
798 | $this->stat( 'jitm', $module_slug.'-activated-' . JETPACK__VERSION ); |
||
799 | $this->do_stats( 'server_side' ); |
||
800 | |||
801 | wp_send_json_success(); |
||
802 | } |
||
803 | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'dismiss' == $_REQUEST['jitmActionToTake'] ) { |
||
804 | // get the hide_jitm options array |
||
805 | $jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' ); |
||
806 | $module_slug = $_REQUEST['jitmModule']; |
||
807 | |||
808 | if( ! $jetpack_hide_jitm ) { |
||
809 | $jetpack_hide_jitm = array( |
||
810 | $module_slug => 'hide' |
||
811 | ); |
||
812 | } else { |
||
813 | $jetpack_hide_jitm[$module_slug] = 'hide'; |
||
814 | } |
||
815 | |||
816 | Jetpack_Options::update_option( 'hide_jitm', $jetpack_hide_jitm ); |
||
817 | |||
818 | //jitm is being dismissed forever, track it |
||
819 | $this->stat( 'jitm', $module_slug.'-dismissed-' . JETPACK__VERSION ); |
||
820 | $this->do_stats( 'server_side' ); |
||
821 | |||
822 | wp_send_json_success(); |
||
823 | } |
||
824 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'launch' == $_REQUEST['jitmActionToTake'] ) { |
|
825 | $module_slug = $_REQUEST['jitmModule']; |
||
826 | |||
827 | // User went to WordPress.com, track this |
||
828 | $this->stat( 'jitm', $module_slug.'-wordpress-tools-' . JETPACK__VERSION ); |
||
829 | $this->do_stats( 'server_side' ); |
||
830 | |||
831 | wp_send_json_success(); |
||
832 | } |
||
833 | View Code Duplication | if ( isset( $_REQUEST['jitmActionToTake'] ) && 'viewed' == $_REQUEST['jitmActionToTake'] ) { |
|
834 | $track = $_REQUEST['jitmModule']; |
||
835 | |||
836 | // User is viewing JITM, track it. |
||
837 | $this->stat( 'jitm', $track . '-viewed-' . JETPACK__VERSION ); |
||
838 | $this->do_stats( 'server_side' ); |
||
839 | |||
840 | wp_send_json_success(); |
||
841 | } |
||
842 | } |
||
843 | |||
844 | /** |
||
845 | * If there are any stats that need to be pushed, but haven't been, push them now. |
||
846 | */ |
||
847 | function push_stats() { |
||
848 | if ( ! empty( $this->stats ) ) { |
||
849 | $this->do_stats( 'server_side' ); |
||
850 | } |
||
851 | } |
||
852 | |||
853 | function jetpack_custom_caps( $caps, $cap, $user_id, $args ) { |
||
854 | switch( $cap ) { |
||
855 | case 'jetpack_connect' : |
||
856 | case 'jetpack_reconnect' : |
||
857 | if ( Jetpack::is_development_mode() ) { |
||
858 | $caps = array( 'do_not_allow' ); |
||
859 | break; |
||
860 | } |
||
861 | /** |
||
862 | * Pass through. If it's not development mode, these should match disconnect. |
||
863 | * Let users disconnect if it's development mode, just in case things glitch. |
||
864 | */ |
||
865 | case 'jetpack_disconnect' : |
||
866 | /** |
||
867 | * In multisite, can individual site admins manage their own connection? |
||
868 | * |
||
869 | * Ideally, this should be extracted out to a separate filter in the Jetpack_Network class. |
||
870 | */ |
||
871 | if ( is_multisite() && ! is_super_admin() && is_plugin_active_for_network( 'jetpack/jetpack.php' ) ) { |
||
872 | if ( ! Jetpack_Network::init()->get_option( 'sub-site-connection-override' ) ) { |
||
873 | /** |
||
874 | * We need to update the option name -- it's terribly unclear which |
||
875 | * direction the override goes. |
||
876 | * |
||
877 | * @todo: Update the option name to `sub-sites-can-manage-own-connections` |
||
878 | */ |
||
879 | $caps = array( 'do_not_allow' ); |
||
880 | break; |
||
881 | } |
||
882 | } |
||
883 | |||
884 | $caps = array( 'manage_options' ); |
||
885 | break; |
||
886 | case 'jetpack_manage_modules' : |
||
887 | case 'jetpack_activate_modules' : |
||
888 | case 'jetpack_deactivate_modules' : |
||
889 | $caps = array( 'manage_options' ); |
||
890 | break; |
||
891 | case 'jetpack_configure_modules' : |
||
892 | $caps = array( 'manage_options' ); |
||
893 | break; |
||
894 | case 'jetpack_network_admin_page': |
||
895 | case 'jetpack_network_settings_page': |
||
896 | $caps = array( 'manage_network_plugins' ); |
||
897 | break; |
||
898 | case 'jetpack_network_sites_page': |
||
899 | $caps = array( 'manage_sites' ); |
||
900 | break; |
||
901 | case 'jetpack_admin_page' : |
||
902 | if ( Jetpack::is_development_mode() ) { |
||
903 | $caps = array( 'manage_options' ); |
||
904 | break; |
||
905 | } else { |
||
906 | $caps = array( 'read' ); |
||
907 | } |
||
908 | break; |
||
909 | case 'jetpack_connect_user' : |
||
910 | if ( Jetpack::is_development_mode() ) { |
||
911 | $caps = array( 'do_not_allow' ); |
||
912 | break; |
||
913 | } |
||
914 | $caps = array( 'read' ); |
||
915 | break; |
||
916 | } |
||
917 | return $caps; |
||
918 | } |
||
919 | |||
920 | function require_jetpack_authentication() { |
||
921 | // Don't let anyone authenticate |
||
922 | $_COOKIE = array(); |
||
923 | remove_all_filters( 'authenticate' ); |
||
924 | remove_all_actions( 'wp_login_failed' ); |
||
925 | |||
926 | if ( Jetpack::is_active() ) { |
||
927 | // Allow Jetpack authentication |
||
928 | add_filter( 'authenticate', array( $this, 'authenticate_jetpack' ), 10, 3 ); |
||
929 | } |
||
930 | } |
||
931 | |||
932 | /** |
||
933 | * Load language files |
||
934 | * @action plugins_loaded |
||
935 | */ |
||
936 | public static function plugin_textdomain() { |
||
937 | // Note to self, the third argument must not be hardcoded, to account for relocated folders. |
||
938 | load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' ); |
||
939 | } |
||
940 | |||
941 | /** |
||
942 | * Register assets for use in various modules and the Jetpack admin page. |
||
943 | * |
||
944 | * @uses wp_script_is, wp_register_script, plugins_url |
||
945 | * @action wp_loaded |
||
946 | * @return null |
||
947 | */ |
||
948 | public function register_assets() { |
||
949 | if ( ! wp_script_is( 'spin', 'registered' ) ) { |
||
950 | wp_register_script( |
||
951 | 'spin', |
||
952 | self::get_file_url_for_environment( '_inc/build/spin.min.js', '_inc/spin.js' ), |
||
953 | false, |
||
954 | '1.3' |
||
955 | ); |
||
956 | } |
||
957 | |||
958 | if ( ! wp_script_is( 'jquery.spin', 'registered' ) ) { |
||
959 | wp_register_script( |
||
960 | 'jquery.spin', |
||
961 | self::get_file_url_for_environment( '_inc/build/jquery.spin.min.js', '_inc/jquery.spin.js' ), |
||
962 | array( 'jquery', 'spin' ), |
||
963 | '1.3' |
||
964 | ); |
||
965 | } |
||
966 | |||
967 | View Code Duplication | if ( ! wp_script_is( 'jetpack-gallery-settings', 'registered' ) ) { |
|
968 | wp_register_script( |
||
969 | 'jetpack-gallery-settings', |
||
970 | self::get_file_url_for_environment( '_inc/build/gallery-settings.min.js', '_inc/gallery-settings.js' ), |
||
971 | array( 'media-views' ), |
||
972 | '20121225' |
||
973 | ); |
||
974 | } |
||
975 | |||
976 | if ( ! wp_script_is( 'jetpack-twitter-timeline', 'registered' ) ) { |
||
977 | wp_register_script( |
||
978 | 'jetpack-twitter-timeline', |
||
979 | self::get_file_url_for_environment( '_inc/build/twitter-timeline.min.js', '_inc/twitter-timeline.js' ), |
||
980 | array( 'jquery' ), |
||
981 | '4.0.0', |
||
982 | true |
||
983 | ); |
||
984 | } |
||
985 | |||
986 | if ( ! wp_script_is( 'jetpack-facebook-embed', 'registered' ) ) { |
||
987 | wp_register_script( |
||
988 | 'jetpack-facebook-embed', |
||
989 | self::get_file_url_for_environment( '_inc/build/facebook-embed.min.js', '_inc/facebook-embed.js' ), |
||
990 | array( 'jquery' ), |
||
991 | null, |
||
992 | true |
||
993 | ); |
||
994 | |||
995 | /** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
||
996 | $fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
||
997 | if ( ! is_numeric( $fb_app_id ) ) { |
||
998 | $fb_app_id = ''; |
||
999 | } |
||
1000 | wp_localize_script( |
||
1001 | 'jetpack-facebook-embed', |
||
1002 | 'jpfbembed', |
||
1003 | array( |
||
1004 | 'appid' => $fb_app_id, |
||
1005 | 'locale' => $this->get_locale(), |
||
1006 | ) |
||
1007 | ); |
||
1008 | } |
||
1009 | |||
1010 | /** |
||
1011 | * As jetpack_register_genericons is by default fired off a hook, |
||
1012 | * the hook may have already fired by this point. |
||
1013 | * So, let's just trigger it manually. |
||
1014 | */ |
||
1015 | require_once( JETPACK__PLUGIN_DIR . '_inc/genericons.php' ); |
||
1016 | jetpack_register_genericons(); |
||
1017 | |||
1018 | /** |
||
1019 | * Register the social logos |
||
1020 | */ |
||
1021 | require_once( JETPACK__PLUGIN_DIR . '_inc/social-logos.php' ); |
||
1022 | jetpack_register_social_logos(); |
||
1023 | |||
1024 | View Code Duplication | if ( ! wp_style_is( 'jetpack-icons', 'registered' ) ) |
|
1025 | wp_register_style( 'jetpack-icons', plugins_url( 'css/jetpack-icons.min.css', JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION ); |
||
1026 | } |
||
1027 | |||
1028 | /** |
||
1029 | * Guess locale from language code. |
||
1030 | * |
||
1031 | * @param string $lang Language code. |
||
1032 | * @return string|bool |
||
1033 | */ |
||
1034 | View Code Duplication | function guess_locale_from_lang( $lang ) { |
|
1035 | if ( 'en' === $lang || 'en_US' === $lang || ! $lang ) { |
||
1036 | return 'en_US'; |
||
1037 | } |
||
1038 | |||
1039 | if ( ! class_exists( 'GP_Locales' ) ) { |
||
1040 | if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
||
1041 | return false; |
||
1042 | } |
||
1043 | |||
1044 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
||
1045 | } |
||
1046 | |||
1047 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
||
1048 | // WP.com: get_locale() returns 'it' |
||
1049 | $locale = GP_Locales::by_slug( $lang ); |
||
1050 | } else { |
||
1051 | // Jetpack: get_locale() returns 'it_IT'; |
||
1052 | $locale = GP_Locales::by_field( 'facebook_locale', $lang ); |
||
1053 | } |
||
1054 | |||
1055 | if ( ! $locale ) { |
||
1056 | return false; |
||
1057 | } |
||
1058 | |||
1059 | if ( empty( $locale->facebook_locale ) ) { |
||
1060 | if ( empty( $locale->wp_locale ) ) { |
||
1061 | return false; |
||
1062 | } else { |
||
1063 | // Facebook SDK is smart enough to fall back to en_US if a |
||
1064 | // locale isn't supported. Since supported Facebook locales |
||
1065 | // can fall out of sync, we'll attempt to use the known |
||
1066 | // wp_locale value and rely on said fallback. |
||
1067 | return $locale->wp_locale; |
||
1068 | } |
||
1069 | } |
||
1070 | |||
1071 | return $locale->facebook_locale; |
||
1072 | } |
||
1073 | |||
1074 | /** |
||
1075 | * Get the locale. |
||
1076 | * |
||
1077 | * @return string|bool |
||
1078 | */ |
||
1079 | function get_locale() { |
||
1080 | $locale = $this->guess_locale_from_lang( get_locale() ); |
||
1081 | |||
1082 | if ( ! $locale ) { |
||
1083 | $locale = 'en_US'; |
||
1084 | } |
||
1085 | |||
1086 | return $locale; |
||
1087 | } |
||
1088 | |||
1089 | /** |
||
1090 | * Device Pixels support |
||
1091 | * This improves the resolution of gravatars and wordpress.com uploads on hi-res and zoomed browsers. |
||
1092 | */ |
||
1093 | function devicepx() { |
||
1094 | if ( Jetpack::is_active() && ! Jetpack_AMP_Support::is_amp_request() ) { |
||
1095 | wp_enqueue_script( 'devicepx', 'https://s0.wp.com/wp-content/js/devicepx-jetpack.js', array(), gmdate( 'oW' ), true ); |
||
1096 | } |
||
1097 | } |
||
1098 | |||
1099 | /** |
||
1100 | * Return the network_site_url so that .com knows what network this site is a part of. |
||
1101 | * @param bool $option |
||
1102 | * @return string |
||
1103 | */ |
||
1104 | public function jetpack_main_network_site_option( $option ) { |
||
1105 | return network_site_url(); |
||
1106 | } |
||
1107 | /** |
||
1108 | * Network Name. |
||
1109 | */ |
||
1110 | static function network_name( $option = null ) { |
||
1111 | global $current_site; |
||
1112 | return $current_site->site_name; |
||
1113 | } |
||
1114 | /** |
||
1115 | * Does the network allow new user and site registrations. |
||
1116 | * @return string |
||
1117 | */ |
||
1118 | static function network_allow_new_registrations( $option = null ) { |
||
1119 | return ( in_array( get_site_option( 'registration' ), array('none', 'user', 'blog', 'all' ) ) ? get_site_option( 'registration') : 'none' ); |
||
1120 | } |
||
1121 | /** |
||
1122 | * Does the network allow admins to add new users. |
||
1123 | * @return boolian |
||
1124 | */ |
||
1125 | static function network_add_new_users( $option = null ) { |
||
1126 | return (bool) get_site_option( 'add_new_users' ); |
||
1127 | } |
||
1128 | /** |
||
1129 | * File upload psace left per site in MB. |
||
1130 | * -1 means NO LIMIT. |
||
1131 | * @return number |
||
1132 | */ |
||
1133 | static function network_site_upload_space( $option = null ) { |
||
1134 | // value in MB |
||
1135 | return ( get_site_option( 'upload_space_check_disabled' ) ? -1 : get_space_allowed() ); |
||
1136 | } |
||
1137 | |||
1138 | /** |
||
1139 | * Network allowed file types. |
||
1140 | * @return string |
||
1141 | */ |
||
1142 | static function network_upload_file_types( $option = null ) { |
||
1143 | return get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ); |
||
1144 | } |
||
1145 | |||
1146 | /** |
||
1147 | * Maximum file upload size set by the network. |
||
1148 | * @return number |
||
1149 | */ |
||
1150 | static function network_max_upload_file_size( $option = null ) { |
||
1151 | // value in KB |
||
1152 | return get_site_option( 'fileupload_maxk', 300 ); |
||
1153 | } |
||
1154 | |||
1155 | /** |
||
1156 | * Lets us know if a site allows admins to manage the network. |
||
1157 | * @return array |
||
1158 | */ |
||
1159 | static function network_enable_administration_menus( $option = null ) { |
||
1160 | return get_site_option( 'menu_items' ); |
||
1161 | } |
||
1162 | |||
1163 | /** |
||
1164 | * If a user has been promoted to or demoted from admin, we need to clear the |
||
1165 | * jetpack_other_linked_admins transient. |
||
1166 | * |
||
1167 | * @since 4.3.2 |
||
1168 | * @since 4.4.0 $old_roles is null by default and if it's not passed, the transient is cleared. |
||
1169 | * |
||
1170 | * @param int $user_id The user ID whose role changed. |
||
1171 | * @param string $role The new role. |
||
1172 | * @param array $old_roles An array of the user's previous roles. |
||
1173 | */ |
||
1174 | function maybe_clear_other_linked_admins_transient( $user_id, $role, $old_roles = null ) { |
||
1175 | if ( 'administrator' == $role |
||
1176 | || ( is_array( $old_roles ) && in_array( 'administrator', $old_roles ) ) |
||
1177 | || is_null( $old_roles ) |
||
1178 | ) { |
||
1179 | delete_transient( 'jetpack_other_linked_admins' ); |
||
1180 | } |
||
1181 | } |
||
1182 | |||
1183 | /** |
||
1184 | * Checks to see if there are any other users available to become primary |
||
1185 | * Users must both: |
||
1186 | * - Be linked to wpcom |
||
1187 | * - Be an admin |
||
1188 | * |
||
1189 | * @return mixed False if no other users are linked, Int if there are. |
||
1190 | */ |
||
1191 | static function get_other_linked_admins() { |
||
1192 | $other_linked_users = get_transient( 'jetpack_other_linked_admins' ); |
||
1193 | |||
1194 | if ( false === $other_linked_users ) { |
||
1195 | $admins = get_users( array( 'role' => 'administrator' ) ); |
||
1196 | if ( count( $admins ) > 1 ) { |
||
1197 | $available = array(); |
||
1198 | foreach ( $admins as $admin ) { |
||
1199 | if ( Jetpack::is_user_connected( $admin->ID ) ) { |
||
1200 | $available[] = $admin->ID; |
||
1201 | } |
||
1202 | } |
||
1203 | |||
1204 | $count_connected_admins = count( $available ); |
||
1205 | if ( count( $available ) > 1 ) { |
||
1206 | $other_linked_users = $count_connected_admins; |
||
1207 | } else { |
||
1208 | $other_linked_users = 0; |
||
1209 | } |
||
1210 | } else { |
||
1211 | $other_linked_users = 0; |
||
1212 | } |
||
1213 | |||
1214 | set_transient( 'jetpack_other_linked_admins', $other_linked_users, HOUR_IN_SECONDS ); |
||
1215 | } |
||
1216 | |||
1217 | return ( 0 === $other_linked_users ) ? false : $other_linked_users; |
||
1218 | } |
||
1219 | |||
1220 | /** |
||
1221 | * Return whether we are dealing with a multi network setup or not. |
||
1222 | * The reason we are type casting this is because we want to avoid the situation where |
||
1223 | * the result is false since when is_main_network_option return false it cases |
||
1224 | * the rest the get_option( 'jetpack_is_multi_network' ); to return the value that is set in the |
||
1225 | * database which could be set to anything as opposed to what this function returns. |
||
1226 | * @param bool $option |
||
1227 | * |
||
1228 | * @return boolean |
||
1229 | */ |
||
1230 | public function is_main_network_option( $option ) { |
||
1231 | // return '1' or '' |
||
1232 | return (string) (bool) Jetpack::is_multi_network(); |
||
1233 | } |
||
1234 | |||
1235 | /** |
||
1236 | * Return true if we are with multi-site or multi-network false if we are dealing with single site. |
||
1237 | * |
||
1238 | * @param string $option |
||
1239 | * @return boolean |
||
1240 | */ |
||
1241 | public function is_multisite( $option ) { |
||
1242 | return (string) (bool) is_multisite(); |
||
1243 | } |
||
1244 | |||
1245 | /** |
||
1246 | * Implemented since there is no core is multi network function |
||
1247 | * Right now there is no way to tell if we which network is the dominant network on the system |
||
1248 | * |
||
1249 | * @since 3.3 |
||
1250 | * @return boolean |
||
1251 | */ |
||
1252 | public static function is_multi_network() { |
||
1253 | global $wpdb; |
||
1254 | |||
1255 | // if we don't have a multi site setup no need to do any more |
||
1256 | if ( ! is_multisite() ) { |
||
1257 | return false; |
||
1258 | } |
||
1259 | |||
1260 | $num_sites = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->site}" ); |
||
1261 | if ( $num_sites > 1 ) { |
||
1262 | return true; |
||
1263 | } else { |
||
1264 | return false; |
||
1265 | } |
||
1266 | } |
||
1267 | |||
1268 | /** |
||
1269 | * Trigger an update to the main_network_site when we update the siteurl of a site. |
||
1270 | * @return null |
||
1271 | */ |
||
1272 | function update_jetpack_main_network_site_option() { |
||
1273 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1274 | } |
||
1275 | /** |
||
1276 | * Triggered after a user updates the network settings via Network Settings Admin Page |
||
1277 | * |
||
1278 | */ |
||
1279 | function update_jetpack_network_settings() { |
||
1280 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1281 | // Only sync this info for the main network site. |
||
1282 | } |
||
1283 | |||
1284 | /** |
||
1285 | * Get back if the current site is single user site. |
||
1286 | * |
||
1287 | * @return bool |
||
1288 | */ |
||
1289 | public static function is_single_user_site() { |
||
1290 | global $wpdb; |
||
1291 | |||
1292 | View Code Duplication | if ( false === ( $some_users = get_transient( 'jetpack_is_single_user' ) ) ) { |
|
1293 | $some_users = $wpdb->get_var( "SELECT COUNT(*) FROM (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$wpdb->prefix}capabilities' LIMIT 2) AS someusers" ); |
||
1294 | set_transient( 'jetpack_is_single_user', (int) $some_users, 12 * HOUR_IN_SECONDS ); |
||
1295 | } |
||
1296 | return 1 === (int) $some_users; |
||
1297 | } |
||
1298 | |||
1299 | /** |
||
1300 | * Returns true if the site has file write access false otherwise. |
||
1301 | * @return string ( '1' | '0' ) |
||
1302 | **/ |
||
1303 | public static function file_system_write_access() { |
||
1304 | if ( ! function_exists( 'get_filesystem_method' ) ) { |
||
1305 | require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
||
1306 | } |
||
1307 | |||
1308 | require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
||
1309 | |||
1310 | $filesystem_method = get_filesystem_method(); |
||
1311 | if ( $filesystem_method === 'direct' ) { |
||
1312 | return 1; |
||
1313 | } |
||
1314 | |||
1315 | ob_start(); |
||
1316 | $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); |
||
1317 | ob_end_clean(); |
||
1318 | if ( $filesystem_credentials_are_stored ) { |
||
1319 | return 1; |
||
1320 | } |
||
1321 | return 0; |
||
1322 | } |
||
1323 | |||
1324 | /** |
||
1325 | * Finds out if a site is using a version control system. |
||
1326 | * @return string ( '1' | '0' ) |
||
1327 | **/ |
||
1328 | public static function is_version_controlled() { |
||
1329 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Functions::is_version_controlled' ); |
||
1330 | return (string) (int) Jetpack_Sync_Functions::is_version_controlled(); |
||
1331 | } |
||
1332 | |||
1333 | /** |
||
1334 | * Determines whether the current theme supports featured images or not. |
||
1335 | * @return string ( '1' | '0' ) |
||
1336 | */ |
||
1337 | public static function featured_images_enabled() { |
||
1338 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1339 | return current_theme_supports( 'post-thumbnails' ) ? '1' : '0'; |
||
1340 | } |
||
1341 | |||
1342 | /** |
||
1343 | * Wrapper for core's get_avatar_url(). This one is deprecated. |
||
1344 | * |
||
1345 | * @deprecated 4.7 use get_avatar_url instead. |
||
1346 | * @param int|string|object $id_or_email A user ID, email address, or comment object |
||
1347 | * @param int $size Size of the avatar image |
||
1348 | * @param string $default URL to a default image to use if no avatar is available |
||
1349 | * @param bool $force_display Whether to force it to return an avatar even if show_avatars is disabled |
||
1350 | * |
||
1351 | * @return array |
||
1352 | */ |
||
1353 | public static function get_avatar_url( $id_or_email, $size = 96, $default = '', $force_display = false ) { |
||
1354 | _deprecated_function( __METHOD__, 'jetpack-4.7', 'get_avatar_url' ); |
||
1355 | return get_avatar_url( $id_or_email, array( |
||
1356 | 'size' => $size, |
||
1357 | 'default' => $default, |
||
1358 | 'force_default' => $force_display, |
||
1359 | ) ); |
||
1360 | } |
||
1361 | |||
1362 | /** |
||
1363 | * jetpack_updates is saved in the following schema: |
||
1364 | * |
||
1365 | * array ( |
||
1366 | * 'plugins' => (int) Number of plugin updates available. |
||
1367 | * 'themes' => (int) Number of theme updates available. |
||
1368 | * 'wordpress' => (int) Number of WordPress core updates available. |
||
1369 | * 'translations' => (int) Number of translation updates available. |
||
1370 | * 'total' => (int) Total of all available updates. |
||
1371 | * 'wp_update_version' => (string) The latest available version of WordPress, only present if a WordPress update is needed. |
||
1372 | * ) |
||
1373 | * @return array |
||
1374 | */ |
||
1375 | public static function get_updates() { |
||
1376 | $update_data = wp_get_update_data(); |
||
1377 | |||
1378 | // Stores the individual update counts as well as the total count. |
||
1379 | if ( isset( $update_data['counts'] ) ) { |
||
1380 | $updates = $update_data['counts']; |
||
1381 | } |
||
1382 | |||
1383 | // If we need to update WordPress core, let's find the latest version number. |
||
1384 | View Code Duplication | if ( ! empty( $updates['wordpress'] ) ) { |
|
1385 | $cur = get_preferred_from_update_core(); |
||
1386 | if ( isset( $cur->response ) && 'upgrade' === $cur->response ) { |
||
1387 | $updates['wp_update_version'] = $cur->current; |
||
1388 | } |
||
1389 | } |
||
1390 | return isset( $updates ) ? $updates : array(); |
||
1391 | } |
||
1392 | |||
1393 | public static function get_update_details() { |
||
1394 | $update_details = array( |
||
1395 | 'update_core' => get_site_transient( 'update_core' ), |
||
1396 | 'update_plugins' => get_site_transient( 'update_plugins' ), |
||
1397 | 'update_themes' => get_site_transient( 'update_themes' ), |
||
1398 | ); |
||
1399 | return $update_details; |
||
1400 | } |
||
1401 | |||
1402 | public static function refresh_update_data() { |
||
1403 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1404 | |||
1405 | } |
||
1406 | |||
1407 | public static function refresh_theme_data() { |
||
1408 | _deprecated_function( __METHOD__, 'jetpack-4.2' ); |
||
1409 | } |
||
1410 | |||
1411 | /** |
||
1412 | * Is Jetpack active? |
||
1413 | */ |
||
1414 | public static function is_active() { |
||
1415 | return (bool) Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
1416 | } |
||
1417 | |||
1418 | /** |
||
1419 | * Make an API call to WordPress.com for plan status |
||
1420 | * |
||
1421 | * @uses Jetpack_Options::get_option() |
||
1422 | * @uses Jetpack_Client::wpcom_json_api_request_as_blog() |
||
1423 | * @uses update_option() |
||
1424 | * |
||
1425 | * @access public |
||
1426 | * @static |
||
1427 | * |
||
1428 | * @return bool True if plan is updated, false if no update |
||
1429 | */ |
||
1430 | public static function refresh_active_plan_from_wpcom() { |
||
1431 | // Make the API request |
||
1432 | $request = sprintf( '/sites/%d', Jetpack_Options::get_option( 'id' ) ); |
||
1433 | $response = Jetpack_Client::wpcom_json_api_request_as_blog( $request, '1.1' ); |
||
1434 | |||
1435 | // Bail if there was an error or malformed response |
||
1436 | if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) { |
||
1437 | return false; |
||
1438 | } |
||
1439 | |||
1440 | // Decode the results |
||
1441 | $results = json_decode( $response['body'], true ); |
||
1442 | |||
1443 | // Bail if there were no results or plan details returned |
||
1444 | if ( ! is_array( $results ) || ! isset( $results['plan'] ) ) { |
||
1445 | return false; |
||
1446 | } |
||
1447 | |||
1448 | // Store the option and return true if updated |
||
1449 | return update_option( 'jetpack_active_plan', $results['plan'] ); |
||
1450 | } |
||
1451 | |||
1452 | /** |
||
1453 | * Get the plan that this Jetpack site is currently using |
||
1454 | * |
||
1455 | * @uses get_option() |
||
1456 | * |
||
1457 | * @access public |
||
1458 | * @static |
||
1459 | * |
||
1460 | * @return array Active Jetpack plan details |
||
1461 | */ |
||
1462 | public static function get_active_plan() { |
||
1463 | global $active_plan_cache; |
||
1464 | |||
1465 | // this can be expensive to compute so we cache for the duration of a request |
||
1466 | if ( is_array( $active_plan_cache ) && ! empty( $active_plan_cache ) ) { |
||
1467 | return $active_plan_cache; |
||
1468 | } |
||
1469 | |||
1470 | $plan = get_option( 'jetpack_active_plan', array() ); |
||
1471 | |||
1472 | // Set the default options |
||
1473 | $plan = wp_parse_args( $plan, array( |
||
1474 | 'product_slug' => 'jetpack_free', |
||
1475 | 'class' => 'free', |
||
1476 | 'features' => array( |
||
1477 | 'active' => array() |
||
1478 | ), |
||
1479 | ) ); |
||
1480 | |||
1481 | $supports = array(); |
||
1482 | |||
1483 | // Define what paid modules are supported by personal plans |
||
1484 | $personal_plans = array( |
||
1485 | 'jetpack_personal', |
||
1486 | 'jetpack_personal_monthly', |
||
1487 | 'personal-bundle', |
||
1488 | ); |
||
1489 | |||
1490 | if ( in_array( $plan['product_slug'], $personal_plans ) ) { |
||
1491 | // special support value, not a module but a separate plugin |
||
1492 | $supports[] = 'akismet'; |
||
1493 | $plan['class'] = 'personal'; |
||
1494 | } |
||
1495 | |||
1496 | // Define what paid modules are supported by premium plans |
||
1497 | $premium_plans = array( |
||
1498 | 'jetpack_premium', |
||
1499 | 'jetpack_premium_monthly', |
||
1500 | 'value_bundle', |
||
1501 | ); |
||
1502 | |||
1503 | View Code Duplication | if ( in_array( $plan['product_slug'], $premium_plans ) ) { |
|
1504 | $supports[] = 'akismet'; |
||
1505 | $supports[] = 'vaultpress'; |
||
1506 | $plan['class'] = 'premium'; |
||
1507 | } |
||
1508 | |||
1509 | // Define what paid modules are supported by professional plans |
||
1510 | $business_plans = array( |
||
1511 | 'jetpack_business', |
||
1512 | 'jetpack_business_monthly', |
||
1513 | 'business-bundle', |
||
1514 | 'vip', |
||
1515 | ); |
||
1516 | |||
1517 | View Code Duplication | if ( in_array( $plan['product_slug'], $business_plans ) ) { |
|
1518 | $supports[] = 'akismet'; |
||
1519 | $supports[] = 'vaultpress'; |
||
1520 | $plan['class'] = 'business'; |
||
1521 | } |
||
1522 | |||
1523 | // get available features |
||
1524 | foreach ( self::get_available_modules() as $module_slug ) { |
||
1525 | $module = self::get_module( $module_slug ); |
||
1526 | if ( ! isset( $module ) || ! is_array( $module ) ) { |
||
1527 | continue; |
||
1528 | } |
||
1529 | if ( in_array( 'free', $module['plan_classes'] ) || in_array( $plan['class'], $module['plan_classes'] ) ) { |
||
1530 | $supports[] = $module_slug; |
||
1531 | } |
||
1532 | } |
||
1533 | |||
1534 | $plan['supports'] = $supports; |
||
1535 | |||
1536 | $active_plan_cache = $plan; |
||
1537 | |||
1538 | return $plan; |
||
1539 | } |
||
1540 | |||
1541 | /** |
||
1542 | * Determine whether the active plan supports a particular feature |
||
1543 | * |
||
1544 | * @uses Jetpack::get_active_plan() |
||
1545 | * |
||
1546 | * @access public |
||
1547 | * @static |
||
1548 | * |
||
1549 | * @return bool True if plan supports feature, false if not |
||
1550 | */ |
||
1551 | public static function active_plan_supports( $feature ) { |
||
1552 | $plan = Jetpack::get_active_plan(); |
||
1553 | |||
1554 | // Manually mapping WordPress.com features to Jetpack module slugs |
||
1555 | foreach ( $plan['features']['active'] as $wpcom_feature ) { |
||
1556 | switch ( $wpcom_feature ) { |
||
1557 | case 'wordads-jetpack'; |
||
1558 | |||
1559 | // WordAds are supported for this site |
||
1560 | if ( 'wordads' === $feature ) { |
||
1561 | return true; |
||
1562 | } |
||
1563 | break; |
||
1564 | } |
||
1565 | } |
||
1566 | |||
1567 | if ( |
||
1568 | in_array( $feature, $plan['supports'] ) |
||
1569 | || in_array( $feature, $plan['features']['active'] ) |
||
1570 | ) { |
||
1571 | return true; |
||
1572 | } |
||
1573 | |||
1574 | return false; |
||
1575 | } |
||
1576 | |||
1577 | /** |
||
1578 | * Is Jetpack in development (offline) mode? |
||
1579 | */ |
||
1580 | public static function is_development_mode() { |
||
1581 | $development_mode = false; |
||
1582 | |||
1583 | if ( defined( 'JETPACK_DEV_DEBUG' ) ) { |
||
1584 | $development_mode = JETPACK_DEV_DEBUG; |
||
1585 | } elseif ( $site_url = site_url() ) { |
||
1586 | $development_mode = false === strpos( $site_url, '.' ); |
||
1587 | } |
||
1588 | |||
1589 | /** |
||
1590 | * Filters Jetpack's development mode. |
||
1591 | * |
||
1592 | * @see https://jetpack.com/support/development-mode/ |
||
1593 | * |
||
1594 | * @since 2.2.1 |
||
1595 | * |
||
1596 | * @param bool $development_mode Is Jetpack's development mode active. |
||
1597 | */ |
||
1598 | $development_mode = ( bool ) apply_filters( 'jetpack_development_mode', $development_mode ); |
||
1599 | return $development_mode; |
||
1600 | } |
||
1601 | |||
1602 | /** |
||
1603 | * Whether the site is currently onboarding or not. |
||
1604 | * A site is considered as being onboarded if it currently has an onboarding token. |
||
1605 | * |
||
1606 | * @since 5.8 |
||
1607 | * |
||
1608 | * @access public |
||
1609 | * @static |
||
1610 | * |
||
1611 | * @return bool True if the site is currently onboarding, false otherwise |
||
1612 | */ |
||
1613 | public static function is_onboarding() { |
||
1614 | return Jetpack_Options::get_option( 'onboarding' ) !== false; |
||
1615 | } |
||
1616 | |||
1617 | /** |
||
1618 | * Get Jetpack development mode notice text and notice class. |
||
1619 | * |
||
1620 | * Mirrors the checks made in Jetpack::is_development_mode |
||
1621 | * |
||
1622 | */ |
||
1623 | public static function show_development_mode_notice() { |
||
1624 | if ( Jetpack::is_development_mode() ) { |
||
1625 | if ( defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG ) { |
||
1626 | $notice = sprintf( |
||
1627 | /* translators: %s is a URL */ |
||
1628 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the JETPACK_DEV_DEBUG constant being defined in wp-config.php or elsewhere.', 'jetpack' ), |
||
1629 | 'https://jetpack.com/support/development-mode/' |
||
1630 | ); |
||
1631 | } elseif ( site_url() && false === strpos( site_url(), '.' ) ) { |
||
1632 | $notice = sprintf( |
||
1633 | /* translators: %s is a URL */ |
||
1634 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via site URL lacking a dot (e.g. http://localhost).', 'jetpack' ), |
||
1635 | 'https://jetpack.com/support/development-mode/' |
||
1636 | ); |
||
1637 | } else { |
||
1638 | $notice = sprintf( |
||
1639 | /* translators: %s is a URL */ |
||
1640 | __( 'In <a href="%s" target="_blank">Development Mode</a>, via the jetpack_development_mode filter.', 'jetpack' ), |
||
1641 | 'https://jetpack.com/support/development-mode/' |
||
1642 | ); |
||
1643 | } |
||
1644 | |||
1645 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1646 | } |
||
1647 | |||
1648 | // Throw up a notice if using a development version and as for feedback. |
||
1649 | if ( Jetpack::is_development_version() ) { |
||
1650 | /* translators: %s is a URL */ |
||
1651 | $notice = sprintf( __( 'You are currently running a development version of Jetpack. <a href="%s" target="_blank">Submit your feedback</a>', 'jetpack' ), 'https://jetpack.com/contact-support/beta-group/' ); |
||
1652 | |||
1653 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1654 | } |
||
1655 | // Throw up a notice if using staging mode |
||
1656 | if ( Jetpack::is_staging_site() ) { |
||
1657 | /* translators: %s is a URL */ |
||
1658 | $notice = sprintf( __( 'You are running Jetpack on a <a href="%s" target="_blank">staging server</a>.', 'jetpack' ), 'https://jetpack.com/support/staging-sites/' ); |
||
1659 | |||
1660 | echo '<div class="updated" style="border-color: #f0821e;"><p>' . $notice . '</p></div>'; |
||
1661 | } |
||
1662 | } |
||
1663 | |||
1664 | /** |
||
1665 | * Whether Jetpack's version maps to a public release, or a development version. |
||
1666 | */ |
||
1667 | public static function is_development_version() { |
||
1668 | /** |
||
1669 | * Allows filtering whether this is a development version of Jetpack. |
||
1670 | * |
||
1671 | * This filter is especially useful for tests. |
||
1672 | * |
||
1673 | * @since 4.3.0 |
||
1674 | * |
||
1675 | * @param bool $development_version Is this a develoment version of Jetpack? |
||
1676 | */ |
||
1677 | return (bool) apply_filters( |
||
1678 | 'jetpack_development_version', |
||
1679 | ! preg_match( '/^\d+(\.\d+)+$/', Jetpack_Constants::get_constant( 'JETPACK__VERSION' ) ) |
||
1680 | ); |
||
1681 | } |
||
1682 | |||
1683 | /** |
||
1684 | * Is a given user (or the current user if none is specified) linked to a WordPress.com user? |
||
1685 | */ |
||
1686 | public static function is_user_connected( $user_id = false ) { |
||
1687 | $user_id = false === $user_id ? get_current_user_id() : absint( $user_id ); |
||
1688 | if ( ! $user_id ) { |
||
1689 | return false; |
||
1690 | } |
||
1691 | |||
1692 | return (bool) Jetpack_Data::get_access_token( $user_id ); |
||
1693 | } |
||
1694 | |||
1695 | /** |
||
1696 | * Get the wpcom user data of the current|specified connected user. |
||
1697 | */ |
||
1698 | public static function get_connected_user_data( $user_id = null ) { |
||
1699 | if ( ! $user_id ) { |
||
1700 | $user_id = get_current_user_id(); |
||
1701 | } |
||
1702 | |||
1703 | $transient_key = "jetpack_connected_user_data_$user_id"; |
||
1704 | |||
1705 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
||
1706 | return $cached_user_data; |
||
1707 | } |
||
1708 | |||
1709 | Jetpack::load_xml_rpc_client(); |
||
1710 | $xml = new Jetpack_IXR_Client( array( |
||
1711 | 'user_id' => $user_id, |
||
1712 | ) ); |
||
1713 | $xml->query( 'wpcom.getUser' ); |
||
1714 | if ( ! $xml->isError() ) { |
||
1715 | $user_data = $xml->getResponse(); |
||
1716 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
||
1717 | return $user_data; |
||
1718 | } |
||
1719 | |||
1720 | return false; |
||
1721 | } |
||
1722 | |||
1723 | /** |
||
1724 | * Get the wpcom email of the current|specified connected user. |
||
1725 | */ |
||
1726 | View Code Duplication | public static function get_connected_user_email( $user_id = null ) { |
|
1727 | if ( ! $user_id ) { |
||
1728 | $user_id = get_current_user_id(); |
||
1729 | } |
||
1730 | Jetpack::load_xml_rpc_client(); |
||
1731 | $xml = new Jetpack_IXR_Client( array( |
||
1732 | 'user_id' => $user_id, |
||
1733 | ) ); |
||
1734 | $xml->query( 'wpcom.getUserEmail' ); |
||
1735 | if ( ! $xml->isError() ) { |
||
1736 | return $xml->getResponse(); |
||
1737 | } |
||
1738 | return false; |
||
1739 | } |
||
1740 | |||
1741 | /** |
||
1742 | * Get the wpcom email of the master user. |
||
1743 | */ |
||
1744 | public static function get_master_user_email() { |
||
1745 | $master_user_id = Jetpack_Options::get_option( 'master_user' ); |
||
1746 | if ( $master_user_id ) { |
||
1747 | return self::get_connected_user_email( $master_user_id ); |
||
1748 | } |
||
1749 | return ''; |
||
1750 | } |
||
1751 | |||
1752 | function current_user_is_connection_owner() { |
||
1753 | $user_token = Jetpack_Data::get_access_token( JETPACK_MASTER_USER ); |
||
1754 | return $user_token && is_object( $user_token ) && isset( $user_token->external_user_id ) && get_current_user_id() === $user_token->external_user_id; |
||
1755 | } |
||
1756 | |||
1757 | /** |
||
1758 | * Gets current user IP address. |
||
1759 | * |
||
1760 | * @param bool $check_all_headers Check all headers? Default is `false`. |
||
1761 | * |
||
1762 | * @return string Current user IP address. |
||
1763 | */ |
||
1764 | public static function current_user_ip( $check_all_headers = false ) { |
||
1765 | if ( $check_all_headers ) { |
||
1766 | foreach ( array( |
||
1767 | 'HTTP_CF_CONNECTING_IP', |
||
1768 | 'HTTP_CLIENT_IP', |
||
1769 | 'HTTP_X_FORWARDED_FOR', |
||
1770 | 'HTTP_X_FORWARDED', |
||
1771 | 'HTTP_X_CLUSTER_CLIENT_IP', |
||
1772 | 'HTTP_FORWARDED_FOR', |
||
1773 | 'HTTP_FORWARDED', |
||
1774 | 'HTTP_VIA', |
||
1775 | ) as $key ) { |
||
1776 | if ( ! empty( $_SERVER[ $key ] ) ) { |
||
1777 | return $_SERVER[ $key ]; |
||
1778 | } |
||
1779 | } |
||
1780 | } |
||
1781 | |||
1782 | return ! empty( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : ''; |
||
1783 | } |
||
1784 | |||
1785 | /** |
||
1786 | * Add any extra oEmbed providers that we know about and use on wpcom for feature parity. |
||
1787 | */ |
||
1788 | function extra_oembed_providers() { |
||
1789 | // Cloudup: https://dev.cloudup.com/#oembed |
||
1790 | wp_oembed_add_provider( 'https://cloudup.com/*' , 'https://cloudup.com/oembed' ); |
||
1791 | wp_oembed_add_provider( 'https://me.sh/*', 'https://me.sh/oembed?format=json' ); |
||
1792 | wp_oembed_add_provider( '#https?://(www\.)?gfycat\.com/.*#i', 'https://api.gfycat.com/v1/oembed', true ); |
||
1793 | wp_oembed_add_provider( '#https?://[^.]+\.(wistia\.com|wi\.st)/(medias|embed)/.*#', 'https://fast.wistia.com/oembed', true ); |
||
1794 | wp_oembed_add_provider( '#https?://sketchfab\.com/.*#i', 'https://sketchfab.com/oembed', true ); |
||
1795 | wp_oembed_add_provider( '#https?://(www\.)?icloud\.com/keynote/.*#i', 'https://iwmb.icloud.com/iwmb/oembed', true ); |
||
1796 | } |
||
1797 | |||
1798 | /** |
||
1799 | * Synchronize connected user role changes |
||
1800 | */ |
||
1801 | function user_role_change( $user_id ) { |
||
1802 | _deprecated_function( __METHOD__, 'jetpack-4.2', 'Jetpack_Sync_Users::user_role_change()' ); |
||
1803 | Jetpack_Sync_Users::user_role_change( $user_id ); |
||
1804 | } |
||
1805 | |||
1806 | /** |
||
1807 | * Loads the currently active modules. |
||
1808 | */ |
||
1809 | public static function load_modules() { |
||
1810 | if ( |
||
1811 | ! self::is_active() |
||
1812 | && ! self::is_development_mode() |
||
1813 | && ! self::is_onboarding() |
||
1814 | && ( |
||
1815 | ! is_multisite() |
||
1816 | || ! get_site_option( 'jetpack_protect_active' ) |
||
1817 | ) |
||
1818 | ) { |
||
1819 | return; |
||
1820 | } |
||
1821 | |||
1822 | $version = Jetpack_Options::get_option( 'version' ); |
||
1823 | View Code Duplication | if ( ! $version ) { |
|
1824 | $version = $old_version = JETPACK__VERSION . ':' . time(); |
||
1825 | /** This action is documented in class.jetpack.php */ |
||
1826 | do_action( 'updating_jetpack_version', $version, false ); |
||
1827 | Jetpack_Options::update_options( compact( 'version', 'old_version' ) ); |
||
1828 | } |
||
1829 | list( $version ) = explode( ':', $version ); |
||
1830 | |||
1831 | $modules = array_filter( Jetpack::get_active_modules(), array( 'Jetpack', 'is_module' ) ); |
||
1832 | |||
1833 | $modules_data = array(); |
||
1834 | |||
1835 | // Don't load modules that have had "Major" changes since the stored version until they have been deactivated/reactivated through the lint check. |
||
1836 | if ( version_compare( $version, JETPACK__VERSION, '<' ) ) { |
||
1837 | $updated_modules = array(); |
||
1838 | foreach ( $modules as $module ) { |
||
1839 | $modules_data[ $module ] = Jetpack::get_module( $module ); |
||
1840 | if ( ! isset( $modules_data[ $module ]['changed'] ) ) { |
||
1841 | continue; |
||
1842 | } |
||
1843 | |||
1844 | if ( version_compare( $modules_data[ $module ]['changed'], $version, '<=' ) ) { |
||
1845 | continue; |
||
1846 | } |
||
1847 | |||
1848 | $updated_modules[] = $module; |
||
1849 | } |
||
1850 | |||
1851 | $modules = array_diff( $modules, $updated_modules ); |
||
1852 | } |
||
1853 | |||
1854 | $is_development_mode = Jetpack::is_development_mode(); |
||
1855 | |||
1856 | foreach ( $modules as $index => $module ) { |
||
1857 | // If we're in dev mode, disable modules requiring a connection |
||
1858 | if ( $is_development_mode ) { |
||
1859 | // Prime the pump if we need to |
||
1860 | if ( empty( $modules_data[ $module ] ) ) { |
||
1861 | $modules_data[ $module ] = Jetpack::get_module( $module ); |
||
1862 | } |
||
1863 | // If the module requires a connection, but we're in local mode, don't include it. |
||
1864 | if ( $modules_data[ $module ]['requires_connection'] ) { |
||
1865 | continue; |
||
1866 | } |
||
1867 | } |
||
1868 | |||
1869 | if ( did_action( 'jetpack_module_loaded_' . $module ) ) { |
||
1870 | continue; |
||
1871 | } |
||
1872 | |||
1873 | if ( ! include_once( Jetpack::get_module_path( $module ) ) ) { |
||
1874 | unset( $modules[ $index ] ); |
||
1875 | self::update_active_modules( array_values( $modules ) ); |
||
1876 | continue; |
||
1877 | } |
||
1878 | |||
1879 | /** |
||
1880 | * Fires when a specific module is loaded. |
||
1881 | * The dynamic part of the hook, $module, is the module slug. |
||
1882 | * |
||
1883 | * @since 1.1.0 |
||
1884 | */ |
||
1885 | do_action( 'jetpack_module_loaded_' . $module ); |
||
1886 | } |
||
1887 | |||
1888 | /** |
||
1889 | * Fires when all the modules are loaded. |
||
1890 | * |
||
1891 | * @since 1.1.0 |
||
1892 | */ |
||
1893 | do_action( 'jetpack_modules_loaded' ); |
||
1894 | |||
1895 | // Load module-specific code that is needed even when a module isn't active. Loaded here because code contained therein may need actions such as setup_theme. |
||
1896 | require_once( JETPACK__PLUGIN_DIR . 'modules/module-extras.php' ); |
||
1897 | } |
||
1898 | |||
1899 | /** |
||
1900 | * Check if Jetpack's REST API compat file should be included |
||
1901 | * @action plugins_loaded |
||
1902 | * @return null |
||
1903 | */ |
||
1904 | public function check_rest_api_compat() { |
||
1905 | /** |
||
1906 | * Filters the list of REST API compat files to be included. |
||
1907 | * |
||
1908 | * @since 2.2.5 |
||
1909 | * |
||
1910 | * @param array $args Array of REST API compat files to include. |
||
1911 | */ |
||
1912 | $_jetpack_rest_api_compat_includes = apply_filters( 'jetpack_rest_api_compat', array() ); |
||
1913 | |||
1914 | if ( function_exists( 'bbpress' ) ) |
||
1915 | $_jetpack_rest_api_compat_includes[] = JETPACK__PLUGIN_DIR . 'class.jetpack-bbpress-json-api-compat.php'; |
||
1916 | |||
1917 | foreach ( $_jetpack_rest_api_compat_includes as $_jetpack_rest_api_compat_include ) |
||
1918 | require_once $_jetpack_rest_api_compat_include; |
||
1919 | } |
||
1920 | |||
1921 | /** |
||
1922 | * Gets all plugins currently active in values, regardless of whether they're |
||
1923 | * traditionally activated or network activated. |
||
1924 | * |
||
1925 | * @todo Store the result in core's object cache maybe? |
||
1926 | */ |
||
1927 | public static function get_active_plugins() { |
||
1928 | $active_plugins = (array) get_option( 'active_plugins', array() ); |
||
1929 | |||
1930 | if ( is_multisite() ) { |
||
1931 | // Due to legacy code, active_sitewide_plugins stores them in the keys, |
||
1932 | // whereas active_plugins stores them in the values. |
||
1933 | $network_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
||
1934 | if ( $network_plugins ) { |
||
1935 | $active_plugins = array_merge( $active_plugins, $network_plugins ); |
||
1936 | } |
||
1937 | } |
||
1938 | |||
1939 | sort( $active_plugins ); |
||
1940 | |||
1941 | return array_unique( $active_plugins ); |
||
1942 | } |
||
1943 | |||
1944 | /** |
||
1945 | * Gets and parses additional plugin data to send with the heartbeat data |
||
1946 | * |
||
1947 | * @since 3.8.1 |
||
1948 | * |
||
1949 | * @return array Array of plugin data |
||
1950 | */ |
||
1951 | public static function get_parsed_plugin_data() { |
||
1952 | if ( ! function_exists( 'get_plugins' ) ) { |
||
1953 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
||
1954 | } |
||
1955 | /** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ |
||
1956 | $all_plugins = apply_filters( 'all_plugins', get_plugins() ); |
||
1957 | $active_plugins = Jetpack::get_active_plugins(); |
||
1958 | |||
1959 | $plugins = array(); |
||
1960 | foreach ( $all_plugins as $path => $plugin_data ) { |
||
1961 | $plugins[ $path ] = array( |
||
1962 | 'is_active' => in_array( $path, $active_plugins ), |
||
1963 | 'file' => $path, |
||
1964 | 'name' => $plugin_data['Name'], |
||
1965 | 'version' => $plugin_data['Version'], |
||
1966 | 'author' => $plugin_data['Author'], |
||
1967 | ); |
||
1968 | } |
||
1969 | |||
1970 | return $plugins; |
||
1971 | } |
||
1972 | |||
1973 | /** |
||
1974 | * Gets and parses theme data to send with the heartbeat data |
||
1975 | * |
||
1976 | * @since 3.8.1 |
||
1977 | * |
||
1978 | * @return array Array of theme data |
||
1979 | */ |
||
1980 | public static function get_parsed_theme_data() { |
||
1981 | $all_themes = wp_get_themes( array( 'allowed' => true ) ); |
||
1982 | $header_keys = array( 'Name', 'Author', 'Version', 'ThemeURI', 'AuthorURI', 'Status', 'Tags' ); |
||
1983 | |||
1984 | $themes = array(); |
||
1985 | foreach ( $all_themes as $slug => $theme_data ) { |
||
1986 | $theme_headers = array(); |
||
1987 | foreach ( $header_keys as $header_key ) { |
||
1988 | $theme_headers[ $header_key ] = $theme_data->get( $header_key ); |
||
1989 | } |
||
1990 | |||
1991 | $themes[ $slug ] = array( |
||
1992 | 'is_active_theme' => $slug == wp_get_theme()->get_template(), |
||
1993 | 'slug' => $slug, |
||
1994 | 'theme_root' => $theme_data->get_theme_root_uri(), |
||
1995 | 'parent' => $theme_data->parent(), |
||
1996 | 'headers' => $theme_headers |
||
1997 | ); |
||
1998 | } |
||
1999 | |||
2000 | return $themes; |
||
2001 | } |
||
2002 | |||
2003 | /** |
||
2004 | * Checks whether a specific plugin is active. |
||
2005 | * |
||
2006 | * We don't want to store these in a static variable, in case |
||
2007 | * there are switch_to_blog() calls involved. |
||
2008 | */ |
||
2009 | public static function is_plugin_active( $plugin = 'jetpack/jetpack.php' ) { |
||
2010 | return in_array( $plugin, self::get_active_plugins() ); |
||
2011 | } |
||
2012 | |||
2013 | /** |
||
2014 | * Check if Jetpack's Open Graph tags should be used. |
||
2015 | * If certain plugins are active, Jetpack's og tags are suppressed. |
||
2016 | * |
||
2017 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2018 | * @action plugins_loaded |
||
2019 | * @return null |
||
2020 | */ |
||
2021 | public function check_open_graph() { |
||
2022 | if ( in_array( 'publicize', Jetpack::get_active_modules() ) || in_array( 'sharedaddy', Jetpack::get_active_modules() ) ) { |
||
2023 | add_filter( 'jetpack_enable_open_graph', '__return_true', 0 ); |
||
2024 | } |
||
2025 | |||
2026 | $active_plugins = self::get_active_plugins(); |
||
2027 | |||
2028 | if ( ! empty( $active_plugins ) ) { |
||
2029 | foreach ( $this->open_graph_conflicting_plugins as $plugin ) { |
||
2030 | if ( in_array( $plugin, $active_plugins ) ) { |
||
2031 | add_filter( 'jetpack_enable_open_graph', '__return_false', 99 ); |
||
2032 | break; |
||
2033 | } |
||
2034 | } |
||
2035 | } |
||
2036 | |||
2037 | /** |
||
2038 | * Allow the addition of Open Graph Meta Tags to all pages. |
||
2039 | * |
||
2040 | * @since 2.0.3 |
||
2041 | * |
||
2042 | * @param bool false Should Open Graph Meta tags be added. Default to false. |
||
2043 | */ |
||
2044 | if ( apply_filters( 'jetpack_enable_open_graph', false ) ) { |
||
2045 | require_once JETPACK__PLUGIN_DIR . 'functions.opengraph.php'; |
||
2046 | } |
||
2047 | } |
||
2048 | |||
2049 | /** |
||
2050 | * Check if Jetpack's Twitter tags should be used. |
||
2051 | * If certain plugins are active, Jetpack's twitter tags are suppressed. |
||
2052 | * |
||
2053 | * @uses Jetpack::get_active_modules, add_filter, get_option, apply_filters |
||
2054 | * @action plugins_loaded |
||
2055 | * @return null |
||
2056 | */ |
||
2057 | public function check_twitter_tags() { |
||
2058 | |||
2059 | $active_plugins = self::get_active_plugins(); |
||
2060 | |||
2061 | if ( ! empty( $active_plugins ) ) { |
||
2062 | foreach ( $this->twitter_cards_conflicting_plugins as $plugin ) { |
||
2063 | if ( in_array( $plugin, $active_plugins ) ) { |
||
2064 | add_filter( 'jetpack_disable_twitter_cards', '__return_true', 99 ); |
||
2065 | break; |
||
2066 | } |
||
2067 | } |
||
2068 | } |
||
2069 | |||
2070 | /** |
||
2071 | * Allow Twitter Card Meta tags to be disabled. |
||
2072 | * |
||
2073 | * @since 2.6.0 |
||
2074 | * |
||
2075 | * @param bool true Should Twitter Card Meta tags be disabled. Default to true. |
||
2076 | */ |
||
2077 | if ( ! apply_filters( 'jetpack_disable_twitter_cards', false ) ) { |
||
2078 | require_once JETPACK__PLUGIN_DIR . 'class.jetpack-twitter-cards.php'; |
||
2079 | } |
||
2080 | } |
||
2081 | |||
2082 | /** |
||
2083 | * Allows plugins to submit security reports. |
||
2084 | * |
||
2085 | * @param string $type Report type (login_form, backup, file_scanning, spam) |
||
2086 | * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data |
||
2087 | * @param array $args See definitions above |
||
2088 | */ |
||
2089 | public static function submit_security_report( $type = '', $plugin_file = '', $args = array() ) { |
||
2090 | _deprecated_function( __FUNCTION__, 'jetpack-4.2', null ); |
||
2091 | } |
||
2092 | |||
2093 | /* Jetpack Options API */ |
||
2094 | |||
2095 | public static function get_option_names( $type = 'compact' ) { |
||
2096 | return Jetpack_Options::get_option_names( $type ); |
||
2097 | } |
||
2098 | |||
2099 | /** |
||
2100 | * Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate. |
||
2101 | * |
||
2102 | * @param string $name Option name |
||
2103 | * @param mixed $default (optional) |
||
2104 | */ |
||
2105 | public static function get_option( $name, $default = false ) { |
||
2106 | return Jetpack_Options::get_option( $name, $default ); |
||
2107 | } |
||
2108 | |||
2109 | /** |
||
2110 | * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. |
||
2111 | * |
||
2112 | * @deprecated 3.4 use Jetpack_Options::update_option() instead. |
||
2113 | * @param string $name Option name |
||
2114 | * @param mixed $value Option value |
||
2115 | */ |
||
2116 | public static function update_option( $name, $value ) { |
||
2120 | |||
2121 | /** |
||
2122 | * Updates the multiple given options. Updates jetpack_options and/or jetpack_$name as appropriate. |
||
2123 | * |
||
2124 | * @deprecated 3.4 use Jetpack_Options::update_options() instead. |
||
2125 | * @param array $array array( option name => option value, ... ) |
||
2126 | */ |
||
2127 | public static function update_options( $array ) { |
||
2131 | |||
2132 | /** |
||
2133 | * Deletes the given option. May be passed multiple option names as an array. |
||
2134 | * Updates jetpack_options and/or deletes jetpack_$name as appropriate. |
||
2135 | * |
||
2136 | * @deprecated 3.4 use Jetpack_Options::delete_option() instead. |
||
2137 | * @param string|array $names |
||
2138 | */ |
||
2139 | public static function delete_option( $names ) { |
||
2143 | |||
2144 | /** |
||
2145 | * Enters a user token into the user_tokens option |
||
2146 | * |
||
2147 | * @param int $user_id |
||
2148 | * @param string $token |
||
2149 | * return bool |
||
2150 | */ |
||
2151 | public static function update_user_token( $user_id, $token, $is_master_user ) { |
||
2165 | |||
2166 | /** |
||
2167 | * Returns an array of all PHP files in the specified absolute path. |
||
2168 | * Equivalent to glob( "$absolute_path/*.php" ). |
||
2169 | * |
||
2170 | * @param string $absolute_path The absolute path of the directory to search. |
||
2171 | * @return array Array of absolute paths to the PHP files. |
||
2172 | */ |
||
2173 | public static function glob_php( $absolute_path ) { |
||
2202 | |||
2203 | public static function activate_new_modules( $redirect = false ) { |
||
2261 | |||
2262 | /** |
||
2263 | * List available Jetpack modules. Simply lists .php files in /modules/. |
||
2264 | * Make sure to tuck away module "library" files in a sub-directory. |
||
2265 | */ |
||
2266 | public static function get_available_modules( $min_version = false, $max_version = false ) { |
||
2323 | |||
2324 | /** |
||
2325 | * Default modules loaded on activation. |
||
2326 | */ |
||
2327 | public static function get_default_modules( $min_version = false, $max_version = false ) { |
||
2358 | |||
2359 | /** |
||
2360 | * Checks activated modules during auto-activation to determine |
||
2361 | * if any of those modules are being deprecated. If so, close |
||
2362 | * them out, and add any replacement modules. |
||
2363 | * |
||
2364 | * Runs at priority 99 by default. |
||
2365 | * |
||
2366 | * This is run late, so that it can still activate a module if |
||
2367 | * the new module is a replacement for another that the user |
||
2368 | * currently has active, even if something at the normal priority |
||
2369 | * would kibosh everything. |
||
2370 | * |
||
2371 | * @since 2.6 |
||
2372 | * @uses jetpack_get_default_modules filter |
||
2373 | * @param array $modules |
||
2374 | * @return array |
||
2375 | */ |
||
2376 | function handle_deprecated_modules( $modules ) { |
||
2402 | |||
2403 | /** |
||
2404 | * Checks activated plugins during auto-activation to determine |
||
2405 | * if any of those plugins are in the list with a corresponding module |
||
2406 | * that is not compatible with the plugin. The module will not be allowed |
||
2407 | * to auto-activate. |
||
2408 | * |
||
2409 | * @since 2.6 |
||
2410 | * @uses jetpack_get_default_modules filter |
||
2411 | * @param array $modules |
||
2412 | * @return array |
||
2413 | */ |
||
2414 | function filter_default_modules( $modules ) { |
||
2438 | |||
2439 | /** |
||
2440 | * Extract a module's slug from its full path. |
||
2441 | */ |
||
2442 | public static function get_module_slug( $file ) { |
||
2445 | |||
2446 | /** |
||
2447 | * Generate a module's path from its slug. |
||
2448 | */ |
||
2449 | public static function get_module_path( $slug ) { |
||
2452 | |||
2453 | /** |
||
2454 | * Load module data from module file. Headers differ from WordPress |
||
2455 | * plugin headers to avoid them being identified as standalone |
||
2456 | * plugins on the WordPress plugins page. |
||
2457 | */ |
||
2458 | public static function get_module( $module ) { |
||
2459 | $headers = array( |
||
2460 | 'name' => 'Module Name', |
||
2461 | 'description' => 'Module Description', |
||
2462 | 'jumpstart_desc' => 'Jumpstart Description', |
||
2463 | 'sort' => 'Sort Order', |
||
2464 | 'recommendation_order' => 'Recommendation Order', |
||
2465 | 'introduced' => 'First Introduced', |
||
2466 | 'changed' => 'Major Changes In', |
||
2467 | 'deactivate' => 'Deactivate', |
||
2468 | 'free' => 'Free', |
||
2469 | 'requires_connection' => 'Requires Connection', |
||
2470 | 'auto_activate' => 'Auto Activate', |
||
2471 | 'module_tags' => 'Module Tags', |
||
2472 | 'feature' => 'Feature', |
||
2473 | 'additional_search_queries' => 'Additional Search Queries', |
||
2474 | 'plan_classes' => 'Plans', |
||
2475 | ); |
||
2476 | |||
2477 | $file = Jetpack::get_module_path( Jetpack::get_module_slug( $module ) ); |
||
2478 | |||
2479 | $mod = Jetpack::get_file_data( $file, $headers ); |
||
2480 | if ( empty( $mod['name'] ) ) { |
||
2481 | return false; |
||
2482 | } |
||
2483 | |||
2484 | $mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort']; |
||
2485 | $mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order']; |
||
2486 | $mod['deactivate'] = empty( $mod['deactivate'] ); |
||
2487 | $mod['free'] = empty( $mod['free'] ); |
||
2488 | $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' == $mod['requires_connection'] ) ? false : true; |
||
2489 | |||
2490 | if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ) ) ) { |
||
2491 | $mod['auto_activate'] = 'No'; |
||
2492 | } else { |
||
2493 | $mod['auto_activate'] = (string) $mod['auto_activate']; |
||
2494 | } |
||
2495 | |||
2496 | if ( $mod['module_tags'] ) { |
||
2497 | $mod['module_tags'] = explode( ',', $mod['module_tags'] ); |
||
2498 | $mod['module_tags'] = array_map( 'trim', $mod['module_tags'] ); |
||
2499 | $mod['module_tags'] = array_map( array( __CLASS__, 'translate_module_tag' ), $mod['module_tags'] ); |
||
2500 | } else { |
||
2501 | $mod['module_tags'] = array( self::translate_module_tag( 'Other' ) ); |
||
2502 | } |
||
2503 | |||
2504 | View Code Duplication | if ( $mod['plan_classes'] ) { |
|
2505 | $mod['plan_classes'] = explode( ',', $mod['plan_classes'] ); |
||
2506 | $mod['plan_classes'] = array_map( 'strtolower', array_map( 'trim', $mod['plan_classes'] ) ); |
||
2507 | } else { |
||
2508 | $mod['plan_classes'] = array( 'free' ); |
||
2509 | } |
||
2510 | |||
2511 | View Code Duplication | if ( $mod['feature'] ) { |
|
2512 | $mod['feature'] = explode( ',', $mod['feature'] ); |
||
2513 | $mod['feature'] = array_map( 'trim', $mod['feature'] ); |
||
2514 | } else { |
||
2515 | $mod['feature'] = array( self::translate_module_tag( 'Other' ) ); |
||
2516 | } |
||
2517 | |||
2518 | /** |
||
2519 | * Filters the feature array on a module. |
||
2520 | * |
||
2521 | * This filter allows you to control where each module is filtered: Recommended, |
||
2522 | * Jumpstart, and the default "Other" listing. |
||
2523 | * |
||
2524 | * @since 3.5.0 |
||
2525 | * |
||
2526 | * @param array $mod['feature'] The areas to feature this module: |
||
2527 | * 'Jumpstart' adds to the "Jumpstart" option to activate many modules at once. |
||
2528 | * 'Recommended' shows on the main Jetpack admin screen. |
||
2529 | * 'Other' should be the default if no other value is in the array. |
||
2530 | * @param string $module The slug of the module, e.g. sharedaddy. |
||
2531 | * @param array $mod All the currently assembled module data. |
||
2532 | */ |
||
2533 | $mod['feature'] = apply_filters( 'jetpack_module_feature', $mod['feature'], $module, $mod ); |
||
2534 | |||
2535 | /** |
||
2536 | * Filter the returned data about a module. |
||
2537 | * |
||
2538 | * This filter allows overriding any info about Jetpack modules. It is dangerous, |
||
2539 | * so please be careful. |
||
2540 | * |
||
2541 | * @since 3.6.0 |
||
2542 | * |
||
2543 | * @param array $mod The details of the requested module. |
||
2544 | * @param string $module The slug of the module, e.g. sharedaddy |
||
2545 | * @param string $file The path to the module source file. |
||
2546 | */ |
||
2547 | return apply_filters( 'jetpack_get_module', $mod, $module, $file ); |
||
2548 | } |
||
2549 | |||
2550 | /** |
||
2551 | * Like core's get_file_data implementation, but caches the result. |
||
2552 | */ |
||
2553 | public static function get_file_data( $file, $headers ) { |
||
2554 | //Get just the filename from $file (i.e. exclude full path) so that a consistent hash is generated |
||
2555 | $file_name = basename( $file ); |
||
2556 | |||
2557 | $cache_key = 'jetpack_file_data_' . JETPACK__VERSION; |
||
2558 | |||
2559 | $file_data_option = get_transient( $cache_key ); |
||
2560 | |||
2561 | if ( false === $file_data_option ) { |
||
2562 | $file_data_option = array(); |
||
2563 | } |
||
2564 | |||
2565 | $key = md5( $file_name . serialize( $headers ) ); |
||
2566 | $refresh_cache = is_admin() && isset( $_GET['page'] ) && 'jetpack' === substr( $_GET['page'], 0, 7 ); |
||
2567 | |||
2568 | // If we don't need to refresh the cache, and already have the value, short-circuit! |
||
2569 | if ( ! $refresh_cache && isset( $file_data_option[ $key ] ) ) { |
||
2570 | return $file_data_option[ $key ]; |
||
2571 | } |
||
2572 | |||
2573 | $data = get_file_data( $file, $headers ); |
||
2574 | |||
2575 | $file_data_option[ $key ] = $data; |
||
2576 | |||
2577 | set_transient( $cache_key, $file_data_option, 29 * DAY_IN_SECONDS ); |
||
2578 | |||
2579 | return $data; |
||
2580 | } |
||
2581 | |||
2582 | |||
2583 | /** |
||
2584 | * Return translated module tag. |
||
2585 | * |
||
2586 | * @param string $tag Tag as it appears in each module heading. |
||
2587 | * |
||
2588 | * @return mixed |
||
2589 | */ |
||
2590 | public static function translate_module_tag( $tag ) { |
||
2593 | |||
2594 | /** |
||
2595 | * Get i18n strings as a JSON-encoded string |
||
2596 | * |
||
2597 | * @return string The locale as JSON |
||
2598 | */ |
||
2599 | public static function get_i18n_data_json() { |
||
2600 | $i18n_json = JETPACK__PLUGIN_DIR . 'languages/json/jetpack-' . jetpack_get_user_locale() . '.json'; |
||
2601 | |||
2602 | if ( is_file( $i18n_json ) && is_readable( $i18n_json ) ) { |
||
2603 | $locale_data = @file_get_contents( $i18n_json ); |
||
2604 | if ( $locale_data ) { |
||
2605 | return $locale_data; |
||
2606 | } |
||
2607 | } |
||
2608 | |||
2609 | // Return valid empty Jed locale |
||
2610 | return json_encode( array( |
||
2611 | '' => array( |
||
2612 | 'domain' => 'jetpack', |
||
2613 | 'lang' => is_admin() ? get_user_locale() : get_locale(), |
||
2614 | ), |
||
2615 | ) ); |
||
2616 | } |
||
2617 | |||
2618 | /** |
||
2619 | * Return module name translation. Uses matching string created in modules/module-headings.php. |
||
2620 | * |
||
2621 | * @since 3.9.2 |
||
2622 | * |
||
2623 | * @param array $modules |
||
2624 | * |
||
2625 | * @return string|void |
||
2626 | */ |
||
2627 | public static function get_translated_modules( $modules ) { |
||
2628 | foreach ( $modules as $index => $module ) { |
||
2629 | $i18n_module = jetpack_get_module_i18n( $module['module'] ); |
||
2630 | if ( isset( $module['name'] ) ) { |
||
2631 | $modules[ $index ]['name'] = $i18n_module['name']; |
||
2632 | } |
||
2633 | if ( isset( $module['description'] ) ) { |
||
2634 | $modules[ $index ]['description'] = $i18n_module['description']; |
||
2635 | $modules[ $index ]['short_description'] = $i18n_module['description']; |
||
2636 | } |
||
2637 | } |
||
2638 | return $modules; |
||
2639 | } |
||
2640 | |||
2641 | /** |
||
2642 | * Get a list of activated modules as an array of module slugs. |
||
2643 | */ |
||
2644 | public static function get_active_modules() { |
||
2645 | $active = Jetpack_Options::get_option( 'active_modules' ); |
||
2646 | |||
2647 | if ( ! is_array( $active ) ) { |
||
2648 | $active = array(); |
||
2649 | } |
||
2650 | |||
2651 | if ( class_exists( 'VaultPress' ) || function_exists( 'vaultpress_contact_service' ) ) { |
||
2652 | $active[] = 'vaultpress'; |
||
2653 | } else { |
||
2654 | $active = array_diff( $active, array( 'vaultpress' ) ); |
||
2655 | } |
||
2656 | |||
2657 | //If protect is active on the main site of a multisite, it should be active on all sites. |
||
2658 | if ( ! in_array( 'protect', $active ) && is_multisite() && get_site_option( 'jetpack_protect_active' ) ) { |
||
2659 | $active[] = 'protect'; |
||
2660 | } |
||
2661 | |||
2662 | /** |
||
2663 | * Allow filtering of the active modules. |
||
2664 | * |
||
2665 | * Gives theme and plugin developers the power to alter the modules that |
||
2666 | * are activated on the fly. |
||
2667 | * |
||
2668 | * @since 5.8.0 |
||
2669 | * |
||
2676 | |||
2677 | /** |
||
2678 | * Check whether or not a Jetpack module is active. |
||
2679 | * |
||
2680 | * @param string $module The slug of a Jetpack module. |
||
2681 | * @return bool |
||
2682 | * |
||
2683 | * @static |
||
2684 | */ |
||
2685 | public static function is_module_active( $module ) { |
||
2688 | |||
2689 | public static function is_module( $module ) { |
||
2692 | |||
2693 | /** |
||
2694 | * Catches PHP errors. Must be used in conjunction with output buffering. |
||
2695 | * |
||
2696 | * @param bool $catch True to start catching, False to stop. |
||
2697 | * |
||
2698 | * @static |
||
2699 | */ |
||
2700 | public static function catch_errors( $catch ) { |
||
2713 | |||
2714 | /** |
||
2715 | * Saves any generated PHP errors in ::state( 'php_errors', {errors} ) |
||
2716 | */ |
||
2717 | public static function catch_errors_on_shutdown() { |
||
2720 | |||
2721 | /** |
||
2722 | * Rewrite any string to make paths easier to read. |
||
2723 | * |
||
2724 | * Rewrites ABSPATH (eg `/home/jetpack/wordpress/`) to ABSPATH, and if WP_CONTENT_DIR |
||
2725 | * is located outside of ABSPATH, rewrites that to WP_CONTENT_DIR. |
||
2726 | * |
||
2727 | * @param $string |
||
2728 | * @return mixed |
||
2729 | */ |
||
2730 | public static function alias_directories( $string ) { |
||
2738 | |||
2739 | public static function activate_default_modules( |
||
2875 | |||
2876 | public static function activate_module( $module, $exit = true, $redirect = true ) { |
||
2973 | |||
2974 | function activate_module_actions( $module ) { |
||
2977 | |||
2978 | public static function deactivate_module( $module ) { |
||
3005 | |||
3006 | public static function enable_module_configurable( $module ) { |
||
3010 | |||
3011 | public static function module_configuration_url( $module ) { |
||
3015 | |||
3016 | public static function module_configuration_load( $module, $method ) { |
||
3020 | |||
3021 | public static function module_configuration_head( $module, $method ) { |
||
3025 | |||
3026 | public static function module_configuration_screen( $module, $method ) { |
||
3030 | |||
3031 | public static function module_configuration_activation_screen( $module, $method ) { |
||
3035 | |||
3036 | /* Installation */ |
||
3037 | |||
3038 | public static function bail_on_activation( $message, $deactivate = true ) { |
||
3078 | |||
3079 | /** |
||
3080 | * Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook() |
||
3081 | * @static |
||
3082 | */ |
||
3083 | public static function plugin_activation( $network_wide ) { |
||
3100 | |||
3101 | public static function get_activation_source( $referer_url ) { |
||
3150 | |||
3151 | /** |
||
3152 | * Runs before bumping version numbers up to a new version |
||
3153 | * @param string $version Version:timestamp |
||
3154 | * @param string $old_version Old Version:timestamp or false if not set yet. |
||
3155 | * @return null [description] |
||
3156 | */ |
||
3157 | public static function do_version_bump( $version, $old_version ) { |
||
3164 | |||
3165 | /** |
||
3166 | * Sets the internal version number and activation state. |
||
3167 | * @static |
||
3168 | */ |
||
3169 | public static function plugin_initialize() { |
||
3186 | |||
3187 | /** |
||
3188 | * Removes all connection options |
||
3189 | * @static |
||
3190 | */ |
||
3191 | public static function plugin_deactivation( ) { |
||
3200 | |||
3201 | /** |
||
3202 | * Disconnects from the Jetpack servers. |
||
3203 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
3204 | * @static |
||
3205 | */ |
||
3206 | public static function disconnect( $update_activated_state = true ) { |
||
3267 | |||
3268 | /** |
||
3269 | * Unlinks the current user from the linked WordPress.com user |
||
3270 | */ |
||
3271 | public static function unlink_user( $user_id = null ) { |
||
3302 | |||
3303 | /** |
||
3304 | * Attempts Jetpack registration. If it fail, a state flag is set: @see ::admin_page_load() |
||
3305 | */ |
||
3306 | public static function try_registration() { |
||
3334 | |||
3335 | /** |
||
3336 | * Tracking an internal event log. Try not to put too much chaff in here. |
||
3337 | * |
||
3338 | * [Everyone Loves a Log!](https://www.youtube.com/watch?v=2C7mNr5WMjA) |
||
3339 | */ |
||
3340 | public static function log( $code, $data = null ) { |
||
3380 | |||
3381 | /** |
||
3382 | * Get the internal event log. |
||
3383 | * |
||
3384 | * @param $event (string) - only return the specific log events |
||
3385 | * @param $num (int) - get specific number of latest results, limited to 200 |
||
3386 | * |
||
3387 | * @return array of log events || WP_Error for invalid params |
||
3388 | */ |
||
3389 | public static function get_log( $event = false, $num = false ) { |
||
3425 | |||
3426 | /** |
||
3427 | * Log modification of important settings. |
||
3428 | */ |
||
3429 | public static function log_settings_change( $option, $old_value, $value ) { |
||
3436 | |||
3437 | /** |
||
3438 | * Return stat data for WPCOM sync |
||
3439 | */ |
||
3440 | public static function get_stat_data( $encode = true, $extended = true ) { |
||
3454 | |||
3455 | /** |
||
3456 | * Get additional stat data to sync to WPCOM |
||
3457 | */ |
||
3458 | public static function get_additional_stat_data( $prefix = '' ) { |
||
3469 | |||
3470 | private static function get_site_user_count() { |
||
3485 | |||
3486 | /* Admin Pages */ |
||
3487 | |||
3488 | function admin_init() { |
||
3537 | |||
3538 | function admin_body_class( $admin_body_class = '' ) { |
||
3546 | |||
3547 | static function add_jetpack_pagestyles( $admin_body_class = '' ) { |
||
3550 | |||
3551 | /** |
||
3552 | * Call this function if you want the Big Jetpack Manage Notice to show up. |
||
3553 | * |
||
3554 | * @return null |
||
3555 | */ |
||
3556 | function prepare_manage_jetpack_notice() { |
||
3561 | |||
3562 | function manage_activate_screen() { |
||
3565 | /** |
||
3566 | * Sometimes a plugin can activate without causing errors, but it will cause errors on the next page load. |
||
3567 | * This function artificially throws errors for such cases (whitelisted). |
||
3568 | * |
||
3569 | * @param string $plugin The activated plugin. |
||
3570 | */ |
||
3571 | function throw_error_on_activate_plugin( $plugin ) { |
||
3595 | |||
3596 | function intercept_plugin_error_scrape_init() { |
||
3599 | |||
3600 | function intercept_plugin_error_scrape( $action, $result ) { |
||
3611 | |||
3612 | function add_remote_request_handlers() { |
||
3616 | |||
3617 | function remote_request_handlers() { |
||
3657 | |||
3658 | /** |
||
3659 | * Uploads a file gotten from the global $_FILES. |
||
3660 | * If `$update_media_item` is true and `post_id` is defined |
||
3661 | * the attachment file of the media item (gotten through of the post_id) |
||
3662 | * will be updated instead of add a new one. |
||
3663 | * |
||
3664 | * @param boolean $update_media_item - update media attachment |
||
3665 | * @return array - An array describing the uploadind files process |
||
3666 | */ |
||
3667 | function upload_handler( $update_media_item = false ) { |
||
3789 | |||
3790 | /** |
||
3791 | * Add help to the Jetpack page |
||
3792 | * |
||
3793 | * @since Jetpack (1.2.3) |
||
3794 | * @return false if not the Jetpack page |
||
3795 | */ |
||
3796 | function admin_help() { |
||
3837 | |||
3838 | function admin_menu_css() { |
||
3841 | |||
3842 | function admin_menu_order() { |
||
3845 | |||
3846 | function enqueue_gutenberg_locale() { |
||
3852 | |||
3853 | View Code Duplication | function jetpack_menu_order( $menu_order ) { |
|
3868 | |||
3869 | function admin_head() { |
||
3874 | |||
3875 | function admin_banner_styles() { |
||
3896 | |||
3897 | function plugin_action_links( $actions ) { |
||
3912 | |||
3913 | /** |
||
3914 | * This is the first banner |
||
3915 | * It should be visible only to user that can update the option |
||
3916 | * Are not connected |
||
3917 | * |
||
3918 | * @return null |
||
3919 | */ |
||
3920 | function admin_jetpack_manage_notice() { |
||
3950 | |||
3951 | /** |
||
3952 | * Returns the url that the user clicks to remove the notice for the big banner |
||
3953 | * @return string |
||
3954 | */ |
||
3955 | function opt_out_jetpack_manage_url() { |
||
3959 | /** |
||
3960 | * Returns the url that the user clicks to opt in to Jetpack Manage |
||
3961 | * @return string |
||
3962 | */ |
||
3963 | function opt_in_jetpack_manage_url() { |
||
3966 | |||
3967 | function opt_in_jetpack_manage_notice() { |
||
3977 | /** |
||
3978 | * Determines whether to show the notice of not true = display notice |
||
3979 | * @return bool |
||
3980 | */ |
||
3981 | function can_display_jetpack_manage_notice() { |
||
4003 | |||
4004 | /* |
||
4005 | * Registration flow: |
||
4006 | * 1 - ::admin_page_load() action=register |
||
4007 | * 2 - ::try_registration() |
||
4008 | * 3 - ::register() |
||
4009 | * - Creates jetpack_register option containing two secrets and a timestamp |
||
4010 | * - Calls https://jetpack.wordpress.com/jetpack.register/1/ with |
||
4011 | * siteurl, home, gmt_offset, timezone_string, site_name, secret_1, secret_2, site_lang, timeout, stats_id |
||
4012 | * - That request to jetpack.wordpress.com does not immediately respond. It first makes a request BACK to this site's |
||
4013 | * xmlrpc.php?for=jetpack: RPC method: jetpack.verifyRegistration, Parameters: secret_1 |
||
4014 | * - The XML-RPC request verifies secret_1, deletes both secrets and responds with: secret_2 |
||
4015 | * - https://jetpack.wordpress.com/jetpack.register/1/ verifies that XML-RPC response (secret_2) then finally responds itself with |
||
4016 | * jetpack_id, jetpack_secret, jetpack_public |
||
4017 | * - ::register() then stores jetpack_options: id => jetpack_id, blog_token => jetpack_secret |
||
4018 | * 4 - redirect to https://wordpress.com/start/jetpack-connect |
||
4019 | * 5 - user logs in with WP.com account |
||
4020 | * 6 - remote request to this site's xmlrpc.php with action remoteAuthorize, Jetpack_XMLRPC_Server->remote_authorize |
||
4021 | * - Jetpack_Client_Server::authorize() |
||
4022 | * - Jetpack_Client_Server::get_token() |
||
4023 | * - GET https://jetpack.wordpress.com/jetpack.token/1/ with |
||
4024 | * client_id, client_secret, grant_type, code, redirect_uri:action=authorize, state, scope, user_email, user_login |
||
4025 | * - which responds with access_token, token_type, scope |
||
4026 | * - Jetpack_Client_Server::authorize() stores jetpack_options: user_token => access_token.$user_id |
||
4027 | * - Jetpack::activate_default_modules() |
||
4028 | * - Deactivates deprecated plugins |
||
4029 | * - Activates all default modules |
||
4030 | * - Responds with either error, or 'connected' for new connection, or 'linked' for additional linked users |
||
4031 | * 7 - For a new connection, user selects a Jetpack plan on wordpress.com |
||
4032 | * 8 - User is redirected back to wp-admin/index.php?page=jetpack with state:message=authorized |
||
4033 | * Done! |
||
4034 | */ |
||
4035 | |||
4036 | /** |
||
4037 | * Handles the page load events for the Jetpack admin page |
||
4038 | */ |
||
4039 | function admin_page_load() { |
||
4314 | |||
4315 | function admin_notices() { |
||
4412 | |||
4413 | /** |
||
4414 | * Record a stat for later output. This will only currently output in the admin_footer. |
||
4415 | */ |
||
4416 | function stat( $group, $detail ) { |
||
4421 | |||
4422 | /** |
||
4423 | * Load stats pixels. $group is auto-prefixed with "x_jetpack-" |
||
4424 | */ |
||
4425 | function do_stats( $method = '' ) { |
||
4440 | |||
4441 | /** |
||
4442 | * Runs stats code for a one-off, server-side. |
||
4443 | * |
||
4444 | * @param $args array|string The arguments to append to the URL. Should include `x_jetpack-{$group}={$stats}` or whatever we want to store. |
||
4445 | * |
||
4446 | * @return bool If it worked. |
||
4447 | */ |
||
4448 | static function do_server_side_stat( $args ) { |
||
4458 | |||
4459 | /** |
||
4460 | * Builds the stats url. |
||
4461 | * |
||
4462 | * @param $args array|string The arguments to append to the URL. |
||
4463 | * |
||
4464 | * @return string The URL to be pinged. |
||
4465 | */ |
||
4466 | static function build_stats_url( $args ) { |
||
4486 | |||
4487 | static function translate_current_user_to_role() { |
||
4496 | |||
4497 | static function translate_user_to_role( $user ) { |
||
4506 | |||
4507 | static function translate_role_to_cap( $role ) { |
||
4514 | |||
4515 | static function sign_role( $role, $user_id = null ) { |
||
4531 | |||
4532 | |||
4533 | /** |
||
4534 | * Builds a URL to the Jetpack connection auth page |
||
4535 | * |
||
4536 | * @since 3.9.5 |
||
4537 | * |
||
4538 | * @param bool $raw If true, URL will not be escaped. |
||
4539 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
4540 | * If string, will be a custom redirect. |
||
4541 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
4542 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0 |
||
4543 | * |
||
4544 | * @return string Connect URL |
||
4545 | */ |
||
4546 | function build_connect_url( $raw = false, $redirect = false, $from = false, $register = false ) { |
||
4667 | |||
4668 | public static function apply_activation_source_to_args( &$args ) { |
||
4679 | |||
4680 | function build_reconnect_url( $raw = false ) { |
||
4684 | |||
4685 | public static function admin_url( $args = null ) { |
||
4690 | |||
4691 | public static function nonce_url_no_esc( $actionurl, $action = -1, $name = '_wpnonce' ) { |
||
4695 | |||
4696 | function dismiss_jetpack_notice() { |
||
4770 | |||
4771 | public static function admin_screen_configure_module( $module_id ) { |
||
4823 | |||
4824 | /** |
||
4825 | * Display link to activate the module to see the settings screen. |
||
4826 | * @param string $module_id |
||
4827 | * @return null |
||
4828 | */ |
||
4829 | public static function display_activate_module_link( $module_id ) { |
||
4881 | |||
4882 | public static function sort_modules( $a, $b ) { |
||
4888 | |||
4889 | function ajax_recheck_ssl() { |
||
4897 | |||
4898 | /* Client API */ |
||
4899 | |||
4900 | /** |
||
4901 | * Returns the requested Jetpack API URL |
||
4902 | * |
||
4903 | * @return string |
||
4904 | */ |
||
4905 | public static function api_url( $relative_url ) { |
||
4908 | |||
4909 | /** |
||
4910 | * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets |
||
4911 | */ |
||
4912 | public static function fix_url_for_bad_hosts( $url ) { |
||
4928 | |||
4929 | /** |
||
4930 | * Create a random secret for validating onboarding payload |
||
4931 | * |
||
4932 | * @return string Secret token |
||
4933 | */ |
||
4934 | public static function create_onboarding_token() { |
||
4942 | |||
4943 | /** |
||
4944 | * Remove the onboarding token |
||
4945 | * |
||
4946 | * @return bool True on success, false on failure |
||
4947 | */ |
||
4948 | public static function invalidate_onboarding_token() { |
||
4951 | |||
4952 | /** |
||
4953 | * Validate an onboarding token for a specific action |
||
4954 | * |
||
4955 | * @return boolean True if token/action pair is accepted, false if not |
||
4956 | */ |
||
4957 | public static function validate_onboarding_token_action( $token, $action ) { |
||
4975 | |||
4976 | /** |
||
4977 | * Checks to see if the URL is using SSL to connect with Jetpack |
||
4978 | * |
||
4979 | * @since 2.3.3 |
||
4980 | * @return boolean |
||
4981 | */ |
||
4982 | public static function permit_ssl( $force_recheck = false ) { |
||
5024 | |||
5025 | /* |
||
5026 | * Displays an admin_notice, alerting the user to their JETPACK_CLIENT__HTTPS constant being 'AUTO' but SSL isn't working. |
||
5027 | */ |
||
5028 | public function alert_auto_ssl_fail() { |
||
5077 | |||
5078 | /** |
||
5079 | * Returns the Jetpack XML-RPC API |
||
5080 | * |
||
5081 | * @return string |
||
5082 | */ |
||
5083 | public static function xmlrpc_api_url() { |
||
5087 | |||
5088 | /** |
||
5089 | * Creates two secret tokens and the end of life timestamp for them. |
||
5090 | * |
||
5091 | * Note these tokens are unique per call, NOT static per site for connecting. |
||
5092 | * |
||
5093 | * @since 2.6 |
||
5094 | * @return array |
||
5095 | */ |
||
5096 | public static function generate_secrets( $action, $user_id = false, $exp = 600 ) { |
||
5122 | |||
5123 | public static function get_secrets( $action, $user_id ) { |
||
5138 | |||
5139 | public static function delete_secrets( $action, $user_id ) { |
||
5147 | |||
5148 | /** |
||
5149 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5150 | * |
||
5151 | * Based on local php max_execution_time in php.ini |
||
5152 | * |
||
5153 | * @since 2.6 |
||
5154 | * @return int |
||
5155 | * @deprecated |
||
5156 | **/ |
||
5157 | public function get_remote_query_timeout_limit() { |
||
5161 | |||
5162 | /** |
||
5163 | * Builds the timeout limit for queries talking with the wpcom servers. |
||
5164 | * |
||
5165 | * Based on local php max_execution_time in php.ini |
||
5166 | * |
||
5167 | * @since 5.4 |
||
5168 | * @return int |
||
5169 | **/ |
||
5170 | public static function get_max_execution_time() { |
||
5179 | |||
5180 | /** |
||
5181 | * Sets a minimum request timeout, and returns the current timeout |
||
5182 | * |
||
5183 | * @since 5.4 |
||
5184 | **/ |
||
5185 | public static function set_min_time_limit( $min_timeout ) { |
||
5193 | |||
5194 | |||
5195 | /** |
||
5196 | * Takes the response from the Jetpack register new site endpoint and |
||
5197 | * verifies it worked properly. |
||
5198 | * |
||
5199 | * @since 2.6 |
||
5200 | * @return string|Jetpack_Error A JSON object on success or Jetpack_Error on failures |
||
5201 | **/ |
||
5202 | public function validate_remote_register_response( $response ) { |
||
5242 | /** |
||
5243 | * @return bool|WP_Error |
||
5244 | */ |
||
5245 | public static function register() { |
||
5349 | |||
5350 | /** |
||
5351 | * If the db version is showing something other that what we've got now, bump it to current. |
||
5352 | * |
||
5353 | * @return bool: True if the option was incorrect and updated, false if nothing happened. |
||
5354 | */ |
||
5355 | public static function maybe_set_version_option() { |
||
5369 | |||
5370 | /* Client Server API */ |
||
5371 | |||
5372 | /** |
||
5373 | * Loads the Jetpack XML-RPC client |
||
5374 | */ |
||
5375 | public static function load_xml_rpc_client() { |
||
5379 | |||
5380 | /** |
||
5381 | * Resets the saved authentication state in between testing requests. |
||
5382 | */ |
||
5383 | public function reset_saved_auth_state() { |
||
5387 | |||
5388 | function verify_xml_rpc_signature() { |
||
5518 | |||
5519 | /** |
||
5520 | * Authenticates XML-RPC and other requests from the Jetpack Server |
||
5521 | */ |
||
5522 | function authenticate_jetpack( $user, $username, $password ) { |
||
5545 | |||
5546 | // Authenticates requests from Jetpack server to WP REST API endpoints. |
||
5547 | // Uses the existing XMLRPC request signing implementation. |
||
5548 | function wp_rest_authenticate( $user ) { |
||
5642 | |||
5643 | /** |
||
5644 | * Report authentication status to the WP REST API. |
||
5645 | * |
||
5646 | * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not |
||
5647 | * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} |
||
5648 | */ |
||
5649 | public function wp_rest_authentication_errors( $value ) { |
||
5655 | |||
5656 | function add_nonce( $timestamp, $nonce ) { |
||
5694 | |||
5695 | /** |
||
5696 | * In some setups, $HTTP_RAW_POST_DATA can be emptied during some IXR_Server paths since it is passed by reference to various methods. |
||
5697 | * Capture it here so we can verify the signature later. |
||
5698 | */ |
||
5699 | function xmlrpc_methods( $methods ) { |
||
5703 | |||
5704 | function public_xmlrpc_methods( $methods ) { |
||
5710 | |||
5711 | function jetpack_getOptions( $args ) { |
||
5751 | |||
5752 | function xmlrpc_options( $options ) { |
||
5770 | |||
5771 | public static function clean_nonces( $all = false ) { |
||
5792 | |||
5793 | /** |
||
5794 | * State is passed via cookies from one request to the next, but never to subsequent requests. |
||
5795 | * SET: state( $key, $value ); |
||
5796 | * GET: $value = state( $key ); |
||
5797 | * |
||
5798 | * @param string $key |
||
5799 | * @param string $value |
||
5800 | * @param bool $restate private |
||
5801 | */ |
||
5802 | public static function state( $key = null, $value = null, $restate = false ) { |
||
5852 | |||
5853 | public static function restate() { |
||
5856 | |||
5857 | public static function check_privacy( $file ) { |
||
5892 | |||
5893 | /** |
||
5894 | * Helper method for multicall XMLRPC. |
||
5895 | */ |
||
5896 | public static function xmlrpc_async_call() { |
||
5938 | |||
5939 | public static function staticize_subdomain( $url ) { |
||
5974 | |||
5975 | /* JSON API Authorization */ |
||
5976 | |||
5977 | /** |
||
5978 | * Handles the login action for Authorizing the JSON API |
||
5979 | */ |
||
5980 | function login_form_json_api_authorization() { |
||
5989 | |||
5990 | // Make sure the login form is POSTed to the signed URL so we can reverify the request |
||
5991 | function post_login_form_to_signed_url( $url, $path, $scheme ) { |
||
6004 | |||
6005 | // Make sure the POSTed request is handled by the same action |
||
6006 | function preserve_action_in_login_form_for_json_api_authorization() { |
||
6010 | |||
6011 | // If someone logs in to approve API access, store the Access Code in usermeta |
||
6012 | function store_json_api_authorization_token( $user_login, $user ) { |
||
6018 | |||
6019 | // Add public-api.wordpress.com to the safe redirect whitelist - only added when someone allows API access |
||
6020 | function allow_wpcom_public_api_domain( $domains ) { |
||
6024 | |||
6025 | // Add all wordpress.com environments to the safe redirect whitelist |
||
6026 | function allow_wpcom_environments( $domains ) { |
||
6033 | |||
6034 | // Add the Access Code details to the public-api.wordpress.com redirect |
||
6035 | function add_token_to_login_redirect_json_api_authorization( $redirect_to, $original_redirect_to, $user ) { |
||
6047 | |||
6048 | |||
6049 | /** |
||
6050 | * Verifies the request by checking the signature |
||
6051 | * |
||
6052 | * @since 4.6.0 Method was updated to use `$_REQUEST` instead of `$_GET` and `$_POST`. Method also updated to allow |
||
6053 | * passing in an `$environment` argument that overrides `$_REQUEST`. This was useful for integrating with SSO. |
||
6054 | * |
||
6055 | * @param null|array $environment |
||
6056 | */ |
||
6057 | function verify_json_api_authorization_request( $environment = null ) { |
||
6150 | |||
6151 | function login_message_json_api_authorization( $message ) { |
||
6157 | |||
6158 | /** |
||
6159 | * Get $content_width, but with a <s>twist</s> filter. |
||
6160 | */ |
||
6161 | public static function get_content_width() { |
||
6172 | |||
6173 | /** |
||
6174 | * Pings the WordPress.com Mirror Site for the specified options. |
||
6175 | * |
||
6176 | * @param string|array $option_names The option names to request from the WordPress.com Mirror Site |
||
6177 | * |
||
6178 | * @return array An associative array of the option values as stored in the WordPress.com Mirror Site |
||
6179 | */ |
||
6180 | public function get_cloud_site_options( $option_names ) { |
||
6196 | |||
6197 | /** |
||
6198 | * Checks if the site is currently in an identity crisis. |
||
6199 | * |
||
6200 | * @return array|bool Array of options that are in a crisis, or false if everything is OK. |
||
6201 | */ |
||
6202 | public static function check_identity_crisis() { |
||
6209 | |||
6210 | /** |
||
6211 | * Checks whether the home and siteurl specifically are whitelisted |
||
6212 | * Written so that we don't have re-check $key and $value params every time |
||
6213 | * we want to check if this site is whitelisted, for example in footer.php |
||
6214 | * |
||
6215 | * @since 3.8.0 |
||
6216 | * @return bool True = already whitelisted False = not whitelisted |
||
6217 | */ |
||
6218 | public static function is_staging_site() { |
||
6277 | |||
6278 | /** |
||
6279 | * Checks whether the sync_error_idc option is valid or not, and if not, will do cleanup. |
||
6280 | * |
||
6281 | * @since 4.4.0 |
||
6282 | * @since 5.4.0 Do not call get_sync_error_idc_option() unless site is in IDC |
||
6283 | * |
||
6284 | * @return bool |
||
6285 | */ |
||
6286 | public static function validate_sync_error_idc_option() { |
||
6330 | |||
6331 | /** |
||
6332 | * Normalizes a url by doing three things: |
||
6333 | * - Strips protocol |
||
6334 | * - Strips www |
||
6335 | * - Adds a trailing slash |
||
6336 | * |
||
6337 | * @since 4.4.0 |
||
6338 | * @param string $url |
||
6339 | * @return WP_Error|string |
||
6340 | */ |
||
6341 | public static function normalize_url_protocol_agnostic( $url ) { |
||
6351 | |||
6352 | /** |
||
6353 | * Gets the value that is to be saved in the jetpack_sync_error_idc option. |
||
6354 | * |
||
6355 | * @since 4.4.0 |
||
6356 | * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB |
||
6357 | * |
||
6358 | * @param array $response |
||
6359 | * @return array Array of the local urls, wpcom urls, and error code |
||
6360 | */ |
||
6361 | public static function get_sync_error_idc_option( $response = array() ) { |
||
6394 | |||
6395 | /** |
||
6396 | * Returns the value of the jetpack_sync_idc_optin filter, or constant. |
||
6397 | * If set to true, the site will be put into staging mode. |
||
6398 | * |
||
6399 | * @since 4.3.2 |
||
6400 | * @return bool |
||
6401 | */ |
||
6402 | public static function sync_idc_optin() { |
||
6420 | |||
6421 | /** |
||
6422 | * Maybe Use a .min.css stylesheet, maybe not. |
||
6423 | * |
||
6424 | * Hooks onto `plugins_url` filter at priority 1, and accepts all 3 args. |
||
6425 | */ |
||
6426 | public static function maybe_min_asset( $url, $path, $plugin ) { |
||
6468 | |||
6469 | /** |
||
6470 | * If the asset is minified, let's flag .min as the suffix. |
||
6471 | * |
||
6472 | * Attached to `style_loader_src` filter. |
||
6473 | * |
||
6474 | * @param string $tag The tag that would link to the external asset. |
||
6475 | * @param string $handle The registered handle of the script in question. |
||
6476 | * @param string $href The url of the asset in question. |
||
6477 | */ |
||
6478 | public static function set_suffix_on_min( $src, $handle ) { |
||
6494 | |||
6495 | /** |
||
6496 | * Maybe inlines a stylesheet. |
||
6497 | * |
||
6498 | * If you'd like to inline a stylesheet instead of printing a link to it, |
||
6499 | * wp_style_add_data( 'handle', 'jetpack-inline', true ); |
||
6500 | * |
||
6501 | * Attached to `style_loader_tag` filter. |
||
6502 | * |
||
6503 | * @param string $tag The tag that would link to the external asset. |
||
6504 | * @param string $handle The registered handle of the script in question. |
||
6505 | * |
||
6506 | * @return string |
||
6507 | */ |
||
6508 | public static function maybe_inline_style( $tag, $handle ) { |
||
6558 | |||
6559 | /** |
||
6560 | * Loads a view file from the views |
||
6561 | * |
||
6562 | * Data passed in with the $data parameter will be available in the |
||
6563 | * template file as $data['value'] |
||
6564 | * |
||
6565 | * @param string $template - Template file to load |
||
6566 | * @param array $data - Any data to pass along to the template |
||
6567 | * @return boolean - If template file was found |
||
6568 | **/ |
||
6569 | public function load_view( $template, $data = array() ) { |
||
6580 | |||
6581 | /** |
||
6582 | * Throws warnings for deprecated hooks to be removed from Jetpack |
||
6583 | */ |
||
6584 | public function deprecated_hooks() { |
||
6644 | |||
6645 | /** |
||
6646 | * Converts any url in a stylesheet, to the correct absolute url. |
||
6647 | * |
||
6648 | * Considerations: |
||
6649 | * - Normal, relative URLs `feh.png` |
||
6650 | * - Data URLs `data:image/gif;base64,eh129ehiuehjdhsa==` |
||
6651 | * - Schema-agnostic URLs `//domain.com/feh.png` |
||
6652 | * - Absolute URLs `http://domain.com/feh.png` |
||
6653 | * - Domain root relative URLs `/feh.png` |
||
6654 | * |
||
6655 | * @param $css string: The raw CSS -- should be read in directly from the file. |
||
6656 | * @param $css_file_url : The URL that the file can be accessed at, for calculating paths from. |
||
6657 | * |
||
6658 | * @return mixed|string |
||
6659 | */ |
||
6660 | public static function absolutize_css_urls( $css, $css_file_url ) { |
||
6704 | |||
6705 | /** |
||
6706 | * This methods removes all of the registered css files on the front end |
||
6707 | * from Jetpack in favor of using a single file. In effect "imploding" |
||
6708 | * all the files into one file. |
||
6709 | * |
||
6710 | * Pros: |
||
6711 | * - Uses only ONE css asset connection instead of 15 |
||
6712 | * - Saves a minimum of 56k |
||
6713 | * - Reduces server load |
||
6714 | * - Reduces time to first painted byte |
||
6715 | * |
||
6716 | * Cons: |
||
6717 | * - Loads css for ALL modules. However all selectors are prefixed so it |
||
6718 | * should not cause any issues with themes. |
||
6719 | * - Plugins/themes dequeuing styles no longer do anything. See |
||
6720 | * jetpack_implode_frontend_css filter for a workaround |
||
6721 | * |
||
6722 | * For some situations developers may wish to disable css imploding and |
||
6723 | * instead operate in legacy mode where each file loads seperately and |
||
6724 | * can be edited individually or dequeued. This can be accomplished with |
||
6725 | * the following line: |
||
6726 | * |
||
6727 | * add_filter( 'jetpack_implode_frontend_css', '__return_false' ); |
||
6728 | * |
||
6729 | * @since 3.2 |
||
6730 | **/ |
||
6731 | public function implode_frontend_css( $travis_test = false ) { |
||
6783 | |||
6784 | function concat_remove_style_loader_tag( $tag, $handle ) { |
||
6794 | |||
6795 | /* |
||
6796 | * Check the heartbeat data |
||
6797 | * |
||
6798 | * Organizes the heartbeat data by severity. For example, if the site |
||
6799 | * is in an ID crisis, it will be in the $filtered_data['bad'] array. |
||
6800 | * |
||
6801 | * Data will be added to "caution" array, if it either: |
||
6802 | * - Out of date Jetpack version |
||
6803 | * - Out of date WP version |
||
6804 | * - Out of date PHP version |
||
6805 | * |
||
6806 | * $return array $filtered_data |
||
6807 | */ |
||
6808 | public static function jetpack_check_heartbeat_data() { |
||
6861 | |||
6862 | |||
6863 | /* |
||
6864 | * This method is used to organize all options that can be reset |
||
6865 | * without disconnecting Jetpack. |
||
6866 | * |
||
6867 | * It is used in class.jetpack-cli.php to reset options |
||
6868 | * |
||
6869 | * @since 5.4.0 Logic moved to Jetpack_Options class. Method left in Jetpack class for backwards compat. |
||
6870 | * |
||
6871 | * @return array of options to delete. |
||
6872 | */ |
||
6873 | public static function get_jetpack_options_for_reset() { |
||
6876 | |||
6877 | /** |
||
6878 | * Check if an option of a Jetpack module has been updated. |
||
6879 | * |
||
6880 | * If any module option has been updated before Jump Start has been dismissed, |
||
6881 | * update the 'jumpstart' option so we can hide Jump Start. |
||
6882 | * |
||
6883 | * @param string $option_name |
||
6884 | * |
||
6885 | * @return bool |
||
6886 | */ |
||
6887 | public static function jumpstart_has_updated_module_option( $option_name = '' ) { |
||
6908 | |||
6909 | /* |
||
6910 | * Strip http:// or https:// from a url, replaces forward slash with ::, |
||
6911 | * so we can bring them directly to their site in calypso. |
||
6912 | * |
||
6913 | * @param string | url |
||
6914 | * @return string | url without the guff |
||
6915 | */ |
||
6916 | public static function build_raw_urls( $url ) { |
||
6922 | |||
6923 | /** |
||
6924 | * Stores and prints out domains to prefetch for page speed optimization. |
||
6925 | * |
||
6926 | * @param mixed $new_urls |
||
6927 | */ |
||
6928 | public static function dns_prefetch( $new_urls = null ) { |
||
6945 | |||
6946 | public function wp_dashboard_setup() { |
||
6970 | |||
6971 | /** |
||
6972 | * @param mixed $result Value for the user's option |
||
6973 | * @return mixed |
||
6974 | */ |
||
6975 | function get_user_option_meta_box_order_dashboard( $sorted ) { |
||
7000 | |||
7001 | public static function dashboard_widget() { |
||
7009 | |||
7010 | public static function dashboard_widget_footer() { |
||
7043 | |||
7044 | /** |
||
7045 | * Return string containing the Jetpack logo. |
||
7046 | * |
||
7047 | * @since 3.9.0 |
||
7048 | * |
||
7049 | * @return string |
||
7050 | */ |
||
7051 | public static function get_jp_emblem() { |
||
7054 | |||
7055 | /* |
||
7056 | * Adds a "blank" column in the user admin table to display indication of user connection. |
||
7057 | */ |
||
7058 | function jetpack_icon_user_connected( $columns ) { |
||
7062 | |||
7063 | /* |
||
7064 | * Show Jetpack icon if the user is linked. |
||
7065 | */ |
||
7066 | function jetpack_show_user_connected_icon( $val, $col, $user_id ) { |
||
7078 | |||
7079 | /* |
||
7080 | * Style the Jetpack user column |
||
7081 | */ |
||
7082 | function jetpack_user_col_style() { |
||
7099 | |||
7100 | /** |
||
7101 | * Checks if Akismet is active and working. |
||
7102 | * |
||
7103 | * @since 5.1.0 |
||
7104 | * @return bool True = Akismet available. False = Aksimet not available. |
||
7105 | */ |
||
7106 | public static function is_akismet_active() { |
||
7112 | |||
7113 | /** |
||
7114 | * Checks if one or more function names is in debug_backtrace |
||
7115 | * |
||
7116 | * @param $names Mixed string name of function or array of string names of functions |
||
7117 | * |
||
7118 | * @return bool |
||
7119 | */ |
||
7120 | public static function is_function_in_backtrace( $names ) { |
||
7143 | |||
7144 | /** |
||
7145 | * Given a minified path, and a non-minified path, will return |
||
7146 | * a minified or non-minified file URL based on whether SCRIPT_DEBUG is set and truthy. |
||
7147 | * |
||
7148 | * Both `$min_base` and `$non_min_base` are expected to be relative to the |
||
7149 | * root Jetpack directory. |
||
7150 | * |
||
7151 | * @since 5.6.0 |
||
7152 | * |
||
7153 | * @param string $min_path |
||
7154 | * @param string $non_min_path |
||
7155 | * @return string The URL to the file |
||
7156 | */ |
||
7157 | public static function get_file_url_for_environment( $min_path, $non_min_path ) { |
||
7164 | |||
7165 | /** |
||
7166 | * Checks for whether Jetpack Rewind is enabled. |
||
7167 | * Will return true if the state of Rewind is anything except "unavailable". |
||
7168 | * @return bool|int|mixed |
||
7169 | */ |
||
7170 | public static function is_rewind_enabled() { |
||
7189 | |||
7190 | /** |
||
7191 | * Checks whether or not TOS has been agreed upon. |
||
7192 | * Will return true if a user has clicked to register, or is already connected. |
||
7193 | */ |
||
7194 | public static function jetpack_tos_agreed() { |
||
7197 | |||
7198 | /** |
||
7199 | * Handles activating default modules as well general cleanup for the new connection. |
||
7200 | * |
||
7201 | * @param boolean $activate_sso Whether to activate the SSO module when activating default modules. |
||
7202 | * @param boolean $redirect_on_activation_error Whether to redirect on activation error. |
||
7203 | * @return void |
||
7204 | */ |
||
7205 | public static function handle_post_authorization_actions( $activate_sso = false, $redirect_on_activation_error = false ) { |
||
7228 | } |
||
7229 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.