暂无描述

jetpack.php 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /**
  3. * Plugin Name: Jetpack
  4. * Plugin URI: https://jetpack.com
  5. * Description: Security, performance, and marketing tools made by WordPress experts. Jetpack keeps your site protected so you can focus on more important things.
  6. * Author: Automattic
  7. * Version: 10.2
  8. * Author URI: https://jetpack.com
  9. * License: GPL2+
  10. * Text Domain: jetpack
  11. * Requires at least: 5.7
  12. * Requires PHP: 5.6
  13. *
  14. * @package automattic/jetpack
  15. */
  16. /*
  17. This program is free software; you can redistribute it and/or
  18. modify it under the terms of the GNU General Public License
  19. as published by the Free Software Foundation; either version 2
  20. of the License, or (at your option) any later version.
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. GNU General Public License for more details.
  25. You should have received a copy of the GNU General Public License
  26. along with this program; if not, write to the Free Software
  27. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  28. */
  29. define( 'JETPACK__MINIMUM_WP_VERSION', '5.7' );
  30. define( 'JETPACK__MINIMUM_PHP_VERSION', '5.6' );
  31. define( 'JETPACK__VERSION', '10.2' );
  32. /**
  33. * Constant used to fetch the connection owner token
  34. *
  35. * @deprecated 9.0.0
  36. * @var boolean
  37. */
  38. define( 'JETPACK_MASTER_USER', true );
  39. define( 'JETPACK__API_VERSION', 1 );
  40. define( 'JETPACK__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  41. define( 'JETPACK__PLUGIN_FILE', __FILE__ );
  42. defined( 'JETPACK__RELEASE_POST_BLOG_SLUG' ) || define( 'JETPACK__RELEASE_POST_BLOG_SLUG', 'jetpackreleaseblog.wordpress.com' );
  43. defined( 'JETPACK_CLIENT__AUTH_LOCATION' ) || define( 'JETPACK_CLIENT__AUTH_LOCATION', 'header' );
  44. /**
  45. * WP.com API no longer supports `http://` protocol.
  46. * This means Jetpack can't function properly on servers that can't send outbound HTTPS requests.
  47. * The constant is no longer used.
  48. *
  49. * @deprecated 9.1.0
  50. */
  51. defined( 'JETPACK_CLIENT__HTTPS' ) || define( 'JETPACK_CLIENT__HTTPS', 'AUTO' );
  52. defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || define( 'JETPACK__GLOTPRESS_LOCALES_PATH', JETPACK__PLUGIN_DIR . 'locales.php' );
  53. defined( 'JETPACK__API_BASE' ) || define( 'JETPACK__API_BASE', 'https://jetpack.wordpress.com/jetpack.' );
  54. defined( 'JETPACK_PROTECT__API_HOST' ) || define( 'JETPACK_PROTECT__API_HOST', 'https://api.bruteprotect.com/' );
  55. defined( 'JETPACK__WPCOM_JSON_API_BASE' ) || define( 'JETPACK__WPCOM_JSON_API_BASE', 'https://public-api.wordpress.com' );
  56. /**
  57. * WP.com API no longer supports `http://` protocol.
  58. * Use `JETPACK__WPCOM_JSON_API_BASE` instead, which has the protocol hardcoded.
  59. *
  60. * @deprecated 9.1.0
  61. */
  62. defined( 'JETPACK__WPCOM_JSON_API_HOST' ) || define( 'JETPACK__WPCOM_JSON_API_HOST', 'public-api.wordpress.com' );
  63. defined( 'JETPACK__SANDBOX_DOMAIN' ) || define( 'JETPACK__SANDBOX_DOMAIN', '' );
  64. defined( 'JETPACK__DEBUGGER_PUBLIC_KEY' ) || define(
  65. 'JETPACK__DEBUGGER_PUBLIC_KEY',
  66. "\r\n" . '-----BEGIN PUBLIC KEY-----' . "\r\n"
  67. . 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm+uLLVoxGCY71LS6KFc6' . "\r\n"
  68. . '1UnF6QGBAsi5XF8ty9kR3/voqfOkpW+gRerM2Kyjy6DPCOmzhZj7BFGtxSV2ZoMX' . "\r\n"
  69. . '9ZwWxzXhl/Q/6k8jg8BoY1QL6L2K76icXJu80b+RDIqvOfJruaAeBg1Q9NyeYqLY' . "\r\n"
  70. . 'lEVzN2vIwcFYl+MrP/g6Bc2co7Jcbli+tpNIxg4Z+Hnhbs7OJ3STQLmEryLpAxQO' . "\r\n"
  71. . 'q8cbhQkMx+FyQhxzSwtXYI/ClCUmTnzcKk7SgGvEjoKGAmngILiVuEJ4bm7Q1yok' . "\r\n"
  72. . 'xl9+wcfW6JAituNhml9dlHCWnn9D3+j8pxStHihKy2gVMwiFRjLEeD8K/7JVGkb/' . "\r\n"
  73. . 'EwIDAQAB' . "\r\n"
  74. . '-----END PUBLIC KEY-----' . "\r\n"
  75. );
  76. /*
  77. * These constants can be set in wp-config.php to ensure sites behind proxies will still work.
  78. * Setting these constants, though, is *not* the preferred method. It's better to configure
  79. * the proxy to send the X-Forwarded-Port header.
  80. */
  81. defined( 'JETPACK_SIGNATURE__HTTP_PORT' ) || define( 'JETPACK_SIGNATURE__HTTP_PORT', 80 );
  82. defined( 'JETPACK_SIGNATURE__HTTPS_PORT' ) || define( 'JETPACK_SIGNATURE__HTTPS_PORT', 443 );
  83. /**
  84. * Check if the version of WordPress in use on the site is supported by Jetpack.
  85. */
  86. if ( version_compare( $GLOBALS['wp_version'], JETPACK__MINIMUM_WP_VERSION, '<' ) ) {
  87. if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
  88. error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
  89. sprintf(
  90. /* translators: Placeholders are numbers, versions of WordPress in use on the site, and required by WordPress. */
  91. esc_html__( 'Your version of WordPress (%1$s) is lower than the version required by Jetpack (%2$s). Please update WordPress to continue enjoying Jetpack.', 'jetpack' ),
  92. $GLOBALS['wp_version'],
  93. JETPACK__MINIMUM_WP_VERSION
  94. )
  95. );
  96. }
  97. /**
  98. * Outputs for an admin notice about running Jetpack on outdated WordPress.
  99. *
  100. * @since 7.2.0
  101. */
  102. function jetpack_admin_unsupported_wp_notice() { ?>
  103. <div class="notice notice-error is-dismissible">
  104. <p><?php esc_html_e( 'Jetpack requires a more recent version of WordPress and has been paused. Please update WordPress to continue enjoying Jetpack.', 'jetpack' ); ?></p>
  105. </div>
  106. <?php
  107. }
  108. add_action( 'admin_notices', 'jetpack_admin_unsupported_wp_notice' );
  109. return;
  110. }
  111. /**
  112. * This is where the loading of Jetpack begins.
  113. *
  114. * First, we try to load our composer autoloader.
  115. *
  116. * - If it fails, we "pause" Jetpack by ending the loading process
  117. * and displaying an admin_notice to inform the site owner.
  118. * (We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader.)
  119. * - If it succeeds, we require load-jetpack.php, where all legacy files are required,
  120. * and where we add on to various hooks that we expect to always run.
  121. */
  122. $jetpack_autoloader = JETPACK__PLUGIN_DIR . 'vendor/autoload_packages.php';
  123. $jetpack_module_headings_file = JETPACK__PLUGIN_DIR . 'modules/module-headings.php'; // This file is loaded later in load-jetpack.php, but let's check here to pause before half-loading Jetpack.
  124. if ( is_readable( $jetpack_autoloader ) && is_readable( $jetpack_module_headings_file ) ) {
  125. require_once $jetpack_autoloader;
  126. } else {
  127. if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
  128. error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
  129. sprintf(
  130. /* translators: Placeholder is a link to a support document. */
  131. __( 'Your installation of Jetpack is incomplete. If you installed Jetpack from GitHub, please refer to this document to set up your development environment: %1$s', 'jetpack' ),
  132. 'https://github.com/Automattic/jetpack/blob/master/docs/development-environment.md'
  133. )
  134. );
  135. }
  136. /**
  137. * Outputs an admin notice for folks running Jetpack without having run composer install.
  138. *
  139. * @since 7.4.0
  140. */
  141. function jetpack_admin_missing_files() {
  142. ?>
  143. <div class="notice notice-error is-dismissible">
  144. <p>
  145. <?php
  146. printf(
  147. wp_kses(
  148. /* translators: Placeholder is a link to a support document. */
  149. __( 'Your installation of Jetpack is incomplete. If you installed Jetpack from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack must have Composer dependencies installed and built via the build command.', 'jetpack' ),
  150. array(
  151. 'a' => array(
  152. 'href' => array(),
  153. 'target' => array(),
  154. 'rel' => array(),
  155. ),
  156. )
  157. ),
  158. 'https://github.com/Automattic/jetpack/blob/master/docs/development-environment.md#building-your-project'
  159. );
  160. ?>
  161. </p>
  162. </div>
  163. <?php
  164. }
  165. add_action( 'admin_notices', 'jetpack_admin_missing_files' );
  166. return;
  167. }
  168. register_activation_hook( __FILE__, array( 'Jetpack', 'plugin_activation' ) );
  169. register_deactivation_hook( __FILE__, array( 'Jetpack', 'plugin_deactivation' ) );
  170. // Require everything else, that is not loaded via the autoloader.
  171. require_once JETPACK__PLUGIN_DIR . 'load-jetpack.php';