Features.php
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
namespace AIOSEO\Plugin\Common\Utils;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Contains helper methods specific to the addons.
*
* @since 4.3.0
*/
class Features {
/**
* The features URL.
*
* @since 4.3.0
*
* @var string
*/
protected $featuresUrl = 'https://licensing-cdn.aioseo.com/keys/lite/all-in-one-seo-pack-pro-features.json';
/**
* Returns our features.
*
* @since 4.3.0
*
* @param boolean $flushCache Whether or not to flush the cache.
* @return array An array of addon data.
*/
public function getFeatures( $flushCache = false ) {
$features = aioseo()->core->networkCache->get( 'license_features' );
if ( null === $features || $flushCache ) {
$response = aioseo()->helpers->wpRemoteGet( $this->getFeaturesUrl() );
if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
$features = json_decode( wp_remote_retrieve_body( $response ) );
}
if ( ! $features || ! empty( $features->error ) ) {
$features = $this->getDefaultFeatures();
}
aioseo()->core->networkCache->update( 'license_features', $features );
}
return $features;
}
/**
* Get the URL to get features.
*
* @since 4.1.8
*
* @return string The URL.
*/
protected function getFeaturesUrl() {
$url = $this->featuresUrl;
if ( defined( 'AIOSEO_FEATURES_URL' ) ) {
$url = AIOSEO_FEATURES_URL;
}
return $url;
}
/**
* Retrieves a default list of all external saas features available for the current user if the API cannot be reached.
*
* @since 4.3.0
*
* @return array An array of features.
*/
protected function getDefaultFeatures() {
return json_decode( wp_json_encode( [
[
'license_level' => 'pro',
'section' => 'schema',
'feature' => 'event'
],
[
'license_level' => 'elite',
'section' => 'schema',
'feature' => 'event'
],
[
'license_level' => 'elite',
'section' => 'schema',
'feature' => 'job-posting'
],
[
'license_level' => 'elite',
'section' => 'tools',
'feature' => 'network-tools-site-activation'
],
[
'license_level' => 'elite',
'section' => 'tools',
'feature' => 'network-tools-database'
],
[
'license_level' => 'elite',
'section' => 'tools',
'feature' => 'network-tools-import-export'
],
[
'license_level' => 'elite',
'section' => 'tools',
'feature' => 'network-tools-robots'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'seo-statistics'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'keyword-rankings'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'keyword-rankings-pages'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'post-detail'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'post-detail-page-speed'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'post-detail-seo-statistics'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'post-detail-keywords'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'post-detail-focus-keyword-trend'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'keyword-tracking'
],
[
'license_level' => 'elite',
'section' => 'search-statistics',
'feature' => 'post-detail-keyword-tracking'
]
] ) );
}
/**
* Get the plans for a given feature.
*
* @since 4.3.0
*
* @param string $sectionSlug The section name.
* @param string $feature The feature name.
* @return array The plans for the feature.
*/
public function getPlansForFeature( $sectionSlug, $feature = '' ) {
$plans = [];
// Loop through all the features and find the plans that have access to the feature.
foreach ( $this->getFeatures() as $featureArray ) {
if ( $featureArray->section !== $sectionSlug ) {
continue;
}
if ( ! empty( $feature ) && $featureArray->feature !== $feature ) {
continue;
}
$plans[] = ucfirst( $featureArray->license_level );
}
return array_unique( $plans );
}
}