PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.17
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.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.2.17, at Inc/Classes/Addons_Plugins.php

161 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc\Classes;
4
5 use PXLBSAdminify\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 = 'pxlbsadminify_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 // Read the add-ons catalogue from the copy bundled with the plugin
80 // (no remote request).
81 $catalogue_file = PXLBSADMINIFY_PATH . 'Inc/data/adminify-plugins.json';
82
83 if (!is_readable($catalogue_file)) {
84 return array();
85 }
86
87 $data_array = wp_json_file_decode($catalogue_file, array('associative' => true));
88
89 if (empty($data_array) || !is_array($data_array)) {
90 return array();
91 }
92
93 $plugins_data = [];
94
95 foreach ($data_array as $plugin_data) {
96
97 $plugins_data[$plugin_data['slug']] = $plugin_data;
98
99 if (str_contains($plugin_data['download_link'], 'downloads.wordpress.org')) {
100
101 require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
102
103 $plugin_info = \plugins_api('plugin_information', array('slug' => $plugin_data['slug']));
104 if (is_wp_error($plugin_info)) {
105 unset($plugins_data[$plugin_data['slug']]);
106 continue;
107 }
108 $plugins_data[$plugin_data['slug']]['version'] = $plugin_info->version;
109 } else {
110
111 if (! isset($plugin_data['version'])) {
112 unset($plugins_data[$plugin_data['slug']]);
113 continue;
114 }
115
116 $download_link = add_query_arg('version', $plugin_data['version'], $plugin_data['download_link']);
117 $plugins_data[$plugin_data['slug']]['download_link'] = $download_link;
118 }
119 }
120
121 // Cache the processed catalogue.
122 set_transient($this->transient_key, $plugins_data, DAY_IN_SECONDS / 2);
123
124 return $plugins_data;
125 }
126
127
128 /**
129 * Plugins List
130 *
131 * @author Jewel Theme <support@jeweltheme.com>
132 */
133 public function plugins_list()
134 {
135 // Do not hit the remote source on every admin load. At construction
136 // we only return the cached catalogue; the live fetch happens on the
137 // Add-ons page (get_addons_plugins_list) and on addon install, both
138 // of which are explicit user actions.
139 $cached = get_transient( $this->transient_key );
140 return ! empty( $cached ) ? $cached : array();
141 }
142
143 /**
144 * Admin submenu
145 */
146 public function admin_menu()
147 {
148 $submenu_position = apply_filters('pxlbsadminify_submenu_position', 50);
149 add_submenu_page(
150 'wp-adminify-settings', // Ex. wp-adminify-settings / edit.php?post_type=page .
151 __('Addons', 'adminify'),
152 sprintf('<span class="adminify-addons-text">%s</span>', __('Addons', 'adminify')),
153 'manage_options',
154 'wp-adminify-addons-plugins',
155 array($this, 'render_addons_plugins'),
156 $submenu_position
157 );
158 }
159 }
160 }
161