PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.17
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.17
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Addons_Plugins.php

Addons_Plugins.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.1.17, at Inc/Classes/Addons_Plugins.php

168 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Classes;
4
5 use WPAdminify\Libs\Addons;
6
7 // no direct access allowed
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 if (!class_exists('Addons_Plugins')) {
13 /**
14 * Addons Plugins class
15 *
16 * Jewel Theme <support@jeweltheme.com>
17 */
18 class Addons_Plugins extends Addons
19 {
20
21 private $transient_key = 'wp_adminify_addon_plugins_data';
22
23 /**
24 * Constructor method
25 */
26 public function __construct()
27 {
28 $this->menu_order = 99; // for submenu order value should be more than 10 .
29 parent::__construct($this->menu_order);
30 add_action('admin_enqueue_scripts', [$this, 'add_addons_thickbox']);
31 }
32
33 public function add_addons_thickbox()
34 {
35 add_thickbox();
36 }
37
38 /**
39 * Menu list
40 */
41 public function menu_items()
42 {
43 return array(
44 array(
45 'key' => 'all',
46 'label' => 'All',
47 ),
48 array(
49 'key' => 'featured', // key should be used as category to the plugin list.
50 'label' => 'Featured Item',
51 ),
52 array(
53 'key' => 'popular',
54 'label' => 'Popular',
55 ),
56 array(
57 'key' => 'favorites',
58 'label' => 'Favorites',
59 ),
60 array(
61 'key' => 'recommended',
62 'label' => 'Recommended',
63 ),
64 );
65 }
66
67 /**
68 * Get data from github
69 *
70 * @return void
71 */
72 public function get_adminify_plugins_lists()
73 {
74
75 // Return plugins data from cache if found
76 $plugins_data = get_transient($this->transient_key);
77 if (!empty($plugins_data)) return $plugins_data;
78
79 // URL of the raw file in the GitHub repository
80 $file_url = 'https://raw.githubusercontent.com/jeweltheme/adminify-addons-assets/main/adminify-plugins.json';
81
82 // Make the request to fetch the file contents
83 $response = wp_remote_get($file_url);
84
85
86 // Check if the request was successful
87 if (!is_wp_error($response) && $response['response']['code'] === 200) {
88 // Get the body of the response (file contents)
89 $file_contents = wp_remote_retrieve_body($response);
90
91 // Decode the JSON data into an array
92 $data_array = json_decode($file_contents, true);
93
94 // Check if JSON decoding was successful
95 if (!empty($data_array)) {
96 // Now you have the data in an array format, you can use it as needed
97 $plugins_data = [];
98
99 foreach ($data_array as $plugin_data) {
100
101 $plugins_data[$plugin_data['slug']] = $plugin_data;
102
103 if (str_contains($plugin_data['download_link'], 'downloads.wordpress.org')) {
104
105 require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
106
107 $plugin_info = \plugins_api('plugin_information', array('slug' => $plugin_data['slug']));
108 if (is_wp_error($plugin_info)) {
109 unset($plugins_data[$plugin_data['slug']]);
110 continue;
111 }
112 $plugins_data[$plugin_data['slug']]['version'] = $plugin_info->version;
113 } else {
114
115 if (! isset($plugin_data['version'])) {
116 unset($plugins_data[$plugin_data['slug']]);
117 continue;
118 }
119
120 $download_link = add_query_arg('version', $plugin_data['version'], $plugin_data['download_link']);
121 $plugins_data[$plugin_data['slug']]['download_link'] = $download_link;
122 }
123 }
124
125 // Get plugins data from API and cache it
126 $status = set_transient($this->transient_key, $plugins_data, DAY_IN_SECONDS / 2);
127 if (!$status) return [];
128 return $plugins_data;
129 } else {
130 // JSON decoding failed
131 echo esc_html__('Error while data retrieval.', 'adminify');
132 }
133 } else {
134 // Request failed
135 echo esc_html__('Failed to retrieve file from Source.', 'adminify');
136 }
137 }
138
139
140 /**
141 * Plugins List
142 *
143 * @author Jewel Theme <support@jeweltheme.com>
144 */
145 public function plugins_list()
146 {
147 return $this->get_adminify_plugins_lists();
148 }
149
150 /**
151 * Admin submenu
152 */
153 public function admin_menu()
154 {
155 $submenu_position = apply_filters('jltwp_adminify_submenu_position', 50);
156 add_submenu_page(
157 'wp-adminify-settings', // Ex. wp-adminify-settings / edit.php?post_type=page .
158 __('Addons', 'adminify'),
159 sprintf('<span class="adminify-addons-text">%s</span>', __('Addons', 'adminify')),
160 'manage_options',
161 'wp-adminify-addons-plugins',
162 array($this, 'render_addons_plugins'),
163 $submenu_position
164 );
165 }
166 }
167 }
168