PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.2
Elementor Website Builder – more than just a page builder v3.13.2
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | app/modules/kit-library/data/repository.php +8 -28 4.1.0-dev23.13.2 View file →
@@ -1,8 +1,7 @@
1 1 <?php
2 2 namespace Elementor\App\Modules\KitLibrary\Data;
3 3
4 -use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
5 4 use Elementor\Core\Utils\Collection;
6 5 use Elementor\Data\V2\Base\Exceptions\Error_404;
7 6 use Elementor\Data\V2\Base\Exceptions\WP_Error_Exception;
8 7 use Elementor\Modules\Library\User_Favorites;
@@ -63,10 +62,8 @@
63 62 * @param $id
64 63 * @param array $options
65 64 *
66 65 * @return array|null
67 - *
68 - * @throws WP_Error_Exception If kit is not found.
69 66 */
70 67 public function find( $id, $options = [] ) {
71 68 $options = wp_parse_args( $options, [
72 69 'manifest_included' => true,
@@ -86,9 +83,9 @@
86 83 if ( $options['manifest_included'] ) {
87 84 $manifest = $this->api->get_manifest( $id );
88 85
89 86 if ( is_wp_error( $manifest ) ) {
90 - throw new WP_Error_Exception( esc_html( $manifest ) );
87 + throw new WP_Error_Exception( $manifest );
91 88 }
92 89 }
93 90
94 91 return $this->transform_kit_api_response( $item, $manifest );
@@ -124,16 +121,14 @@
124 121 /**
125 122 * @param $id
126 123 *
127 124 * @return array
128 - *
129 - * @throws WP_Error_Exception If download link retrieval fails or API errors occur.
130 125 */
131 126 public function get_download_link( $id ) {
132 127 $response = $this->api->download_link( $id );
133 128
134 129 if ( is_wp_error( $response ) ) {
135 - throw new WP_Error_Exception( esc_html( $response ) );
130 + throw new WP_Error_Exception( $response );
136 131 }
137 132
138 133 return [ 'download_link' => $response->download_link ];
139 134 }
@@ -141,10 +136,9 @@
141 136 /**
142 137 * @param $id
143 138 *
144 139 * @return array
145 - *
146 - * @throws Error_404 If kit is not found.
140 + * @throws \Exception
147 141 */
148 142 public function add_to_favorites( $id ) {
149 143 $kit = $this->find( $id, [ 'manifest_included' => false ] );
150 144
@@ -162,10 +156,9 @@
162 156 /**
163 157 * @param $id
164 158 *
165 159 * @return array
166 - *
167 - * @throws Error_404 If kit is not found.
160 + * @throws \Exception
168 161 */
169 162 public function remove_from_favorites( $id ) {
170 163 $kit = $this->find( $id, [ 'manifest_included' => false ] );
171 164
@@ -183,10 +176,8 @@
183 176 /**
184 177 * @param bool $force_api_request
185 178 *
186 179 * @return Collection
187 - *
188 - * @throws WP_Error_Exception If kits data retrieval fails.
189 180 */
190 181 private function get_kits_data( $force_api_request = false ) {
191 182 $data = get_transient( static::KITS_CACHE_KEY );
192 183
@@ -211,9 +202,9 @@
211 202
212 203 $data = $this->api->get_all( $args );
213 204
214 205 if ( is_wp_error( $data ) ) {
215 - throw new WP_Error_Exception( esc_html( $data ) );
206 + throw new WP_Error_Exception( $data );
216 207 }
217 208
218 209 set_transient( static::KITS_CACHE_KEY, $data, static::KITS_CACHE_TTL_HOURS * HOUR_IN_SECONDS );
219 210 }
@@ -224,10 +215,8 @@
224 215 /**
225 216 * @param bool $force_api_request
226 217 *
227 218 * @return Collection
228 - *
229 - * @throws WP_Error_Exception If taxonomies data retrieval fails.
230 219 */
231 220 private function get_taxonomies_data( $force_api_request = false ) {
232 221 $data = get_transient( static::KITS_TAXONOMIES_CACHE_KEY );
233 222
@@ -234,9 +223,9 @@
234 223 if ( ! $data || $force_api_request ) {
235 224 $data = $this->api->get_taxonomies();
236 225
237 226 if ( is_wp_error( $data ) ) {
238 - throw new WP_Error_Exception( esc_html( $data ) );
227 + throw new WP_Error_Exception( $data );
239 228 }
240 229
241 230 set_transient( static::KITS_TAXONOMIES_CACHE_KEY, $data, static::KITS_TAXONOMIES_CACHE_TTL_HOURS * HOUR_IN_SECONDS );
242 231 }
@@ -250,19 +239,10 @@
250 239 *
251 240 * @return array
252 241 */
253 242 private function transform_kit_api_response( $kit, $manifest = null ) {
254 - // BC: Support legacy APIs that don't have access tiers.
255 - if ( isset( $kit->access_tier ) ) {
256 - $access_tier = $kit->access_tier;
257 - } else {
258 - $access_tier = 0 === $kit->access_level
259 - ? ConnectModule::ACCESS_TIER_FREE
260 - : ConnectModule::ACCESS_TIER_ESSENTIAL;
261 - }
243 + $subscription_plan_tag = $this->subscription_plans->get( $kit->access_level );
262 244
263 - $subscription_plan_tag = $this->subscription_plans->get( $access_tier );
264 -
265 245 $taxonomies = ( new Collection( ( (array) $kit )['taxonomies'] ) )
266 246 ->filter( function ( $taxonomy ) {
267 247 return in_array( $taxonomy->type, self::TAXONOMIES_KEYS );
268 248 } )
@@ -275,9 +255,8 @@
275 255 'id' => $kit->_id,
276 256 'title' => $kit->title,
277 257 'thumbnail_url' => $kit->thumbnail,
278 258 'access_level' => $kit->access_level,
279 - 'access_tier' => $access_tier,
280 259 'keywords' => $kit->keywords,
281 260 'taxonomies' => $taxonomies->values(),
282 261 'is_favorite' => $this->user_favorites->exists( 'elementor', 'kits', $kit->_id ),
283 262 // TODO: Remove all the isset when the API stable.
@@ -285,8 +264,9 @@
285 264 'featured_index' => isset( $kit->featured_index ) ? $kit->featured_index : 0,
286 265 'popularity_index' => isset( $kit->popularity_index ) ? $kit->popularity_index : 0,
287 266 'created_at' => isset( $kit->created_at ) ? $kit->created_at : null,
288 267 'updated_at' => isset( $kit->updated_at ) ? $kit->updated_at : null,
268 + //
289 269 ],
290 270 $manifest ? $this->transform_manifest_api_response( $manifest ) : []
291 271 );
292 272 }