updated plugin Jetpack Protect version 3.0.2

This commit is contained in:
KawaiiPunk 2024-10-09 12:44:31 +00:00 committed by Gitium
parent a35dc419bc
commit f970470c59
283 changed files with 6970 additions and 2338 deletions

View File

@ -5,6 +5,43 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 3.0.2 - 2024-09-06
### Changed
- Internal updates.
## 3.0.1 - 2024-09-06
### Added
- Threats List: Add pagination. [#39058]
### Changed
- Admin menu: change order of Jetpack sub-menu items. [#39095]
- Updated package dependencies. [#39176]
### Fixed
- Security Scanning: Adds a background to the scan progress bar. [#38847]
- General: Delete relevant Protect options on deactivation. [#38815]
- Auto Fixers: Disable the unignore threats button when a fixer is in progress. [#38898]
- Security Scanning: Fix the threat fixed on date in the history view. [#39164]
- General: Improves the manual scan link button loading state. [#38897]
## 3.0.0-beta - 2024-08-09
### Added
- Firewall: add dedicated WAF allow and block list toggles [#38265]
- General: add "contact support" links [#38416]
- Security Scanning: add threats history view [#38117]
### Changed
- General: indicate compatibility with the upcoming version of WordPress - 6.6. [#37962]
### Removed
- General: update WordPress version requirements to WordPress 6.5. [#38382]
### Fixed
- Fix an issue where the connection error hook was always resetting the notice [#38120]
- Fix image optimization [#38573]
- Fix in-progress threat fixer loading indicator [#38051]
- Fix threat fix modal title [#38312]
## 2.2.0 - 2024-05-24 ## 2.2.0 - 2024-05-24
### Added ### Added
- Add data to WAF logs and a toggle for users to opt-in to share more data with us if needed. [#36377] - Add data to WAF logs and a toggle for users to opt-in to share more data with us if needed. [#36377]

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1 +1 @@
<?php return array('dependencies' => array('moment', 'react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'fe97d1535658daaa9984'); <?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'moment', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '8d3412963d3c47f0ac0a');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,12 +6,6 @@
* @see https://github.com/kvz/phpjs/blob/ffe1356af23a6f2512c84c954dd4e828e92579fa/functions/strings/number_format.js * @see https://github.com/kvz/phpjs/blob/ffe1356af23a6f2512c84c954dd4e828e92579fa/functions/strings/number_format.js
*/ */
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/** /**
* React Router DOM v6.2.2 * React Router DOM v6.2.2
* *

File diff suppressed because one or more lines are too long

View File

@ -5,23 +5,23 @@
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"automattic/jetpack-assets": "^2.1.11", "automattic/jetpack-assets": "^2.3.7",
"automattic/jetpack-admin-ui": "^0.4.2", "automattic/jetpack-admin-ui": "^0.4.5",
"automattic/jetpack-autoloader": "^3.0.7", "automattic/jetpack-autoloader": "^3.1.0",
"automattic/jetpack-composer-plugin": "^2.0.1", "automattic/jetpack-composer-plugin": "^2.0.3",
"automattic/jetpack-config": "^2.0.2", "automattic/jetpack-config": "^2.0.4",
"automattic/jetpack-identity-crisis": "^0.20.0", "automattic/jetpack-my-jetpack": "^4.35.3",
"automattic/jetpack-my-jetpack": "^4.24.1", "automattic/jetpack-plugins-installer": "^0.4.3",
"automattic/jetpack-plugins-installer": "^0.4.0", "automattic/jetpack-sync": "^3.10.0",
"automattic/jetpack-sync": "^2.16.6", "automattic/jetpack-transport-helper": "^0.2.4",
"automattic/jetpack-transport-helper": "^0.2.3", "automattic/jetpack-plans": "^0.4.10",
"automattic/jetpack-plans": "^0.4.7", "automattic/jetpack-waf": "^0.18.5",
"automattic/jetpack-waf": "^0.16.8", "automattic/jetpack-status": "^4.0.1",
"automattic/jetpack-status": "^3.2.0" "automattic/jetpack-protect-status": "^0.1.5"
}, },
"require-dev": { "require-dev": {
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.2.4", "automattic/jetpack-changelogger": "^4.2.6",
"automattic/wordbless": "0.4.2" "automattic/wordbless": "0.4.2"
}, },
"autoload": { "autoload": {
@ -71,6 +71,6 @@
"automattic/jetpack-autoloader": true, "automattic/jetpack-autoloader": true,
"automattic/jetpack-composer-plugin": true "automattic/jetpack-composer-plugin": true
}, },
"autoloader-suffix": "c4802e05bbcf59fd3b6350e8d3e5482c_protectⓥ2_2_0" "autoloader-suffix": "c4802e05bbcf59fd3b6350e8d3e5482c_protectⓥ3_0_2"
} }
} }

View File

@ -3,7 +3,7 @@
* Plugin Name: Jetpack Protect * Plugin Name: Jetpack Protect
* Plugin URI: https://wordpress.org/plugins/jetpack-protect * Plugin URI: https://wordpress.org/plugins/jetpack-protect
* Description: Security tools that keep your site safe and sound, from posts to plugins. * Description: Security tools that keep your site safe and sound, from posts to plugins.
* Version: 2.2.0 * Version: 3.0.2
* Author: Automattic - Jetpack Security team * Author: Automattic - Jetpack Security team
* Author URI: https://jetpack.com/protect/ * Author URI: https://jetpack.com/protect/
* License: GPLv2 or later * License: GPLv2 or later
@ -32,7 +32,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
define( 'JETPACK_PROTECT_VERSION', '2.2.0' ); define( 'JETPACK_PROTECT_VERSION', '3.0.2' );
define( 'JETPACK_PROTECT_DIR', plugin_dir_path( __FILE__ ) ); define( 'JETPACK_PROTECT_DIR', plugin_dir_path( __FILE__ ) );
define( 'JETPACK_PROTECT_ROOT_FILE', __FILE__ ); define( 'JETPACK_PROTECT_ROOT_FILE', __FILE__ );
define( 'JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) ); define( 'JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) );

View File

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.0.2] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
## [2.0.1] - 2024-03-12 ## [2.0.1] - 2024-03-12
### Changed ### Changed
- Internal updates. - Internal updates.
@ -135,6 +139,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Creates the MC Stats package - Creates the MC Stats package
[2.0.2]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v2.0.0...v2.0.1 [2.0.1]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.22...v2.0.0 [2.0.0]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.22...v2.0.0
[1.4.22]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.21...v1.4.22 [1.4.22]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.21...v1.4.22

View File

@ -7,8 +7,8 @@
"php": ">=7.0" "php": ">=7.0"
}, },
"require-dev": { "require-dev": {
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.1.1" "automattic/jetpack-changelogger": "^4.2.6"
}, },
"suggest": { "suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."

View File

@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.4.5] - 2024-09-05
### Changed
- Jetpack menu: only register Jetpack admin page for contributor roles and above. [#39081]
## [0.4.4] - 2024-08-29
### Changed
- Admin menu: change order of Jetpack sub-menu items [#39095]
## [0.4.3] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
## [0.4.2] - 2024-04-22 ## [0.4.2] - 2024-04-22
### Changed ### Changed
- Internal updates. - Internal updates.
@ -148,6 +160,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixing menu visibility issues. - Fixing menu visibility issues.
[0.4.5]: https://github.com/Automattic/jetpack-admin-ui/compare/0.4.4...0.4.5
[0.4.4]: https://github.com/Automattic/jetpack-admin-ui/compare/0.4.3...0.4.4
[0.4.3]: https://github.com/Automattic/jetpack-admin-ui/compare/0.4.2...0.4.3
[0.4.2]: https://github.com/Automattic/jetpack-admin-ui/compare/0.4.1...0.4.2 [0.4.2]: https://github.com/Automattic/jetpack-admin-ui/compare/0.4.1...0.4.2
[0.4.1]: https://github.com/Automattic/jetpack-admin-ui/compare/0.4.0...0.4.1 [0.4.1]: https://github.com/Automattic/jetpack-admin-ui/compare/0.4.0...0.4.1
[0.4.0]: https://github.com/Automattic/jetpack-admin-ui/compare/0.3.2...0.4.0 [0.4.0]: https://github.com/Automattic/jetpack-admin-ui/compare/0.3.2...0.4.0

View File

@ -7,9 +7,9 @@
"php": ">=7.0" "php": ">=7.0"
}, },
"require-dev": { "require-dev": {
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.2.2", "automattic/jetpack-changelogger": "^4.2.6",
"automattic/jetpack-logo": "^2.0.2", "automattic/jetpack-logo": "^2.0.4",
"automattic/wordbless": "dev-master" "automattic/wordbless": "dev-master"
}, },
"suggest": { "suggest": {

View File

@ -13,7 +13,7 @@ namespace Automattic\Jetpack\Admin_UI;
*/ */
class Admin_Menu { class Admin_Menu {
const PACKAGE_VERSION = '0.4.2'; const PACKAGE_VERSION = '0.4.5';
/** /**
* Whether this class has been initialized * Whether this class has been initialized
@ -58,7 +58,7 @@ class Admin_Menu {
remove_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 ); remove_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 );
// Add an Anti-spam menu item for Jetpack. // Add an Anti-spam menu item for Jetpack.
self::add_menu( __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) ); self::add_menu( __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ), 6 );
}, },
4 4
); );
@ -82,7 +82,7 @@ class Admin_Menu {
add_menu_page( add_menu_page(
'Jetpack', 'Jetpack',
'Jetpack', 'Jetpack',
'read', 'edit_posts',
'jetpack', 'jetpack',
'__return_null', '__return_null',
$icon, $icon,

View File

@ -0,0 +1,3 @@
module.exports = {
extends: [ require.resolve( 'jetpack-js-tools/eslintrc/react' ) ],
};

View File

@ -5,6 +5,53 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.3.7] - 2024-09-05
### Changed
- Internal updates.
## [2.3.6] - 2024-09-05
### Changed
- Updated package dependencies. [#39176]
### Fixed
- Fixed script data not available in block editor iframe [#39221]
## [2.3.5] - 2024-08-29
### Changed
- Updated package dependencies. [#39111]
## [2.3.4] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
## [2.3.3] - 2024-08-21
### Changed
- i18n loader script & React JSX runtime: load scripts in the footer. [#38929]
## [2.3.2] - 2024-08-15
### Changed
- Updated package dependencies. [#38662]
## [2.3.1] - 2024-08-12
### Fixed
- Fixed variable names. [#38606]
## [2.3.0] - 2024-08-08
### Added
- Added jetpack-initial-state package to consolidate the logic for Initial state. [#38430]
## [2.2.0] - 2024-07-23
### Added
- Assets: Add JSX runtime polyfill `react-jsx-runtime` for WordPress < 6.6. [#38428]
## [2.1.13] - 2024-07-03
### Changed
- Updated package dependencies. [#38132]
## [2.1.12] - 2024-06-05
### Changed
- Updated package dependencies. [#37669]
## [2.1.11] - 2024-05-20 ## [2.1.11] - 2024-05-20
### Changed ### Changed
- Internal updates. - Internal updates.
@ -450,6 +497,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Statically access asset tools - Statically access asset tools
[2.3.7]: https://github.com/Automattic/jetpack-assets/compare/v2.3.6...v2.3.7
[2.3.6]: https://github.com/Automattic/jetpack-assets/compare/v2.3.5...v2.3.6
[2.3.5]: https://github.com/Automattic/jetpack-assets/compare/v2.3.4...v2.3.5
[2.3.4]: https://github.com/Automattic/jetpack-assets/compare/v2.3.3...v2.3.4
[2.3.3]: https://github.com/Automattic/jetpack-assets/compare/v2.3.2...v2.3.3
[2.3.2]: https://github.com/Automattic/jetpack-assets/compare/v2.3.1...v2.3.2
[2.3.1]: https://github.com/Automattic/jetpack-assets/compare/v2.3.0...v2.3.1
[2.3.0]: https://github.com/Automattic/jetpack-assets/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/Automattic/jetpack-assets/compare/v2.1.13...v2.2.0
[2.1.13]: https://github.com/Automattic/jetpack-assets/compare/v2.1.12...v2.1.13
[2.1.12]: https://github.com/Automattic/jetpack-assets/compare/v2.1.11...v2.1.12
[2.1.11]: https://github.com/Automattic/jetpack-assets/compare/v2.1.10...v2.1.11 [2.1.11]: https://github.com/Automattic/jetpack-assets/compare/v2.1.10...v2.1.11
[2.1.10]: https://github.com/Automattic/jetpack-assets/compare/v2.1.9...v2.1.10 [2.1.10]: https://github.com/Automattic/jetpack-assets/compare/v2.1.9...v2.1.10
[2.1.9]: https://github.com/Automattic/jetpack-assets/compare/v2.1.8...v2.1.9 [2.1.9]: https://github.com/Automattic/jetpack-assets/compare/v2.1.8...v2.1.9

View File

@ -9,6 +9,7 @@
// drop data into `$wp_filter` for `WP_Hook::build_preinitialized_hooks()`. // drop data into `$wp_filter` for `WP_Hook::build_preinitialized_hooks()`.
if ( function_exists( 'add_action' ) ) { if ( function_exists( 'add_action' ) ) {
add_action( 'wp_default_scripts', array( Automattic\Jetpack\Assets::class, 'wp_default_scripts_hook' ) ); add_action( 'wp_default_scripts', array( Automattic\Jetpack\Assets::class, 'wp_default_scripts_hook' ) );
add_action( 'plugins_loaded', array( Automattic\Jetpack\Assets\Script_Data::class, 'configure' ), 1 );
} else { } else {
global $wp_filter; global $wp_filter;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
@ -16,4 +17,9 @@ if ( function_exists( 'add_action' ) ) {
'accepted_args' => 1, 'accepted_args' => 1,
'function' => array( Automattic\Jetpack\Assets::class, 'wp_default_scripts_hook' ), 'function' => array( Automattic\Jetpack\Assets::class, 'wp_default_scripts_hook' ),
); );
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$wp_filter['plugins_loaded'][1][] = array(
'accepted_args' => 0,
'function' => array( Automattic\Jetpack\Assets\Script_Data::class, 'configure' ),
);
} }

View File

@ -1 +1 @@
<?php return array('dependencies' => array('wp-i18n'), 'version' => 'b5d2a25bb8ad1698db1c'); <?php return array('dependencies' => array('wp-i18n'), 'version' => 'becd7d9884bc1b331e45');

View File

@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => '0274966690f87adbeccb');

View File

@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JetpackScriptDataModule=t():e.JetpackScriptDataModule=t()}(self,(()=>(()=>{var e={729:(e,t,r)=>{"use strict";r.r(t),r.d(t,{getActiveFeatures:()=>a.mH,getAdminUrl:()=>a.hT,getJetpackAdminPageUrl:()=>a.oQ,getMyJetpackUrl:()=>a.e5,getScriptData:()=>a.au,getSiteData:()=>a.sV});var o=r(428),n={};for(const e in o)"default"!==e&&(n[e]=()=>o[e]);r.d(t,n);var a=r(336)},428:()=>{},336:(e,t,r)=>{"use strict";function o(){return window.JetpackScriptData}function n(){return o().site}function a(e=""){return`${o().site.admin_url}${e}`}function i(e=""){return a(`admin.php?page=jetpack${e}`)}function u(e=""){return a(`admin.php?page=my-jetpack${e}`)}function p(){return o().site.plan?.features?.active??[]}r.d(t,{au:()=>o,e5:()=>u,hT:()=>a,mH:()=>p,oQ:()=>i,sV:()=>n})}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";r.r(o);var e=r(729),t={};for(const r in e)"default"!==r&&(t[r]=()=>e[r]);r.d(o,t)})(),o})()));

View File

@ -0,0 +1,2 @@
/*! For license information please see react-jsx-runtime.js.LICENSE.txt */
(()=>{"use strict";var r={572:(r,e,t)=>{var o=t(609),n=Symbol.for("react.element"),s=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,f=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function _(r,e,t){var o,s={},_=null,i=null;for(o in void 0!==t&&(_=""+t),void 0!==e.key&&(_=""+e.key),void 0!==e.ref&&(i=e.ref),e)a.call(e,o)&&!p.hasOwnProperty(o)&&(s[o]=e[o]);if(r&&r.defaultProps)for(o in e=r.defaultProps)void 0===s[o]&&(s[o]=e[o]);return{$$typeof:n,type:r,key:_,ref:i,props:s,_owner:f.current}}e.Fragment=s,e.jsx=_,e.jsxs=_},48:(r,e,t)=>{r.exports=t(572)},609:r=>{r.exports=window.React}},e={},t=function t(o){var n=e[o];if(void 0!==n)return n.exports;var s=e[o]={exports:{}};return r[o](s,s.exports,t),s.exports}(48);window.ReactJSXRuntime=t})();

View File

@ -0,0 +1,9 @@
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

View File

@ -5,12 +5,12 @@
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",
"require": { "require": {
"php": ">=7.0", "php": ">=7.0",
"automattic/jetpack-constants": "^2.0.2" "automattic/jetpack-constants": "^2.0.4"
}, },
"require-dev": { "require-dev": {
"brain/monkey": "2.6.1", "brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.2.4", "automattic/jetpack-changelogger": "^4.2.6",
"wikimedia/testing-access-wrapper": "^1.0 || ^2.0 || ^3.0" "wikimedia/testing-access-wrapper": "^1.0 || ^2.0 || ^3.0"
}, },
"suggest": { "suggest": {
@ -51,7 +51,7 @@
"link-template": "https://github.com/Automattic/jetpack-assets/compare/v${old}...v${new}" "link-template": "https://github.com/Automattic/jetpack-assets/compare/v${old}...v${new}"
}, },
"branch-alias": { "branch-alias": {
"dev-trunk": "2.1.x-dev" "dev-trunk": "2.3.x-dev"
} }
} }
} }

View File

@ -109,9 +109,8 @@ class Assets {
*/ */
public static function enqueue_async_script( $handle, $min_path, $non_min_path, $deps = array(), $ver = false, $in_footer = true ) { public static function enqueue_async_script( $handle, $min_path, $non_min_path, $deps = array(), $ver = false, $in_footer = true ) {
_deprecated_function( __METHOD__, '2.1.0' ); _deprecated_function( __METHOD__, '2.1.0' );
$assets_instance = self::instance();
$assets_instance->add_async_script( $handle );
wp_enqueue_script( $handle, self::get_file_url_for_environment( $min_path, $non_min_path ), $deps, $ver, $in_footer ); wp_enqueue_script( $handle, self::get_file_url_for_environment( $min_path, $non_min_path ), $deps, $ver, $in_footer );
wp_script_add_data( $handle, 'strategy', 'defer' );
} }
// endregion . // endregion .
@ -258,11 +257,11 @@ class Assets {
$ret = ''; $ret = '';
$ret .= isset( $parts['scheme'] ) ? $parts['scheme'] . '://' : ''; $ret .= isset( $parts['scheme'] ) ? $parts['scheme'] . '://' : '';
if ( isset( $parts['user'] ) || isset( $parts['pass'] ) ) { if ( isset( $parts['user'] ) || isset( $parts['pass'] ) ) {
$ret .= isset( $parts['user'] ) ? $parts['user'] : ''; $ret .= $parts['user'] ?? '';
$ret .= isset( $parts['pass'] ) ? ':' . $parts['pass'] : ''; $ret .= isset( $parts['pass'] ) ? ':' . $parts['pass'] : '';
$ret .= '@'; $ret .= '@';
} }
$ret .= isset( $parts['host'] ) ? $parts['host'] : ''; $ret .= $parts['host'] ?? '';
$ret .= isset( $parts['port'] ) ? ':' . $parts['port'] : ''; $ret .= isset( $parts['port'] ) ? ':' . $parts['port'] : '';
$pp = explode( '/', $parts['path'] ); $pp = explode( '/', $parts['path'] );
@ -323,6 +322,7 @@ class Assets {
* - `strategy`: (string) Specify a script strategy to use, eg. `defer` or `async`. Default is `""`. * - `strategy`: (string) Specify a script strategy to use, eg. `defer` or `async`. Default is `""`.
* - `textdomain`: (string) Text domain for the script. Required if the script depends on wp-i18n. * - `textdomain`: (string) Text domain for the script. Required if the script depends on wp-i18n.
* - `version`: (string) Override the version from the `asset_path` file. * - `version`: (string) Override the version from the `asset_path` file.
* @phan-param array{asset_path?:?string,async?:bool,css_dependencies?:string[],css_path?:?string,dependencies?:string[],enqueue?:bool,in_footer?:bool,media?:string,minify?:?bool,nonmin_path?:string,strategy?:string,textdomain?:string,version?:string} $options
* @throws \InvalidArgumentException If arguments are invalid. * @throws \InvalidArgumentException If arguments are invalid.
*/ */
public static function register_script( $handle, $path, $relative_to, array $options = array() ) { public static function register_script( $handle, $path, $relative_to, array $options = array() ) {
@ -349,8 +349,9 @@ class Assets {
'strategy' => '', 'strategy' => '',
'textdomain' => null, 'textdomain' => null,
); );
'@phan-var array{asset_path:?string,async:bool,css_dependencies:string[],css_path:?string,dependencies:string[],enqueue:bool,in_footer:bool,media:string,minify:?bool,nonmin_path?:string,strategy:string,textdomain:string,version?:string} $options'; // Phan gets confused by the array addition.
if ( $options['css_path'] && substr( $options['css_path'], -4 ) !== '.css' ) { if ( is_string( $options['css_path'] ) && $options['css_path'] !== '' && substr( $options['css_path'], -4 ) !== '.css' ) {
throw new \InvalidArgumentException( '$options[\'css_path\'] must end in ".css"' ); throw new \InvalidArgumentException( '$options[\'css_path\'] must end in ".css"' );
} }
@ -376,9 +377,10 @@ class Assets {
), ),
$options['css_dependencies'] $options['css_dependencies']
); );
$ver = isset( $options['version'] ) ? $options['version'] : $asset['version']; $ver = $options['version'] ?? $asset['version'];
} else { } else {
$ver = isset( $options['version'] ) ? $options['version'] : filemtime( "$dir/$path" ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$ver = $options['version'] ?? @filemtime( "$dir/$path" );
} }
if ( $options['async'] && '' === $options['strategy'] ) { // Handle the deprecated `async` option if ( $options['async'] && '' === $options['strategy'] ) { // Handle the deprecated `async` option
@ -407,7 +409,7 @@ class Assets {
); );
} }
if ( $options['css_path'] && file_exists( "$dir/{$options['css_path']}" ) ) { if ( is_string( $options['css_path'] ) && $options['css_path'] !== '' && file_exists( "$dir/{$options['css_path']}" ) ) {
$csspath = $options['css_path']; $csspath = $options['css_path'];
if ( is_rtl() ) { if ( is_rtl() ) {
$rtlcsspath = substr( $csspath, 0, -4 ) . '.rtl.css'; $rtlcsspath = substr( $csspath, 0, -4 ) . '.rtl.css';
@ -508,26 +510,39 @@ class Assets {
} }
$url = self::normalize_path( plugins_url( $path, __FILE__ ) ); $url = self::normalize_path( plugins_url( $path, __FILE__ ) );
$url = add_query_arg( 'minify', 'true', $url ); $url = add_query_arg( 'minify', 'true', $url );
$wp_scripts->add( 'wp-jp-i18n-loader', $url, $asset['dependencies'], $asset['version'] );
$handle = 'wp-jp-i18n-loader';
$wp_scripts->add( $handle, $url, $asset['dependencies'], $asset['version'] );
// Ensure the script is loaded in the footer and deferred.
$wp_scripts->add_data( $handle, 'group', 1 );
if ( ! is_array( $data ) || if ( ! is_array( $data ) ||
! isset( $data['baseUrl'] ) || ! ( is_string( $data['baseUrl'] ) || false === $data['baseUrl'] ) || ! isset( $data['baseUrl'] ) || ! ( is_string( $data['baseUrl'] ) || false === $data['baseUrl'] ) ||
! isset( $data['locale'] ) || ! is_string( $data['locale'] ) || ! isset( $data['locale'] ) || ! is_string( $data['locale'] ) ||
! isset( $data['domainMap'] ) || ! is_array( $data['domainMap'] ) || ! isset( $data['domainMap'] ) || ! is_array( $data['domainMap'] ) ||
! isset( $data['domainPaths'] ) || ! is_array( $data['domainPaths'] ) ! isset( $data['domainPaths'] ) || ! is_array( $data['domainPaths'] )
) { ) {
$wp_scripts->add_inline_script( 'wp-jp-i18n-loader', 'console.warn( "I18n state deleted by jetpack_i18n_state hook" );' ); $wp_scripts->add_inline_script( $handle, 'console.warn( "I18n state deleted by jetpack_i18n_state hook" );' );
} elseif ( ! $data['baseUrl'] ) { } elseif ( ! $data['baseUrl'] ) {
$wp_scripts->add_inline_script( 'wp-jp-i18n-loader', 'console.warn( "Failed to determine languages base URL. Is WP_LANG_DIR in the WordPress root?" );' ); $wp_scripts->add_inline_script( $handle, 'console.warn( "Failed to determine languages base URL. Is WP_LANG_DIR in the WordPress root?" );' );
} else { } else {
$data['domainMap'] = (object) $data['domainMap']; // Ensure it becomes a json object. $data['domainMap'] = (object) $data['domainMap']; // Ensure it becomes a json object.
$data['domainPaths'] = (object) $data['domainPaths']; // Ensure it becomes a json object. $data['domainPaths'] = (object) $data['domainPaths']; // Ensure it becomes a json object.
$wp_scripts->add_inline_script( 'wp-jp-i18n-loader', 'wp.jpI18nLoader.state = ' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES ) . ';' ); $wp_scripts->add_inline_script( $handle, 'wp.jpI18nLoader.state = ' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES ) . ';' );
} }
// Deprecated state module: Depend on wp-i18n to ensure global `wp` exists and because anything needing this will need that too. // Deprecated state module: Depend on wp-i18n to ensure global `wp` exists and because anything needing this will need that too.
$wp_scripts->add( 'wp-jp-i18n-state', false, array( 'wp-deprecated', 'wp-jp-i18n-loader' ) ); $wp_scripts->add( 'wp-jp-i18n-state', false, array( 'wp-deprecated', $handle ) );
$wp_scripts->add_inline_script( 'wp-jp-i18n-state', 'wp.deprecated( "wp-jp-i18n-state", { alternative: "wp-jp-i18n-loader" } );' ); $wp_scripts->add_inline_script( 'wp-jp-i18n-state', 'wp.deprecated( "wp-jp-i18n-state", { alternative: "wp-jp-i18n-loader" } );' );
$wp_scripts->add_inline_script( 'wp-jp-i18n-state', 'wp.jpI18nState = wp.jpI18nLoader.state;' ); $wp_scripts->add_inline_script( 'wp-jp-i18n-state', 'wp.jpI18nState = wp.jpI18nLoader.state;' );
// Register the React JSX runtime script - used as a polyfill until we can update JSX transforms. See https://github.com/Automattic/jetpack/issues/38424.
// @todo Remove this when we drop support for WordPress 6.5, as well as the script inclusion in test_wp_default_scripts_hook.
$jsx_url = self::normalize_path( plugins_url( '../build/react-jsx-runtime.js', __FILE__ ) );
$wp_scripts->add( 'react-jsx-runtime', $jsx_url, array( 'react' ), '18.3.1', true );
$wp_scripts->add_data( 'react-jsx-runtime', 'group', 1 );
} }
// endregion . // endregion .
@ -667,7 +682,7 @@ class Assets {
* @param string $translation Translated text. * @param string $translation Translated text.
* @param string $single The text to be used if the number is singular. * @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural. * @param string $plural The text to be used if the number is plural.
* @param string $number The number to compare against to use either the singular or plural form. * @param int $number The number to compare against to use either the singular or plural form.
* @param string $domain Text domain. * @param string $domain Text domain.
* @return string Translated text. * @return string Translated text.
*/ */
@ -704,7 +719,7 @@ class Assets {
* @param string $translation Translated text. * @param string $translation Translated text.
* @param string $single The text to be used if the number is singular. * @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural. * @param string $plural The text to be used if the number is plural.
* @param string $number The number to compare against to use either the singular or plural form. * @param int $number The number to compare against to use either the singular or plural form.
* @param string $context Context information for the translators. * @param string $context Context information for the translators.
* @param string $domain Text domain. * @param string $domain Text domain.
* @return string Translated text. * @return string Translated text.

View File

@ -0,0 +1,220 @@
<?php
/**
* Jetpack script data.
*
* @package automattic/jetpack-assets
*/
namespace Automattic\Jetpack\Assets;
use Automattic\Jetpack\Assets;
/**
* Class script data
*/
class Script_Data {
const SCRIPT_HANDLE = 'jetpack-script-data';
/**
* Whether the script data has been rendered.
*
* @var bool
*/
private static $did_render_script_data = false;
/**
* Configure.
*/
public static function configure() {
/**
* Ensure that assets are registered on wp_loaded,
* which is fired before *_enqueue_scripts actions.
* It means that when the dependent scripts are registered,
* the scripts here are already registered.
*/
add_action( 'wp_loaded', array( self::class, 'register_assets' ) );
/**
* Notes:
* 1. wp_print_scripts action is fired on both admin and public pages.
* On admin pages, it's fired before admin_enqueue_scripts action,
* which can be a problem if the consumer package uses admin_enqueue_scripts
* to hook into the script data. Thus, we prefer to use admin_print_scripts on admin pages.
* 2. We want to render the script data on print, instead of init or enqueue actions,
* so that the hook callbacks have enough time and information
* to decide whether to update the script data or not.
*/
$hook = is_admin() ? 'admin_print_scripts' : 'wp_print_scripts';
add_action( $hook, array( self::class, 'render_script_data' ), 1 );
add_action( 'enqueue_block_editor_assets', array( self::class, 'render_script_data' ), 1 );
}
/**
* Register assets.
*
* @access private
*/
public static function register_assets() {
Assets::register_script(
self::SCRIPT_HANDLE,
'../build/jetpack-script-data.js',
__FILE__,
array(
'in_footer' => true,
'textdomain' => 'jetpack-assets',
)
);
}
/**
* Render the script data using an inline script.
*
* @access private
*
* @return void
*/
public static function render_script_data() {
// In case of 'enqueue_block_editor_assets' action, this can be called multiple times.
if ( self::$did_render_script_data ) {
return;
}
self::$did_render_script_data = true;
$script_data = is_admin() ? self::get_admin_script_data() : self::get_public_script_data();
$script_data = wp_json_encode(
$script_data,
JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE
);
wp_add_inline_script(
self::SCRIPT_HANDLE,
sprintf( 'window.JetpackScriptData = %s;', $script_data ),
'before'
);
}
/**
* Get the admin script data.
*
* @return array
*/
protected static function get_admin_script_data() {
global $wp_version;
$data = array(
'site' => array(
'admin_url' => esc_url_raw( admin_url() ),
'date_format' => get_option( 'date_format' ),
'icon' => self::get_site_icon(),
'is_multisite' => is_multisite(),
'plan' => array(
// The properties here should be updated by the consumer package/plugin.
// It includes properties like 'product_slug', 'features', etc.
'product_slug' => '',
),
'rest_nonce' => wp_create_nonce( 'wp_rest' ),
'rest_root' => esc_url_raw( rest_url() ),
'title' => self::get_site_title(),
'wp_version' => $wp_version,
'wpcom' => array(
// This should contain the connected site details like blog_id, is_atomic etc.
'blog_id' => 0,
),
),
'user' => array(
'current_user' => self::get_current_user_data(),
),
);
/**
* Filter the admin script data.
*
* When using this filter, ensure that the data is added only if it is used by some script.
* This filter may be called on almost every admin page load. So, one should check if the data is needed/used on that page.
* For example, the social (publicize) data is used only on Social admin page, Jetpack settings page and the post editor.
* So, the social data should be added only on those pages.
*
* @since 2.3.0
*
* @param array $data The script data.
*/
return apply_filters( 'jetpack_admin_js_script_data', $data );
}
/**
* Get the admin script data.
*
* @return array
*/
protected static function get_public_script_data() {
$data = array(
'site' => array(
'icon' => self::get_site_icon(),
'title' => self::get_site_title(),
),
);
/**
* Filter the public script data.
*
* See the docs for `jetpack_admin_js_script_data` filter for more information.
*
* @since 2.3.0
*
* @param array $data The script data.
*/
return apply_filters( 'jetpack_public_js_script_data', $data );
}
/**
* Get the site title.
*
* @return string
*/
protected static function get_site_title() {
$title = get_bloginfo( 'name' );
return $title ? $title : esc_url_raw( ( get_site_url() ) );
}
/**
* Get the site icon.
*
* @return string
*/
protected static function get_site_icon() {
if ( ! has_site_icon() ) {
return '';
}
/**
* Filters the site icon using Photon.
*
* @see https://developer.wordpress.com/docs/photon/
*
* @param string $url The URL of the site icon.
* @param array|string $args An array of arguments, e.g. array( 'w' => '300', 'resize' => array( 123, 456 ) ), or in string form (w=123&h=456).
*/
return apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) );
}
/**
* Get the current user data.
*
* @return array
*/
protected static function get_current_user_data() {
$current_user = wp_get_current_user();
return array(
'display_name' => $current_user->display_name,
'id' => $current_user->ID,
);
}
}

View File

@ -102,7 +102,7 @@ class Semver {
if ( ctype_digit( $a ) ) { if ( ctype_digit( $a ) ) {
if ( ctype_digit( $b ) ) { if ( ctype_digit( $b ) ) {
if ( (int) $a !== (int) $b ) { if ( (int) $a !== (int) $b ) {
return $a - $b; return (int) $a - (int) $b;
} }
} else { } else {
return -1; return -1;

View File

@ -20,10 +20,10 @@ module.exports = {
/** /**
* Download and register translations for a bundle. * Download and register translations for a bundle.
* *
* @param {string} path - Bundle path being fetched. May have a query part. * @param {string} path - Bundle path being fetched. May have a query part.
* @param {string} domain - Text domain to register into. * @param {string} domain - Text domain to register into.
* @param {string} location - Location for the translation: 'plugin', 'theme', or 'core'. * @param {string} location - Location for the translation: 'plugin', 'theme', or 'core'.
* @returns {Promise} Resolved when the translations are registered, or rejected with an `Error`. * @return {Promise} Resolved when the translations are registered, or rejected with an `Error`.
*/ */
async downloadI18n( path, domain, location ) { async downloadI18n( path, domain, location ) {
const state = this.state; const state = this.state;

View File

@ -0,0 +1 @@
export * from '@automattic/jetpack-script-data';

View File

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.7] - 2024-08-26
### Changed
- Updated package dependencies. [#39004]
## [0.2.6] - 2024-04-08 ## [0.2.6] - 2024-04-08
### Changed ### Changed
- Internal updates. - Internal updates.
@ -37,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Initial release (improved helper script installer logging). [#34297] - Initial release (improved helper script installer logging). [#34297]
[0.2.7]: https://github.com/Automattic/jetpack-backup-helper-script-manager/compare/v0.2.6...v0.2.7
[0.2.6]: https://github.com/Automattic/jetpack-backup-helper-script-manager/compare/v0.2.5...v0.2.6 [0.2.6]: https://github.com/Automattic/jetpack-backup-helper-script-manager/compare/v0.2.5...v0.2.6
[0.2.5]: https://github.com/Automattic/jetpack-backup-helper-script-manager/compare/v0.2.4...v0.2.5 [0.2.5]: https://github.com/Automattic/jetpack-backup-helper-script-manager/compare/v0.2.4...v0.2.5
[0.2.4]: https://github.com/Automattic/jetpack-backup-helper-script-manager/compare/v0.2.3...v0.2.4 [0.2.4]: https://github.com/Automattic/jetpack-backup-helper-script-manager/compare/v0.2.3...v0.2.4

View File

@ -7,8 +7,8 @@
"php": ">=7.0" "php": ">=7.0"
}, },
"require-dev": { "require-dev": {
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.1.2", "automattic/jetpack-changelogger": "^4.2.6",
"automattic/wordbless": "@dev" "automattic/wordbless": "@dev"
}, },
"suggest": { "suggest": {

View File

@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.11] - 2024-09-05
### Changed
- Update dependencies.
## [0.2.10] - 2024-09-05
### Changed
- Update dependencies.
## [0.2.9] - 2024-08-26
### Changed
- Updated package dependencies. [#39004]
## [0.2.8] - 2024-08-15
### Fixed
- Fix incorrect next-version tokens in php `@since` and/or `@deprecated` docs. [#38869]
## [0.2.7] - 2024-05-06 ## [0.2.7] - 2024-05-06
### Added ### Added
- Add missing package dependencies. [#37141] - Add missing package dependencies. [#37141]
@ -57,6 +73,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Introduce new package. [#31163] - Introduce new package. [#31163]
[0.2.11]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.10...v0.2.11
[0.2.10]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.9...v0.2.10
[0.2.9]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.8...v0.2.9
[0.2.8]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.7...v0.2.8
[0.2.7]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.6...v0.2.7 [0.2.7]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.6...v0.2.7
[0.2.6]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.5...v0.2.6 [0.2.6]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.5...v0.2.6
[0.2.5]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.4...v0.2.5 [0.2.5]: https://github.com/Automattic/jetpack-boost-core/compare/v0.2.4...v0.2.5

View File

@ -5,11 +5,11 @@
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",
"require": { "require": {
"php": ">=7.0", "php": ">=7.0",
"automattic/jetpack-connection": "^2.7.6" "automattic/jetpack-connection": "^4.0.0"
}, },
"require-dev": { "require-dev": {
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.2.3", "automattic/jetpack-changelogger": "^4.2.6",
"automattic/wordbless": "dev-master" "automattic/wordbless": "dev-master"
}, },
"autoload": { "autoload": {

View File

@ -27,7 +27,7 @@ class Boost_API {
* Get the API client instance. * Get the API client instance.
* *
* @return Boost_API_Client * @return Boost_API_Client
* @deprecated $$next_version$$ Use get(), and post() directly instead. * @deprecated 3.1.1 Use get(), and post() directly instead.
*/ */
public static function get_client() { public static function get_client() {
return self::get_api_client(); return self::get_api_client();

View File

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.3.12] - 2024-08-26
### Changed
- Updated package dependencies. [#39004]
## [0.3.11] - 2024-04-22 ## [0.3.11] - 2024-04-22
### Changed ### Changed
- Internal updates. - Internal updates.
@ -84,6 +88,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add a new package for Boost Speed Score [#30914] - Add a new package for Boost Speed Score [#30914]
- Add a new argument to `Speed_Score` to identify where the request was made from (e.g. 'boost-plugin', 'jetpack-dashboard', etc). [#31012] - Add a new argument to `Speed_Score` to identify where the request was made from (e.g. 'boost-plugin', 'jetpack-dashboard', etc). [#31012]
[0.3.12]: https://github.com/Automattic/jetpack-boost-speed-score/compare/v0.3.11...v0.3.12
[0.3.11]: https://github.com/Automattic/jetpack-boost-speed-score/compare/v0.3.10...v0.3.11 [0.3.11]: https://github.com/Automattic/jetpack-boost-speed-score/compare/v0.3.10...v0.3.11
[0.3.10]: https://github.com/Automattic/jetpack-boost-speed-score/compare/v0.3.9...v0.3.10 [0.3.10]: https://github.com/Automattic/jetpack-boost-speed-score/compare/v0.3.9...v0.3.10
[0.3.9]: https://github.com/Automattic/jetpack-boost-speed-score/compare/v0.3.8...v0.3.9 [0.3.9]: https://github.com/Automattic/jetpack-boost-speed-score/compare/v0.3.8...v0.3.9

View File

@ -4,8 +4,8 @@
"type": "jetpack-library", "type": "jetpack-library",
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",
"require-dev": { "require-dev": {
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.2.2", "automattic/jetpack-changelogger": "^4.2.6",
"brain/monkey": "^2.6" "brain/monkey": "^2.6"
}, },
"autoload-dev": { "autoload-dev": {
@ -15,7 +15,7 @@
}, },
"require": { "require": {
"php": ">=7.0", "php": ">=7.0",
"automattic/jetpack-boost-core": "^0.2.6" "automattic/jetpack-boost-core": "^0.2.9"
}, },
"autoload": { "autoload": {
"classmap": [ "classmap": [

View File

@ -23,7 +23,7 @@ if ( ! defined( 'JETPACK_BOOST_REST_PREFIX' ) ) {
*/ */
class Speed_Score { class Speed_Score {
const PACKAGE_VERSION = '0.3.11'; const PACKAGE_VERSION = '0.3.12';
/** /**
* Array of module slugs that are currently active and can impact speed score. * Array of module slugs that are currently active and can impact speed score.

View File

@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.0.4] - 2024-06-24
### Changed
- Internal updates.
## [2.0.3] - 2024-06-03
### Removed
- Remove the Identity Crisis package dev dependency. [#37654]
## [2.0.2] - 2024-05-06 ## [2.0.2] - 2024-05-06
### Changed ### Changed
- Internal updates. - Internal updates.
@ -200,6 +208,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Trying to add deterministic initialization. - Trying to add deterministic initialization.
[2.0.4]: https://github.com/Automattic/jetpack-config/compare/v2.0.3...v2.0.4
[2.0.3]: https://github.com/Automattic/jetpack-config/compare/v2.0.2...v2.0.3
[2.0.2]: https://github.com/Automattic/jetpack-config/compare/v2.0.1...v2.0.2 [2.0.2]: https://github.com/Automattic/jetpack-config/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/Automattic/jetpack-config/compare/v2.0.0...v2.0.1 [2.0.1]: https://github.com/Automattic/jetpack-config/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/Automattic/jetpack-config/compare/v1.15.4...v2.0.0 [2.0.0]: https://github.com/Automattic/jetpack-config/compare/v1.15.4...v2.0.0

View File

@ -7,9 +7,8 @@
"php": ">=7.0" "php": ">=7.0"
}, },
"require-dev": { "require-dev": {
"automattic/jetpack-changelogger": "^4.2.3", "automattic/jetpack-changelogger": "^4.2.4",
"automattic/jetpack-connection": "@dev", "automattic/jetpack-connection": "@dev",
"automattic/jetpack-identity-crisis": "@dev",
"automattic/jetpack-import": "@dev", "automattic/jetpack-import": "@dev",
"automattic/jetpack-jitm": "@dev", "automattic/jetpack-jitm": "@dev",
"automattic/jetpack-post-list": "@dev", "automattic/jetpack-post-list": "@dev",
@ -46,7 +45,6 @@
"dependencies": { "dependencies": {
"test-only": [ "test-only": [
"packages/connection", "packages/connection",
"packages/identity-crisis",
"packages/import", "packages/import",
"packages/jitm", "packages/jitm",
"packages/post-list", "packages/post-list",

View File

@ -0,0 +1,3 @@
module.exports = {
extends: [ require.resolve( 'jetpack-js-tools/eslintrc/react' ) ],
};

View File

@ -5,6 +5,113 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [4.0.1] - 2024-09-06
### Removed
- Removed throwing of warning if a given Jetpack options does not exist [#39270]
## [4.0.0] - 2024-09-05
### Deprecated
- Deprecated Jetpack Onboarding system. [#39229]
## [3.0.0] - 2024-09-05
### Changed
- Jetpack Connection: Restrict handling verified errors on admin pages only [#39233]
- Updated connection js to load its bundle via connection package [#38877]
- Updated package dependencies. [#39176]
### Removed
- Removed registering of Jetpack option edit_links_calypso_redirect [#39171]
### Fixed
- Fixed connection assets for wpcom simple sites [#39201]
## [2.12.5] - 2024-08-29
### Changed
- Sync: Remove the checksum for active plugins if present when sync is not active, so it gets recalculated when sync gets activated [#39098]
- Updated package dependencies. [#39111]
## [2.12.4] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
### Removed
- SSO: Removed the ability to skip the automatic login if site uses the WP.com classic interface [#38996]
## [2.12.3] - 2024-08-21
### Changed
- Internal updates.
## [2.12.2] - 2024-08-19
### Changed
- `Jetpack_Options::update_option()` now documents `$autoload` as `bool|null` to match the similar change in WordPress 6.6. String values are still accepted for as long as core's `update_option()` accepts them. [#38822]
## [2.12.1] - 2024-08-15
### Changed
- Updated package dependencies. [#38662]
## [2.12.0] - 2024-08-13
### Added
- Updated the connection initial state to fallback on the new consolidated Jetpack script data [#38825]
## [2.11.4] - 2024-08-09
### Fixed
- Fix type for tracking product string [#38748]
## [2.11.3] - 2024-08-01
### Added
- Added support for 'recommendations_evaluation' Jetpack option" [#38534]
## [2.11.2] - 2024-07-22
### Fixed
- Fixed textdomain on i18n messages imported from the IDC package. [#38412]
## [2.11.1] - 2024-07-03
### Changed
- Updated package dependencies. [#38132]
## [2.11.0] - 2024-06-26
### Added
- Add blog_id to tracks data [#37902]
## [2.10.2] - 2024-06-25
### Changed
- Internal updates.
## [2.10.1] - 2024-06-12
### Changed
- Updated package dependencies. [#37796]
## [2.10.0] - 2024-06-10
### Added
- Staging: deprecating staging mode and separating the logic into is_development_site and in_safe_mode [#37023]
### Fixed
- Jetpack Connection: Add stricter check before updating 'jetpack_connection_active_plugins' option [#37755]
## [2.9.3] - 2024-06-06
### Added
- Add mechanism to track previously working plugins [#37537]
## [2.9.2] - 2024-06-05
### Changed
- Updated package dependencies. [#37669]
## [2.9.1] - 2024-06-03
### Fixed
- Remove tabindex from tooltip modal. [#37663]
## [2.9.0] - 2024-05-29
### Added
- Move Identity Crisis handling functionality into the package. [#36968]
## [2.8.6] - 2024-05-28
### Changed
- Internal updates.
## [2.8.5] - 2024-05-27
### Fixed
- SSO: Use filter instead of action for user custom column to prevent interference with other custom columns. [#37575]
## [2.8.4] - 2024-05-22 ## [2.8.4] - 2024-05-22
### Deprecated ### Deprecated
- Jetpack Connection Manager: Deprecate `request_params` arg in setup_xmlrpc_handlers method. [#37445] - Jetpack Connection Manager: Deprecate `request_params` arg in setup_xmlrpc_handlers method. [#37445]
@ -1080,6 +1187,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Separate the connection library into its own package. - Separate the connection library into its own package.
[4.0.1]: https://github.com/Automattic/jetpack-connection/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/Automattic/jetpack-connection/compare/v3.0.0...v4.0.0
[3.0.0]: https://github.com/Automattic/jetpack-connection/compare/v2.12.5...v3.0.0
[2.12.5]: https://github.com/Automattic/jetpack-connection/compare/v2.12.4...v2.12.5
[2.12.4]: https://github.com/Automattic/jetpack-connection/compare/v2.12.3...v2.12.4
[2.12.3]: https://github.com/Automattic/jetpack-connection/compare/v2.12.2...v2.12.3
[2.12.2]: https://github.com/Automattic/jetpack-connection/compare/v2.12.1...v2.12.2
[2.12.1]: https://github.com/Automattic/jetpack-connection/compare/v2.12.0...v2.12.1
[2.12.0]: https://github.com/Automattic/jetpack-connection/compare/v2.11.4...v2.12.0
[2.11.4]: https://github.com/Automattic/jetpack-connection/compare/v2.11.3...v2.11.4
[2.11.3]: https://github.com/Automattic/jetpack-connection/compare/v2.11.2...v2.11.3
[2.11.2]: https://github.com/Automattic/jetpack-connection/compare/v2.11.1...v2.11.2
[2.11.1]: https://github.com/Automattic/jetpack-connection/compare/v2.11.0...v2.11.1
[2.11.0]: https://github.com/Automattic/jetpack-connection/compare/v2.10.2...v2.11.0
[2.10.2]: https://github.com/Automattic/jetpack-connection/compare/v2.10.1...v2.10.2
[2.10.1]: https://github.com/Automattic/jetpack-connection/compare/v2.10.0...v2.10.1
[2.10.0]: https://github.com/Automattic/jetpack-connection/compare/v2.9.3...v2.10.0
[2.9.3]: https://github.com/Automattic/jetpack-connection/compare/v2.9.2...v2.9.3
[2.9.2]: https://github.com/Automattic/jetpack-connection/compare/v2.9.1...v2.9.2
[2.9.1]: https://github.com/Automattic/jetpack-connection/compare/v2.9.0...v2.9.1
[2.9.0]: https://github.com/Automattic/jetpack-connection/compare/v2.8.6...v2.9.0
[2.8.6]: https://github.com/Automattic/jetpack-connection/compare/v2.8.5...v2.8.6
[2.8.5]: https://github.com/Automattic/jetpack-connection/compare/v2.8.4...v2.8.5
[2.8.4]: https://github.com/Automattic/jetpack-connection/compare/v2.8.3...v2.8.4 [2.8.4]: https://github.com/Automattic/jetpack-connection/compare/v2.8.3...v2.8.4
[2.8.3]: https://github.com/Automattic/jetpack-connection/compare/v2.8.2...v2.8.3 [2.8.3]: https://github.com/Automattic/jetpack-connection/compare/v2.8.2...v2.8.3
[2.8.2]: https://github.com/Automattic/jetpack-connection/compare/v2.8.1...v2.8.2 [2.8.2]: https://github.com/Automattic/jetpack-connection/compare/v2.8.1...v2.8.2

View File

@ -0,0 +1,23 @@
<?php
/**
* Action Hooks for Jetpack connection assets.
*
* @package automattic/jetpack-connection
*/
// If WordPress's plugin API is available already, use it. If not,
// drop data into `$wp_filter` for `WP_Hook::build_preinitialized_hooks()`.
if ( function_exists( 'add_action' ) ) {
add_action(
'plugins_loaded',
array( Automattic\Jetpack\Connection\Connection_Assets::class, 'configure' ),
1
);
} else {
global $wp_filter;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$wp_filter['plugins_loaded'][1][] = array(
'accepted_args' => 0,
'function' => array( Automattic\Jetpack\Connection\Connection_Assets::class, 'configure' ),
);
}

View File

@ -5,28 +5,32 @@
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",
"require": { "require": {
"php": ">=7.0", "php": ">=7.0",
"automattic/jetpack-a8c-mc-stats": "^2.0.1", "automattic/jetpack-a8c-mc-stats": "^2.0.2",
"automattic/jetpack-admin-ui": "^0.4.2", "automattic/jetpack-admin-ui": "^0.4.5",
"automattic/jetpack-assets": "^2.1.11", "automattic/jetpack-assets": "^2.3.7",
"automattic/jetpack-constants": "^2.0.2", "automattic/jetpack-constants": "^2.0.4",
"automattic/jetpack-roles": "^2.0.2", "automattic/jetpack-roles": "^2.0.3",
"automattic/jetpack-status": "^3.2.0", "automattic/jetpack-status": "^4.0.1",
"automattic/jetpack-redirect": "^2.0.2" "automattic/jetpack-redirect": "^2.0.4"
}, },
"require-dev": { "require-dev": {
"automattic/wordbless": "@dev", "automattic/wordbless": "@dev",
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"brain/monkey": "2.6.1", "brain/monkey": "2.6.1",
"automattic/jetpack-changelogger": "^4.2.4" "automattic/jetpack-changelogger": "^4.2.6"
}, },
"suggest": { "suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
}, },
"autoload": { "autoload": {
"files": [
"actions.php"
],
"classmap": [ "classmap": [
"legacy", "legacy",
"src/", "src/",
"src/webhooks" "src/webhooks",
"src/identity-crisis"
] ]
}, },
"scripts": { "scripts": {
@ -58,7 +62,7 @@
"link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}" "link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}"
}, },
"branch-alias": { "branch-alias": {
"dev-trunk": "2.8.x-dev" "dev-trunk": "4.0.x-dev"
}, },
"dependencies": { "dependencies": {
"test-only": [ "test-only": [

View File

@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => 'f6bce0e6b8e0527839ee');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
<?php return array('dependencies' => array('jetpack-script-data', 'react', 'react-jsx-runtime', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-url'), 'version' => '633f5b84c0735e749fc1');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,7 @@
/*
* Exposes number format capability
*
* @copyright Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io) and Contributors (http://phpjs.org/authors).
* @license See CREDITS.md
* @see https://github.com/kvz/phpjs/blob/ffe1356af23a6f2512c84c954dd4e828e92579fa/functions/strings/number_format.js
*/

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'd9dbf909a3d10fb26f39'); <?php return array('dependencies' => array(), 'version' => 'a8b23de97e9658b5993f');

View File

@ -1 +1 @@
(()=>{var e={775:e=>{let n;window._tkq=window._tkq||[];const t=console.error;const o={initialize:function(e,n){o.setUser(e,n),o.identifyUser()},mc:{bumpStat:function(e,n){const t=function(e,n){let t="";if("object"==typeof e)for(const n in e)t+="&x_"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]);else t="&x_"+encodeURIComponent(e)+"="+encodeURIComponent(n);return t}(e,n);(new Image).src=document.location.protocol+"//pixel.wp.com/g.gif?v=wpcom-no-pv"+t+"&t="+Math.random()}},tracks:{recordEvent:function(e,n){n=n||{},0===e.indexOf("jetpack_")?window._tkq.push(["recordEvent",e,n]):t('- Event name must be prefixed by "jetpack_"')},recordPageView:function(e){o.tracks.recordEvent("jetpack_page_view",{path:e})}},setUser:function(e,t){n={ID:e,username:t}},identifyUser:function(){n&&window._tkq.push(["identifyUser",n.ID,n.username])},clearedIdentity:function(){window._tkq.push(["clearIdentity"])}};e.exports=o}},n={};var t=function t(o){var r=n[o];if(void 0!==r)return r.exports;var i=n[o]={exports:{}};return e[o](i,i.exports,t),i.exports}(775);window.analytics=t})(); (()=>{var e={7961:e=>{let n;window._tkq=window._tkq||[];const t=console.error;const o={initialize:function(e,n){o.setUser(e,n),o.identifyUser()},mc:{bumpStat:function(e,n){const t=function(e,n){let t="";if("object"==typeof e)for(const n in e)t+="&x_"+encodeURIComponent(n)+"="+encodeURIComponent(e[n]);else t="&x_"+encodeURIComponent(e)+"="+encodeURIComponent(n);return t}(e,n);(new Image).src=document.location.protocol+"//pixel.wp.com/g.gif?v=wpcom-no-pv"+t+"&t="+Math.random()}},tracks:{recordEvent:function(e,n){n=n||{},0===e.indexOf("jetpack_")?window._tkq.push(["recordEvent",e,n]):t('- Event name must be prefixed by "jetpack_"')},recordPageView:function(e){o.tracks.recordEvent("jetpack_page_view",{path:e})}},setUser:function(e,t){n={ID:e,username:t}},identifyUser:function(){n&&window._tkq.push(["identifyUser",n.ID,n.username])},clearedIdentity:function(){window._tkq.push(["clearIdentity"])}};e.exports=o}},n={};var t=function t(o){var r=n[o];if(void 0!==r)return r.exports;var i=n[o]={exports:{}};return e[o](i,i.exports,t),i.exports}(7961);window.analytics=t})();

View File

@ -77,7 +77,7 @@ class Jetpack_IXR_Client extends IXR_Client {
/** /**
* Perform the IXR request. * Perform the IXR request.
* *
* @param string[] ...$args IXR args. * @param mixed ...$args IXR method and args.
* *
* @return bool True if request succeeded, false otherwise. * @return bool True if request succeeded, false otherwise.
*/ */

View File

@ -40,7 +40,6 @@ class Jetpack_Options {
'allowed_xsite_search_ids', // (array) Array of WP.com blog ids that are allowed to search the content of this site 'allowed_xsite_search_ids', // (array) Array of WP.com blog ids that are allowed to search the content of this site
'available_modules', 'available_modules',
'do_activate', 'do_activate',
'edit_links_calypso_redirect', // (bool) Whether post/page edit links on front end should point to Calypso.
'log', 'log',
'slideshow_background_color', 'slideshow_background_color',
'widget_twitter', 'widget_twitter',
@ -66,7 +65,6 @@ class Jetpack_Options {
'safe_mode_confirmed', // (bool) True if someone confirms that this site was correctly put into safe mode automatically after an identity crisis is discovered. 'safe_mode_confirmed', // (bool) True if someone confirms that this site was correctly put into safe mode automatically after an identity crisis is discovered.
'migrate_for_idc', // (bool) True if someone confirms that this site should migrate stats and subscribers from its previous URL 'migrate_for_idc', // (bool) True if someone confirms that this site should migrate stats and subscribers from its previous URL
'ab_connect_banner_green_bar', // (int) Version displayed of the A/B test for the green bar at the top of the connect banner. 'ab_connect_banner_green_bar', // (int) Version displayed of the A/B test for the green bar at the top of the connect banner.
'onboarding', // (string) Auth token to be used in the onboarding connection flow
'tos_agreed', // (bool) Whether or not the TOS for connection has been agreed upon. 'tos_agreed', // (bool) Whether or not the TOS for connection has been agreed upon.
'static_asset_cdn_files', // (array) An nested array of files that we can swap out for cdn versions. 'static_asset_cdn_files', // (array) An nested array of files that we can swap out for cdn versions.
'mapbox_api_key', // (string) Mapbox API Key, for use with Map block. 'mapbox_api_key', // (string) Mapbox API Key, for use with Map block.
@ -86,7 +84,6 @@ class Jetpack_Options {
case 'network': case 'network':
return array( return array(
'onboarding', // (string) Auth token to be used in the onboarding connection flow
'file_data', // (array) List of absolute paths to all Jetpack modules 'file_data', // (array) List of absolute paths to all Jetpack modules
); );
} }
@ -128,6 +125,9 @@ class Jetpack_Options {
'identity_crisis_url_secret', // (array) The IDC URL secret and its expiration date. 'identity_crisis_url_secret', // (array) The IDC URL secret and its expiration date.
'identity_crisis_ip_requester', // (array) The IDC IP address and its expiration date. 'identity_crisis_ip_requester', // (array) The IDC IP address and its expiration date.
'dismissed_welcome_banner', // (bool) Determines if the welcome banner has been dismissed or not. 'dismissed_welcome_banner', // (bool) Determines if the welcome banner has been dismissed or not.
'recommendations_evaluation', // (object) Catalog of recommended modules with corresponding score following successful site evaluation in Welcome Banner.
'dismissed_recommendations', // (bool) Determines if the recommendations have been dismissed or not.
'historically_active_modules', // (array) List of installed plugins/enabled modules that have at one point in time been active and working
); );
} }
@ -228,8 +228,6 @@ class Jetpack_Options {
} }
} }
trigger_error( sprintf( 'Invalid Jetpack option name: %s', esc_html( $name ) ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Don't wish to change legacy behavior.
return $default; return $default;
} }
@ -284,9 +282,9 @@ class Jetpack_Options {
/** /**
* Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate. * Updates the single given option. Updates jetpack_options or jetpack_$name as appropriate.
* *
* @param string $name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name. * @param string $name Option name. It must come _without_ `jetpack_%` prefix. The method will prefix the option name.
* @param mixed $value Option value. * @param mixed $value Option value.
* @param string $autoload If not compact option, allows specifying whether to autoload or not. * @param bool|null $autoload If not compact option, allows specifying whether to autoload or not.
* *
* @return bool Was the option successfully updated? * @return bool Was the option successfully updated?
*/ */
@ -636,10 +634,6 @@ class Jetpack_Options {
'jetpack_sso_require_two_step', 'jetpack_sso_require_two_step',
'jetpack_sso_remove_login_form', 'jetpack_sso_remove_login_form',
'jetpack_last_connect_url_check', 'jetpack_last_connect_url_check',
'jpo_business_address',
'jpo_site_type',
'jpo_homepage_format',
'jpo_contact_page',
'jetpack_excluded_extensions', 'jetpack_excluded_extensions',
); );
} }

View File

@ -521,6 +521,7 @@ class Jetpack_XMLRPC_Server {
* Getter for the local user to act as. * Getter for the local user to act as.
* *
* @param array $request the current request data. * @param array $request the current request data.
* @return WP_User|IXR_Error|false IXR_Error if the request is missing a local_user field, WP_User object on success, or false on failure to find a user.
*/ */
private function fetch_and_verify_local_user( $request ) { private function fetch_and_verify_local_user( $request ) {
if ( empty( $request['local_user'] ) ) { if ( empty( $request['local_user'] ) ) {
@ -544,6 +545,7 @@ class Jetpack_XMLRPC_Server {
* Gets the user object by its data. * Gets the user object by its data.
* *
* @param string $user_id can be any identifying user data. * @param string $user_id can be any identifying user data.
* @return WP_User|false WP_User object on success, false on failure.
*/ */
private function get_user_by_anything( $user_id ) { private function get_user_by_anything( $user_id ) {
$user = get_user_by( 'login', $user_id ); $user = get_user_by( 'login', $user_id );

View File

@ -0,0 +1,41 @@
<?php
/**
* Connection_Assets.
*
* @package automattic/jetpack-connection
*/
namespace Automattic\Jetpack\Connection;
use Automattic\Jetpack\Assets;
/**
* Connection_Assets class.
*/
class Connection_Assets {
/**
* Initialize the class.
*/
public static function configure() {
add_action( 'wp_loaded', array( __CLASS__, 'register_assets' ) );
add_filter( 'jetpack_admin_js_script_data', array( Initial_State::class, 'set_connection_script_data' ), 10, 1 );
}
/**
* Register assets.
*/
public static function register_assets() {
Assets::register_script(
'jetpack-connection',
'../dist/jetpack-connection.js',
__FILE__,
array(
'in_footer' => true,
'textdomain' => 'jetpack-connection',
)
);
}
}

View File

@ -136,7 +136,8 @@ class Error_Handler {
add_action( 'rest_api_init', array( $this, 'register_verify_error_endpoint' ) ); add_action( 'rest_api_init', array( $this, 'register_verify_error_endpoint' ) );
$this->handle_verified_errors(); // Handle verified errors on admin pages.
add_action( 'admin_init', array( $this, 'handle_verified_errors' ) );
// If the site gets reconnected, clear errors. // If the site gets reconnected, clear errors.
add_action( 'jetpack_site_registered', array( $this, 'delete_all_errors' ) ); add_action( 'jetpack_site_registered', array( $this, 'delete_all_errors' ) );

View File

@ -39,6 +39,18 @@ class Initial_State {
); );
} }
/**
* Set the connection script data.
*
* @param array $data The script data.
*/
public static function set_connection_script_data( $data ) {
$data['connection'] = self::get_data();
return $data;
}
/** /**
* Render the initial state into a JavaScript variable. * Render the initial state into a JavaScript variable.
* *

View File

@ -199,7 +199,10 @@ class Manager {
if ( ! Constants::get_constant( 'XMLRPC_REQUEST' ) ) { if ( ! Constants::get_constant( 'XMLRPC_REQUEST' ) ) {
return false; return false;
} }
// Display errors can cause the XML to be not well formed. // Display errors can cause the XML to be not well formed.
// This only affects Jetpack XML-RPC endpoints received from WordPress.com servers.
// All other XML-RPC requests are unaffected.
@ini_set( 'display_errors', false ); // phpcs:ignore @ini_set( 'display_errors', false ); // phpcs:ignore
if ( $xmlrpc_server ) { if ( $xmlrpc_server ) {
@ -1879,10 +1882,10 @@ class Manager {
* *
* @since 2.7.6 Added optional $from and $raw parameters. * @since 2.7.6 Added optional $from and $raw parameters.
* *
* @param WP_User $user (optional) defaults to the current logged in user. * @param WP_User|null $user (optional) defaults to the current logged in user.
* @param string $redirect (optional) a redirect URL to use instead of the default. * @param string|null $redirect (optional) a redirect URL to use instead of the default.
* @param bool|string $from If not false, adds 'from=$from' param to the connect URL. * @param bool|string $from If not false, adds 'from=$from' param to the connect URL.
* @param bool $raw If true, URL will not be escaped. * @param bool $raw If true, URL will not be escaped.
* *
* @return string Connect URL. * @return string Connect URL.
*/ */
@ -2123,7 +2126,7 @@ class Manager {
( new Nonce_Handler() )->clean_all(); ( new Nonce_Handler() )->clean_all();
/** /**
* Fires when a site is disconnected. * Fires before a site is disconnected.
* *
* @since 1.36.3 * @since 1.36.3
*/ */

View File

@ -12,7 +12,7 @@ namespace Automattic\Jetpack\Connection;
*/ */
class Package_Version { class Package_Version {
const PACKAGE_VERSION = '2.8.4'; const PACKAGE_VERSION = '4.0.1';
const PACKAGE_SLUG = 'connection'; const PACKAGE_SLUG = 'connection';

View File

@ -7,6 +7,7 @@
namespace Automattic\Jetpack\Connection; namespace Automattic\Jetpack\Connection;
use Jetpack_Options;
use WP_Error; use WP_Error;
/** /**
@ -204,9 +205,12 @@ class Plugin_Storage {
// If a plugin was activated or deactivated. // If a plugin was activated or deactivated.
// self::$plugins is populated in Config::ensure_options_connection(). // self::$plugins is populated in Config::ensure_options_connection().
$number_of_plugins_differ = count( self::$plugins ) !== count( (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() ) ); $configured_plugin_keys = array_keys( self::$plugins );
$stored_plugin_keys = array_keys( (array) get_option( self::ACTIVE_PLUGINS_OPTION_NAME, array() ) );
sort( $configured_plugin_keys );
sort( $stored_plugin_keys );
if ( $number_of_plugins_differ ) { if ( $configured_plugin_keys !== $stored_plugin_keys ) {
self::update_active_plugins_option(); self::update_active_plugins_option();
} }
} }
@ -219,9 +223,14 @@ class Plugin_Storage {
public static function update_active_plugins_option() { public static function update_active_plugins_option() {
// Note: Since this option is synced to wpcom, if you change its structure, you have to update the sanitizer at wpcom side. // Note: Since this option is synced to wpcom, if you change its structure, you have to update the sanitizer at wpcom side.
update_option( self::ACTIVE_PLUGINS_OPTION_NAME, self::$plugins ); update_option( self::ACTIVE_PLUGINS_OPTION_NAME, self::$plugins );
if ( ! class_exists( 'Automattic\Jetpack\Sync\Settings' ) || ! \Automattic\Jetpack\Sync\Settings::is_sync_enabled() ) { if ( ! class_exists( 'Automattic\Jetpack\Sync\Settings' ) || ! \Automattic\Jetpack\Sync\Settings::is_sync_enabled() ) {
self::update_active_plugins_wpcom_no_sync_fallback(); self::update_active_plugins_wpcom_no_sync_fallback();
// Remove the checksum for active plugins, so it gets recalculated when sync gets activated.
$jetpack_callables_sync_checksum = Jetpack_Options::get_raw_option( 'jetpack_callables_sync_checksum' );
if ( isset( $jetpack_callables_sync_checksum['jetpack_connection_active_plugins'] ) ) {
unset( $jetpack_callables_sync_checksum['jetpack_connection_active_plugins'] );
Jetpack_Options::update_raw_option( 'jetpack_callables_sync_checksum', $jetpack_callables_sync_checksum );
}
} }
} }

View File

@ -444,7 +444,7 @@ class REST_Connector {
$connection_status = array( $connection_status = array(
'isActive' => $connection->has_connected_owner(), // TODO deprecate this. 'isActive' => $connection->has_connected_owner(), // TODO deprecate this.
'isStaging' => $status->is_staging_site(), 'isStaging' => $status->in_safe_mode(), // TODO deprecate this.
'isRegistered' => $connection->is_connected(), 'isRegistered' => $connection->is_connected(),
'isUserConnected' => $connection->is_user_connected(), 'isUserConnected' => $connection->is_user_connected(),
'hasConnectedOwner' => $connection->has_connected_owner(), 'hasConnectedOwner' => $connection->has_connected_owner(),

View File

@ -38,7 +38,7 @@ class Tracking {
/** /**
* Creates the Tracking object. * Creates the Tracking object.
* *
* @param String $product_name the slug of the product that we are tracking. * @param string $product_name the slug of the product that we are tracking.
* @param \Automattic\Jetpack\Connection\Manager $connection the connection manager object. * @param \Automattic\Jetpack\Connection\Manager $connection the connection manager object.
*/ */
public function __construct( $product_name = 'jetpack', $connection = null ) { public function __construct( $product_name = 'jetpack', $connection = null ) {
@ -252,6 +252,7 @@ class Tracking {
$blog_details = array( $blog_details = array(
'blog_lang' => isset( $properties['blog_lang'] ) ? $properties['blog_lang'] : get_bloginfo( 'language' ), 'blog_lang' => isset( $properties['blog_lang'] ) ? $properties['blog_lang'] : get_bloginfo( 'language' ),
'blog_id' => \Jetpack_Options::get_option( 'id' ),
); );
$timestamp = ( false !== $event_timestamp_millis ) ? $event_timestamp_millis : round( microtime( true ) * 1000 ); $timestamp = ( false !== $event_timestamp_millis ) ? $event_timestamp_millis : round( microtime( true ) * 1000 );

View File

@ -9,7 +9,7 @@ import './style.scss';
* The initial renderer function. * The initial renderer function.
*/ */
function render() { function render() {
if ( ! window.hasOwnProperty( 'JP_IDENTITY_CRISIS__INITIAL_STATE' ) ) { if ( ! Object.hasOwn( window, 'JP_IDENTITY_CRISIS__INITIAL_STATE' ) ) {
return; return;
} }
@ -33,6 +33,7 @@ function render() {
consumerData, consumerData,
isAdmin, isAdmin,
possibleDynamicSiteUrlDetected, possibleDynamicSiteUrlDetected,
isDevelopmentSite,
} = window.JP_IDENTITY_CRISIS__INITIAL_STATE; } = window.JP_IDENTITY_CRISIS__INITIAL_STATE;
if ( ! isSafeModeConfirmed ) { if ( ! isSafeModeConfirmed ) {
@ -46,11 +47,12 @@ function render() {
tracksUserData={ tracksUserData || {} } tracksUserData={ tracksUserData || {} }
tracksEventData={ tracksEventData } tracksEventData={ tracksEventData }
customContent={ customContent={
consumerData.hasOwnProperty( 'customContent' ) ? consumerData.customContent : {} Object.hasOwn( consumerData, 'customContent' ) ? consumerData.customContent : {}
} }
isAdmin={ isAdmin } isAdmin={ isAdmin }
logo={ consumerData.hasOwnProperty( 'logo' ) ? consumerData.logo : undefined } logo={ Object.hasOwn( consumerData, 'logo' ) ? consumerData.logo : undefined }
possibleDynamicSiteUrlDetected={ possibleDynamicSiteUrlDetected } possibleDynamicSiteUrlDetected={ possibleDynamicSiteUrlDetected }
isDevelopmentSite={ isDevelopmentSite }
/> />
); );
WPElement.createRoot( container ).render( component ); WPElement.createRoot( container ).render( component );

View File

@ -0,0 +1,13 @@
<?php
/**
* Exception class for the Identity Crisis component.
*
* @package automattic/jetpack-connection
*/
namespace Automattic\Jetpack\IdentityCrisis;
/**
* Exception class for the Identity Crisis component.
*/
class Exception extends \Exception {}

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* Identity_Crisis package. * Identity_Crisis class of the Connection package.
* *
* @package automattic/jetpack-identity-crisis * @package automattic/jetpack-connection
*/ */
namespace Automattic\Jetpack; namespace Automattic\Jetpack;
@ -18,21 +18,11 @@ use WP_Error;
/** /**
* This class will handle everything involved with fixing an Identity Crisis. * This class will handle everything involved with fixing an Identity Crisis.
* *
* @since 0.2.0 * @since automattic/jetpack-identity-crisis:0.2.0
* @since-jetpack 4.4.0 * @since-jetpack 4.4.0
* @since 2.9.0
*/ */
class Identity_Crisis { class Identity_Crisis {
/**
* Package Version
*/
const PACKAGE_VERSION = '0.20.0';
/**
* Package Slug
*/
const PACKAGE_SLUG = 'identity-crisis';
/** /**
* Persistent WPCOM blog ID that stays in the options after disconnect. * Persistent WPCOM blog ID that stays in the options after disconnect.
*/ */
@ -103,9 +93,6 @@ class Identity_Crisis {
add_filter( 'jetpack_register_request_body', array( static::class, 'register_request_body' ) ); add_filter( 'jetpack_register_request_body', array( static::class, 'register_request_body' ) );
add_action( 'jetpack_site_registered', array( static::class, 'site_registered' ) ); add_action( 'jetpack_site_registered', array( static::class, 'site_registered' ) );
// Set up package version hook.
add_filter( 'jetpack_package_versions', array( static::class, 'send_package_version_to_tracker' ) );
$urls_in_crisis = self::check_identity_crisis(); $urls_in_crisis = self::check_identity_crisis();
if ( false === $urls_in_crisis ) { if ( false === $urls_in_crisis ) {
return; return;
@ -115,19 +102,6 @@ class Identity_Crisis {
add_action( 'init', array( $this, 'wordpress_init' ) ); add_action( 'init', array( $this, 'wordpress_init' ) );
} }
/**
* Adds the package slug and version to the package version tracker's data.
*
* @param array $package_versions The package version array.
*
* @return array The package version array.
*/
public static function send_package_version_to_tracker( $package_versions ) {
$package_versions[ self::PACKAGE_SLUG ] = self::PACKAGE_VERSION;
return $package_versions;
}
/** /**
* Disconnect current connection and clear IDC options. * Disconnect current connection and clear IDC options.
*/ */
@ -193,8 +167,8 @@ class Identity_Crisis {
public function wordpress_init() { public function wordpress_init() {
if ( current_user_can( 'jetpack_disconnect' ) ) { if ( current_user_can( 'jetpack_disconnect' ) ) {
if ( if (
isset( $_GET['jetpack_idc_clear_confirmation'] ) && isset( $_GET['_wpnonce'] ) && isset( $_GET['jetpack_idc_clear_confirmation'] ) && isset( $_GET['_wpnonce'] ) &&
wp_verify_nonce( $_GET['_wpnonce'], 'jetpack_idc_clear_confirmation' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either. wp_verify_nonce( $_GET['_wpnonce'], 'jetpack_idc_clear_confirmation' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- WordPress core doesn't unslash or verify nonces either.
) { ) {
Jetpack_Options::delete_option( 'safe_mode_confirmed' ); Jetpack_Options::delete_option( 'safe_mode_confirmed' );
self::$is_safe_mode_confirmed = false; self::$is_safe_mode_confirmed = false;
@ -267,7 +241,7 @@ class Identity_Crisis {
$consumer_data = UI::get_consumer_data(); $consumer_data = UI::get_consumer_data();
$label = isset( $consumer_data['customContent']['adminBarSafeModeLabel'] ) $label = isset( $consumer_data['customContent']['adminBarSafeModeLabel'] )
? esc_html( $consumer_data['customContent']['adminBarSafeModeLabel'] ) ? esc_html( $consumer_data['customContent']['adminBarSafeModeLabel'] )
: esc_html__( 'Jetpack Safe Mode', 'jetpack-idc' ); : esc_html__( 'Jetpack Safe Mode', 'jetpack-connection' );
$title = sprintf( $title = sprintf(
'<span class="jp-idc-admin-bar">%s %s</span>', '<span class="jp-idc-admin-bar">%s %s</span>',
@ -339,10 +313,6 @@ class Identity_Crisis {
* @return bool Whether the site is in an identity crisis. * @return bool Whether the site is in an identity crisis.
*/ */
public function check_response_for_idc( $response ) { public function check_response_for_idc( $response ) {
if ( ! is_array( $response ) ) {
return false;
}
if ( is_array( $response ) && isset( $response['error_code'] ) ) { if ( is_array( $response ) && isset( $response['error_code'] ) ) {
$error_code = $response['error_code']; $error_code = $response['error_code'];
$allowed_idc_error_codes = array( $allowed_idc_error_codes = array(
@ -415,7 +385,6 @@ class Identity_Crisis {
$sync_error['wpcom_home'] === $local_options['home'] && $sync_error['wpcom_home'] === $local_options['home'] &&
$sync_error['wpcom_siteurl'] === $local_options['siteurl'] $sync_error['wpcom_siteurl'] === $local_options['siteurl']
) { ) {
$is_valid = false;
// Enable migrate_for_idc so that sync actions are accepted. // Enable migrate_for_idc so that sync actions are accepted.
Jetpack_Options::update_option( 'migrate_for_idc', true ); Jetpack_Options::update_option( 'migrate_for_idc', true );
} elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) { } elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) {
@ -479,7 +448,7 @@ class Identity_Crisis {
'cannot_parse_url', 'cannot_parse_url',
sprintf( sprintf(
/* translators: %s: URL to parse. */ /* translators: %s: URL to parse. */
esc_html__( 'Cannot parse URL %s', 'jetpack-idc' ), esc_html__( 'Cannot parse URL %s', 'jetpack-connection' ),
$url $url
) )
); );
@ -605,7 +574,7 @@ class Identity_Crisis {
! isset( $data['home'] ) || ! isset( $data['home'] ) ||
! isset( $data['wpcom_siteurl'] ) || ! isset( $data['wpcom_siteurl'] ) ||
! isset( $data['siteurl'] ) ! isset( $data['siteurl'] )
) { ) {
// The jetpack_sync_error_idc option is missing a key. // The jetpack_sync_error_idc option is missing a key.
return false; return false;
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* Identity_Crisis package. * Identity_Crisis REST endpoints of the Connection package.
* *
* @package automattic/jetpack-identity-crisis * @package automattic/jetpack-connection
*/ */
namespace Automattic\Jetpack\IdentityCrisis; namespace Automattic\Jetpack\IdentityCrisis;
@ -17,7 +17,8 @@ use WP_REST_Server;
/** /**
* This class will handle Identity Crisis Endpoints * This class will handle Identity Crisis Endpoints
* *
* @since 0.2.0 * @since automattic/jetpack-identity-crisis:0.2.0
* @since 2.9.0
*/ */
class REST_Endpoints { class REST_Endpoints {
@ -58,7 +59,7 @@ class REST_Endpoints {
'permission_callback' => __CLASS__ . '::identity_crisis_mitigation_permission_check', 'permission_callback' => __CLASS__ . '::identity_crisis_mitigation_permission_check',
'args' => array( 'args' => array(
'redirect_uri' => array( 'redirect_uri' => array(
'description' => __( 'URI of the admin page where the user should be redirected after connection flow', 'jetpack-idc' ), 'description' => __( 'URI of the admin page where the user should be redirected after connection flow', 'jetpack-connection' ),
'type' => 'string', 'type' => 'string',
), ),
), ),
@ -97,7 +98,7 @@ class REST_Endpoints {
'permission_callback' => array( static::class, 'compare_url_secret_permission_check' ), 'permission_callback' => array( static::class, 'compare_url_secret_permission_check' ),
'args' => array( 'args' => array(
'secret' => array( 'secret' => array(
'description' => __( 'URL secret to compare to the ones stored in the database.', 'jetpack-idc' ), 'description' => __( 'URL secret to compare to the ones stored in the database.', 'jetpack-connection' ),
'type' => 'string', 'type' => 'string',
'required' => true, 'required' => true,
), ),
@ -126,7 +127,7 @@ class REST_Endpoints {
return new WP_Error( return new WP_Error(
'error_setting_jetpack_safe_mode', 'error_setting_jetpack_safe_mode',
esc_html__( 'Could not confirm safe mode.', 'jetpack-idc' ), esc_html__( 'Could not confirm safe mode.', 'jetpack-connection' ),
array( 'status' => 500 ) array( 'status' => 500 )
); );
} }
@ -143,7 +144,7 @@ class REST_Endpoints {
if ( Jetpack_Options::get_option( 'sync_error_idc' ) && ! Jetpack_Options::delete_option( 'sync_error_idc' ) ) { if ( Jetpack_Options::get_option( 'sync_error_idc' ) && ! Jetpack_Options::delete_option( 'sync_error_idc' ) ) {
return new WP_Error( return new WP_Error(
'error_deleting_sync_error_idc', 'error_deleting_sync_error_idc',
esc_html__( 'Could not delete sync error option.', 'jetpack-idc' ), esc_html__( 'Could not delete sync error option.', 'jetpack-connection' ),
array( 'status' => 500 ) array( 'status' => 500 )
); );
} }
@ -157,7 +158,7 @@ class REST_Endpoints {
} }
return new WP_Error( return new WP_Error(
'error_setting_jetpack_migrate', 'error_setting_jetpack_migrate',
esc_html__( 'Could not confirm migration.', 'jetpack-idc' ), esc_html__( 'Could not confirm migration.', 'jetpack-connection' ),
array( 'status' => 500 ) array( 'status' => 500 )
); );
} }
@ -220,7 +221,7 @@ class REST_Endpoints {
$error_msg = esc_html__( $error_msg = esc_html__(
'You do not have the correct user permissions to perform this action. 'You do not have the correct user permissions to perform this action.
Please contact your site admin if you think this is a mistake.', Please contact your site admin if you think this is a mistake.',
'jetpack-idc' 'jetpack-connection'
); );
return new WP_Error( 'invalid_user_permission_identity_crisis', $error_msg, array( 'status' => rest_authorization_required_code() ) ); return new WP_Error( 'invalid_user_permission_identity_crisis', $error_msg, array( 'status' => rest_authorization_required_code() ) );
@ -249,7 +250,7 @@ class REST_Endpoints {
$secret = new URL_Secret(); $secret = new URL_Secret();
if ( ! $secret->exists() ) { if ( ! $secret->exists() ) {
return new WP_Error( 'missing_url_secret', esc_html__( 'URL secret does not exist.', 'jetpack-idc' ) ); return new WP_Error( 'missing_url_secret', esc_html__( 'URL secret does not exist.', 'jetpack-connection' ) );
} }
return rest_ensure_response( return rest_ensure_response(
@ -298,7 +299,7 @@ class REST_Endpoints {
? true ? true
: new WP_Error( : new WP_Error(
'invalid_user_permission_identity_crisis', 'invalid_user_permission_identity_crisis',
esc_html__( 'You do not have the correct user permissions to perform this action.', 'jetpack-idc' ), esc_html__( 'You do not have the correct user permissions to perform this action.', 'jetpack-connection' ),
array( 'status' => rest_authorization_required_code() ) array( 'status' => rest_authorization_required_code() )
); );
} }
@ -313,7 +314,7 @@ class REST_Endpoints {
return ( new Connection_Manager() )->is_connected() return ( new Connection_Manager() )->is_connected()
? new WP_Error( ? new WP_Error(
'invalid_connection_status', 'invalid_connection_status',
esc_html__( 'The endpoint is not available on connected sites.', 'jetpack-idc' ), esc_html__( 'The endpoint is not available on connected sites.', 'jetpack-connection' ),
array( 'status' => 403 ) array( 'status' => 403 )
) )
: true; : true;

View File

@ -1,14 +1,15 @@
<?php <?php
/** /**
* Identity_Crisis package. * Identity_Crisis UI class of the Connection package.
* *
* @package automattic/jetpack-identity-crisis * @package automattic/jetpack-connection
*/ */
namespace Automattic\Jetpack\IdentityCrisis; namespace Automattic\Jetpack\IdentityCrisis;
use Automattic\Jetpack\Assets; use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Identity_Crisis; use Automattic\Jetpack\Identity_Crisis;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host; use Automattic\Jetpack\Status\Host;
use Automattic\Jetpack\Tracking; use Automattic\Jetpack\Tracking;
use Jetpack_Options; use Jetpack_Options;
@ -59,11 +60,11 @@ class UI {
if ( is_admin() ) { if ( is_admin() ) {
Assets::register_script( Assets::register_script(
'jp_identity_crisis_banner', 'jp_identity_crisis_banner',
'../build/index.js', '../../dist/identity-crisis.js',
__FILE__, __FILE__,
array( array(
'in_footer' => true, 'in_footer' => true,
'textdomain' => 'jetpack-idc', 'textdomain' => 'jetpack-connection',
) )
); );
Assets::enqueue_script( 'jp_identity_crisis_banner' ); Assets::enqueue_script( 'jp_identity_crisis_banner' );
@ -101,6 +102,7 @@ class UI {
$current_screen = get_current_screen(); $current_screen = get_current_screen();
$is_admin = current_user_can( 'jetpack_disconnect' ); $is_admin = current_user_can( 'jetpack_disconnect' );
$possible_dynamic_site_url_detected = (bool) Identity_Crisis::detect_possible_dynamic_site_url(); $possible_dynamic_site_url_detected = (bool) Identity_Crisis::detect_possible_dynamic_site_url();
$is_development_site = (bool) Status::is_development_site();
return array( return array(
'WP_API_root' => esc_url_raw( rest_url() ), 'WP_API_root' => esc_url_raw( rest_url() ),
@ -119,6 +121,7 @@ class UI {
'consumerData' => static::get_consumer_data(), 'consumerData' => static::get_consumer_data(),
'isAdmin' => $is_admin, 'isAdmin' => $is_admin,
'possibleDynamicSiteUrlDetected' => $possible_dynamic_site_url_detected, 'possibleDynamicSiteUrlDetected' => $possible_dynamic_site_url_detected,
'isDevelopmentSite' => $is_development_site,
/** /**
* Use the filter to provide custom HTML elecontainer ID. * Use the filter to provide custom HTML elecontainer ID.

View File

@ -2,7 +2,7 @@
/** /**
* IDC URL secret functionality. * IDC URL secret functionality.
* *
* @package automattic/jetpack-identity-crisis * @package automattic/jetpack-connection
*/ */
namespace Automattic\Jetpack\IdentityCrisis; namespace Automattic\Jetpack\IdentityCrisis;
@ -83,13 +83,13 @@ class URL_Secret {
public function create() { public function create() {
$secret_data = array( $secret_data = array(
'secret' => $this->generate_secret(), 'secret' => $this->generate_secret(),
'expires_at' => time() + static::LIFESPAN, 'expires_at' => strval( time() + static::LIFESPAN ),
); );
$result = Jetpack_Options::update_option( static::OPTION_KEY, $secret_data ); $result = Jetpack_Options::update_option( static::OPTION_KEY, $secret_data );
if ( ! $result ) { if ( ! $result ) {
throw new Exception( esc_html__( 'Unable to save new URL secret', 'jetpack-idc' ) ); throw new Exception( esc_html__( 'Unable to save new URL secret', 'jetpack-connection' ) );
} }
$this->secret = $secret_data['secret']; $this->secret = $secret_data['secret'];
@ -138,22 +138,22 @@ class URL_Secret {
* Generate secret for response. * Generate secret for response.
* *
* @param string $flow used to tell which flow generated the exception. * @param string $flow used to tell which flow generated the exception.
* @return string * @return string|null
*/ */
public static function create_secret( $flow = 'generating_secret_failed' ) { public static function create_secret( $flow = 'generating_secret_failed' ) {
$secret = null; $secret_value = null;
try { try {
$secret = new self(); $secret = new self();
$secret->create(); $secret->create();
if ( $secret->exists() ) { if ( $secret->exists() ) {
$secret = $secret->get_secret(); $secret_value = $secret->get_secret();
} }
} catch ( Exception $e ) { } catch ( Exception $e ) {
// Track the error and proceed. // Track the error and proceed.
( new Tracking() )->record_user_event( $flow, array( 'current_url' => Urls::site_url() ) ); ( new Tracking() )->record_user_event( $flow, array( 'current_url' => Urls::site_url() ) );
} }
return $secret; return $secret_value;
} }
} }

View File

@ -214,12 +214,14 @@ class Notices {
* Error message that is displayed when the current site is in an identity crisis and SSO can not be used. * Error message that is displayed when the current site is in an identity crisis and SSO can not be used.
* *
* @since jetpack-4.4.0 * @since jetpack-4.4.0
* @deprecated since 2.10.0
* *
* @param string $message Error message. * @param string $message Error message.
* *
* @return string * @return string
*/ */
public static function sso_not_allowed_in_staging( $message ) { public static function sso_not_allowed_in_staging( $message ) {
_deprecated_function( __FUNCTION__, '2.10.0', 'sso_not_allowed_in_safe_mode' );
$error = __( $error = __(
'Logging in with WordPress.com is disabled for sites that are in staging mode.', 'Logging in with WordPress.com is disabled for sites that are in staging mode.',
'jetpack-connection' 'jetpack-connection'
@ -234,7 +236,36 @@ class Notices {
* *
* @param string $error Error text. * @param string $error Error text.
*/ */
$error = apply_filters( 'jetpack_sso_disallowed_staging_notice', $error ); $error = apply_filters_deprecated( 'jetpack_sso_disallowed_staging_notice', array( $error ), '2.9.1', 'jetpack_sso_disallowed_safe_mode_notice' );
$message .= sprintf( '<p class="message">%s</p>', esc_html( $error ) );
return $message;
}
/**
* Error message that is displayed when the current site is in an identity crisis and SSO can not be used.
*
* @since 2.10.0
*
* @param string $message Error message.
*
* @return string
*/
public static function sso_not_allowed_in_safe_mode( $message ) {
$error = __(
'Logging in with WordPress.com is disabled for sites that are in safe mode.',
'jetpack-connection'
);
/**
* Filters the disallowed notice for sites in safe mode attempting SSO.
*
* @module sso
*
* @since 2.10.0
*
* @param string $error Error text.
*/
$error = apply_filters( 'jetpack_sso_disallowed_safe_mode_notice', $error );
$message .= sprintf( '<p class="message">%s</p>', esc_html( $error ) ); $message .= sprintf( '<p class="message">%s</p>', esc_html( $error ) );
return $message; return $message;
} }

View File

@ -268,7 +268,7 @@ class SSO {
// Always add the jetpack-sso class so that we can add SSO specific styling even when the SSO form isn't being displayed. // Always add the jetpack-sso class so that we can add SSO specific styling even when the SSO form isn't being displayed.
$classes[] = 'jetpack-sso'; $classes[] = 'jetpack-sso';
if ( ! ( new Status() )->is_staging_site() ) { if ( ! ( new Status() )->in_safe_mode() ) {
/** /**
* Should we show the SSO login form? * Should we show the SSO login form?
* *
@ -446,13 +446,6 @@ class SSO {
return $wants_to_login; return $wants_to_login;
} }
/**
* Checks to determine if the user has indicated they want to use the wp-admin interface.
*/
private function use_wp_admin_interface() {
return 'wp-admin' === get_option( 'wpcom_admin_interface' );
}
/** /**
* Initialization for a SSO request. * Initialization for a SSO request.
*/ */
@ -488,8 +481,8 @@ class SSO {
if ( isset( $_GET['result'] ) && isset( $_GET['user_id'] ) && isset( $_GET['sso_nonce'] ) && 'success' === $_GET['result'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['result'] ) && isset( $_GET['user_id'] ) && isset( $_GET['sso_nonce'] ) && 'success' === $_GET['result'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$this->handle_login(); $this->handle_login();
$this->display_sso_login_form(); $this->display_sso_login_form();
} elseif ( ( new Status() )->is_staging_site() ) { } elseif ( ( new Status() )->in_safe_mode() ) {
add_filter( 'login_message', array( Notices::class, 'sso_not_allowed_in_staging' ) ); add_filter( 'login_message', array( Notices::class, 'sso_not_allowed_in_safe_mode' ) );
} else { } else {
// Is it wiser to just use wp_redirect than do this runaround to wp_safe_redirect? // Is it wiser to just use wp_redirect than do this runaround to wp_safe_redirect?
add_filter( 'allowed_redirect_hosts', array( Helpers::class, 'allowed_redirect_hosts' ) ); add_filter( 'allowed_redirect_hosts', array( Helpers::class, 'allowed_redirect_hosts' ) );
@ -510,7 +503,7 @@ class SSO {
* to the WordPress.com login page AND that the request to wp-login.php * to the WordPress.com login page AND that the request to wp-login.php
* is not something other than login (Like logout!) * is not something other than login (Like logout!)
*/ */
if ( ! $this->use_wp_admin_interface() && Helpers::bypass_login_forward_wpcom() && $this->wants_to_login() ) { if ( Helpers::bypass_login_forward_wpcom() && $this->wants_to_login() ) {
add_filter( 'allowed_redirect_hosts', array( Helpers::class, 'allowed_redirect_hosts' ) ); add_filter( 'allowed_redirect_hosts', array( Helpers::class, 'allowed_redirect_hosts' ) );
$reauth = ! empty( $_GET['force_reauth'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $reauth = ! empty( $_GET['force_reauth'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$sso_url = $this->get_sso_url_or_die( $reauth ); $sso_url = $this->get_sso_url_or_die( $reauth );
@ -531,8 +524,8 @@ class SSO {
add_filter( 'login_body_class', array( $this, 'login_body_class' ) ); add_filter( 'login_body_class', array( $this, 'login_body_class' ) );
add_action( 'login_head', array( $this, 'print_inline_admin_css' ) ); add_action( 'login_head', array( $this, 'print_inline_admin_css' ) );
if ( ( new Status() )->is_staging_site() ) { if ( ( new Status() )->in_safe_mode() ) {
add_filter( 'login_message', array( Notices::class, 'sso_not_allowed_in_staging' ) ); add_filter( 'login_message', array( Notices::class, 'sso_not_allowed_in_safe_mode' ) );
return; return;
} }

View File

@ -57,7 +57,7 @@ class User_Admin {
add_action( 'delete_user_form', array( $this, 'render_invitations_notices_for_deleted_users' ) ); add_action( 'delete_user_form', array( $this, 'render_invitations_notices_for_deleted_users' ) );
add_action( 'delete_user', array( $this, 'revoke_user_invite' ) ); add_action( 'delete_user', array( $this, 'revoke_user_invite' ) );
add_filter( 'manage_users_columns', array( $this, 'jetpack_user_connected_th' ) ); add_filter( 'manage_users_columns', array( $this, 'jetpack_user_connected_th' ) );
add_action( 'manage_users_custom_column', array( $this, 'jetpack_show_connection_status' ), 10, 3 ); add_filter( 'manage_users_custom_column', array( $this, 'jetpack_show_connection_status' ), 10, 3 );
add_action( 'user_row_actions', array( $this, 'jetpack_user_table_row_actions' ), 10, 2 ); add_action( 'user_row_actions', array( $this, 'jetpack_user_table_row_actions' ), 10, 2 );
add_action( 'admin_notices', array( $this, 'handle_invitation_results' ) ); add_action( 'admin_notices', array( $this, 'handle_invitation_results' ) );
add_action( 'admin_post_jetpack_invite_user_to_wpcom', array( $this, 'invite_user_to_wpcom' ) ); add_action( 'admin_post_jetpack_invite_user_to_wpcom', array( $this, 'invite_user_to_wpcom' ) );
@ -1203,7 +1203,7 @@ class User_Admin {
'<span tabindex="0" role="tooltip" aria-label="%4$s: %3$s" class="jetpack-sso-invitation-tooltip-icon sso-disconnected-user"> '<span tabindex="0" role="tooltip" aria-label="%4$s: %3$s" class="jetpack-sso-invitation-tooltip-icon sso-disconnected-user">
<a href="%1$s" class="jetpack-sso-invitation sso-disconnected-user">%2$s</a> <a href="%1$s" class="jetpack-sso-invitation sso-disconnected-user">%2$s</a>
<span class="sso-disconnected-user-icon dashicons dashicons-warning"> <span class="sso-disconnected-user-icon dashicons dashicons-warning">
<span class="jetpack-sso-invitation-tooltip jetpack-sso-td-tooltip" tabindex="0">%3$s</span> <span class="jetpack-sso-invitation-tooltip jetpack-sso-td-tooltip">%3$s</span>
</span> </span>
</span>', </span>',
add_query_arg( add_query_arg(
@ -1221,6 +1221,7 @@ class User_Admin {
return $connection_html; return $connection_html;
} }
} }
return $val;
} }
/** /**

View File

@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.0.4] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
## [2.0.3] - 2024-05-29
### Fixed
- Fix phpdoc type on `Constants::set_constant()` value parameter. [#37606]
## [2.0.2] - 2024-04-30 ## [2.0.2] - 2024-04-30
### Changed ### Changed
- Internal updates. - Internal updates.
@ -166,6 +174,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Packages: Finish the constants package - Packages: Finish the constants package
[2.0.4]: https://github.com/Automattic/jetpack-constants/compare/v2.0.3...v2.0.4
[2.0.3]: https://github.com/Automattic/jetpack-constants/compare/v2.0.2...v2.0.3
[2.0.2]: https://github.com/Automattic/jetpack-constants/compare/v2.0.1...v2.0.2 [2.0.2]: https://github.com/Automattic/jetpack-constants/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/Automattic/jetpack-constants/compare/v2.0.0...v2.0.1 [2.0.1]: https://github.com/Automattic/jetpack-constants/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/Automattic/jetpack-constants/compare/v1.6.23...v2.0.0 [2.0.0]: https://github.com/Automattic/jetpack-constants/compare/v1.6.23...v2.0.0

View File

@ -8,8 +8,8 @@
}, },
"require-dev": { "require-dev": {
"brain/monkey": "2.6.1", "brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.2.2" "automattic/jetpack-changelogger": "^4.2.6"
}, },
"suggest": { "suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."

View File

@ -91,8 +91,8 @@ class Constants {
/** /**
* Sets the value of the "constant" within constants Manager. * Sets the value of the "constant" within constants Manager.
* *
* @param string $name The name of the constant. * @param string $name The name of the constant.
* @param string $value The value of the constant. * @param int|float|string|bool|array|null $value The value of the constant.
*/ */
public static function set_constant( $name, $value ) { public static function set_constant( $name, $value ) {
self::$set_constants[ $name ] = $value; self::$set_constants[ $name ] = $value;

View File

@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.1.4] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
## [2.1.3] - 2024-04-08 ## [2.1.3] - 2024-04-08
### Added ### Added
- Added functionality for extracting the browser and desktop platform from a user agent. [#36568] - Added functionality for extracting the browser and desktop platform from a user agent. [#36568]
@ -196,6 +200,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Moving jetpack_is_mobile into a package - Moving jetpack_is_mobile into a package
[2.1.4]: https://github.com/Automattic/jetpack-device-detection/compare/v2.1.3...v2.1.4
[2.1.3]: https://github.com/Automattic/jetpack-device-detection/compare/v2.1.2...v2.1.3 [2.1.3]: https://github.com/Automattic/jetpack-device-detection/compare/v2.1.2...v2.1.3
[2.1.2]: https://github.com/Automattic/jetpack-device-detection/compare/v2.1.1...v2.1.2 [2.1.2]: https://github.com/Automattic/jetpack-device-detection/compare/v2.1.1...v2.1.2
[2.1.1]: https://github.com/Automattic/jetpack-device-detection/compare/v2.1.0...v2.1.1 [2.1.1]: https://github.com/Automattic/jetpack-device-detection/compare/v2.1.0...v2.1.1

View File

@ -7,8 +7,8 @@
"php": ">=7.0" "php": ">=7.0"
}, },
"require-dev": { "require-dev": {
"yoast/phpunit-polyfills": "1.1.0", "yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.1.2" "automattic/jetpack-changelogger": "^4.2.6"
}, },
"suggest": { "suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."

View File

@ -0,0 +1,52 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.1.7] - 2024-09-05
### Changed
- Update dependencies.
## [0.1.6] - 2024-09-05
### Changed
- Updated package dependencies. [#39176]
## [0.1.5] - 2024-08-29
### Changed
- Updated package dependencies. [#39111]
## [0.1.4] - 2024-08-26
### Changed
- Updated package dependencies. [#39004]
## [0.1.3] - 2024-08-21
### Changed
- Internal updates.
## [0.1.2] - 2024-08-15
### Changed
- Updated package dependencies. [#38662]
## [0.1.1] - 2024-08-01
### Changed
- Internal updates.
## 0.1.0 - 2024-07-29
### Added
- Adds a new component to fetch experiments specifically for authenticated users [#37999]
- Initial version. [#37910]
- Introduce the both the backend layer and frontend components for the ExPlat package. [#37958]
### Changed
- ExPlat: add condition to prevent fetching the experiment assignment if there's not anon id (meaning that Tracks is likely disabled) [#38327]
- Updated package dependencies. [#38132]
[0.1.7]: https://github.com/Automattic/jetpack-explat/compare/v0.1.6...v0.1.7
[0.1.6]: https://github.com/Automattic/jetpack-explat/compare/v0.1.5...v0.1.6
[0.1.5]: https://github.com/Automattic/jetpack-explat/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/Automattic/jetpack-explat/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/Automattic/jetpack-explat/compare/v0.1.2...v0.1.3
[0.1.2]: https://github.com/Automattic/jetpack-explat/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/Automattic/jetpack-explat/compare/v0.1.0...v0.1.1

View File

@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-polyfill', 'wp-url'), 'version' => '94dc255b5871f56d5cf3');

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,6 @@
/*!
* cookie
* Copyright(c) 2012-2014 Roman Shtylman
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/

View File

@ -0,0 +1,63 @@
{
"name": "automattic/jetpack-explat",
"description": "A package for running A/B tests on the Experimentation Platform (ExPlat) in the plugin.",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-connection": "^4.0.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "^1.1.1",
"automattic/jetpack-changelogger": "^4.2.6"
},
"autoload": {
"classmap": [
"src/"
]
},
"scripts": {
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-php": [
"@composer phpunit"
],
"test-js": [
"echo 'Run `pnpm run test` when ready'"
],
"test-js-watch": [
"Composer\\Config::disableProcessTimeout",
"pnpm run test --watch"
],
"build-development": [
"pnpm run build"
],
"build-production": [
"NODE_ENV=production pnpm run build"
],
"watch": [
"Composer\\Config::disableProcessTimeout",
"pnpm run watch"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"autotagger": true,
"branch-alias": {
"dev-trunk": "0.1.x-dev"
},
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-explat/compare/v${old}...v${new}"
},
"mirror-repo": "Automattic/jetpack-explat",
"textdomain": "jetpack-explat",
"version-constants": {
"::PACKAGE_VERSION": "src/class-explat.php"
}
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
}
}

View File

@ -0,0 +1,9 @@
export declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: 'development' | 'production' | 'test';
}
}
}
export {};

View File

@ -0,0 +1,44 @@
<?php
/**
* Package description here
*
* @package automattic/jetpack-explat
*/
namespace Automattic\Jetpack;
use Automattic\Jetpack\Connection\Rest_Authentication;
use Automattic\Jetpack\ExPlat\REST_Controller;
/**
* Class description.
*/
class ExPlat {
/**
* ExPlat package version
*
* @var string
*/
const PACKAGE_VERSION = '0.1.7';
/**
* Initializer.
* Used to configure the ExPlat package
*
* @return void
*/
public static function init() {
if ( did_action( 'jetpack_explat_initialized' ) ) {
return;
}
// Set up the REST authentication hooks.
Rest_Authentication::init();
add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) );
// Runs right after the Jetpack ExPlat package is initialized.
do_action( 'jetpack_explat_initialized' );
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* The ExPlat Rest Controller class.
* Registers the REST routes for ExPlat backend
*
* @package automattic/jetpack-explat
*/
namespace Automattic\Jetpack\ExPlat;
use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Connection\Manager as Jetpack_Connection;
use WP_Error;
use WP_REST_Server;
/**
* Registers general REST routes for ExPlat.
*/
class REST_Controller {
/**
* Namespace for the REST API.
*
* @var string
*/
public static $namespace = 'jetpack/v4/explat';
/**
* Current version of the ExPlat API and components
*
* @var string
*/
const EXPLAT_API_VERSION = '0.1.0';
/**
* Base API URI for WordPress.com
*
* @var string
*/
const WPCOM_API_BASE_URL = 'https://public-api.wordpress.com/wpcom/v2';
/**
* Registers the REST routes.
*
* @access public
* @static
*/
public function register_rest_routes() {
register_rest_route(
static::$namespace,
'assignments',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_assignments' ),
'permission_callback' => '__return_true',
'args' => array(
'experiment_name' => array(
'type' => 'string',
),
'anon_id' => array(
'type' => 'string',
),
'as_connected_user' => array(
'type' => 'boolean',
),
),
)
);
}
/**
* Get the assignments for a given experiment and anon_id
*
* @param WP_REST_Request $request The REST request object.
* @return WP_REST_Response
*/
public function get_assignments( $request ) {
$response = null;
$is_user_connected = ( new Jetpack_Connection() )->is_user_connected();
$request_path = '/experiments/' . self::EXPLAT_API_VERSION . '/assignments/jetpack';
$args = array(
'experiment_name' => $request['experiment_name'],
'anon_id' => $request['anon_id'],
);
if ( $request['as_connected_user'] && $is_user_connected ) {
$response = Client::wpcom_json_api_request_as_user(
add_query_arg( $args, $request_path ),
'v2'
);
} else {
$response = wp_remote_get(
add_query_arg( $args, self::WPCOM_API_BASE_URL . $request_path )
);
}
if ( is_wp_error( $response ) ) {
return new WP_Error(
'wp_error_fetching_assignment',
$response->get_error_message(),
array( 'status' => 500 )
);
}
$response_code = wp_remote_retrieve_response_code( $response );
if ( 200 !== $response_code ) {
return new WP_Error(
'http_error_fetching_assignment',
wp_remote_retrieve_response_message( $response ),
array( 'status' => $response_code )
);
}
return rest_ensure_response(
json_decode( wp_remote_retrieve_body( $response ), true )
);
}
}

View File

@ -0,0 +1,61 @@
/**
* External dependencies
*/
import cookie from 'cookie';
let initializeAnonIdPromise: Promise< string | null > | null = null;
const anonIdPollingIntervalMilliseconds = 50;
const anonIdPollingIntervalMaxAttempts = 100; // 50 * 100 = 5000 = 5 seconds
/**
* Gather w.js anonymous cookie, tk_ai
*
* @return {?string} The anonymous cookie value, or null if it doesn't exist
*/
export const readAnonCookie = (): string | null => {
return cookie.parse( document.cookie ).tk_ai || null;
};
/**
* Initializes the anonId:
* - Polls for AnonId receival
* - Should only be called once at startup
* - Happens to be safe to call multiple times if it is necessary to reset the anonId - something like this was necessary for testing.
*
* This purely for boot-time initialization, in usual circumstances it will be retrieved within 100-300ms, it happens in parallel booting
* so should only delay experiment loading that much for boot-time experiments. In some circumstances such as a very slow connection this
* can take a lot longer.
*
* The state of initializeAnonIdPromise should be used rather than the return of this function.
* The return is only avaliable to make this easier to test.
*
* Throws on error.
*
* @return {Promise<string | null>} The anonymous cookie value, or null if it doesn't exist
*/
export const initializeAnonId = async (): Promise< string | null > => {
let attempt = 0;
initializeAnonIdPromise = new Promise( res => {
const poll = () => {
const anonId = readAnonCookie();
if ( typeof anonId === 'string' && anonId !== '' ) {
res( anonId );
return;
}
if ( anonIdPollingIntervalMaxAttempts - 1 <= attempt ) {
res( null );
return;
}
attempt += 1;
setTimeout( poll, anonIdPollingIntervalMilliseconds );
};
poll();
} );
return initializeAnonIdPromise;
};
export const getAnonId = async (): Promise< string | null > => {
return await initializeAnonIdPromise;
};

View File

@ -0,0 +1,29 @@
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
const fetchExperimentAssignment =
( asConnectedUser = false ) =>
async ( {
experimentName,
anonId,
}: {
experimentName: string;
anonId: string | null;
} ): Promise< unknown > => {
if ( ! anonId ) {
throw new Error( `Tracking is disabled, can't fetch experimentAssignment` );
}
const params = {
experiment_name: experimentName,
anon_id: anonId ?? undefined,
as_connected_user: asConnectedUser,
};
const assignmentsRequestUrl = addQueryArgs( 'jetpack/v4/explat/assignments', params );
return await apiFetch( { path: assignmentsRequestUrl } );
};
export const fetchExperimentAssignmentAnonymously = fetchExperimentAssignment( false );
export const fetchExperimentAssignmentWithAuth = fetchExperimentAssignment( true );

View File

@ -0,0 +1,39 @@
/**
* Internal dependencies
*/
import { isDevelopmentMode } from './utils';
export const logError = ( error: Record< string, string > & { message: string } ): void => {
const onLoggingError = ( e: unknown ) => {
if ( isDevelopmentMode ) {
console.error( '[ExPlat] Unable to send error to server:', e ); // eslint-disable-line no-console
}
};
try {
const { message, ...properties } = error;
const logStashError = {
message,
properties: {
...properties,
context: 'explat',
explat_client: 'jetpack',
},
};
if ( isDevelopmentMode ) {
console.error( '[ExPlat] ', error.message, error ); // eslint-disable-line no-console
} else {
const body = new window.FormData();
body.append( 'error', JSON.stringify( logStashError ) );
window
.fetch( 'https://public-api.wordpress.com/rest/v1.1/js-error', {
method: 'POST',
body,
} )
.catch( onLoggingError );
}
} catch ( e ) {
onLoggingError( e );
}
};

View File

@ -0,0 +1,51 @@
/**
* External dependencies
*/
import { createExPlatClient } from '@automattic/explat-client';
import createExPlatClientReactHelpers from '@automattic/explat-client-react-helpers';
/**
* Internal dependencies
*/
import { getAnonId, initializeAnonId } from './anon';
import {
fetchExperimentAssignmentAnonymously,
fetchExperimentAssignmentWithAuth,
} from './assignment';
import { logError } from './error';
import { isDevelopmentMode } from './utils';
export const initializeExPlat = (): void => {
initializeAnonId().catch( e => logError( { message: e.message } ) );
};
initializeExPlat();
const exPlatClient = createExPlatClient( {
fetchExperimentAssignment: fetchExperimentAssignmentAnonymously,
getAnonId,
logError,
isDevelopmentMode,
} );
export const { loadExperimentAssignment, dangerouslyGetExperimentAssignment } = exPlatClient;
export const { useExperiment, Experiment, ProvideExperimentData } =
createExPlatClientReactHelpers( exPlatClient );
const exPlatClientWithAuth = createExPlatClient( {
fetchExperimentAssignment: fetchExperimentAssignmentWithAuth,
getAnonId,
logError,
isDevelopmentMode,
} );
export const {
loadExperimentAssignment: loadExperimentAssignmentWithAuth,
dangerouslyGetExperimentAssignment: dangerouslyGetExperimentAssignmentWithAuth,
} = exPlatClientWithAuth;
export const {
useExperiment: useExperimentWithAuth,
Experiment: ExperimentWithAuth,
ProvideExperimentData: ProvideExperimentDataWithAuth,
} = createExPlatClientReactHelpers( exPlatClientWithAuth );

View File

@ -0,0 +1,4 @@
/**
* Boolean determining if environment is development.
*/
export const isDevelopmentMode = process.env.NODE_ENV === 'development';

Some files were not shown because too many files have changed in this diff Show More