PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / app / Assist / Controllers / RecommendationsController.php

RecommendationsController.php in Extendify 3.1.5, at app/Assist/Controllers/RecommendationsController.php

61 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Controls Recommendations
5 */
6
7 namespace Extendify\Assist\Controllers;
8
9 use Extendify\Constants;
10
11 defined('ABSPATH') || die('No direct access.');
12
13 /**
14 * The controller for fetching recommendations
15 */
16
17 class RecommendationsController
18 {
19 /**
20 * Return recommendations from source.
21 *
22 * @return \WP_REST_Response
23 */
24 public static function fetchRecommendations()
25 {
26 if (!defined('EXTENDIFY_PARTNER_ID')) {
27 return new \WP_REST_Response([], 200);
28 }
29
30 $partnerData = \get_option('extendify_partner_data_v2', []);
31 if (($partnerData['disableRecommendations'] ?? false)) {
32 return new \WP_REST_Response([], 200);
33 }
34
35 $params = http_build_query([
36 'wp_language' => get_locale(),
37 'sdk_partner' => defined('EXTENDIFY_PARTNER_ID') ? EXTENDIFY_PARTNER_ID : '',
38 ]);
39 $response = \wp_remote_get(
40 sprintf('%s/api/assist/recommendations?%s', Constants::DASHBOARD_HOST, $params),
41 [
42 'headers' => [
43 'Content-Type' => 'application/json',
44 'Accept' => 'application/json',
45 ],
46 ]
47 );
48
49 if (\is_wp_error($response)) {
50 return new \WP_REST_Response([], 500);
51 }
52
53 $body = json_decode(\wp_remote_retrieve_body($response), true);
54 if (!isset($body['success']) || !isset($body['data'])) {
55 return new \WP_REST_Response([], 500);
56 }
57
58 return new \WP_REST_Response($body['data'], \wp_remote_retrieve_response_code($response));
59 }
60 }
61