PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.2
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.2
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / admin / templates / includes / classes / api.php

api.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.2, at inc/admin/templates/includes/classes/api.php

114 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Author Name: Liton Arefin
4 * Author URL: https://jeweltheme.com
5 * Date: 9/8/19
6 */
7
8
9 namespace MasterAddons\Inc\Admin\Templates\Includes\Classes;
10
11 use MasterAddons\Inc\Admin\Templates;
12
13 if( ! defined( 'ABSPATH' ) ) exit; // No access of directly access
14
15 if ( ! class_exists( 'API' ) ) {
16
17 class API {
18
19 private $config = array();
20
21 private $enabled = null;
22
23 public function __construct() {
24 $this->config = Templates\master_addons_templates()->config->get( 'api' );
25 }
26
27
28 public function is_enabled() {
29
30 if ( null !== $this->enabled ) {
31 return $this->enabled;
32 }
33
34 if ( empty( $this->config['enabled'] ) || true !== $this->config['enabled'] ) {
35 $this->enabled = false;
36 return $this->enabled;
37 }
38
39 if ( empty( $this->config['base'] ) || empty( $this->config['path'] ) || empty( $this->config['endpoints'] ) ) {
40 $this->enabled = false;
41 return $this->enabled;
42 }
43
44 $this->enabled = true;
45
46 return $this->enabled;
47 }
48
49 public function api_url( $flag ) {
50
51 if ( ! $this->is_enabled() ) {
52 return false;
53 }
54
55 if ( empty( $this->config['endpoints'][ $flag ] ) ) {
56 return false;
57 }
58
59 return $this->config['base'] . $this->config['path'] . $this->config['endpoints'][ $flag ];
60 }
61
62
63 public function get_info( $key = '' ) {
64
65 $api_url = $this->api_url( 'info' );
66
67 if ( ! $api_url ) {
68 return false;
69 }
70
71 $response = wp_remote_get( $api_url, $this->request_args() );
72
73 $body = wp_remote_retrieve_body( $response );
74 $body = json_decode( $body, true );
75
76 if ( ! $body || ! isset( $body['success'] ) || true !== $body['success'] ) {
77 return false;
78 }
79
80 if ( ! $key ) {
81 unset( $body['success'] );
82 return $body;
83 }
84
85 if ( is_string( $key ) ) {
86 return isset( $body[ $key ] ) ? $body[ $key ] : false;
87 }
88
89 if ( is_array( $key ) ) {
90
91 $result = array();
92
93 foreach ( $key as $_key ) {
94 $result[ $_key ] = isset( $body[ $_key ] ) ? $body[ $_key ] : false;
95 }
96
97 return $result;
98
99 }
100
101 }
102
103
104 public function request_args() {
105 return array(
106 'timeout' => 60,
107 'sslverify' => false
108 );
109 }
110
111 }
112
113 }
114