updated plugin `Jetpack Protect` version 1.3.0

This commit is contained in:
KawaiiPunk 2023-03-17 22:34:13 +00:00 committed by Gitium
parent 19e086d1c4
commit 1e9ac45ec6
183 changed files with 4388 additions and 2345 deletions

View File

@ -5,10 +5,28 @@ 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).
## 1.2.1-alpha - unreleased
## 1.3.1-alpha - unreleased
This is an alpha version! The changes listed here are not final.
## 1.3.0 - 2023-03-13
### Added
- Add ability to toggle automatic and manual firewall rules independently. [#27726]
- Add improved messaging for currently enabled firewall features. [#27845]
- Disable Jetpack Firewall on unsupported environments. [#27939]
- Add link to pricing page for getting started with an existing plan or license key. [#27745]
### Changed
- Updated package dependencies. [#29297]
- Update to React 18. [#28710]
- Use `flex-start`/`flex-end` instead of `start`/`end` for better browser compatibility. [#28530]
### Fixed
- Fix connection button loading indicators. [#28514]
- Fix Protect status report caching. [#28766]
- Remove unnecessary full path from example in UI. [#29037]
- Other assorted fixes for minor bugs and grammar. [#27846] [#28091] [#28397] [#28273]
## 1.2.0 - 2023-01-16
### Added
- Add web application firewall (WAF) features [#27528]

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'e640beb5bef26d89962f');
<?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' => 'b9bb051878ccf8c991dd');

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

@ -5,24 +5,24 @@
"license": "GPL-2.0-or-later",
"require": {
"ext-json": "*",
"automattic/jetpack-assets": "^1.17.28",
"automattic/jetpack-admin-ui": "^0.2.14",
"automattic/jetpack-autoloader": "^2.11.13",
"automattic/jetpack-composer-plugin": "^1.1.7",
"automattic/jetpack-config": "^1.11.1",
"automattic/jetpack-identity-crisis": "^0.8.33",
"automattic/jetpack-my-jetpack": "^2.6.0",
"automattic/jetpack-plugins-installer": "^0.2.2",
"automattic/jetpack-sync": "^1.44.1",
"automattic/jetpack-transport-helper": "^0.1.2",
"automattic/jetpack-plans": "^0.2.8",
"automattic/jetpack-waf": "^0.8.1",
"automattic/jetpack-status": "^1.15.2"
"automattic/jetpack-assets": "^1.17.33",
"automattic/jetpack-admin-ui": "^0.2.17",
"automattic/jetpack-autoloader": "^2.11.16",
"automattic/jetpack-composer-plugin": "^1.1.10",
"automattic/jetpack-config": "^1.14.0",
"automattic/jetpack-identity-crisis": "^0.8.39",
"automattic/jetpack-my-jetpack": "^2.7.13",
"automattic/jetpack-plugins-installer": "^0.2.3",
"automattic/jetpack-sync": "^1.47.2",
"automattic/jetpack-transport-helper": "^0.1.4",
"automattic/jetpack-plans": "^0.2.10",
"automattic/jetpack-waf": "^0.10.1",
"automattic/jetpack-status": "^1.16.2"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2",
"automattic/wordbless": "0.4.0"
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/wordbless": "0.4.1"
},
"autoload": {
"classmap": [
@ -33,9 +33,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
],
@ -74,6 +71,6 @@
"automattic/jetpack-autoloader": true,
"automattic/jetpack-composer-plugin": true
},
"autoloader-suffix": "c4802e05bbcf59fd3b6350e8d3e5482c_protectⓥ1_2_0"
"autoloader-suffix": "c4802e05bbcf59fd3b6350e8d3e5482c_protectⓥ1_3_0"
}
}

View File

@ -3,7 +3,7 @@
* Plugin Name: Jetpack Protect
* Plugin URI: https://wordpress.org/plugins/jetpack-protect
* Description: Security tools that keep your site safe and sound, from posts to plugins.
* Version: 1.2.0
* Version: 1.3.0
* Author: Automattic - Jetpack Security team
* Author URI: https://jetpack.com/protect/
* License: GPLv2 or later
@ -32,7 +32,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'JETPACK_PROTECT_VERSION', '1.2.0' );
define( 'JETPACK_PROTECT_VERSION', '1.3.0' );
define( 'JETPACK_PROTECT_DIR', plugin_dir_path( __FILE__ ) );
define( 'JETPACK_PROTECT_ROOT_FILE', __FILE__ );
define( 'JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) );
@ -116,6 +116,7 @@ add_filter(
}
);
register_activation_hook( __FILE__, array( 'Jetpack_Protect', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Jetpack_Protect', 'plugin_deactivation' ) );
// Main plugin class.

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.4.19] - 2023-02-20
### Changed
- Minor internal updates.
## [1.4.18] - 2023-01-11
### Changed
- Updated package dependencies.
## [1.4.17] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -107,6 +115,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Creates the MC Stats package
[1.4.19]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.18...v1.4.19
[1.4.18]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.17...v1.4.18
[1.4.17]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.16...v1.4.17
[1.4.16]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.15...v1.4.16
[1.4.15]: https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v1.4.14...v1.4.15

View File

@ -6,7 +6,7 @@
"require": {},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -17,9 +17,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]

View File

@ -100,7 +100,6 @@ class A8c_Mc_Stats {
}
return $urls;
}
/**

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.17] - 2023-02-20
### Changed
- Minor internal updates.
## [0.2.16] - 2023-01-25
### Changed
- Minor internal updates.
## [0.2.15] - 2023-01-11
### Changed
- Updated package dependencies.
## [0.2.14] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -84,6 +96,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixing menu visibility issues.
[0.2.17]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.16...0.2.17
[0.2.16]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.15...0.2.16
[0.2.15]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.14...0.2.15
[0.2.14]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.13...0.2.14
[0.2.13]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.12...0.2.13
[0.2.12]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.11...0.2.12

View File

@ -6,7 +6,7 @@
"require": {},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2",
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/wordbless": "dev-master"
},
"autoload": {
@ -18,9 +18,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
],

View File

@ -13,7 +13,7 @@ namespace Automattic\Jetpack\Admin_UI;
*/
class Admin_Menu {
const PACKAGE_VERSION = '0.2.14';
const PACKAGE_VERSION = '0.2.17';
/**
* Whether this class has been initialized

View File

@ -5,10 +5,29 @@ 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).
## [1.17.33] - 2023-03-07
### Changed
- Updated package dependencies. [#29289]
## [1.17.32] - 2023-02-20
### Changed
- Minor internal updates.
## [1.17.31] - 2023-02-15
### Changed
- Update to React 18. [#28710]
## [1.17.30] - 2023-01-25
### Changed
- Minor internal updates.
## [1.17.29] - 2023-01-11
### Changed
- Updated package dependencies.
## [1.17.28] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
- Updated package dependencies. [#27696]
- Updated package dependencies.
## [1.17.27] - 2022-11-28
### Changed
@ -289,6 +308,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Statically access asset tools
[1.17.33]: https://github.com/Automattic/jetpack-assets/compare/v1.17.32...v1.17.33
[1.17.32]: https://github.com/Automattic/jetpack-assets/compare/v1.17.31...v1.17.32
[1.17.31]: https://github.com/Automattic/jetpack-assets/compare/v1.17.30...v1.17.31
[1.17.30]: https://github.com/Automattic/jetpack-assets/compare/v1.17.29...v1.17.30
[1.17.29]: https://github.com/Automattic/jetpack-assets/compare/v1.17.28...v1.17.29
[1.17.28]: https://github.com/Automattic/jetpack-assets/compare/v1.17.27...v1.17.28
[1.17.27]: https://github.com/Automattic/jetpack-assets/compare/v1.17.26...v1.17.27
[1.17.26]: https://github.com/Automattic/jetpack-assets/compare/v1.17.25...v1.17.26

View File

@ -4,12 +4,12 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-constants": "^1.6.20"
"automattic/jetpack-constants": "^1.6.21"
},
"require-dev": {
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2",
"automattic/jetpack-changelogger": "^3.3.2",
"wikimedia/testing-access-wrapper": "^1.0 || ^2.0"
},
"autoload": {
@ -30,10 +30,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/php/clover.xml\"",
"pnpm run test-coverage"
],
"test-js": [
"pnpm run test"
],

View File

@ -278,7 +278,7 @@ class Assets {
} elseif ( '..' === $pp[ $i ] ) {
array_splice( $pp, --$i, 2 );
} else {
$i++;
++$i;
}
}
$ret .= join( '/', $pp );

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.14.0] - 2023-02-20
### Added
- Added the Import package. [#28824]
## [1.13.0] - 2023-01-02
### Added
- Blaze package: Add config initialization, initialization checks for loading. [#28077]
## [1.12.0] - 2022-12-12
### Added
- Config: add option to init stats-admin [#27565]
## [1.11.1] - 2022-11-22
### Changed
- Updated package dependencies. [#27043]
@ -156,6 +168,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Trying to add deterministic initialization.
[1.14.0]: https://github.com/Automattic/jetpack-config/compare/v1.13.0...v1.14.0
[1.13.0]: https://github.com/Automattic/jetpack-config/compare/v1.12.0...v1.13.0
[1.12.0]: https://github.com/Automattic/jetpack-config/compare/v1.11.1...v1.12.0
[1.11.1]: https://github.com/Automattic/jetpack-config/compare/v1.11.0...v1.11.1
[1.11.0]: https://github.com/Automattic/jetpack-config/compare/v1.10.0...v1.11.0
[1.10.0]: https://github.com/Automattic/jetpack-config/compare/v1.9.6...v1.10.0

View File

@ -5,7 +5,7 @@
"license": "GPL-2.0-or-later",
"require": {},
"require-dev": {
"automattic/jetpack-changelogger": "^3.2.1"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -22,7 +22,7 @@
"link-template": "https://github.com/Automattic/jetpack-config/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.11.x-dev"
"dev-trunk": "1.14.x-dev"
}
}
}

View File

@ -12,14 +12,17 @@ namespace Automattic\Jetpack;
* contain the package classes shown below. The consumer plugin
* must require the corresponding packages to use these features.
*/
use Automattic\Jetpack\Blaze as Blaze;
use Automattic\Jetpack\Connection\Manager;
use Automattic\Jetpack\Connection\Plugin;
use Automattic\Jetpack\Import\Main as Import_Main;
use Automattic\Jetpack\JITM as JITM;
use Automattic\Jetpack\JITMS\JITM as JITMS_JITM;
use Automattic\Jetpack\Post_List\Post_List as Post_List;
use Automattic\Jetpack\Publicize\Publicize_Setup as Publicize_Setup;
use Automattic\Jetpack\Search\Initializer as Jetpack_Search_Main;
use Automattic\Jetpack\Stats\Main as Stats_Main;
use Automattic\Jetpack\Stats_Admin\Main as Stats_Admin_Main;
use Automattic\Jetpack\Sync\Main as Sync_Main;
use Automattic\Jetpack\VideoPress\Initializer as VideoPress_Pkg_Initializer;
use Automattic\Jetpack\Waf\Waf_Initializer as Jetpack_Waf_Main;
@ -51,6 +54,9 @@ class Config {
'waf' => false,
'videopress' => false,
'stats' => false,
'stats_admin' => false,
'blaze' => false,
'import' => false,
);
/**
@ -151,6 +157,18 @@ class Config {
if ( $this->config['stats'] ) {
$this->ensure_class( 'Automattic\Jetpack\Stats\Main' ) && $this->ensure_feature( 'stats' );
}
if ( $this->config['stats_admin'] ) {
$this->ensure_class( 'Automattic\Jetpack\Stats_Admin\Main' ) && $this->ensure_feature( 'stats_admin' );
}
if ( $this->config['blaze'] ) {
$this->ensure_class( 'Automattic\Jetpack\Blaze' ) && $this->ensure_feature( 'blaze' );
}
if ( $this->config['import'] ) {
$this->ensure_class( 'Automattic\Jetpack\Import\Main' )
&& $this->ensure_feature( 'import' );
}
}
/**
@ -317,6 +335,14 @@ class Config {
return true;
}
/**
* Enables Stats Admin.
*/
protected function enable_stats_admin() {
Stats_Admin_Main::init();
return true;
}
/**
* Handles VideoPress options
*/
@ -328,6 +354,23 @@ class Config {
return true;
}
/**
* Enables Blaze.
*/
protected function enable_blaze() {
Blaze::init();
return true;
}
/**
* Enables the Import feature.
*/
protected function enable_import() {
Import_Main::configure();
return true;
}
/**
* Setup the Connection options.
*/

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.51.1] - 2023-03-07
### Changed
- Improve JS code in the connection owner removal notice. [#29087]
- Updated package dependencies. [#29216]
## [1.51.0] - 2023-02-20
### Changed
- Moving deleting connection owner notice from JITM to Connection package. [#28516]
## [1.50.1] - 2023-02-15
### Changed
- Update to React 18. [#28710]
## [1.50.0] - 2023-02-07
### Added
- Call the Licensing package for license verification.
## [1.49.1] - 2023-01-25
### Changed
- Minor internal updates.
## [1.49.0] - 2023-01-11
### Added
- Add new method to get a connected site's blog ID. [#28208]
## [1.48.1] - 2022-12-27
### Removed
- Remove src/js files from final bundle [#27931]
## [1.48.0] - 2022-12-19
### Changed
- Provide user locale when fetching info about connected WordPress.com user. [#27928]
- Update for PHP 8.2 compatibility. [#27949]
### Fixed
- Declare fields for PHP 8.2 compatibility. [#27968]
## [1.47.1] - 2022-12-02
### Changed
- Updated package dependencies. [#27696]
@ -733,6 +770,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Separate the connection library into its own package.
[1.51.1]: https://github.com/Automattic/jetpack-connection/compare/v1.51.0...v1.51.1
[1.51.0]: https://github.com/Automattic/jetpack-connection/compare/v1.50.1...v1.51.0
[1.50.1]: https://github.com/Automattic/jetpack-connection/compare/v1.50.0...v1.50.1
[1.50.0]: https://github.com/Automattic/jetpack-connection/compare/v1.49.1...v1.50.0
[1.49.1]: https://github.com/Automattic/jetpack-connection/compare/v1.49.0...v1.49.1
[1.49.0]: https://github.com/Automattic/jetpack-connection/compare/v1.48.1...v1.49.0
[1.48.1]: https://github.com/Automattic/jetpack-connection/compare/v1.48.0...v1.48.1
[1.48.0]: https://github.com/Automattic/jetpack-connection/compare/v1.47.1...v1.48.0
[1.47.1]: https://github.com/Automattic/jetpack-connection/compare/v1.47.0...v1.47.1
[1.47.0]: https://github.com/Automattic/jetpack-connection/compare/v1.46.4...v1.47.0
[1.46.4]: https://github.com/Automattic/jetpack-connection/compare/v1.46.3...v1.46.4

View File

@ -4,18 +4,18 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.17",
"automattic/jetpack-admin-ui": "^0.2.14",
"automattic/jetpack-constants": "^1.6.20",
"automattic/jetpack-roles": "^1.4.19",
"automattic/jetpack-status": "^1.15.2",
"automattic/jetpack-redirect": "^1.7.21"
"automattic/jetpack-a8c-mc-stats": "^1.4.19",
"automattic/jetpack-admin-ui": "^0.2.17",
"automattic/jetpack-constants": "^1.6.21",
"automattic/jetpack-roles": "^1.4.22",
"automattic/jetpack-status": "^1.16.2",
"automattic/jetpack-redirect": "^1.7.24"
},
"require-dev": {
"automattic/wordbless": "@dev",
"yoast/phpunit-polyfills": "1.0.4",
"brain/monkey": "2.6.1",
"automattic/jetpack-changelogger": "^3.2.2"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -36,9 +36,6 @@
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]
@ -56,7 +53,7 @@
"link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.47.x-dev"
"dev-trunk": "1.51.x-dev"
}
},
"config": {

View File

@ -27,6 +27,14 @@ class Jetpack_Signature {
*/
public $secret;
/**
* Timezone difference (in seconds).
*
* @access public
* @var int
*/
public $time_diff;
/**
* The current request URL.
*
@ -66,12 +74,10 @@ class Jetpack_Signature {
if ( ! in_array( $scheme, array( 'http', 'https' ), true ) ) {
return new WP_Error( 'invalid_scheme', 'Invalid URL scheme' );
}
} elseif ( is_ssl() ) {
$scheme = 'https';
} else {
if ( is_ssl() ) {
$scheme = 'https';
} else {
$scheme = 'http';
}
$scheme = 'http';
}
$port = $this->get_current_request_port();
@ -205,14 +211,12 @@ class Jetpack_Signature {
if ( ! empty( $parsed['port'] ) ) {
$port = $parsed['port'];
} elseif ( 'http' === $parsed['scheme'] ) {
$port = 80;
} elseif ( 'https' === $parsed['scheme'] ) {
$port = 443;
} else {
if ( 'http' === $parsed['scheme'] ) {
$port = 80;
} elseif ( 'https' === $parsed['scheme'] ) {
$port = 443;
} else {
return new WP_Error( 'unknown_scheme_port', "The scheme's port is unknown", compact( 'signature_details' ) );
}
return new WP_Error( 'unknown_scheme_port', "The scheme's port is unknown", compact( 'signature_details' ) );
}
if ( ! ctype_digit( "$timestamp" ) || 10 < strlen( $timestamp ) ) { // If Jetpack is around in 275 years, you can blame mdawaffe for the bug.

View File

@ -220,9 +220,10 @@ class Jetpack_Tracks_Client {
}
return array(
'blogid' => Jetpack_Options::get_option( 'id', 0 ),
'userid' => $user_data['ID'],
'username' => $user_data['login'],
'blogid' => Jetpack_Options::get_option( 'id', 0 ),
'userid' => $user_data['ID'],
'username' => $user_data['login'],
'user_locale' => $user_data['user_locale'],
);
}
}

View File

@ -42,6 +42,7 @@
/**
* Class Jetpack_Tracks_Event
*/
#[AllowDynamicProperties]
class Jetpack_Tracks_Event {
const EVENT_NAME_REGEX = '/^(([a-z0-9]+)_){2}([a-z0-9_]+)$/';
const PROP_NAME_REGEX = '/^[a-z_][a-z0-9_]*$/';

View File

@ -0,0 +1,244 @@
<?php
/**
* Admin connection notices.
*
* @package automattic/jetpack-admin-ui
*/
namespace Automattic\Jetpack\Connection;
use Automattic\Jetpack\Redirect;
use Automattic\Jetpack\Tracking;
/**
* Admin connection notices.
*/
class Connection_Notice {
/**
* Whether the class has been initialized.
*
* @var bool
*/
private static $is_initialized = false;
/**
* The constructor.
*/
public function __construct() {
if ( ! static::$is_initialized ) {
add_action( 'current_screen', array( $this, 'initialize_notices' ) );
static::$is_initialized = true;
}
}
/**
* Initialize the notices if needed.
*
* @param \WP_Screen $screen WP Core's screen object.
*
* @return void
*/
public function initialize_notices( $screen ) {
if ( ! in_array(
$screen->id,
array(
'jetpack_page_akismet-key-config',
'admin_page_jetpack_modules',
),
true
) ) {
add_action( 'admin_notices', array( $this, 'delete_user_update_connection_owner_notice' ) );
}
}
/**
* This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete
* the connection owner.
*/
public function delete_user_update_connection_owner_notice() {
global $current_screen;
/*
* phpcs:disable WordPress.Security.NonceVerification.Recommended
*
* This function is firing within wp-admin and checks (below) if it is in the midst of a deletion on the users
* page. Nonce will be already checked by WordPress, so we do not need to check ourselves.
*/
if ( ! isset( $current_screen->base ) || 'users' !== $current_screen->base ) {
return;
}
if ( ! isset( $_REQUEST['action'] ) || 'delete' !== $_REQUEST['action'] ) {
return;
}
// Get connection owner or bail.
$connection_manager = new Manager();
$connection_owner_id = $connection_manager->get_connection_owner_id();
if ( ! $connection_owner_id ) {
return;
}
$connection_owner_userdata = get_userdata( $connection_owner_id );
// Bail if we're not trying to delete connection owner.
$user_ids_to_delete = array();
if ( isset( $_REQUEST['users'] ) ) {
$user_ids_to_delete = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['users'] ) );
} elseif ( isset( $_REQUEST['user'] ) ) {
$user_ids_to_delete[] = sanitize_text_field( wp_unslash( $_REQUEST['user'] ) );
}
// phpcs:enable
$user_ids_to_delete = array_map( 'absint', $user_ids_to_delete );
$deleting_connection_owner = in_array( $connection_owner_id, (array) $user_ids_to_delete, true );
if ( ! $deleting_connection_owner ) {
return;
}
// Bail if they're trying to delete themselves to avoid confusion.
if ( get_current_user_id() === $connection_owner_id ) {
return;
}
$tracking = new Tracking();
// Track it!
if ( method_exists( $tracking, 'record_user_event' ) ) {
$tracking->record_user_event( 'delete_connection_owner_notice_view' );
}
$connected_admins = $connection_manager->get_connected_users( 'jetpack_disconnect' );
$user = is_a( $connection_owner_userdata, 'WP_User' ) ? esc_html( $connection_owner_userdata->data->user_login ) : '';
echo "<div class='notice notice-warning' id='jetpack-notice-switch-connection-owner'>";
echo '<h2>' . esc_html__( 'Important notice about your Jetpack connection:', 'jetpack-connection' ) . '</h2>';
echo '<p>' . sprintf(
/* translators: WordPress User, if available. */
esc_html__( 'Warning! You are about to delete the Jetpack connection owner (%s) for this site, which may cause some of your Jetpack features to stop working.', 'jetpack-connection' ),
esc_html( $user )
) . '</p>';
if ( ! empty( $connected_admins ) && count( $connected_admins ) > 1 ) {
echo '<form id="jp-switch-connection-owner" action="" method="post">';
echo "<label for='owner'>" . esc_html__( 'You can choose to transfer connection ownership to one of these already-connected admins:', 'jetpack-connection' ) . ' </label>';
$connected_admin_ids = array_map(
function ( $connected_admin ) {
return $connected_admin->ID;
},
$connected_admins
);
wp_dropdown_users(
array(
'name' => 'owner',
'include' => array_diff( $connected_admin_ids, array( $connection_owner_id ) ),
'show' => 'display_name_with_login',
)
);
echo '<p>';
submit_button( esc_html__( 'Set new connection owner', 'jetpack-connection' ), 'primary', 'jp-switch-connection-owner-submit', false );
echo '</p>';
echo "<div id='jp-switch-user-results'></div>";
echo '</form>';
?>
<script type="text/javascript">
( function() {
const switchOwnerButton = document.getElementById('jp-switch-connection-owner');
if ( ! switchOwnerButton ) {
return;
}
switchOwnerButton.addEventListener( 'submit', function ( e ) {
e.preventDefault();
const submitBtn = document.getElementById('jp-switch-connection-owner-submit');
submitBtn.disabled = true;
const results = document.getElementById('jp-switch-user-results');
results.innerHTML = '';
results.classList.remove( 'error-message' );
const handleAPIError = ( message ) => {
submitBtn.disabled = false;
results.classList.add( 'error-message' );
results.innerHTML = message || "<?php esc_html_e( 'Something went wrong. Please try again.', 'jetpack-connection' ); ?>";
}
fetch(
<?php echo wp_json_encode( esc_url_raw( get_rest_url() . 'jetpack/v4/connection/owner' ), JSON_HEX_TAG | JSON_HEX_AMP ); ?>,
{
method: 'POST',
headers: {
'X-WP-Nonce': <?php echo wp_json_encode( wp_create_nonce( 'wp_rest' ), JSON_HEX_TAG | JSON_HEX_AMP ); ?>,
},
body: new URLSearchParams( new FormData( this ) ),
}
)
.then( response => response.json() )
.then( data => {
if ( data.hasOwnProperty( 'code' ) && data.code === 'success' ) {
// Owner successfully changed.
results.innerHTML = <?php echo wp_json_encode( esc_html__( 'Success!', 'jetpack-connection' ), JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
setTimeout(function () {
document.getElementById( 'jetpack-notice-switch-connection-owner' ).style.display = 'none';
}, 1000);
return;
}
handleAPIError( data?.message );
} )
.catch( () => handleAPIError() );
});
} )();
</script>
<?php
} else {
echo '<p>' . esc_html__( 'Every Jetpack site needs at least one connected admin for the features to work properly. Please connect to your WordPress.com account via the button below. Once you connect, you may refresh this page to see an option to change the connection owner.', 'jetpack-connection' ) . '</p>';
$connect_url = $connection_manager->get_authorization_url();
$connect_url = add_query_arg( 'from', 'delete_connection_owner_notice', $connect_url );
echo "<a href='" . esc_url( $connect_url ) . "' target='_blank' rel='noopener noreferrer' class='button-primary'>" . esc_html__( 'Connect to WordPress.com', 'jetpack-connection' ) . '</a>';
}
echo '<p>';
printf(
wp_kses(
/* translators: URL to Jetpack support doc regarding the primary user. */
__( "<a href='%s' target='_blank' rel='noopener noreferrer'>Learn more</a> about the connection owner and what will break if you do not have one.", 'jetpack-connection' ),
array(
'a' => array(
'href' => true,
'target' => true,
'rel' => true,
),
)
),
esc_url( Redirect::get_url( 'jetpack-support-primary-user' ) )
);
echo '</p>';
echo '<p>';
printf(
wp_kses(
/* translators: URL to contact Jetpack support. */
__( 'As always, feel free to <a href="%s" target="_blank" rel="noopener noreferrer">contact our support team</a> if you have any questions.', 'jetpack-connection' ),
array(
'a' => array(
'href' => true,
'target' => true,
'rel' => true,
),
)
),
esc_url( Redirect::get_url( 'jetpack-contact-support' ) )
);
echo '</p>';
echo '</div>';
}
}

View File

@ -288,7 +288,6 @@ class Error_Handler {
}
return false;
}
/**
@ -326,7 +325,6 @@ class Error_Handler {
);
return $error_array;
}
/**
@ -380,7 +378,6 @@ class Error_Handler {
}
return $encrypted_data;
}
/**
@ -401,7 +398,6 @@ class Error_Handler {
}
return $user_id;
}
/**
@ -566,7 +562,6 @@ class Error_Handler {
$verified_errors[ $error_code ][ $user_id ] = $error;
update_option( self::STORED_VERIFIED_ERRORS_OPTION, $verified_errors );
}
/**
@ -612,7 +607,6 @@ class Error_Handler {
}
return new \WP_REST_Response( false, 200 );
}
/**

View File

@ -164,7 +164,6 @@ class Heartbeat {
}
return $return;
}
/**

View File

@ -45,6 +45,20 @@ class Manager {
*/
private $plugin = null;
/**
* Error handler object.
*
* @var Error_Handler
*/
public $error_handler = null;
/**
* Jetpack_XMLRPC_Server object
*
* @var Jetpack_XMLRPC_Server
*/
public $xmlrpc_server = null;
/**
* Holds extra parameters that will be sent along in the register request body.
*
@ -117,6 +131,9 @@ class Manager {
if ( defined( 'JETPACK__SANDBOX_DOMAIN' ) && JETPACK__SANDBOX_DOMAIN ) {
( new Server_Sandbox() )->init();
}
// Initialize connection notices.
new Connection_Notice();
}
/**
@ -900,7 +917,8 @@ class Manager {
* @return true|WP_Error True if owner successfully changed, WP_Error otherwise.
*/
public function update_connection_owner( $new_owner_id ) {
if ( ! user_can( $new_owner_id, 'administrator' ) ) {
$roles = new Roles();
if ( ! user_can( $new_owner_id, $roles->translate_role_to_cap( 'administrator' ) ) ) {
return new WP_Error(
'new_owner_not_admin',
__( 'New owner is not admin', 'jetpack-connection' ),
@ -1764,7 +1782,6 @@ class Manager {
* Should be changed to protected.
*/
public function handle_authorization() {
}
/**
@ -1857,7 +1874,7 @@ class Manager {
'user_email' => $user->user_email,
'user_login' => $user->user_login,
'is_active' => $this->has_connected_owner(), // TODO Deprecate this.
'jp_version' => Constants::get_constant( 'JETPACK__VERSION' ),
'jp_version' => (string) Constants::get_constant( 'JETPACK__VERSION' ),
'auth_type' => $auth_type,
'secret' => $secrets['secret_1'],
'blogname' => get_option( 'blogname' ),
@ -2474,4 +2491,22 @@ class Manager {
}
return $stats;
}
/**
* Get the WPCOM or self-hosted site ID.
*
* @return int|WP_Error
*/
public static function get_site_id() {
$is_wpcom = ( defined( 'IS_WPCOM' ) && IS_WPCOM );
$site_id = $is_wpcom ? get_current_blog_id() : \Jetpack_Options::get_option( 'id' );
if ( ! $site_id ) {
return new \WP_Error(
'unavailable_site_id',
__( 'Sorry, something is wrong with your Jetpack connection.', 'jetpack-connection' ),
403
);
}
return (int) $site_id;
}
}

View File

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

View File

@ -180,7 +180,6 @@ class Plugin_Storage {
}
self::$configured = true;
}
/**

View File

@ -365,7 +365,6 @@ class REST_Connector {
}
return array_values( $plugins );
}
/**
@ -398,7 +397,6 @@ class REST_Connector {
}
return new WP_Error( 'invalid_user_permission_activate_plugins', self::get_user_permissions_error_msg(), array( 'status' => rest_authorization_required_code() ) );
}
/**
@ -495,7 +493,6 @@ class REST_Connector {
}
return $response;
}
/**
@ -513,7 +510,6 @@ class REST_Connector {
self::get_user_permissions_error_msg(),
array( 'status' => rest_authorization_required_code() )
);
}
/**

View File

@ -40,7 +40,7 @@ class Secrets {
$attempts = 1;
$secret_length = strlen( $secret );
while ( $secret_length < 32 && $attempts < 32 ) {
$attempts++;
++$attempts;
$secret .= wp_generate_password( 32, false );
$secret_length = strlen( $secret );
}

View File

@ -146,7 +146,6 @@ class Server_Sandbox {
} else {
$this->log_new_signature_error( 'Empty Authorization Header' );
}
}
/**

View File

@ -316,6 +316,5 @@ class Tracking {
'_ut' => 'anon',
'_ui' => $anon_id,
);
}
}

View File

@ -128,7 +128,7 @@ class Urls {
Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
) {
$scheme = is_ssl() ? 'https' : 'http';
$url = self::get_raw_url( $url_type );
$url = (string) self::get_raw_url( $url_type );
$url = set_url_scheme( $url, $scheme );
} else {
$url = self::normalize_www_in_url( $url_type, $url_function );

View File

@ -93,7 +93,6 @@ class Webhooks {
break;
// Class Jetpack::admin_page_load() still handles other cases.
}
}
/**
@ -193,23 +192,20 @@ class Webhooks {
}
wp_safe_redirect( $connect_url );
$this->do_exit();
} elseif ( ! isset( $_GET['calypso_env'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no site changes.
( new CookieState() )->state( 'message', 'already_authorized' );
wp_safe_redirect( $redirect );
$this->do_exit();
} else {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no site changes.
if ( ! isset( $_GET['calypso_env'] ) ) {
( new CookieState() )->state( 'message', 'already_authorized' );
wp_safe_redirect( $redirect );
$this->do_exit();
} else {
$connect_url = add_query_arg(
array(
'from' => $from,
'already_authorized' => true,
),
$this->connection->get_authorization_url()
);
wp_safe_redirect( $connect_url );
$this->do_exit();
}
$connect_url = add_query_arg(
array(
'from' => $from,
'already_authorized' => true,
),
$this->connection->get_authorization_url()
);
wp_safe_redirect( $connect_url );
$this->do_exit();
}
}
}

View File

@ -1,63 +0,0 @@
/* global jpTracksAJAX */
( function ( $, jpTracksAJAX ) {
window.jpTracksAJAX = window.jpTracksAJAX || {};
const debugSet = localStorage.getItem( 'debug' ) === 'dops:analytics';
window.jpTracksAJAX.record_ajax_event = function ( eventName, eventType, eventProp ) {
const data = {
tracksNonce: jpTracksAJAX.jpTracksAJAX_nonce,
action: 'jetpack_tracks',
tracksEventType: eventType,
tracksEventName: eventName,
tracksEventProp: eventProp || false,
};
return $.ajax( {
type: 'POST',
url: jpTracksAJAX.ajaxurl,
data: data,
success: function ( response ) {
if ( debugSet ) {
// eslint-disable-next-line
console.log( 'AJAX tracks event recorded: ', data, response );
}
},
} );
};
$( document ).ready( function () {
$( 'body' ).on( 'click', '.jptracks a, a.jptracks', function ( event ) {
const $this = $( event.target );
// We know that the jptracks element is either this, or its ancestor
const $jptracks = $this.closest( '.jptracks' );
// We need an event name at least
const eventName = $jptracks.attr( 'data-jptracks-name' );
if ( undefined === eventName ) {
return;
}
const eventProp = $jptracks.attr( 'data-jptracks-prop' ) || false;
const url = $this.attr( 'href' );
const target = $this.get( 0 ).target;
let newTabWindow = null;
if ( url && target && '_self' !== target ) {
newTabWindow = window.open( '', target );
newTabWindow.opener = null;
}
event.preventDefault();
window.jpTracksAJAX.record_ajax_event( eventName, 'click', eventProp ).always( function () {
// Continue on to whatever url they were trying to get to.
if ( url && ! $this.hasClass( 'thickbox' ) ) {
if ( newTabWindow ) {
newTabWindow.location = url;
return;
}
window.location = url;
}
} );
} );
} );
} )( jQuery, jpTracksAJAX );

View File

@ -1,94 +0,0 @@
/**
* This was abstracted from wp-calypso's analytics lib: https://github.com/Automattic/wp-calypso/blob/trunk/client/lib/analytics/README.md
* Some stuff was removed like GA tracking and other things not necessary for Jetpack tracking.
*
* This library should only be used and loaded if the Jetpack site is connected.
*/
// Load tracking scripts
window._tkq = window._tkq || [];
let _user;
const debug = console.error; // eslint-disable-line no-console
/**
* Build a query string.
*
* @param {string|object} group - Stat group, or object mapping groups to names.
* @param {string} [name] - Stat name, when `group` is a string.
* @returns {string} Query string fragment.
*/
function buildQuerystring( group, name ) {
let uriComponent = '';
if ( 'object' === typeof group ) {
for ( const key in group ) {
uriComponent += '&x_' + encodeURIComponent( key ) + '=' + encodeURIComponent( group[ key ] );
}
} else {
uriComponent = '&x_' + encodeURIComponent( group ) + '=' + encodeURIComponent( name );
}
return uriComponent;
}
const analytics = {
initialize: function ( userId, username ) {
analytics.setUser( userId, username );
analytics.identifyUser();
},
mc: {
bumpStat: function ( group, name ) {
const uriComponent = buildQuerystring( group, name ); // prints debug info
new Image().src =
document.location.protocol +
'//pixel.wp.com/g.gif?v=wpcom-no-pv' +
uriComponent +
'&t=' +
Math.random();
},
},
tracks: {
recordEvent: function ( eventName, eventProperties ) {
eventProperties = eventProperties || {};
if ( eventName.indexOf( 'jetpack_' ) !== 0 ) {
debug( '- Event name must be prefixed by "jetpack_"' );
return;
}
window._tkq.push( [ 'recordEvent', eventName, eventProperties ] );
},
recordPageView: function ( urlPath ) {
analytics.tracks.recordEvent( 'jetpack_page_view', {
path: urlPath,
} );
},
},
setUser: function ( userId, username ) {
_user = { ID: userId, username: username };
},
identifyUser: function () {
// Don't identify the user if we don't have one
if ( _user ) {
window._tkq.push( [ 'identifyUser', _user.ID, _user.username ] );
}
},
clearedIdentity: function () {
window._tkq.push( [ 'clearIdentity' ] );
},
};
if ( typeof module !== 'undefined' ) {
// Bundled by Webpack.
module.exports = analytics;
} else {
// Direct load.
window.analytics = analytics;
}

View File

@ -9,6 +9,7 @@ namespace Automattic\Jetpack\Connection\Webhooks;
use Automattic\Jetpack\Admin_UI\Admin_Menu;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\Licensing;
use Automattic\Jetpack\Tracking;
use GP_Locales;
use Jetpack_Network;
@ -56,8 +57,12 @@ class Authorize_Redirect {
exit;
}
// The user is either already connected, or finished the connection process.
if ( $this->connection->is_connected() && $this->connection->is_user_connected() ) {
// The user is either already connected, or finished the connection process.
if ( class_exists( '\Automattic\Jetpack\Licensing' ) && method_exists( '\Automattic\Jetpack\Licensing', 'handle_user_connected_redirect' ) ) {
Licensing::instance()->handle_user_connected_redirect( $dest_url );
}
wp_safe_redirect( $dest_url );
exit;
} elseif ( ! empty( $_GET['done'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.6.21] - 2023-02-20
### Changed
- Minor internal updates.
## [1.6.20] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -142,6 +146,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Packages: Finish the constants package
[1.6.21]: https://github.com/Automattic/jetpack-constants/compare/v1.6.20...v1.6.21
[1.6.20]: https://github.com/Automattic/jetpack-constants/compare/v1.6.19...v1.6.20
[1.6.19]: https://github.com/Automattic/jetpack-constants/compare/v1.6.18...v1.6.19
[1.6.18]: https://github.com/Automattic/jetpack-constants/compare/v1.6.17...v1.6.18

View File

@ -7,7 +7,7 @@
"require-dev": {
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -18,9 +18,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.4.24] - 2023-02-20
### Changed
- Minor internal updates.
## [1.4.23] - 2023-01-11
### Changed
- Updated package dependencies.
## [1.4.22] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -143,6 +151,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Moving jetpack_is_mobile into a package
[1.4.24]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.23...v1.4.24
[1.4.23]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.22...v1.4.23
[1.4.22]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.21...v1.4.22
[1.4.21]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.20...v1.4.21
[1.4.20]: https://github.com/Automattic/jetpack-device-detection/compare/v1.4.19...v1.4.20

View File

@ -6,7 +6,7 @@
"require": {},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -17,9 +17,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]

View File

@ -136,10 +136,8 @@ class User_Agent_Info {
public function __construct( $ua = '' ) {
if ( $ua ) {
$this->useragent = $ua;
} else {
if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
$this->useragent = strtolower( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This class is all about validating.
}
} elseif ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
$this->useragent = strtolower( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This class is all about validating.
}
}
@ -815,12 +813,10 @@ class User_Agent_Info {
if ( false === strpos( $ua, 'windows phone os 7' ) ) {
return false;
} elseif ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) {
return false;
} else {
if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) {
return false;
} else {
return true;
}
return true;
}
}
@ -856,12 +852,10 @@ class User_Agent_Info {
if ( false === strpos( $ua, 'webos' ) ) {
return false;
} elseif ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) {
return false;
} else {
if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) {
return false;
} else {
return true;
}
return true;
}
}
@ -1041,12 +1035,10 @@ class User_Agent_Info {
if ( false === strpos( $ua, 'meego' ) ) {
return false;
} elseif ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) {
return false;
} else {
if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) {
return false;
} else {
return true;
}
return true;
}
}
@ -1315,20 +1307,17 @@ class User_Agent_Info {
$pos_torch = stripos( $agent, 'BlackBerry 9800' );
if ( false !== $pos_torch ) {
return 'blackberry-torch'; // Match the torch first edition. the 2nd edition should use the OS7 and doesn't need any special rule.
} else {
// Detecting the BB OS version for devices running OS 6.0 or higher.
if ( preg_match( '#Version\/([\d\.]+)#i', $agent, $matches ) ) {
$version = $matches[1];
$version_num = explode( '.', $version );
if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
return 'blackberry-6'; // not a BB device that match our rule.
} else {
return 'blackberry-' . $version_num[0];
}
} else {
// if doesn't match returns the minimun version with a webkit browser. we should never fall here.
} elseif ( preg_match( '#Version\/([\d\.]+)#i', $agent, $matches ) ) { // Detecting the BB OS version for devices running OS 6.0 or higher.
$version = $matches[1];
$version_num = explode( '.', $version );
if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) {
return 'blackberry-6'; // not a BB device that match our rule.
} else {
return 'blackberry-' . $version_num[0];
}
} else {
// if doesn't match returns the minimun version with a webkit browser. we should never fall here.
return 'blackberry-6'; // not a BB device that match our rule.
}
}
@ -1360,7 +1349,6 @@ class User_Agent_Info {
} else {
return false;
}
}
/**
@ -1423,7 +1411,6 @@ class User_Agent_Info {
return false;
}
}
}
/**

View File

@ -5,6 +5,30 @@ 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.8.39] - 2023-03-07
### Changed
- Updated package dependencies. [#29216]
## [0.8.38] - 2023-02-20
### Changed
- Minor internal updates.
## [0.8.37] - 2023-02-15
### Changed
- Update to React 18. [#28710]
## [0.8.36] - 2023-02-08
### Changed
- Updated package dependencies. [#28682]
## [0.8.35] - 2023-01-25
### Changed
- Minor internal updates.
## [0.8.34] - 2023-01-11
### Changed
- Updated package dependencies. [#28127]
## [0.8.33] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -308,6 +332,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated package dependencies.
- Use Connection/Urls for home_url and site_url functions migrated from Sync.
[0.8.39]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.38...v0.8.39
[0.8.38]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.37...v0.8.38
[0.8.37]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.36...v0.8.37
[0.8.36]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.35...v0.8.36
[0.8.35]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.34...v0.8.35
[0.8.34]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.33...v0.8.34
[0.8.33]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.32...v0.8.33
[0.8.32]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.31...v0.8.32
[0.8.31]: https://github.com/Automattic/jetpack-identity-crisis/compare/v0.8.30...v0.8.31

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => '9a46a33179a7b5b5ae30');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => '52ddba6f415e978d2aac');

View File

@ -4,14 +4,14 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.47.1",
"automattic/jetpack-constants": "^1.6.20",
"automattic/jetpack-status": "^1.15.2",
"automattic/jetpack-logo": "^1.5.20",
"automattic/jetpack-assets": "^1.17.28"
"automattic/jetpack-connection": "^1.51.1",
"automattic/jetpack-constants": "^1.6.21",
"automattic/jetpack-status": "^1.16.2",
"automattic/jetpack-logo": "^1.5.22",
"automattic/jetpack-assets": "^1.17.33"
},
"require-dev": {
"automattic/jetpack-changelogger": "^3.2.2",
"automattic/jetpack-changelogger": "^3.3.2",
"yoast/phpunit-polyfills": "1.0.4",
"automattic/wordbless": "@dev"
},
@ -30,9 +30,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
],

View File

@ -1,6 +1,6 @@
import { IDCScreen } from '@automattic/jetpack-idc';
import * as WPElement from '@wordpress/element';
import React from 'react';
import ReactDOM from 'react-dom';
import './admin-bar.scss';
import './style.scss';
@ -30,7 +30,8 @@ function render() {
} = window.JP_IDENTITY_CRISIS__INITIAL_STATE;
if ( ! isSafeModeConfirmed ) {
ReactDOM.render(
// @todo: Remove fallback when we drop support for WP 6.1
const component = (
<IDCScreen
wpcomHomeUrl={ wpcomHomeUrl }
currentUrl={ currentUrl }
@ -45,9 +46,13 @@ function render() {
isAdmin={ isAdmin }
logo={ consumerData.hasOwnProperty( 'logo' ) ? consumerData.logo : undefined }
possibleDynamicSiteUrlDetected={ possibleDynamicSiteUrlDetected }
/>,
container
/>
);
if ( WPElement.createRoot ) {
WPElement.createRoot( container ).render( component );
} else {
WPElement.render( component, container );
}
}
}

View File

@ -28,7 +28,7 @@ class Identity_Crisis {
/**
* Package Version
*/
const PACKAGE_VERSION = '0.8.33';
const PACKAGE_VERSION = '0.8.39';
/**
* Instance of the object.

View File

@ -0,0 +1,12 @@
# 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.0 - 2023-02-28
### Added
- Added a utility function to extract an array of IP addresses from a given string. [#29131]
- Add jetpack-ip package functionality [#28846]
- Initialized the package. [#28765]

View File

@ -0,0 +1,357 @@
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===================================
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@ -0,0 +1,38 @@
# Security Policy
Full details of the Automattic Security Policy can be found on [automattic.com](https://automattic.com/security/).
## Supported Versions
Generally, only the latest version of Jetpack has continued support. If a critical vulnerability is found in the current version of Jetpack, we may opt to backport any patches to previous versions.
## Reporting a Vulnerability
[Jetpack](https://jetpack.com/) is an open-source plugin for WordPress. Our HackerOne program covers the plugin software, as well as a variety of related projects and infrastructure.
**For responsible disclosure of security issues and to be eligible for our bug bounty program, please submit your report via the [HackerOne](https://hackerone.com/automattic) portal.**
Our most critical targets are:
* Jetpack and the Jetpack composer packages (all within this repo)
* Jetpack.com -- the primary marketing site.
* cloud.jetpack.com -- a management site.
* wordpress.com -- the shared management site for both Jetpack and WordPress.com sites.
For more targets, see the `In Scope` section on [HackerOne](https://hackerone.com/automattic).
_Please note that the **WordPress software is a separate entity** from Automattic. Please report vulnerabilities for WordPress through [the WordPress Foundation's HackerOne page](https://hackerone.com/wordpress)._
## Guidelines
We're committed to working with security researchers to resolve the vulnerabilities they discover. You can help us by following these guidelines:
* Follow [HackerOne's disclosure guidelines](https://www.hackerone.com/disclosure-guidelines).
* Pen-testing Production:
* Please **setup a local environment** instead whenever possible. Most of our code is open source (see above).
* If that's not possible, **limit any data access/modification** to the bare minimum necessary to reproduce a PoC.
* **_Don't_ automate form submissions!** That's very annoying for us, because it adds extra work for the volunteers who manage those systems, and reduces the signal/noise ratio in our communication channels.
* To be eligible for a bounty, all of these guidelines must be followed.
* Be Patient - Give us a reasonable time to correct the issue before you disclose the vulnerability.
We also expect you to comply with all applicable laws. You're responsible to pay any taxes associated with your bounties.

View File

@ -0,0 +1,41 @@
{
"name": "automattic/jetpack-ip",
"description": "Utilities for working with IP addresses.",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require-dev": {
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
"src/"
]
},
"scripts": {
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-php": [
"@composer phpunit"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"autotagger": true,
"mirror-repo": "Automattic/jetpack-ip",
"changelogger": {
"link-template": "https://github.com/automattic/jetpack-ip/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "0.1.x-dev"
},
"textdomain": "jetpack-ip",
"version-constants": {
"::PACKAGE_VERSION": "src/class-utils.php"
}
}
}

View File

@ -0,0 +1,246 @@
<?php
/**
* Utils class file.
*
* @package automattic/jetpack-ip
*/
namespace Automattic\Jetpack\IP;
/**
* Class that provides static methods for working with IP addresses.
*/
class Utils {
const PACKAGE_VERSION = '0.1.0';
/**
* Get the current user's IP address.
*
* @return string|false IP address.
*/
public static function get_ip() {
$trusted_header_data = get_site_option( 'trusted_ip_header' );
if ( isset( $trusted_header_data->trusted_header ) && isset( $_SERVER[ $trusted_header_data->trusted_header ] ) ) {
$ip = wp_unslash( $_SERVER[ $trusted_header_data->trusted_header ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- clean_ip does it below.
$segments = $trusted_header_data->segments;
$reverse_order = $trusted_header_data->reverse;
} else {
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? wp_unslash( $_SERVER['REMOTE_ADDR'] ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- clean_ip does it below.
}
if ( ! $ip ) {
return false;
}
$ips = explode( ',', $ip );
if ( ! isset( $segments ) || ! $segments ) {
$segments = 1;
}
if ( isset( $reverse_order ) && $reverse_order ) {
$ips = array_reverse( $ips );
}
$ip_count = count( $ips );
if ( 1 === $ip_count ) {
return self::clean_ip( $ips[0] );
} elseif ( $ip_count >= $segments ) {
$the_one = $ip_count - $segments;
return self::clean_ip( $ips[ $the_one ] );
} else {
return self::clean_ip( isset( $_SERVER['REMOTE_ADDR'] ) ? wp_unslash( $_SERVER['REMOTE_ADDR'] ) : null ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- clean_ip does it.
}
}
/**
* Clean IP address.
*
* @param string $ip The IP address to clean.
* @return string|false The cleaned IP address.
*/
public static function clean_ip( $ip ) {
// Some misconfigured servers give back extra info, which comes after "unless".
$ips = explode( ' unless ', $ip );
$ip = $ips[0];
$ip = strtolower( trim( $ip ) );
// Check for IPv4 with port.
if ( preg_match( '/^(\d+\.\d+\.\d+\.\d+):\d+$/', $ip, $matches ) ) {
$ip = $matches[1];
}
// Check for IPv6 (or IPvFuture) with brackets and optional port.
if ( preg_match( '/^\[([a-z0-9\-._~!$&\'()*+,;=:]+)\](?::\d+)?$/', $ip, $matches ) ) {
$ip = $matches[1];
}
// Check for IPv4 IP cast as IPv6.
if ( preg_match( '/^::ffff:(\d+\.\d+\.\d+\.\d+)$/', $ip, $matches ) ) {
$ip = $matches[1];
}
// Validate and return.
return filter_var( $ip, FILTER_VALIDATE_IP ) ? $ip : false;
}
/**
* Checks an IP to see if it is within a private range.
*
* @param int $ip IP address.
* @return bool True if IP address is private, false otherwise.
*/
public static function ip_is_private( $ip ) {
// We are dealing with ipv6, so we can simply rely on filter_var.
if ( false === strpos( $ip, '.' ) ) {
return ! filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE );
}
// We are dealing with ipv4.
$private_ip4_addresses = array(
'10.0.0.0|10.255.255.255', // Single class A network.
'172.16.0.0|172.31.255.255', // 16 contiguous class B network.
'192.168.0.0|192.168.255.255', // 256 contiguous class C network.
'169.254.0.0|169.254.255.255', // Link-local address also referred to as Automatic Private IP Addressing.
'127.0.0.0|127.255.255.255', // localhost.
);
$long_ip = ip2long( $ip );
if ( -1 !== $long_ip ) {
foreach ( $private_ip4_addresses as $pri_addr ) {
list ( $start, $end ) = explode( '|', $pri_addr );
if ( $long_ip >= ip2long( $start ) && $long_ip <= ip2long( $end ) ) {
return true;
}
}
}
return false;
}
/**
* Uses inet_pton if available to convert an IP address to a binary string.
* If inet_pton is not available, ip2long will convert the address to an integer.
* Returns false if an invalid IP address is given.
*
* NOTE: ip2long will return false for any ipv6 address. servers that do not support
* inet_pton will not support ipv6
*
* @param mixed $ip IP address.
* @return int|string|bool
*/
public static function convert_ip_address( $ip ) {
if ( function_exists( 'inet_pton' ) ) {
return inet_pton( $ip );
}
return ip2long( $ip );
}
/**
* Checks that a given IP address is within a given low - high range.
* Servers that support inet_pton will use that function to convert the ip to number,
* while other servers will use ip2long.
*
* NOTE: servers that do not support inet_pton cannot support ipv6.
*
* @param mixed $ip IP.
* @param mixed $range_low Range Low.
* @param mixed $range_high Range High.
* @return Bool
*/
public static function ip_address_is_in_range( $ip, $range_low, $range_high ) {
// The inet_pton will give us binary string of an ipv4 or ipv6.
// We can then use strcmp to see if the address is in range.
if ( function_exists( 'inet_pton' ) ) {
$ip_num = inet_pton( $ip );
$ip_low = inet_pton( $range_low );
$ip_high = inet_pton( $range_high );
if ( $ip_num && $ip_low && $ip_high && strcmp( $ip_num, $ip_low ) >= 0 && strcmp( $ip_num, $ip_high ) <= 0 ) {
return true;
}
// The ip2long will give us an integer of an ipv4 address only. it will produce FALSE for ipv6.
} else {
$ip_num = ip2long( $ip );
$ip_low = ip2long( $range_low );
$ip_high = ip2long( $range_high );
if ( $ip_num && $ip_low && $ip_high && $ip_num >= $ip_low && $ip_num <= $ip_high ) {
return true;
}
}
return false;
}
/**
* Extracts IP addresses from a given string.
*
* We allow for both, one IP per line or comma-; semicolon; or whitespace-separated lists. This also validates the IP addresses
* and only returns the ones that look valid. IP ranges using the "-" character are also supported.
*
* @param string $ips List of ips - example: "8.8.8.8\n4.4.4.4,2.2.2.2;1.1.1.1 9.9.9.9,5555.5555.5555.5555,1.1.1.10-1.1.1.20".
* @return array List of valid IP addresses. - example based on input example: array('8.8.8.8', '4.4.4.4', '2.2.2.2', '1.1.1.1', '9.9.9.9', '1.1.1.10-1.1.1.20')
*/
public static function get_ip_addresses_from_string( $ips ) {
$ips = (string) $ips;
$ips = preg_split( '/[\s,;]/', $ips );
$result = array();
foreach ( $ips as $ip ) {
// Validate both IP values from the range.
$range = explode( '-', $ip );
if ( count( $range ) === 2 ) {
if ( self::validate_ip_range( $range[0], $range[1] ) ) {
$result[] = $ip;
}
continue;
}
// Validate the single IP value.
if ( filter_var( $ip, FILTER_VALIDATE_IP ) !== false ) {
$result[] = $ip;
}
}
return $result;
}
/**
* Validates the low and high IP addresses of a range.
*
* NOTE: servers that do not support inet_pton cannot support ipv6.
*
* @param string $range_low Low IP address.
* @param string $range_high High IP address.
* @return bool True if the range is valid, false otherwise.
*/
public static function validate_ip_range( $range_low, $range_high ) {
// Validate that both IP addresses are valid.
if ( ! filter_var( $range_low, FILTER_VALIDATE_IP ) || ! filter_var( $range_high, FILTER_VALIDATE_IP ) ) {
return false;
}
// Validate that the $range_low is lower or equal to $range_high.
if ( function_exists( 'inet_pton' ) ) {
// The inet_pton will give us binary string of an ipv4 or ipv6.
// We can then use strcmp to see if the address is in range.
$ip_low = inet_pton( $range_low );
$ip_high = inet_pton( $range_high );
if ( false === $ip_low || false === $ip_high ) {
return false;
}
if ( strcmp( $ip_low, $ip_high ) > 0 ) {
return false;
}
} else {
// The ip2long will give us an integer of an ipv4 address only. it will produce FALSE for ipv6.
$ip_low = ip2long( $range_low );
$ip_high = ip2long( $range_high );
if ( false === $ip_low || false === $ip_high ) {
return false;
}
if ( $ip_low > $ip_high ) {
return false;
}
}
return true;
}
}

View File

@ -5,6 +5,42 @@ 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).
## [2.3.1] - 2023-03-07
### Changed
- Updated package dependencies. [#29216]
## [2.3.0] - 2023-02-20
### Changed
- Moving deleting connection owner notice from JITM to Connection package. [#28516]
## [2.2.42] - 2023-02-15
### Changed
- Update to React 18. [#28710]
## [2.2.41] - 2023-02-06
### Fixed
- JITM: minor fix for styles on Safari browser.
## [2.2.40] - 2023-01-30
### Changed
- Updated styles for Just in Time Messages (notices) [#27515]
## [2.2.39] - 2023-01-25
### Changed
- Minor internal updates.
## [2.2.38] - 2023-01-23
### Fixed
- Prevent the activation page from displaying the JP License Activation JITM. [#27959]
## [2.2.37] - 2023-01-11
### Changed
- Updated package dependencies.
## [2.2.36] - 2022-12-27
### Removed
- Remove src/js files from final bundle [#27930]
## [2.2.35] - 2022-12-02
### Changed
- Updated package dependencies. [#27696]
@ -514,6 +550,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update Jetpack to use new JITM package
[2.3.1]: https://github.com/Automattic/jetpack-jitm/compare/v2.3.0...v2.3.1
[2.3.0]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.42...v2.3.0
[2.2.42]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.41...v2.2.42
[2.2.41]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.40...v2.2.41
[2.2.40]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.39...v2.2.40
[2.2.39]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.38...v2.2.39
[2.2.38]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.37...v2.2.38
[2.2.37]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.36...v2.2.37
[2.2.36]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.35...v2.2.36
[2.2.35]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.34...v2.2.35
[2.2.34]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.33...v2.2.34
[2.2.33]: https://github.com/Automattic/jetpack-jitm/compare/v2.2.32...v2.2.33

View File

@ -1 +1 @@
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '00af8e5432ff8e29efed');
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '7c399cb086c6eb967ade');

View File

@ -1 +1 @@
!function(){"use strict";jQuery(document).ready((function(t){var a={default:function(a){var e='<div class="jitm-card jitm-banner '+(a.CTA.message?"has-call-to-action":"")+" is-upgrade-premium "+a.content.classes+'" data-stats_url="'+a.jitm_stats_url+'">';if(e+='<div class="jitm-banner__content">',e+='<div class="jitm-banner__icon-plan">'+a.content.icon+"</div>",e+='<div class="jitm-banner__info">',e+='<div class="jitm-banner__title">'+a.content.message+"</div>",a.content.description&&""!==a.content.description){if(e+='<div class="jitm-banner__description">'+a.content.description,a.content.list.length>0){e+='<ul class="banner__list">';for(var i=0;i<a.content.list.length;i++){var n=a.content.list[i].item;a.content.list[i].url&&(n='<a href="'+a.content.list[i].url+'" target="_blank" rel="noopener noreferrer" data-module="'+a.feature_class+'" data-jptracks-name="nudge_item_click" data-jptracks-prop="jitm-'+a.id+'">'+n+"</a>"),e+='<li><svg class="gridicon gridicons-checkmark" height="16" width="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M9 19.414l-6.707-6.707 1.414-1.414L9 16.586 20.293 5.293l1.414 1.414" /></g></svg>'+n+"</li>"}}e+="</div>"}if(e+="</div>",e+="</div>",e+='<div class="jitm-banner__buttons_container">',a.activate_module&&(e+='<div class="jitm-banner__action" id="jitm-banner__activate">',e+='<a href="#" data-module="'+a.activate_module+'" type="button" class="jitm-button is-compact is-primary jptracks" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-'+a.id+'-activate_module">'+window.jitm_config.activate_module_text+"</a>",e+="</div>"),a.CTA.message){var c="jitm-button is-compact jptracks";a.CTA.primary&&null===a.activate_module&&(c+=" is-primary");var o=a.CTA.ajax_action;e+='<div class="jitm-banner__action">',e+='<a href="'+(a.CTA.hasOwnProperty("link")&&a.CTA.link.length?a.CTA.link:a.url)+'" target="'+(!1===a.CTA.newWindow||o?"_self":"_blank")+'" rel="noopener noreferrer" title="'+a.CTA.message+'" data-module="'+a.feature_class+'" type="button" class="'+c+'" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-'+a.id+'" '+(o?'data-ajax-action="'+o+'"':"")+">"+a.CTA.message+"</a>",e+="</div>"}return e+="</div>",a.is_dismissible&&(e+='<a href="#" data-module="'+a.feature_class+'" class="jitm-banner__dismiss"></a>'),t(e+="</div>")}},e=function(){t(".jetpack-jitm-message").each((function(){var e=t(this),i=e.data("message-path"),n=e.data("query"),c=e.data("redirect"),o=location.hash;"_dashboard"!==(o=o.replace(/#\//,"_"))&&(i=i.replace("toplevel_page_jetpack","toplevel_page_jetpack"+o));var r=!!t(".jetpack-logo__masthead").length;t.get(window.jitm_config.api_root+"jetpack/v4/jitm",{message_path:i,query:n,full_jp_logo_exists:r,_wpnonce:e.data("nonce")}).then((function(i){"object"==typeof i&&i[1]&&(i=[i[1]]),0!==i.length&&i[0].content&&function(e,i,n){var c;(c=i.template)&&a[c]||(c="default"),i.url=i.url+"&redirect="+n;var o,r=a[c](i);r.find(".jitm-banner__dismiss").on("click",(o=r,function(a){a.preventDefault(),o.hide(),t.ajax({url:window.jitm_config.api_root+"jetpack/v4/jitm",method:"POST",beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",window.jitm_config.nonce)},data:{id:i.id,feature_class:i.feature_class}})})),t("#jp-admin-notices").length>0?(e.innerHTML=r,t("#jp-admin-notices").find(".jitm-card")&&t(".jitm-card").replaceWith(r),r.prependTo(t("#jp-admin-notices"))):e.replaceWith(r),r.find("#jitm-banner__activate a").on("click",(function(){var a=t(this);if(a.attr("disabled"))return!1;t.ajax({url:window.jitm_config.api_root+"jetpack/v4/module/"+a.data("module")+"/active",method:"POST",beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",e.data("nonce")),t("#jitm-banner__activate a").text(window.jitm_config.activating_module_text),t("#jitm-banner__activate a").attr("disabled",!0)}}).done((function(){t("#jitm-banner__activate a").text(window.jitm_config.activated_module_text),t("#jitm-banner__activate a").attr("disabled",!0),setTimeout((function(){r.fadeOut("slow")}),2e3)}))})),r.find(".jitm-button[data-ajax-action]").on("click",(function(a){a.preventDefault();var i=t(this);return i.attr("disabled",!0),t.post(window.ajaxurl,{action:i.data("ajax-action"),_nonce:e.data("ajax-nonce")}).done((function(){r.fadeOut("slow")})).fail((function(){i.attr("disabled",!1)})),!1}))}(e,i[0],c)}))}))};e(),t(window).on("hashchange",(function(t){if(t.originalEvent.newURL.indexOf("jetpack#/")>=0){var a=document.querySelector(".jitm-card");a&&a.remove(),e()}}))}))}();
!function(){"use strict";jQuery(document).ready((function(t){var a={default:function(a){var e='<div class="jitm-card jitm-banner '+(a.CTA.message?"has-call-to-action":"")+" is-upgrade-premium "+a.content.classes+'" data-stats_url="'+a.jitm_stats_url+'">';if(e+='<div class="jitm-banner__content">',e+='<div class="jitm-banner__icon-plan">'+a.content.icon+"</div>",e+='<div class="jitm-banner__info">',e+='<div class="jitm-banner__title">'+a.content.message+"</div>",a.content.description&&""!==a.content.description){if(e+='<div class="jitm-banner__description">'+a.content.description,a.content.list.length>0){e+='<ul class="banner__list">';for(var n=0;n<a.content.list.length;n++){var i=a.content.list[n].item;a.content.list[n].url&&(i='<a href="'+a.content.list[n].url+'" target="_blank" rel="noopener noreferrer" data-module="'+a.feature_class+'" data-jptracks-name="nudge_item_click" data-jptracks-prop="jitm-'+a.id+'">'+i+"</a>"),e+='<li><svg class="gridicon gridicons-checkmark" height="16" width="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path d="M9 19.414l-6.707-6.707 1.414-1.414L9 16.586 20.293 5.293l1.414 1.414" /></g></svg>'+i+"</li>"}}e+="</div>"}if(e+="</div>",e+="</div>",e+='<div class="jitm-banner__buttons_container">',a.activate_module&&(e+='<div class="jitm-banner__action" id="jitm-banner__activate">',e+='<a href="#" data-module="'+a.activate_module+'" type="button" class="jitm-button is-compact is-primary jptracks" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-'+a.id+'-activate_module">'+window.jitm_config.activate_module_text+"</a>",e+="</div>"),a.CTA.message){var c="jitm-button is-compact jptracks";a.CTA.primary&&null===a.activate_module&&(c+=" is-primary");var o=a.CTA.ajax_action;e+='<div class="jitm-banner__action">',e+='<a href="'+(a.CTA.hasOwnProperty("link")&&a.CTA.link.length?a.CTA.link:a.url)+'" target="'+(!1===a.CTA.newWindow||o?"_self":"_blank")+'" rel="noopener noreferrer" title="'+a.CTA.message+'" data-module="'+a.feature_class+'" type="button" class="'+c+'" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-'+a.id+'" '+(o?'data-ajax-action="'+o+'"':"")+">"+a.CTA.message+"</a>",e+="</div>"}return e+="</div>",a.is_dismissible&&(e+='<a href="#" data-module="'+a.feature_class+'" class="jitm-banner__dismiss"></a>'),t(e+="</div>")}},e=function(){t(".jetpack-jitm-message").each((function(){var e=t(this),n=e.data("message-path"),i=e.data("query"),c=e.data("redirect"),o=location.hash;o=o.replace(/#\//,"_"),n.includes("jetpack_page_my-jetpack")?n=n.replace("jetpack_page_my-jetpack","jetpack_page_my-jetpack"+o):"_dashboard"!==o&&(n=n.replace("toplevel_page_jetpack","toplevel_page_jetpack"+o));var r=!!t(".jetpack-logo__masthead").length;t.get(window.jitm_config.api_root+"jetpack/v4/jitm",{message_path:n,query:i,full_jp_logo_exists:r,_wpnonce:e.data("nonce")}).then((function(n){"object"==typeof n&&n[1]&&(n=[n[1]]),0!==n.length&&n[0].content&&function(e,n,i){var c;(c=n.template)&&a[c]||(c="default"),n.url=n.url+"&redirect="+i;var o,r=a[c](n);r.find(".jitm-banner__dismiss").on("click",(o=r,function(a){a.preventDefault(),o.hide(),t.ajax({url:window.jitm_config.api_root+"jetpack/v4/jitm",method:"POST",beforeSend:function(t){t.setRequestHeader("X-WP-Nonce",window.jitm_config.nonce)},data:{id:n.id,feature_class:n.feature_class}})})),t("#jp-admin-notices").length>0?(e.innerHTML=r,t("#jp-admin-notices").find(".jitm-card")&&t(".jitm-card").replaceWith(r),r.prependTo(t("#jp-admin-notices"))):e.replaceWith(r),r.find("#jitm-banner__activate a").on("click",(function(){var a=t(this);if(a.attr("disabled"))return!1;t.ajax({url:window.jitm_config.api_root+"jetpack/v4/module/"+a.data("module")+"/active",method:"POST",beforeSend:function(a){a.setRequestHeader("X-WP-Nonce",e.data("nonce")),t("#jitm-banner__activate a").text(window.jitm_config.activating_module_text),t("#jitm-banner__activate a").attr("disabled",!0)}}).done((function(){t("#jitm-banner__activate a").text(window.jitm_config.activated_module_text),t("#jitm-banner__activate a").attr("disabled",!0),setTimeout((function(){r.fadeOut("slow")}),2e3)}))})),r.find(".jitm-button[data-ajax-action]").on("click",(function(a){a.preventDefault();var n=t(this);return n.attr("disabled",!0),t.post(window.ajaxurl,{action:n.data("ajax-action"),_nonce:e.data("ajax-nonce")}).done((function(){r.fadeOut("slow")})).fail((function(){n.attr("disabled",!1)})),!1}))}(e,n[0],c)}))}))};e(),t(window).on("hashchange",(function(t){const a=t.originalEvent.newURL;if(a.indexOf("jetpack#/")>=0||a.indexOf("my-jetpack")>=0){var n=document.querySelector(".jitm-card");n&&n.remove(),e()}}))}))}();

View File

@ -4,19 +4,19 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.17",
"automattic/jetpack-assets": "^1.17.28",
"automattic/jetpack-connection": "^1.47.1",
"automattic/jetpack-device-detection": "^1.4.22",
"automattic/jetpack-logo": "^1.5.20",
"automattic/jetpack-partner": "^1.7.21",
"automattic/jetpack-redirect": "^1.7.21",
"automattic/jetpack-status": "^1.15.2"
"automattic/jetpack-a8c-mc-stats": "^1.4.19",
"automattic/jetpack-assets": "^1.17.33",
"automattic/jetpack-connection": "^1.51.1",
"automattic/jetpack-device-detection": "^1.4.24",
"automattic/jetpack-logo": "^1.5.22",
"automattic/jetpack-partner": "^1.7.22",
"automattic/jetpack-redirect": "^1.7.24",
"automattic/jetpack-status": "^1.16.2"
},
"require-dev": {
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -33,11 +33,12 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
],
"watch": [
"Composer\\Config::disableProcessTimeout",
"pnpm run watch"
]
},
"minimum-stability": "dev",
@ -53,7 +54,7 @@
"link-template": "https://github.com/Automattic/jetpack-jitm/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "2.2.x-dev"
"dev-trunk": "2.3.x-dev"
}
}
}

View File

@ -20,7 +20,7 @@ use Automattic\Jetpack\Status;
*/
class JITM {
const PACKAGE_VERSION = '2.2.35';
const PACKAGE_VERSION = '2.3.1';
/**
* The configuration method that is called from the jetpack-config package.

View File

@ -40,31 +40,6 @@ class Post_Connection_JITM extends JITM {
$this->tracking = new Tracking();
}
/**
* Prepare actions according to screen and post type.
*
* @since 1.1.0
* @since-jetpack 3.8.2
*
* @uses Jetpack_Autoupdate::get_possible_failures()
*
* @param \WP_Screen $screen WP Core's screen object.
*/
public function prepare_jitms( $screen ) {
parent::prepare_jitms( $screen );
if ( ! in_array(
$screen->id,
array(
'jetpack_page_akismet-key-config',
'admin_page_jetpack_modules',
),
true
) ) {
// Not really a JITM. Don't know where else to put this :) .
add_action( 'admin_notices', array( $this, 'delete_user_update_connection_owner_notice' ) );
}
}
/**
* A special filter for WooCommerce, to set a message based on local state.
*
@ -229,172 +204,6 @@ class Post_Connection_JITM extends JITM {
);
}
/**
* This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete
* the connection owner.
*/
public function delete_user_update_connection_owner_notice() {
global $current_screen;
/*
* phpcs:disable WordPress.Security.NonceVerification.Recommended
*
* This function is firing within wp-admin and checks (below) if it is in the midst of a deletion on the users
* page. Nonce will be already checked by WordPress, so we do not need to check ourselves.
*/
if ( ! isset( $current_screen->base ) || 'users' !== $current_screen->base ) {
return;
}
if ( ! isset( $_REQUEST['action'] ) || 'delete' !== $_REQUEST['action'] ) {
return;
}
// Get connection owner or bail.
$connection_manager = new Manager();
$connection_owner_id = $connection_manager->get_connection_owner_id();
if ( ! $connection_owner_id ) {
return;
}
$connection_owner_userdata = get_userdata( $connection_owner_id );
// Bail if we're not trying to delete connection owner.
$user_ids_to_delete = array();
if ( isset( $_REQUEST['users'] ) ) {
$user_ids_to_delete = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['users'] ) );
} elseif ( isset( $_REQUEST['user'] ) ) {
$user_ids_to_delete[] = sanitize_text_field( wp_unslash( $_REQUEST['user'] ) );
}
// phpcs:enable
$user_ids_to_delete = array_map( 'absint', $user_ids_to_delete );
$deleting_connection_owner = in_array( $connection_owner_id, (array) $user_ids_to_delete, true );
if ( ! $deleting_connection_owner ) {
return;
}
// Bail if they're trying to delete themselves to avoid confusion.
if ( get_current_user_id() === $connection_owner_id ) {
return;
}
// Track it!
if ( method_exists( $this->tracking, 'record_user_event' ) ) {
$this->tracking->record_user_event( 'delete_connection_owner_notice_view' );
}
$connected_admins = $connection_manager->get_connected_users( 'jetpack_disconnect' );
$user = is_a( $connection_owner_userdata, 'WP_User' ) ? esc_html( $connection_owner_userdata->data->user_login ) : '';
echo "<div class='notice notice-warning' id='jetpack-notice-switch-connection-owner'>";
echo '<h2>' . esc_html__( 'Important notice about your Jetpack connection:', 'jetpack-jitm' ) . '</h2>';
echo '<p>' . sprintf(
/* translators: WordPress User, if available. */
esc_html__( 'Warning! You are about to delete the Jetpack connection owner (%s) for this site, which may cause some of your Jetpack features to stop working.', 'jetpack-jitm' ),
esc_html( $user )
) . '</p>';
if ( ! empty( $connected_admins ) && count( $connected_admins ) > 1 ) {
echo '<form id="jp-switch-connection-owner" action="" method="post">';
echo "<label for='owner'>" . esc_html__( 'You can choose to transfer connection ownership to one of these already-connected admins:', 'jetpack-jitm' ) . ' </label>';
$connected_admin_ids = array_map(
function ( $connected_admin ) {
return $connected_admin->ID;
},
$connected_admins
);
wp_dropdown_users(
array(
'name' => 'owner',
'include' => array_diff( $connected_admin_ids, array( $connection_owner_id ) ),
'show' => 'display_name_with_login',
)
);
echo '<p>';
submit_button( esc_html__( 'Set new connection owner', 'jetpack-jitm' ), 'primary', 'jp-switch-connection-owner-submit', false );
echo '</p>';
echo "<div id='jp-switch-user-results'></div>";
echo '</form>';
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
$( '#jp-switch-connection-owner' ).on( 'submit', function( e ) {
var formData = $( this ).serialize();
var submitBtn = document.getElementById( 'jp-switch-connection-owner-submit' );
var results = document.getElementById( 'jp-switch-user-results' );
submitBtn.disabled = true;
$.ajax( {
type : "POST",
url : "<?php echo esc_url( get_rest_url() . 'jetpack/v4/connection/owner' ); ?>",
data : formData,
headers : {
'X-WP-Nonce': "<?php echo esc_js( wp_create_nonce( 'wp_rest' ) ); ?>",
},
success: function() {
results.innerHTML = "<?php esc_html_e( 'Success!', 'jetpack-jitm' ); ?>";
setTimeout( function() {
$( '#jetpack-notice-switch-connection-owner' ).hide( 'slow' );
}, 1000 );
}
} ).done( function() {
submitBtn.disabled = false;
} );
e.preventDefault();
return false;
} );
} );
</script>
<?php
} else {
echo '<p>' . esc_html__( 'Every Jetpack site needs at least one connected admin for the features to work properly. Please connect to your WordPress.com account via the button below. Once you connect, you may refresh this page to see an option to change the connection owner.', 'jetpack-jitm' ) . '</p>';
$connect_url = $connection_manager->get_authorization_url();
$connect_url = add_query_arg( 'from', 'delete_connection_owner_notice', $connect_url );
echo "<a href='" . esc_url( $connect_url ) . "' target='_blank' rel='noopener noreferrer' class='button-primary'>" . esc_html__( 'Connect to WordPress.com', 'jetpack-jitm' ) . '</a>';
}
echo '<p>';
printf(
wp_kses(
/* translators: URL to Jetpack support doc regarding the primary user. */
__( "<a href='%s' target='_blank' rel='noopener noreferrer'>Learn more</a> about the connection owner and what will break if you do not have one.", 'jetpack-jitm' ),
array(
'a' => array(
'href' => true,
'target' => true,
'rel' => true,
),
)
),
esc_url( Redirect::get_url( 'jetpack-support-primary-user' ) )
);
echo '</p>';
echo '<p>';
printf(
wp_kses(
/* translators: URL to contact Jetpack support. */
__( 'As always, feel free to <a href="%s" target="_blank" rel="noopener noreferrer">contact our support team</a> if you have any questions.', 'jetpack-jitm' ),
array(
'a' => array(
'href' => true,
'target' => true,
'rel' => true,
),
)
),
esc_url( Redirect::get_url( 'jetpack-contact-support' ) )
);
echo '</p>';
echo '</div>';
}
/**
* Dismisses a JITM feature class so that it will no longer be shown.
*

View File

@ -39,7 +39,6 @@ class Rest_Api_Endpoints {
'permission_callback' => __CLASS__ . '::delete_jitm_message_permission_callback',
)
);
}
/**

View File

@ -17,31 +17,32 @@
}
@mixin jitm-banner-color( $color ) {
border-left-color: $color;
&::before {
background-color: $color;
}
.jitm-banner__icon {
color: $color;
}
.jitm-banner__icon-circle {
background-color: $color;
}
}
// New JITMS - modified calypso banner styles
$blue-grey-light: #f6f7f7;
$blue-medium-dark: #2271b1;
$jp-gray: #dcdcde;
$jp-gray-20: #a7aaad;
.jitm-button {
background: $blue-grey-light;
border-color: $blue-medium-dark;
border-style: solid;
border-width: 1px;
color: $blue-medium-dark;
cursor: pointer;
display: inline-block;
margin: 0;
outline: 0;
overflow: hidden;
font-size: 14px;
text-overflow: ellipsis;
text-decoration: none;
vertical-align: top;
@ -53,34 +54,42 @@ $blue-medium-dark: #2271b1;
appearance: none;
text-align: center;
min-width: 90px;
font-weight: 600;
border-color: black;
background: $white;
color: black;
&:hover {
background: #f0f0f1;
border-color: $blue-grey-dark;
color: $blue-grey-dark;
// Primary buttons
&.is-primary {
background: black;
color: $white;
}
&[disabled],
&:disabled {
color: lighten( $gray, 30% );
background: $white;
border-color: lighten( $gray, 30% );
cursor: default;
&:hover,
&:focus {
border-color: $gray-dark;
background: $gray-dark;
color: $white;
}
&:focus {
background: $white;
border-color: $blue-medium-dark;
box-shadow: 0 0 0 1px $blue-medium-dark;
box-shadow:
0 0 0 1px $white,
0 0 0 3px $blue-medium-dark;
}
&[disabled],
&:disabled {
color: $jp-gray-20;
background: $jp-gray;
border-color: $jp-gray;
cursor: default;
}
&.is-compact {
padding: 7px;
font-size: 11px;
padding: 12px;
font-size: 14px;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
&:disabled {
color: lighten( $gray, 30% );
}
.gridicon {
top: 4px;
margin-top: -8px;
@ -103,48 +112,20 @@ $blue-medium-dark: #2271b1;
}
}
// Primary buttons
.jitm-button.is-primary {
background: $blue-medium;
border-color: $blue-medium;
color: $white;
&:hover,
&:focus {
border-color: $blue-medium-dark;
background: $blue-medium-dark;
color: $white;
}
&:focus {
box-shadow:
0 0 0 1px $white,
0 0 0 3px $blue-medium-dark;
}
&[disabled],
&:disabled {
background: tint( $blue-light, 50% );
border-color: tint( $blue-wordpress, 55% );
color: $white;
}
&.is-compact {
color: $white;
white-space: nowrap;
}
}
.jitm-card {
display: block;
clear: both;
position: relative;
margin: rem( 48px ) rem( 20px ) 0 auto;
padding: rem( 16px );
padding: 16px ;
box-sizing: border-box;
background: $white;
box-shadow:
0 0 0 1px $light-gray-700,
0 1px 1px 1px rgba(0,0,0,.04);
background-color: $white;
background-image: url( "../images/background.png" );
background-repeat: no-repeat;
background-position: right center;
border: 1px solid $white;
border-radius: 2px;
box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.16);
@include clear-fix;
@ -197,15 +178,23 @@ $blue-medium-dark: #2271b1;
}
.jitm-banner.jitm-card {
border-left: 4px solid;
display: flex;
padding: rem( 12px ) rem( 6px ) rem( 12px ) rem( 12px );
position: relative;
z-index: 2;
&::before {
content: '';
width: 4px;
position: absolute;
top: 0;
left: 0;
height: 100%;
border-top-left-radius: 1px;
border-bottom-left-radius: 1px;
}
@include breakpoint( "<480px" ) {
display: flex;
padding: rem( 12px );
flex-direction: column;
}
@ -222,7 +211,7 @@ $blue-medium-dark: #2271b1;
@include jitm-banner-color( $alert-yellow );
}
&.is-upgrade-premium {
@include jitm-banner-color( $alert-green );
@include jitm-banner-color( #069e08 );
}
&.is-upgrade-business,
&.woo-jitm {
@ -255,14 +244,9 @@ $blue-medium-dark: #2271b1;
}
.jitm-banner__buttons_container {
display: grid;
display: flex;
height: 50%;
margin-top: auto;
margin-bottom: auto;
@include breakpoint( ">480px" ) {
display: flex;
}
margin: auto 16px auto;
}
.jitm-banner__icons {
@ -329,7 +313,7 @@ $blue-medium-dark: #2271b1;
.jitm-jp-logo {
height: inherit;
width: 6rem;
width: rem( 42px );
fill: inherit;
}
}
@ -358,7 +342,6 @@ $blue-medium-dark: #2271b1;
}
@include breakpoint( "<960px" ) {
display: grid;
margin-right: 5px;
}
}
@ -376,18 +359,19 @@ $blue-medium-dark: #2271b1;
}
.jitm-banner__title,
.jitm-banner__description {
color: $gray-dark;
.jitm-banner__description,
.jitm-banner__description a {
color: black;
}
.jitm-banner__title {
font-size: 14px;
font-weight: 500;
font-size: 16px;
font-weight: 700;
}
.jitm-banner__description {
font-size: rem( 12px );
line-height: 1.5;
font-size: rem( 14px );
line-height: 1.4;
margin-top: rem( 6px );
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,269 +0,0 @@
import '../css/jetpack-admin-jitm.scss';
jQuery( document ).ready( function ( $ ) {
var templates = {
default: function ( envelope ) {
var html =
'<div class="jitm-card jitm-banner ' +
( envelope.CTA.message ? 'has-call-to-action' : '' ) +
' is-upgrade-premium ' +
envelope.content.classes +
'" data-stats_url="' +
envelope.jitm_stats_url +
'">';
html += '<div class="jitm-banner__content">';
html += '<div class="jitm-banner__icon-plan">' + envelope.content.icon + '</div>';
html += '<div class="jitm-banner__info">';
html += '<div class="jitm-banner__title">' + envelope.content.message + '</div>';
if ( envelope.content.description && envelope.content.description !== '' ) {
html += '<div class="jitm-banner__description">' + envelope.content.description;
if ( envelope.content.list.length > 0 ) {
html += '<ul class="banner__list">';
for ( var i = 0; i < envelope.content.list.length; i++ ) {
var text = envelope.content.list[ i ].item;
if ( envelope.content.list[ i ].url ) {
text =
'<a href="' +
envelope.content.list[ i ].url +
'" target="_blank" rel="noopener noreferrer" data-module="' +
envelope.feature_class +
'" data-jptracks-name="nudge_item_click" data-jptracks-prop="jitm-' +
envelope.id +
'">' +
text +
'</a>';
}
html +=
'<li>' +
'<svg class="gridicon gridicons-checkmark" height="16" width="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g>' +
'<path d="M9 19.414l-6.707-6.707 1.414-1.414L9 16.586 20.293 5.293l1.414 1.414" /></g></svg>' +
text +
'</li>';
}
}
html += '</div>';
}
html += '</div>';
html += '</div>';
html += '<div class="jitm-banner__buttons_container">';
if ( envelope.activate_module ) {
html += '<div class="jitm-banner__action" id="jitm-banner__activate">';
html +=
'<a href="#" data-module="' +
envelope.activate_module +
'" type="button" class="jitm-button is-compact is-primary jptracks" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-' +
envelope.id +
'-activate_module">' +
window.jitm_config.activate_module_text +
'</a>';
html += '</div>';
}
if ( envelope.CTA.message ) {
var ctaClasses = 'jitm-button is-compact jptracks';
if ( envelope.CTA.primary && null === envelope.activate_module ) {
ctaClasses += ' is-primary';
}
var ajaxAction = envelope.CTA.ajax_action;
html += '<div class="jitm-banner__action">';
html +=
'<a href="' +
( envelope.CTA.hasOwnProperty( 'link' ) && envelope.CTA.link.length
? envelope.CTA.link
: envelope.url ) +
'" target="' +
( envelope.CTA.newWindow === false || ajaxAction ? '_self' : '_blank' ) +
'" rel="noopener noreferrer" title="' +
envelope.CTA.message +
'" data-module="' +
envelope.feature_class +
'" type="button" class="' +
ctaClasses +
'" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-' +
envelope.id +
'" ' +
( ajaxAction ? 'data-ajax-action="' + ajaxAction + '"' : '' ) +
'>' +
envelope.CTA.message +
'</a>';
html += '</div>';
}
html += '</div>';
if ( envelope.is_dismissible ) {
html +=
'<a href="#" data-module="' +
envelope.feature_class +
'" class="jitm-banner__dismiss"></a>';
}
html += '</div>';
return $( html );
},
};
var setJITMContent = function ( $el, response, redirect ) {
var template;
var render = function ( $my_template ) {
return function ( e ) {
e.preventDefault();
$my_template.hide();
$.ajax( {
url: window.jitm_config.api_root + 'jetpack/v4/jitm',
method: 'POST', // using DELETE without permalinks is broken in default nginx configuration
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', window.jitm_config.nonce );
},
data: {
id: response.id,
feature_class: response.feature_class,
},
} );
};
};
template = response.template;
// if we don't have a template for this version, just use the default template
if ( ! template || ! templates[ template ] ) {
template = 'default';
}
response.url = response.url + '&redirect=' + redirect;
var $template = templates[ template ]( response );
$template.find( '.jitm-banner__dismiss' ).on( 'click', render( $template ) );
if ( $( '#jp-admin-notices' ).length > 0 ) {
// Add to Jetpack notices within the Jetpack settings app.
$el.innerHTML = $template;
// If we already have a message, replace it.
if ( $( '#jp-admin-notices' ).find( '.jitm-card' ) ) {
$( '.jitm-card' ).replaceWith( $template );
}
// No existing JITM? Add ours to the top of the Jetpack admin notices.
$template.prependTo( $( '#jp-admin-notices' ) );
} else {
// Replace placeholder div on other pages.
$el.replaceWith( $template );
}
// Handle Module activation button if it exists.
$template.find( '#jitm-banner__activate a' ).on( 'click', function () {
var $activate_button = $( this );
// Do not allow any requests if the button is disabled.
if ( $activate_button.attr( 'disabled' ) ) {
return false;
}
// Make request to activate module.
$.ajax( {
url:
window.jitm_config.api_root +
'jetpack/v4/module/' +
$activate_button.data( 'module' ) +
'/active',
method: 'POST',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', $el.data( 'nonce' ) );
// Change the button status to disabled as the change is in progress.
$( '#jitm-banner__activate a' ).text( window.jitm_config.activating_module_text );
$( '#jitm-banner__activate a' ).attr( 'disabled', true );
},
} ).done( function () {
$( '#jitm-banner__activate a' ).text( window.jitm_config.activated_module_text );
$( '#jitm-banner__activate a' ).attr( 'disabled', true );
// Hide the JITM after 2 seconds.
setTimeout( function () {
$template.fadeOut( 'slow' );
}, 2000 );
} );
} );
// Handle CTA ajax actions.
$template.find( '.jitm-button[data-ajax-action]' ).on( 'click', function ( e ) {
e.preventDefault();
var button = $( this );
button.attr( 'disabled', true );
$.post( window.ajaxurl, {
action: button.data( 'ajax-action' ),
_nonce: $el.data( 'ajax-nonce' ),
} )
.done( function () {
$template.fadeOut( 'slow' );
} )
.fail( function () {
button.attr( 'disabled', false );
} );
return false;
} );
};
var reFetch = function () {
$( '.jetpack-jitm-message' ).each( function () {
var $el = $( this );
var message_path = $el.data( 'message-path' );
var query = $el.data( 'query' );
var redirect = $el.data( 'redirect' );
var hash = location.hash;
hash = hash.replace( /#\//, '_' );
if ( '_dashboard' !== hash ) {
message_path = message_path.replace(
'toplevel_page_jetpack',
'toplevel_page_jetpack' + hash
);
}
var full_jp_logo_exists = $( '.jetpack-logo__masthead' ).length ? true : false;
$.get( window.jitm_config.api_root + 'jetpack/v4/jitm', {
message_path: message_path,
query: query,
full_jp_logo_exists: full_jp_logo_exists,
_wpnonce: $el.data( 'nonce' ),
} ).then( function ( response ) {
if ( 'object' === typeof response && response[ '1' ] ) {
response = [ response[ '1' ] ];
}
// properly handle the case of an empty array or no content set
if ( 0 === response.length || ! response[ 0 ].content ) {
return;
}
// for now, always take the first response
setJITMContent( $el, response[ 0 ], redirect );
} );
} );
};
reFetch();
$( window ).on( 'hashchange', function ( e ) {
var newURL = e.originalEvent.newURL;
if ( newURL.indexOf( 'jetpack#/' ) >= 0 ) {
var jitm_card = document.querySelector( '.jitm-card' );
if ( jitm_card ) {
jitm_card.remove();
}
reFetch();
}
} );
} );

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.8.1] - 2023-02-20
### Changed
- Minor internal updates.
## [1.8.0] - 2023-02-08
### Added
- After connection flow, load unattached licenses. If any of them match the product that's being connected, redirect users to the license activation page. [#28509]
## [1.7.14] - 2023-01-11
### Changed
- Updated package dependencies.
## [1.7.13] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -226,6 +238,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Licensing: Add support for Jetpack licenses
[1.8.1]: https://github.com/Automattic/jetpack-licensing/compare/v1.8.0...v1.8.1
[1.8.0]: https://github.com/Automattic/jetpack-licensing/compare/v1.7.14...v1.8.0
[1.7.14]: https://github.com/Automattic/jetpack-licensing/compare/v1.7.13...v1.7.14
[1.7.13]: https://github.com/Automattic/jetpack-licensing/compare/v1.7.12...v1.7.13
[1.7.12]: https://github.com/Automattic/jetpack-licensing/compare/v1.7.11...v1.7.12
[1.7.11]: https://github.com/Automattic/jetpack-licensing/compare/v1.7.10...v1.7.11

View File

@ -4,12 +4,12 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.47.1"
"automattic/jetpack-connection": "^1.51.0"
},
"require-dev": {
"automattic/wordbless": "@dev",
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -22,9 +22,6 @@
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]
@ -39,7 +36,7 @@
"link-template": "https://github.com/Automattic/jetpack-licensing/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.7.x-dev"
"dev-trunk": "1.8.x-dev"
}
},
"config": {

View File

@ -182,7 +182,6 @@ class Endpoints {
}
return new WP_Error( 'invalid_user_permission_set_jetpack_license_key', self::$user_permissions_error_msg, array( 'status' => rest_authorization_required_code() ) );
}
/**

View File

@ -283,4 +283,77 @@ class Licensing {
return $default;
}
/**
* Load current user's licenses.
*
* @param bool $unattached_only Only return unattached licenses.
*
* @return array
*/
public function get_user_licenses( $unattached_only = false ) {
$licenses = Endpoints::get_user_licenses();
if ( empty( $licenses->items ) ) {
return array();
}
$items = $licenses->items;
if ( $unattached_only ) {
$items = array_filter(
$items,
static function ( $item ) {
return $item->attached_at === null;
}
);
}
return $items;
}
/**
* If the destination URL is checkout page,
* see if there are unattached licenses they could use instead of getting a new one.
* If found, redirect the user to license activation.
*
* @param string $dest_url User's destination URL.
*
* @return void
*/
public function handle_user_connected_redirect( $dest_url ) {
if ( ! preg_match( '#^https://[^/]+/checkout/#i', $dest_url ) ) {
return;
}
$licenses = $this->get_user_licenses( true );
$plugin_slug = null;
$query_string = wp_parse_url( $dest_url, PHP_URL_QUERY );
if ( $query_string ) {
parse_str( $query_string, $query_args );
if ( $query_args['redirect_to']
&& preg_match( '/^admin\.php\?page=(jetpack-\w+)/i', $query_args['redirect_to'], $matches )
) {
$plugin_slug = $matches[1];
}
}
/**
* Check for the user's unattached licenses.
*
* @since 3.8.2
*
* @param bool $has_license Whether a license was already found.
* @param array $licenses Unattached licenses belonging to the user.
* @param string $plugin_slug Slug of the plugin that initiated the flow.
*/
if ( $plugin_slug && count( $licenses )
&& apply_filters( 'jetpack_connection_user_has_license', false, $licenses, $plugin_slug )
) {
wp_safe_redirect( '/wp-admin/admin.php?page=my-jetpack#/add-license' );
exit;
}
}
}

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.5.22] - 2023-02-20
### Changed
- Minor internal updates.
## [1.5.21] - 2023-01-30
### Changed
- Updated styles for Just in Time Messages (notices) [#27515]
## [1.5.20] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -138,6 +146,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Packages: Add a basic Jetpack Logo package
[1.5.22]: https://github.com/Automattic/jetpack-logo/compare/v1.5.21...v1.5.22
[1.5.21]: https://github.com/Automattic/jetpack-logo/compare/v1.5.20...v1.5.21
[1.5.20]: https://github.com/Automattic/jetpack-logo/compare/v1.5.19...v1.5.20
[1.5.19]: https://github.com/Automattic/jetpack-logo/compare/v1.5.18...v1.5.19
[1.5.18]: https://github.com/Automattic/jetpack-logo/compare/v1.5.17...v1.5.18

View File

@ -6,7 +6,7 @@
"require": {},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2"
"automattic/jetpack-changelogger": "^3.3.2"
},
"autoload": {
"classmap": [
@ -17,9 +17,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]

View File

@ -64,11 +64,17 @@ class Logo {
/**
* Return string containing the Jetpack logo in a slightly larger format than get_jp_emblem().
*
* @since 1.1.4
* @param bool $logotype Should we use the full logotype (logo + text). Default to false.
* @return string
*/
public function get_jp_emblem_larger() {
public function get_jp_emblem_larger( $logotype = false ) {
$logo_text = $this->get_jp_logo_parts();
return '<svg class="jitm-jp-logo" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" height="32" viewBox="0 0 118 32">' . $logo_text['logo'] . $logo_text['text'] . '</svg>';
return sprintf(
'<svg class="jitm-jp-logo" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" height="32" viewBox="0 0 %1$s 32">%2$s</svg>',
( true === $logotype ? '118' : '32' ),
( true === $logotype ? $logo_text['logo'] . $logo_text['text'] : $logo_text['logo'] )
);
}
/**

View File

@ -5,6 +5,78 @@ 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).
## [2.7.13] - 2023-03-07
### Changed
- Updated package dependencies. [#29289]
## [2.7.12] - 2023-02-28
### Changed
- Update billing language [#29126]
## [2.7.11] - 2023-02-20
### Fixed
- My Jetpack: Fix button to add bundle in product interstitial component [#28984]
## [2.7.10] - 2023-02-15
### Changed
- Update to React 18. [#28710]
## [2.7.9] - 2023-02-08
### Changed
- Updated package dependencies. [#28682, #28700]
## [2.7.8] - 2023-02-06
### Changed
- Updated package dependencies.
## [2.7.7] - 2023-01-26
### Changed
- Use `flex-start` instead of `start` for better browser compatibility. [#28530]
## [2.7.6] - 2023-01-25
### Changed
- Minor internal updates.
## [2.7.5] - 2023-01-23
### Fixed
- Components: Fix usage of box-sizing across the elements [#28489]
- Fixes the price display for products with intro offers for the first month. [#28424]
## [2.7.4] - 2023-01-16
### Changed
- Updated package dependencies. [#28303]
## [2.7.3] - 2023-01-11
### Changed
- Updated package dependencies.
## [2.7.2] - 2023-01-02
### Added
- My Jetpack: Move VideoPress from Hybrid [#28097]
### Changed
- My Jetpack: Move Search out of hybrid and deprecate Hybrid_Product class [#28113]
## [2.7.1] - 2022-12-27
### Changed
- Fix layout visual issues [#28055]
- My Jetpack: Move Backup out of hybrid product [#28022]
- My Jetpack: Move Social out of hybrid product [#28074]
## [2.7.0] - 2022-12-19
### Added
- Implement detached licenses redux store. [#27609]
### Changed
- Updated package dependencies. [#27916]
### Fixed
- Add translation context to Security product name. [#27920]
## [2.6.1] - 2022-12-12
### Changed
- Updated package dependencies. [#27888]
## [2.6.0] - 2022-12-05
### Changed
- Improve design of the error notice. [#27340]
@ -690,6 +762,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Created package
[2.7.13]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.12...2.7.13
[2.7.12]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.11...2.7.12
[2.7.11]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.10...2.7.11
[2.7.10]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.9...2.7.10
[2.7.9]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.8...2.7.9
[2.7.8]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.7...2.7.8
[2.7.7]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.6...2.7.7
[2.7.6]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.5...2.7.6
[2.7.5]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.4...2.7.5
[2.7.4]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.3...2.7.4
[2.7.3]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.2...2.7.3
[2.7.2]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.1...2.7.2
[2.7.1]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.7.0...2.7.1
[2.7.0]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.6.1...2.7.0
[2.6.1]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.6.0...2.6.1
[2.6.0]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.5.2...2.6.0
[2.5.2]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.5.1...2.5.2
[2.5.1]: https://github.com/Automattic/jetpack-my-jetpack/compare/2.5.0...2.5.1

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '813aee29e3796bd68b53');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'f9d5720dee05c77d6f54');

View File

@ -13,7 +13,7 @@
*/
/**
* React Router DOM v6.2.2
* @remix-run/router v1.2.1
*
* Copyright (c) Remix Software Inc.
*
@ -24,7 +24,18 @@
*/
/**
* React Router v6.2.2
* React Router DOM v6.6.2
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
/**
* React Router v6.6.2
*
* Copyright (c) Remix Software Inc.
*

View File

@ -4,19 +4,20 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-admin-ui": "^0.2.14",
"automattic/jetpack-assets": "^1.17.28",
"automattic/jetpack-connection": "^1.47.1",
"automattic/jetpack-jitm": "^2.2.35",
"automattic/jetpack-licensing": "^1.7.13",
"automattic/jetpack-plugins-installer": "^0.2.2",
"automattic/jetpack-redirect": "^1.7.21",
"automattic/jetpack-constants": "^1.6.20"
"automattic/jetpack-admin-ui": "^0.2.17",
"automattic/jetpack-assets": "^1.17.33",
"automattic/jetpack-connection": "^1.51.1",
"automattic/jetpack-jitm": "^2.3.1",
"automattic/jetpack-licensing": "^1.8.1",
"automattic/jetpack-plugins-installer": "^0.2.3",
"automattic/jetpack-redirect": "^1.7.24",
"automattic/jetpack-constants": "^1.6.21"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2",
"automattic/wordbless": "@dev"
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/wordbless": "@dev",
"automattic/jetpack-videopress": "^0.11.1"
},
"autoload": {
"classmap": [
@ -28,10 +29,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/coverage.xml\"",
"pnpm run test --coverageDirectory=\"$COVERAGE_DIR\" --coverage --coverageReporters=clover"
],
"test-php": [
"@composer phpunit"
],
@ -65,7 +62,7 @@
"link-template": "https://github.com/Automattic/jetpack-my-jetpack/compare/${old}...${new}"
},
"branch-alias": {
"dev-trunk": "2.6.x-dev"
"dev-trunk": "2.7.x-dev"
},
"version-constants": {
"::PACKAGE_VERSION": "src/class-initializer.php"

View File

@ -30,7 +30,7 @@ class Initializer {
*
* @var string
*/
const PACKAGE_VERSION = '2.6.0';
const PACKAGE_VERSION = '2.7.13';
/**
* Initialize My Jetpack

View File

@ -142,7 +142,6 @@ class Wpcom_Products {
self::update_cache( $products );
return $products;
}
/**
@ -175,11 +174,13 @@ class Wpcom_Products {
$cost = $product->cost;
$discount_price = $cost;
$is_introductory_offer = false;
$introductory_offer = null;
// Get/compute the discounted price.
if ( isset( $product->introductory_offer->cost_per_interval ) ) {
$discount_price = $product->introductory_offer->cost_per_interval;
$is_introductory_offer = true;
$introductory_offer = $product->introductory_offer;
}
$pricing = array(
@ -187,6 +188,7 @@ class Wpcom_Products {
'full_price' => $cost,
'discount_price' => $discount_price,
'is_introductory_offer' => $is_introductory_offer,
'introductory_offer' => $introductory_offer,
);
return self::populate_with_discount( $product, $pricing, $discount_price );

View File

@ -8,7 +8,7 @@
namespace Automattic\Jetpack\My_Jetpack\Products;
use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\My_Jetpack\Hybrid_Product;
use Automattic\Jetpack\My_Jetpack\Product;
use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
use Automattic\Jetpack\Redirect;
use Jetpack_Options;
@ -17,7 +17,7 @@ use WP_Error;
/**
* Class responsible for handling the Backup product
*/
class Backup extends Hybrid_Product {
class Backup extends Product {
/**
* The product slug
@ -198,9 +198,7 @@ class Backup extends Hybrid_Product {
* @return ?string
*/
public static function get_manage_url() {
if ( static::is_jetpack_plugin_active() ) {
return Redirect::get_url( 'my-jetpack-manage-backup' );
} elseif ( static::is_plugin_active() ) {
if ( static::is_plugin_active() ) {
return admin_url( 'admin.php?page=jetpack-backup' );
}
}

View File

@ -12,6 +12,13 @@ use Automattic\Jetpack\Plugins_Installer;
use WP_Error;
/**
*
* DEPRECATED: This class is deprecated and will be removed in a future version.
*
* All product classes have been moved out of the hybrid class concept
*
* @deprecated 2.7.2
*
* Class responsible for handling the hybrid products
*
* Hybrid products are those that may work both as a stand-alone plugin or with the Jetpack plugin.
@ -120,7 +127,6 @@ abstract class Hybrid_Product extends Product {
}
return true;
}
}

View File

@ -116,7 +116,6 @@ abstract class Module_Product extends Product {
}
return $module_activation;
}
/**

View File

@ -403,7 +403,6 @@ abstract class Product {
$result = apply_filters( "my_jetpack_{$product_slug}_activation", $result );
return $result;
}
/**

View File

@ -174,7 +174,6 @@ class Scan extends Module_Product {
}
return $product_activation;
}
/**

View File

@ -9,7 +9,7 @@ namespace Automattic\Jetpack\My_Jetpack\Products;
use Automattic\Jetpack\Connection\Client;
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\My_Jetpack\Hybrid_Product;
use Automattic\Jetpack\My_Jetpack\Product;
use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
use Automattic\Jetpack\Search\Module_Control as Search_Module_Control;
use Jetpack_Options;
@ -18,7 +18,7 @@ use WP_Error;
/**
* Class responsible for handling the Search product
*/
class Search extends Hybrid_Product {
class Search extends Product {
/**
* The product slug
*

View File

@ -38,7 +38,7 @@ class Security extends Module_Product {
* @return string
*/
public static function get_name() {
return __( 'Security', 'jetpack-my-jetpack' );
return _x( 'Security', 'Jetpack product name', 'jetpack-my-jetpack' );
}
/**
@ -47,7 +47,7 @@ class Security extends Module_Product {
* @return string
*/
public static function get_title() {
return __( 'Security', 'jetpack-my-jetpack' );
return _x( 'Security', 'Jetpack product name', 'jetpack-my-jetpack' );
}
/**
@ -149,7 +149,6 @@ class Security extends Module_Product {
}
return $activation;
}
/**

View File

@ -7,13 +7,13 @@
namespace Automattic\Jetpack\My_Jetpack\Products;
use Automattic\Jetpack\My_Jetpack\Hybrid_Product;
use Automattic\Jetpack\My_Jetpack\Product;
use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
/**
* Class responsible for handling the Social product
*/
class Social extends Hybrid_Product {
class Social extends Product {
/**
* The product slug
@ -126,9 +126,7 @@ class Social extends Hybrid_Product {
* @return string
*/
public static function get_manage_url() {
if ( static::is_jetpack_plugin_active() ) {
return admin_url( 'admin.php?page=jetpack#/settings?term=publicize' );
} elseif ( static::is_plugin_active() ) {
if ( static::is_plugin_active() ) {
return admin_url( 'admin.php?page=jetpack-social' );
}
}

View File

@ -7,13 +7,13 @@
namespace Automattic\Jetpack\My_Jetpack\Products;
use Automattic\Jetpack\My_Jetpack\Hybrid_Product;
use Automattic\Jetpack\My_Jetpack\Product;
use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
/**
* Class responsible for handling the VideoPress product
*/
class Videopress extends Hybrid_Product {
class Videopress extends Product {
/**
* The product slug
@ -145,8 +145,6 @@ class Videopress extends Hybrid_Product {
public static function get_manage_url() {
if ( method_exists( 'Automattic\Jetpack\VideoPress\Initializer', 'should_initialize_admin_ui' ) && \Automattic\Jetpack\VideoPress\Initializer::should_initialize_admin_ui() ) {
return \Automattic\Jetpack\VideoPress\Admin_UI::get_admin_page_url();
} else {
return admin_url( 'admin.php?page=jetpack#/settings?term=videopress' );
}
}

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.7.22] - 2023-02-20
### Changed
- Minor internal updates.
## [1.7.21] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -208,6 +212,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add partner subsidiary id to upgrade URLs.
[1.7.22]: https://github.com/Automattic/jetpack-partner/compare/v1.7.21...v1.7.22
[1.7.21]: https://github.com/Automattic/jetpack-partner/compare/v1.7.20...v1.7.21
[1.7.20]: https://github.com/Automattic/jetpack-partner/compare/v1.7.19...v1.7.20
[1.7.19]: https://github.com/Automattic/jetpack-partner/compare/v1.7.18...v1.7.19

View File

@ -4,13 +4,13 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.47.1",
"automattic/jetpack-status": "^1.15.2"
"automattic/jetpack-connection": "^1.51.0",
"automattic/jetpack-status": "^1.16.2"
},
"require-dev": {
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.0.4",
"automattic/jetpack-changelogger": "^3.2.2",
"automattic/jetpack-changelogger": "^3.3.2",
"automattic/wordbless": "@dev"
},
"autoload": {
@ -24,9 +24,6 @@
],
"post-install-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"post-update-cmd": "WorDBless\\Composer\\InstallDropin::copy",
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]

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/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.11] - 2023-02-20
### Changed
- Minor internal updates.
## [0.2.10] - 2023-01-11
### Changed
- Updated package dependencies.
## [0.2.9] - 2022-12-02
### Changed
- Updated package dependencies. [#27688]
@ -88,6 +96,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Use `composer update` rather than `install` in scripts, as composer.lock isn't checked in.
[0.2.11]: https://github.com/Automattic/jetpack-password-checker/compare/v0.2.10...v0.2.11
[0.2.10]: https://github.com/Automattic/jetpack-password-checker/compare/v0.2.9...v0.2.10
[0.2.9]: https://github.com/Automattic/jetpack-password-checker/compare/v0.2.8...v0.2.9
[0.2.8]: https://github.com/Automattic/jetpack-password-checker/compare/v0.2.7...v0.2.8
[0.2.7]: https://github.com/Automattic/jetpack-password-checker/compare/v0.2.6...v0.2.7

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