← All changes
|
vendor/automattic/jetpack-plans/src/class-plans.php
+29
-0
13.5.2
→
16.3-beta
View file →
| @@ -78,5 +78,34 @@ | ||
| 78 | 78 | return $plan; |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Efficiently get the short name of a plan from a slug. | |
| 85 | + * | |
| 86 | + * @param string $plan_slug Plan slug. | |
| 87 | + * @return string|null Short product name or null if not round. | |
| 88 | + */ | |
| 89 | + public static function get_plan_short_name( $plan_slug ) { | |
| 90 | + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { | |
| 91 | + if ( ! class_exists( 'Store_Product_List' ) ) { | |
| 92 | + require WP_CONTENT_DIR . '/admin-plugins/wpcom-billing/store-product-list.php'; | |
| 93 | + } | |
| 94 | + | |
| 95 | + // Skip additional work like processing of coupons, since we only need the plan's short name. | |
| 96 | + $products = Store_Product_List::get(); | |
| 97 | + | |
| 98 | + foreach ( $products as $product ) { | |
| 99 | + if ( isset( $product['product_slug'] ) && $product['product_slug'] === $plan_slug ) { | |
| 100 | + return $product['product_name_short'] ?? null; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + return null; | |
| 105 | + } | |
| 106 | + | |
| 107 | + // Fallback to less efficient method for Jetpack environments. | |
| 108 | + $plan = self::get_plan( $plan_slug ); | |
| 109 | + return $plan->product_name_short ?? null; | |
| 110 | + } | |
| 82 | 111 | } |