|
1
|
|
|
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
|
2
|
|
|
/** |
|
3
|
|
|
* Get a WordPress.com site's plan, and see if it supports a given feature. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Jetpack |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Provides methods methods for fetching the plan from WordPress.com. |
|
10
|
|
|
*/ |
|
11
|
|
|
class Wpcom_Plan { |
|
12
|
|
|
/** |
|
13
|
|
|
* Check if a site is a WordPress.com site. |
|
14
|
|
|
* |
|
15
|
|
|
* @access public |
|
16
|
|
|
* @static |
|
17
|
|
|
* |
|
18
|
|
|
* @return bool True if the site is a WordPress.com Simple Site. |
|
19
|
|
|
*/ |
|
20
|
|
|
public static function is_wpcom() { |
|
21
|
|
|
return defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'get_blog_stickers' ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Return an array of features supported by current plan or sticker. |
|
26
|
|
|
* |
|
27
|
|
|
* @access public |
|
28
|
|
|
* @static |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $plan Current wpcom plan. |
|
31
|
|
|
* |
|
32
|
|
|
* @return array $features Array of supported features. |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function features( $plan ) { |
|
35
|
|
|
$plan_features = array( |
|
36
|
|
|
'blogger-plan' => array(), |
|
37
|
|
|
'personal-plan' => array( |
|
38
|
|
|
'recurring-payments', |
|
39
|
|
|
), |
|
40
|
|
|
'personal-bundle' => array( |
|
41
|
|
|
'recurring-payments', |
|
42
|
|
|
), |
|
43
|
|
|
'premium-plan' => array( |
|
44
|
|
|
'calendly', |
|
45
|
|
|
'opentable', |
|
46
|
|
|
'recurring-payments', |
|
47
|
|
|
'simple-payments', |
|
48
|
|
|
), |
|
49
|
|
|
'business-plan' => array( |
|
50
|
|
|
'calendly', |
|
51
|
|
|
'opentable', |
|
52
|
|
|
'recurring-payments', |
|
53
|
|
|
'simple-payments', |
|
54
|
|
|
), |
|
55
|
|
|
'ecommerce-plan' => array( |
|
56
|
|
|
'calendly', |
|
57
|
|
|
'opentable', |
|
58
|
|
|
'recurring-payments', |
|
59
|
|
|
'simple-payments', |
|
60
|
|
|
), |
|
61
|
|
|
'wordads' => array( |
|
62
|
|
|
'wordads', |
|
63
|
|
|
), |
|
64
|
|
|
'wordads-approved' => array( |
|
65
|
|
|
'wordads', |
|
66
|
|
|
), |
|
67
|
|
|
'wordads-approved-misfits' => array( |
|
68
|
|
|
'wordads', |
|
69
|
|
|
), |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
if ( ! isset( $plan_features[ $plan ] ) ) { |
|
73
|
|
|
return array(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $plan_features[ $plan ]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Check if a WordPress.com site supports a specific feature. |
|
81
|
|
|
* |
|
82
|
|
|
* @uses get_option() |
|
83
|
|
|
* |
|
84
|
|
|
* @access public |
|
85
|
|
|
* @static |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $feature The module or feature to check. |
|
88
|
|
|
* |
|
89
|
|
|
* @return bool True if plan supports feature, false if not. |
|
90
|
|
|
*/ |
|
91
|
|
|
public static function supports( $feature ) { |
|
92
|
|
|
// If the site is not a WordPress.com site, bail. |
|
93
|
|
|
if ( ! self::is_wpcom() ) { |
|
94
|
|
|
return false; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// Get all the site's plan stickers. |
|
98
|
|
|
$plan_stickers = array_intersect( |
|
99
|
|
|
get_blog_stickers( get_current_blog_id() ), |
|
100
|
|
|
array( |
|
101
|
|
|
'blogger-plan', |
|
102
|
|
|
'personal-plan', |
|
103
|
|
|
'personal-bundle', |
|
104
|
|
|
'premium-plan', |
|
105
|
|
|
'business-plan', |
|
106
|
|
|
'ecommerce-plan', |
|
107
|
|
|
'wordads', |
|
108
|
|
|
'wordads-approved', |
|
109
|
|
|
'wordads-approved-misfits', |
|
110
|
|
|
) |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
|
|
foreach ( $plan_stickers as $plan_sticker ) { |
|
114
|
|
|
if ( in_array( $feature, self::features( $plan_sticker ), true ) ) { |
|
115
|
|
|
return true; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return false; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|