PluginProbe
Extendify / 3.0.5
Extendify v3.0.5
3.2.1 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 All 127 releases
extendify / app / Assist / Controllers / RecommendationsController.php

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

66 lines 1.7 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 defined('ABSPATH') || die('No direct access.');
10
11 /**
12 * The controller for fetching recommendations
13 */
14
15 class RecommendationsController
16 {
17 /**
18 * The url for the server.
19 *
20 * @var string
21 */
22 public static $host = 'https://dashboard.extendify.com';
23
24 /**
25 * Return recommendations from source.
26 *
27 * @return \WP_REST_Response
28 */
29 public static function fetchRecommendations()
30 {
31 if (!defined('EXTENDIFY_PARTNER_ID')) {
32 return new \WP_REST_Response([], 200);
33 }
34
35 $partnerData = \get_option('extendify_partner_data_v2', []);
36 if (($partnerData['disableRecommendations'] ?? false)) {
37 return new \WP_REST_Response([], 200);
38 }
39
40 $params = http_build_query([
41 'wp_language' => get_locale(),
42 'sdk_partner' => defined('EXTENDIFY_PARTNER_ID') ? EXTENDIFY_PARTNER_ID : '',
43 ]);
44 $response = \wp_remote_get(
45 sprintf('%s/api/assist/recommendations?%s', static::$host, $params),
46 [
47 'headers' => [
48 'Content-Type' => 'application/json',
49 'Accept' => 'application/json',
50 ],
51 ]
52 );
53
54 if (\is_wp_error($response)) {
55 return new \WP_REST_Response([], 500);
56 }
57
58 $body = json_decode(\wp_remote_retrieve_body($response), true);
59 if (!isset($body['success']) || !isset($body['data'])) {
60 return new \WP_REST_Response([], 500);
61 }
62
63 return new \WP_REST_Response($body['data'], \wp_remote_retrieve_response_code($response));
64 }
65 }
66