updated plugin Jetpack Protect
version 1.3.0
This commit is contained in:
@ -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
|
||||
|
@ -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": {
|
||||
|
@ -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() ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user