admin-pages
4 years ago
core-api
3 years ago
debugger
3 years ago
markdown
4 years ago
class-jetpack-currencies.php
5 years ago
class-jetpack-instagram-gallery-helper.php
5 years ago
class-jetpack-mapbox-helper.php
4 years ago
class-jetpack-podcast-feed-locator.php
5 years ago
class-jetpack-podcast-helper.php
4 years ago
class-jetpack-recommendations.php
4 years ago
class-jetpack-tweetstorm-helper.php
5 years ago
class-jetpack-wizard.php
5 years ago
class.color.php
4 years ago
class.core-rest-api-endpoints.php
3 years ago
class.jetpack-automatic-install-skin.php
4 years ago
class.jetpack-iframe-embed.php
4 years ago
class.jetpack-keyring-service-helper.php
4 years ago
class.jetpack-password-checker.php
4 years ago
class.jetpack-photon-image-sizes.php
4 years ago
class.jetpack-photon-image.php
4 years ago
class.jetpack-search-performance-logger.php
4 years ago
class.media-extractor.php
4 years ago
class.media-summary.php
4 years ago
class.media.php
4 years ago
components.php
5 years ago
debugger.php
4 years ago
functions.wp-notify.php
4 years ago
icalendar-reader.php
4 years ago
markdown.php
5 years ago
plans.php
4 years ago
plugins.php
4 years ago
tonesque.php
4 years ago
widgets.php
3 years ago
plans.php
76 lines
| 1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Plans Library |
| 4 | * |
| 5 | * Fetch plans data from WordPress.com. |
| 6 | * |
| 7 | * Not to be confused with the `Jetpack_Plan` (singular) |
| 8 | * class, which stores and syncs data about the site's _current_ plan. |
| 9 | * |
| 10 | * @package automattic/jetpack |
| 11 | */ |
| 12 | class Jetpack_Plans { |
| 13 | /** |
| 14 | * Get a list of all available plans from WordPress.com |
| 15 | * |
| 16 | * @since 7.7.0 |
| 17 | * |
| 18 | * @return array The plans list |
| 19 | */ |
| 20 | public static function get_plans() { |
| 21 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 22 | if ( ! class_exists( 'Store_Product_List' ) ) { |
| 23 | require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php'; |
| 24 | } |
| 25 | |
| 26 | return Store_Product_List::api_only_get_active_plans_v1_4(); |
| 27 | } |
| 28 | |
| 29 | // We're on Jetpack, so it's safe to use this namespace. |
| 30 | $request = Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user( |
| 31 | '/plans?_locale=' . get_user_locale(), |
| 32 | // We're using version 1.5 of the endpoint rather than the default version 2 |
| 33 | // since the latter only returns Jetpack Plans, but we're also interested in |
| 34 | // WordPress.com plans, for consumers of this method that run on WP.com. |
| 35 | '1.5', |
| 36 | array( |
| 37 | 'method' => 'GET', |
| 38 | 'headers' => array( |
| 39 | 'X-Forwarded-For' => ( new Automattic\Jetpack\Status\Visitor() )->get_ip( true ), |
| 40 | ), |
| 41 | ), |
| 42 | null, |
| 43 | 'rest' |
| 44 | ); |
| 45 | |
| 46 | $body = wp_remote_retrieve_body( $request ); |
| 47 | if ( 200 === wp_remote_retrieve_response_code( $request ) ) { |
| 48 | return json_decode( $body ); |
| 49 | } else { |
| 50 | return $body; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get plan information for a plan given its slug |
| 56 | * |
| 57 | * @since 7.7.0 |
| 58 | * |
| 59 | * @param string $plan_slug Plan slug. |
| 60 | * |
| 61 | * @return object The plan object |
| 62 | */ |
| 63 | public static function get_plan( $plan_slug ) { |
| 64 | $plans = self::get_plans(); |
| 65 | if ( ! is_array( $plans ) ) { |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | foreach ( $plans as $plan ) { |
| 70 | if ( $plan_slug === $plan->product_slug ) { |
| 71 | return $plan; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 |