initial
This commit is contained in:
+324
@@ -0,0 +1,324 @@
|
||||
# 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.11.9] - 2026-06-08
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.11.8] - 2026-06-05
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.11.7] - 2026-06-01
|
||||
### Changed
|
||||
- Revert Choose plan tier recognition added in #48806; the experiment is being rolled back. [#49276]
|
||||
|
||||
## [0.11.6] - 2026-05-19
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.11.5] - 2026-05-14
|
||||
### Changed
|
||||
- Add "Choose" plan slugs to `PLAN_DATA`. [#48806]
|
||||
|
||||
## [0.11.4] - 2026-05-04
|
||||
### Changed
|
||||
- Internal: No longer require automattic/jetpack-changelogger as a per-project dev dependency. [#48225]
|
||||
|
||||
## [0.11.3] - 2026-02-23
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [0.11.2] - 2026-02-02
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [0.11.1] - 2025-12-08
|
||||
### Fixed
|
||||
- Ensure proper flags are used with `json_encode()`. [#46092]
|
||||
|
||||
## [0.11.0] - 2025-12-01
|
||||
### Changed
|
||||
- Add form-webhooks support on free Jetpack plans. [#46059]
|
||||
|
||||
## [0.10.0] - 2025-08-06
|
||||
### Added
|
||||
- Plan features: add Social Image Generator [#44661]
|
||||
|
||||
## [0.9.1] - 2025-08-04
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.9.0] - 2025-07-21
|
||||
### Added
|
||||
- Forms: Include multistep form in Jetpack and WordPress.com plans. [#44309]
|
||||
|
||||
## [0.8.0] - 2025-05-05
|
||||
### Added
|
||||
- Forms: Add feature/block field-file support to Personal and Complete plans. [#43177]
|
||||
|
||||
## [0.7.1] - 2025-04-28
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.7.0] - 2025-03-31
|
||||
### Added
|
||||
- Add `ai-seo-enhancer` as a feature supported by the Business plan. [#42731]
|
||||
|
||||
## [0.6.1] - 2025-03-21
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.6.0] - 2025-03-18
|
||||
### Changed
|
||||
- Add `Plans::get_plan_short_name()` for WordPress.com environments. [#42485]
|
||||
|
||||
## [0.5.6] - 2025-03-17
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.5.5] - 2025-03-12
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.5.4] - 2025-03-05
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.5.3] - 2025-02-24
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [0.5.2] - 2025-02-03
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.5.1] - 2024-11-25
|
||||
### Changed
|
||||
- Updated dependencies. [#40286]
|
||||
|
||||
## [0.5.0] - 2024-11-14
|
||||
### Removed
|
||||
- General: Update minimum PHP version to 7.2. [#40147]
|
||||
|
||||
## [0.4.13] - 2024-11-04
|
||||
### Added
|
||||
- Enable test coverage. [#39961]
|
||||
|
||||
## [0.4.12] - 2024-10-21
|
||||
### Fixed
|
||||
- Fixed the site features for Simple sites. [#39817]
|
||||
|
||||
## [0.4.11] - 2024-09-23
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [0.4.10] - 2024-09-05
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [0.4.9] - 2024-09-05
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [0.4.8] - 2024-08-23
|
||||
### Changed
|
||||
- Updated package dependencies. [#39004]
|
||||
|
||||
## [0.4.7] - 2024-05-06
|
||||
### Fixed
|
||||
- Correctly reference `Store_Product_List` class in `Plans::get_plans()`. [#37201]
|
||||
|
||||
## [0.4.6] - 2024-04-25
|
||||
### Changed
|
||||
- Update dependencies.
|
||||
|
||||
## [0.4.5] - 2024-04-22
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.4.4] - 2024-04-08
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.4.3] - 2024-03-12
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [0.4.2] - 2024-02-12
|
||||
### Added
|
||||
- Plan features: add "sharing block" to the list of features supported in the free plan. [#35577]
|
||||
|
||||
## [0.4.1] - 2024-01-18
|
||||
### Added
|
||||
- Support the new creator plan in our plan checks [#35071]
|
||||
|
||||
## [0.4.0] - 2023-11-20
|
||||
### Changed
|
||||
- Updated required PHP version to >= 7.0. [#34192]
|
||||
|
||||
## [0.3.5] - 2023-10-24
|
||||
|
||||
- Updated package dependencies.
|
||||
|
||||
## [0.3.4] - 2023-08-23
|
||||
### Changed
|
||||
- Updated package dependencies. [#32605]
|
||||
|
||||
## [0.3.3] - 2023-06-19
|
||||
### Added
|
||||
- Add the Advanced SEO feature to the list of free features. [#31213]
|
||||
|
||||
## [0.3.2] - 2023-06-12
|
||||
### Changed
|
||||
- Remove Jetpack-the-plugin dependencies from Current Plan class. [#31207]
|
||||
|
||||
## [0.3.1] - 2023-06-05
|
||||
### Fixed
|
||||
- Revert gating removal for simple payments [#31067]
|
||||
|
||||
## [0.3.0] - 2023-05-11
|
||||
### Changed
|
||||
- Make Earn products free for all Jetpack plans [#30432]
|
||||
|
||||
## [0.2.12] - 2023-05-08
|
||||
### Changed
|
||||
- Make Premium Content accessible on Free plans. [#30398]
|
||||
|
||||
## [0.2.11] - 2023-04-10
|
||||
### Added
|
||||
- Add Jetpack Autoloader package suggestion. [#29988]
|
||||
|
||||
## [0.2.10] - 2023-02-20
|
||||
### Changed
|
||||
- Minor internal updates.
|
||||
|
||||
## [0.2.9] - 2023-01-25
|
||||
### Changed
|
||||
- Minor internal updates.
|
||||
|
||||
## [0.2.8] - 2022-12-02
|
||||
### Changed
|
||||
- Updated package dependencies. [#27688]
|
||||
|
||||
## [0.2.7] - 2022-11-22
|
||||
### Changed
|
||||
- Updated package dependencies. [#27043]
|
||||
|
||||
## [0.2.6] - 2022-11-07
|
||||
### Changed
|
||||
- Updated package dependencies. [#27278]
|
||||
|
||||
## [0.2.5] - 2022-10-25
|
||||
### Changed
|
||||
- Updated package dependencies. [#26705]
|
||||
|
||||
## [0.2.4] - 2022-09-20
|
||||
### Changed
|
||||
- Updated package dependencies.
|
||||
|
||||
## [0.2.3] - 2022-09-08
|
||||
### Changed
|
||||
- Updated package dependencies.
|
||||
|
||||
## [0.2.2] - 2022-08-30
|
||||
### Changed
|
||||
- Updated package dependencies. [#25694]
|
||||
|
||||
## [0.2.1] - 2022-08-23
|
||||
### Changed
|
||||
- Updated package dependencies. [#25628]
|
||||
|
||||
## [0.2.0] - 2022-08-16
|
||||
### Added
|
||||
- Tweaked the supports method of the plans package to refresh the plan data. [#25347]
|
||||
|
||||
## [0.1.3] - 2022-08-03
|
||||
### Changed
|
||||
- Updated package dependencies. [#25300, #25315]
|
||||
|
||||
## [0.1.2] - 2022-07-26
|
||||
### Changed
|
||||
- Add mirror repository information to package info. [#25142]
|
||||
- Updated package dependencies. [#25158]
|
||||
|
||||
## 0.1.1 - 2022-07-19
|
||||
### Changed
|
||||
- Updated package dependencies.
|
||||
|
||||
## 0.1.0 - 2022-07-06
|
||||
### Added
|
||||
- Add support for WordPress.com Starter plan. [#24496]
|
||||
- Package created. [#23503]
|
||||
|
||||
### Changed
|
||||
- Renaming master to trunk. [#24661]
|
||||
- Updated package dependencies.
|
||||
|
||||
### Deprecated
|
||||
- Moved the options class into Connection. [#24095]
|
||||
|
||||
[0.11.9]: https://github.com/Automattic/jetpack-plans/compare/v0.11.8...v0.11.9
|
||||
[0.11.8]: https://github.com/Automattic/jetpack-plans/compare/v0.11.7...v0.11.8
|
||||
[0.11.7]: https://github.com/Automattic/jetpack-plans/compare/v0.11.6...v0.11.7
|
||||
[0.11.6]: https://github.com/Automattic/jetpack-plans/compare/v0.11.5...v0.11.6
|
||||
[0.11.5]: https://github.com/Automattic/jetpack-plans/compare/v0.11.4...v0.11.5
|
||||
[0.11.4]: https://github.com/Automattic/jetpack-plans/compare/v0.11.3...v0.11.4
|
||||
[0.11.3]: https://github.com/Automattic/jetpack-plans/compare/v0.11.2...v0.11.3
|
||||
[0.11.2]: https://github.com/Automattic/jetpack-plans/compare/v0.11.1...v0.11.2
|
||||
[0.11.1]: https://github.com/Automattic/jetpack-plans/compare/v0.11.0...v0.11.1
|
||||
[0.11.0]: https://github.com/Automattic/jetpack-plans/compare/v0.10.0...v0.11.0
|
||||
[0.10.0]: https://github.com/Automattic/jetpack-plans/compare/v0.9.1...v0.10.0
|
||||
[0.9.1]: https://github.com/Automattic/jetpack-plans/compare/v0.9.0...v0.9.1
|
||||
[0.9.0]: https://github.com/Automattic/jetpack-plans/compare/v0.8.0...v0.9.0
|
||||
[0.8.0]: https://github.com/Automattic/jetpack-plans/compare/v0.7.1...v0.8.0
|
||||
[0.7.1]: https://github.com/Automattic/jetpack-plans/compare/v0.7.0...v0.7.1
|
||||
[0.7.0]: https://github.com/Automattic/jetpack-plans/compare/v0.6.1...v0.7.0
|
||||
[0.6.1]: https://github.com/Automattic/jetpack-plans/compare/v0.6.0...v0.6.1
|
||||
[0.6.0]: https://github.com/Automattic/jetpack-plans/compare/v0.5.6...v0.6.0
|
||||
[0.5.6]: https://github.com/Automattic/jetpack-plans/compare/v0.5.5...v0.5.6
|
||||
[0.5.5]: https://github.com/Automattic/jetpack-plans/compare/v0.5.4...v0.5.5
|
||||
[0.5.4]: https://github.com/Automattic/jetpack-plans/compare/v0.5.3...v0.5.4
|
||||
[0.5.3]: https://github.com/Automattic/jetpack-plans/compare/v0.5.2...v0.5.3
|
||||
[0.5.2]: https://github.com/Automattic/jetpack-plans/compare/v0.5.1...v0.5.2
|
||||
[0.5.1]: https://github.com/Automattic/jetpack-plans/compare/v0.5.0...v0.5.1
|
||||
[0.5.0]: https://github.com/Automattic/jetpack-plans/compare/v0.4.13...v0.5.0
|
||||
[0.4.13]: https://github.com/Automattic/jetpack-plans/compare/v0.4.12...v0.4.13
|
||||
[0.4.12]: https://github.com/Automattic/jetpack-plans/compare/v0.4.11...v0.4.12
|
||||
[0.4.11]: https://github.com/Automattic/jetpack-plans/compare/v0.4.10...v0.4.11
|
||||
[0.4.10]: https://github.com/Automattic/jetpack-plans/compare/v0.4.9...v0.4.10
|
||||
[0.4.9]: https://github.com/Automattic/jetpack-plans/compare/v0.4.8...v0.4.9
|
||||
[0.4.8]: https://github.com/Automattic/jetpack-plans/compare/v0.4.7...v0.4.8
|
||||
[0.4.7]: https://github.com/Automattic/jetpack-plans/compare/v0.4.6...v0.4.7
|
||||
[0.4.6]: https://github.com/Automattic/jetpack-plans/compare/v0.4.5...v0.4.6
|
||||
[0.4.5]: https://github.com/Automattic/jetpack-plans/compare/v0.4.4...v0.4.5
|
||||
[0.4.4]: https://github.com/Automattic/jetpack-plans/compare/v0.4.3...v0.4.4
|
||||
[0.4.3]: https://github.com/Automattic/jetpack-plans/compare/v0.4.2...v0.4.3
|
||||
[0.4.2]: https://github.com/Automattic/jetpack-plans/compare/v0.4.1...v0.4.2
|
||||
[0.4.1]: https://github.com/Automattic/jetpack-plans/compare/v0.4.0...v0.4.1
|
||||
[0.4.0]: https://github.com/Automattic/jetpack-plans/compare/v0.3.5...v0.4.0
|
||||
[0.3.5]: https://github.com/Automattic/jetpack-plans/compare/v0.3.4...v0.3.5
|
||||
[0.3.4]: https://github.com/Automattic/jetpack-plans/compare/v0.3.3...v0.3.4
|
||||
[0.3.3]: https://github.com/Automattic/jetpack-plans/compare/v0.3.2...v0.3.3
|
||||
[0.3.2]: https://github.com/Automattic/jetpack-plans/compare/v0.3.1...v0.3.2
|
||||
[0.3.1]: https://github.com/Automattic/jetpack-plans/compare/v0.3.0...v0.3.1
|
||||
[0.3.0]: https://github.com/Automattic/jetpack-plans/compare/v0.2.12...v0.3.0
|
||||
[0.2.12]: https://github.com/Automattic/jetpack-plans/compare/v0.2.11...v0.2.12
|
||||
[0.2.11]: https://github.com/Automattic/jetpack-plans/compare/v0.2.10...v0.2.11
|
||||
[0.2.10]: https://github.com/Automattic/jetpack-plans/compare/v0.2.9...v0.2.10
|
||||
[0.2.9]: https://github.com/Automattic/jetpack-plans/compare/v0.2.8...v0.2.9
|
||||
[0.2.8]: https://github.com/Automattic/jetpack-plans/compare/v0.2.7...v0.2.8
|
||||
[0.2.7]: https://github.com/Automattic/jetpack-plans/compare/v0.2.6...v0.2.7
|
||||
[0.2.6]: https://github.com/Automattic/jetpack-plans/compare/v0.2.5...v0.2.6
|
||||
[0.2.5]: https://github.com/Automattic/jetpack-plans/compare/v0.2.4...v0.2.5
|
||||
[0.2.4]: https://github.com/Automattic/jetpack-plans/compare/v0.2.3...v0.2.4
|
||||
[0.2.3]: https://github.com/Automattic/jetpack-plans/compare/v0.2.2...v0.2.3
|
||||
[0.2.2]: https://github.com/Automattic/jetpack-plans/compare/v0.2.1...v0.2.2
|
||||
[0.2.1]: https://github.com/Automattic/jetpack-plans/compare/v0.2.0...v0.2.1
|
||||
[0.2.0]: https://github.com/Automattic/jetpack-plans/compare/v0.1.3...v0.2.0
|
||||
[0.1.3]: https://github.com/Automattic/jetpack-plans/compare/v0.1.2...v0.1.3
|
||||
[0.1.2]: https://github.com/Automattic/jetpack-plans/compare/v0.1.1...v0.1.2
|
||||
Vendored
+443
@@ -0,0 +1,443 @@
|
||||
<?php
|
||||
/**
|
||||
* Handles fetching of the site's plan and products from WordPress.com and caching values locally.
|
||||
*
|
||||
* @package automattic/jetpack-plans
|
||||
*/
|
||||
|
||||
namespace Automattic\Jetpack;
|
||||
|
||||
use Automattic\Jetpack\Connection\Client;
|
||||
use Automattic\Jetpack\Connection\Manager;
|
||||
|
||||
/**
|
||||
* Provides methods methods for fetching the site's plan and products from WordPress.com.
|
||||
*/
|
||||
class Current_Plan {
|
||||
/**
|
||||
* A cache variable to hold the active plan for the current request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $active_plan_cache;
|
||||
|
||||
/**
|
||||
* Simple Site-specific features available.
|
||||
* Their calculation can be expensive and slow, so we're caching it for the request.
|
||||
*
|
||||
* @var array Site-specific features
|
||||
*/
|
||||
private static $simple_site_specific_features = array();
|
||||
|
||||
/**
|
||||
* The name of the option that will store the site's plan.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PLAN_OPTION = 'jetpack_active_plan';
|
||||
|
||||
/**
|
||||
* The name of the option that will store the site's products.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SITE_PRODUCTS_OPTION = 'jetpack_site_products';
|
||||
|
||||
const PLAN_DATA = array(
|
||||
'free' => array(
|
||||
'plans' => array(
|
||||
'jetpack_free',
|
||||
),
|
||||
'supports' => array(
|
||||
'advanced-seo',
|
||||
'opentable',
|
||||
'calendly',
|
||||
'send-a-message',
|
||||
'sharing-block',
|
||||
'whatsapp-button',
|
||||
'social-previews',
|
||||
'videopress',
|
||||
'videopress/video',
|
||||
'v6-video-frame-poster',
|
||||
|
||||
'core/video',
|
||||
'core/cover',
|
||||
'core/audio',
|
||||
'multistep-form',
|
||||
'form-webhooks',
|
||||
),
|
||||
),
|
||||
'personal' => array(
|
||||
'plans' => array(
|
||||
'jetpack_personal',
|
||||
'jetpack_personal_monthly',
|
||||
'personal-bundle',
|
||||
'personal-bundle-monthly',
|
||||
'personal-bundle-2y',
|
||||
'personal-bundle-3y',
|
||||
'starter-plan',
|
||||
),
|
||||
'supports' => array(
|
||||
'akismet',
|
||||
'payments',
|
||||
'videopress',
|
||||
),
|
||||
),
|
||||
'premium' => array(
|
||||
'plans' => array(
|
||||
'jetpack_premium',
|
||||
'jetpack_premium_monthly',
|
||||
'value_bundle',
|
||||
'value_bundle-monthly',
|
||||
'value_bundle-2y',
|
||||
'value_bundle-3y',
|
||||
'jetpack_creator_yearly',
|
||||
'jetpack_creator_bi_yearly',
|
||||
'jetpack_creator_monthly',
|
||||
),
|
||||
'supports' => array(
|
||||
'simple-payments',
|
||||
'vaultpress',
|
||||
'videopress',
|
||||
'republicize',
|
||||
),
|
||||
),
|
||||
'security' => array(
|
||||
'plans' => array(
|
||||
'jetpack_security_daily',
|
||||
'jetpack_security_daily_monthly',
|
||||
'jetpack_security_realtime',
|
||||
'jetpack_security_realtime_monthly',
|
||||
'jetpack_security_t1_yearly',
|
||||
'jetpack_security_t1_monthly',
|
||||
'jetpack_security_t2_yearly',
|
||||
'jetpack_security_t2_monthly',
|
||||
),
|
||||
'supports' => array(),
|
||||
),
|
||||
'business' => array(
|
||||
'plans' => array(
|
||||
'jetpack_business',
|
||||
'jetpack_business_monthly',
|
||||
'business-bundle',
|
||||
'business-bundle-monthly',
|
||||
'business-bundle-2y',
|
||||
'business-bundle-3y',
|
||||
'ecommerce-bundle',
|
||||
'ecommerce-bundle-monthly',
|
||||
'ecommerce-bundle-2y',
|
||||
'ecommerce-bundle-3y',
|
||||
'pro-plan',
|
||||
'wp_bundle_migration_trial_monthly',
|
||||
'wp_bundle_hosting_trial_monthly',
|
||||
'ecommerce-trial-bundle-monthly',
|
||||
'wooexpress-small-bundle-yearly',
|
||||
'wooexpress-small-bundle-monthly',
|
||||
'wooexpress-medium-bundle-yearly',
|
||||
'wooexpress-medium-bundle-monthly',
|
||||
'wp_com_hundred_year_bundle_centennially',
|
||||
),
|
||||
'supports' => array(
|
||||
'ai-seo-enhancer',
|
||||
),
|
||||
),
|
||||
|
||||
'complete' => array(
|
||||
'plans' => array(
|
||||
'jetpack_complete',
|
||||
'jetpack_complete_monthly',
|
||||
'vip',
|
||||
),
|
||||
'supports' => array(
|
||||
'field-file', // Forms
|
||||
'social-image-generator',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Given a response to the `/sites/%d` endpoint, will parse the response and attempt to set the
|
||||
* site's plan and products from the response.
|
||||
*
|
||||
* @param array $response The response from `/sites/%d`.
|
||||
* @return bool Was the plan successfully updated?
|
||||
*/
|
||||
public static function update_from_sites_response( $response ) {
|
||||
// Bail if there was an error or malformed response.
|
||||
if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
if ( is_wp_error( $body ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Decode the results.
|
||||
$results = json_decode( $body, true );
|
||||
|
||||
if ( ! is_array( $results ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset( $results['products'] ) ) {
|
||||
// Store the site's products in an option and return true if updated.
|
||||
self::store_data_in_option( self::SITE_PRODUCTS_OPTION, $results['products'] );
|
||||
}
|
||||
|
||||
if ( ! isset( $results['plan'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_plan = get_option( self::PLAN_OPTION, array() );
|
||||
|
||||
if ( ! empty( $current_plan ) && $current_plan === $results['plan'] ) {
|
||||
// Bail if the plans array hasn't changed.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the new plan in an option and return true if updated.
|
||||
$result = self::store_data_in_option( self::PLAN_OPTION, $results['plan'] );
|
||||
|
||||
if ( $result ) {
|
||||
// Reset the cache since we've just updated the plan.
|
||||
self::$active_plan_cache = null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in an option.
|
||||
*
|
||||
* @param string $option The name of the option that will store the data.
|
||||
* @param array $data Data to be store in an option.
|
||||
* @return bool Were the subscriptions successfully updated?
|
||||
*/
|
||||
private static function store_data_in_option( $option, $data ) {
|
||||
$result = update_option( $option, $data, true );
|
||||
|
||||
// If something goes wrong with the update, so delete the current option and then update it.
|
||||
if ( ! $result ) {
|
||||
delete_option( $option );
|
||||
$result = update_option( $option, $data, true );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an API call to WordPress.com for plan status
|
||||
*
|
||||
* @uses Jetpack_Options::get_option()
|
||||
* @uses Client::wpcom_json_api_request_as_blog()
|
||||
* @uses update_option()
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return bool True if plan is updated, false if no update
|
||||
*/
|
||||
public static function refresh_from_wpcom() {
|
||||
$site_id = Manager::get_site_id();
|
||||
if ( is_wp_error( $site_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make the API request.
|
||||
|
||||
$response = Client::wpcom_json_api_request_as_blog(
|
||||
sprintf( '/sites/%d?force=wpcom', $site_id ),
|
||||
'1.1'
|
||||
);
|
||||
|
||||
return self::update_from_sites_response( $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plan that this Jetpack site is currently using.
|
||||
*
|
||||
* @uses get_option()
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return array Active Jetpack plan details
|
||||
*/
|
||||
public static function get() {
|
||||
// this can be expensive to compute so we cache for the duration of a request.
|
||||
if ( is_array( self::$active_plan_cache ) && ! empty( self::$active_plan_cache ) ) {
|
||||
return self::$active_plan_cache;
|
||||
}
|
||||
|
||||
$plan = get_option( self::PLAN_OPTION, array() );
|
||||
|
||||
// Set the default options.
|
||||
$plan = wp_parse_args(
|
||||
$plan,
|
||||
array(
|
||||
'product_slug' => 'jetpack_free',
|
||||
'class' => 'free',
|
||||
'features' => array(
|
||||
'active' => array(),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
list( $plan['class'], $supports ) = self::get_class_and_features( $plan['product_slug'] );
|
||||
|
||||
$modules = new Modules();
|
||||
foreach ( $modules->get_available() as $module_slug ) {
|
||||
$module = $modules->get( $module_slug );
|
||||
if ( ! isset( $module ) || ! is_array( $module ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( in_array( 'free', $module['plan_classes'], true ) || in_array( $plan['class'], $module['plan_classes'], true ) ) {
|
||||
$supports[] = $module_slug;
|
||||
}
|
||||
}
|
||||
|
||||
$plan['supports'] = $supports;
|
||||
|
||||
self::$active_plan_cache = $plan;
|
||||
|
||||
return $plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the site's products.
|
||||
*
|
||||
* @uses get_option()
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return array Active Jetpack products
|
||||
*/
|
||||
public static function get_products() {
|
||||
return get_option( self::SITE_PRODUCTS_OPTION, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class of plan and a list of features it supports
|
||||
*
|
||||
* @param string $plan_slug The plan that we're interested in.
|
||||
* @return array Two item array, the plan class and the an array of features.
|
||||
*/
|
||||
private static function get_class_and_features( $plan_slug ) {
|
||||
$features = array();
|
||||
foreach ( self::PLAN_DATA as $class => $details ) {
|
||||
$features = array_merge( $features, $details['supports'] );
|
||||
if ( in_array( $plan_slug, $details['plans'], true ) ) {
|
||||
return array( $class, $features );
|
||||
}
|
||||
}
|
||||
return array( 'free', self::PLAN_DATA['free']['supports'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum plan slug that supports the given feature
|
||||
*
|
||||
* @param string $feature The name of the feature.
|
||||
* @return string|bool The slug for the minimum plan that supports.
|
||||
* the feature or false if not found
|
||||
*/
|
||||
public static function get_minimum_plan_for_feature( $feature ) {
|
||||
foreach ( self::PLAN_DATA as $details ) {
|
||||
if ( in_array( $feature, $details['supports'], true ) ) {
|
||||
return $details['plans'][0];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the active plan supports a particular feature
|
||||
*
|
||||
* @uses self::get()
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @param string $feature The module or feature to check.
|
||||
* @param bool $refresh_from_wpcom Refresh the local plan cache from wpcom.
|
||||
*
|
||||
* @return bool True if plan supports feature, false if not
|
||||
*/
|
||||
public static function supports( $feature, $refresh_from_wpcom = false ) {
|
||||
if ( $refresh_from_wpcom ) {
|
||||
self::refresh_from_wpcom();
|
||||
}
|
||||
|
||||
// Hijack the feature eligibility check on WordPress.com sites since they are gated differently.
|
||||
$should_wpcom_gate_feature = (
|
||||
function_exists( 'wpcom_site_has_feature' ) &&
|
||||
function_exists( 'wpcom_feature_exists' ) &&
|
||||
wpcom_feature_exists( $feature )
|
||||
);
|
||||
if ( $should_wpcom_gate_feature ) {
|
||||
return wpcom_site_has_feature( $feature );
|
||||
}
|
||||
|
||||
// Search product bypasses plan feature check.
|
||||
if ( 'search' === $feature && (bool) get_option( 'has_jetpack_search_product' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// As of Q3 2021 - a videopress free tier is available to all plans.
|
||||
if ( 'videopress' === $feature ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// As of 05 2023 - all plans support Earn features (minus 'simple-payments').
|
||||
if ( in_array( $feature, array( 'donations', 'recurring-payments', 'premium-content/container' ), true ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$plan = self::get();
|
||||
|
||||
if (
|
||||
in_array( $feature, $plan['supports'], true )
|
||||
|| in_array( $feature, $plan['features']['active'], true )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve site-specific features for Simple sites.
|
||||
*
|
||||
* See Jetpack_Gutenberg::get_site_specific_features()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_simple_site_specific_features() {
|
||||
$is_simple_site = defined( 'IS_WPCOM' ) && constant( 'IS_WPCOM' );
|
||||
|
||||
if ( ! $is_simple_site ) {
|
||||
return array(
|
||||
'active' => array(),
|
||||
'available' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
$current_blog_id = get_current_blog_id();
|
||||
|
||||
// Return the cached value if it exists.
|
||||
if ( isset( self::$simple_site_specific_features[ $current_blog_id ] ) ) {
|
||||
return self::$simple_site_specific_features[ $current_blog_id ];
|
||||
}
|
||||
|
||||
if ( ! class_exists( '\Store_Product_List' ) ) {
|
||||
require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php';
|
||||
}
|
||||
|
||||
$simple_site_specific_features = \Store_Product_List::get_site_specific_features_data( $current_blog_id );
|
||||
|
||||
self::$simple_site_specific_features[ $current_blog_id ] = $simple_site_specific_features;
|
||||
|
||||
return $simple_site_specific_features;
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* Plans Library
|
||||
*
|
||||
* Fetch plans data from WordPress.com.
|
||||
*
|
||||
* This file was copied and adapted from the Jetpack plugin on Mar 2022.
|
||||
*
|
||||
* @package automattic/jetpack-plans
|
||||
*/
|
||||
|
||||
namespace Automattic\Jetpack;
|
||||
|
||||
use Store_Product_List;
|
||||
|
||||
/**
|
||||
* Fetch data about available Plans from WordPress.com
|
||||
*/
|
||||
class Plans {
|
||||
/**
|
||||
* Get a list of all available plans from WordPress.com
|
||||
*
|
||||
* @since-jetpack 7.7.0
|
||||
*
|
||||
* @return array The plans list
|
||||
*/
|
||||
public static function get_plans() {
|
||||
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
|
||||
if ( ! class_exists( 'Store_Product_List' ) ) {
|
||||
require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php';
|
||||
}
|
||||
|
||||
return Store_Product_List::api_only_get_active_plans_v1_4();
|
||||
}
|
||||
|
||||
// We're on Jetpack, so it's safe to use this namespace.
|
||||
$request = \Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user(
|
||||
'/plans?_locale=' . get_user_locale(),
|
||||
// We're using version 1.5 of the endpoint rather than the default version 2
|
||||
// since the latter only returns Jetpack Plans, but we're also interested in
|
||||
// WordPress.com plans, for consumers of this method that run on WP.com.
|
||||
'1.5',
|
||||
array(
|
||||
'method' => 'GET',
|
||||
'headers' => array(
|
||||
'X-Forwarded-For' => ( new \Automattic\Jetpack\Status\Visitor() )->get_ip( true ),
|
||||
),
|
||||
),
|
||||
null,
|
||||
'rest'
|
||||
);
|
||||
|
||||
$body = wp_remote_retrieve_body( $request );
|
||||
if ( 200 === wp_remote_retrieve_response_code( $request ) ) {
|
||||
return json_decode( $body );
|
||||
} else {
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plan information for a plan given its slug
|
||||
*
|
||||
* @since-jetpack 7.7.0
|
||||
*
|
||||
* @param string $plan_slug Plan slug.
|
||||
*
|
||||
* @return object The plan object
|
||||
*/
|
||||
public static function get_plan( $plan_slug ) {
|
||||
$plans = self::get_plans();
|
||||
if ( ! is_array( $plans ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $plans as $plan ) {
|
||||
if ( $plan_slug === $plan->product_slug ) {
|
||||
return $plan;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Efficiently get the short name of a plan from a slug.
|
||||
*
|
||||
* @param string $plan_slug Plan slug.
|
||||
* @return string|null Short product name or null if not round.
|
||||
*/
|
||||
public static function get_plan_short_name( $plan_slug ) {
|
||||
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
|
||||
if ( ! class_exists( 'Store_Product_List' ) ) {
|
||||
require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php';
|
||||
}
|
||||
|
||||
// Skip additional work like processing of coupons, since we only need the plan's short name.
|
||||
$products = Store_Product_List::get();
|
||||
|
||||
foreach ( $products as $product ) {
|
||||
if ( isset( $product['product_slug'] ) && $product['product_slug'] === $plan_slug ) {
|
||||
return $product['product_name_short'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Fallback to less efficient method for Jetpack environments.
|
||||
$plan = self::get_plan( $plan_slug );
|
||||
return $plan->product_name_short ?? null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user