PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 1.0.4
Adminify – White Label, Admin Menu Editor, Login Customizer v1.0.4
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 / Modules / AdminPages / AdminPages_MetaBoxes.php

AdminPages_MetaBoxes.php in Adminify – White Label, Admin Menu Editor, Login Customizer 1.0.4, at Inc/Modules/AdminPages/AdminPages_MetaBoxes.php

346 lines 11.8 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\Modules\AdminPages;
4
5 use WPAdminify\Inc\Utils;
6
7
8 // no direct access allowed
9 if (!defined('ABSPATH')) exit;
10
11 /**
12 * WPAdminify
13 * @package Admin Pages
14 *
15 * @author Jewel Theme <support@jeweltheme.com>
16 */
17
18 class AdminPages_MetaBoxes extends AdminPagesModel
19 {
20 public function __construct()
21 {
22 // this should be first so the default values get stored
23 $this->admin_pages_metaboxes();
24 parent::__construct((array) get_site_option($this->prefix));
25
26 add_filter('submenu_file', [$this, 'set_submenu'], 10, 2);
27
28 add_filter('manage_adminify_admin_page_posts_columns', [$this, 'set_columns']);
29 add_action('manage_adminify_admin_page_posts_custom_column', [$this, 'adminify_column_content'], 10, 2);
30 }
31
32
33 public function get_defaults()
34 {
35 return [
36 '_wp_adminify_menu_type' => 'top_level',
37 '_wp_adminify_sub_menu_item' => '',
38 '_wp_adminify_menu_order' => 10,
39 '_wp_adminify_menu_icon' => 'dashicons-admin-site-alt',
40 '_wp_adminify_page_title' => '',
41 '_wp_adminify_remove_margin' => '',
42 '_wp_adminify_remove_notice' => '',
43 '_wp_adminify_user_roles' => '',
44 '_wp_adminify_script_type' => 'css',
45 '_wp_adminify_custom_js' => '',
46 '_wp_adminify_custom_css' => ''
47 ];
48 }
49
50
51
52 // Set List Table Admin Pages Columns
53 public function set_columns($columns)
54 {
55 $columns = array(
56 'cb' => '<input type="checkbox" />',
57 'title' => __('Page Name', WP_ADMINIFY_TD),
58 'icon' => __('Menu Icon', WP_ADMINIFY_TD),
59 'parent_menu' => __('Parent Menu', WP_ADMINIFY_TD),
60 'roles' => __('User Roles', WP_ADMINIFY_TD)
61 );
62
63 return $columns;
64 }
65
66 // User Roles Column Content
67 public function user_roles_column_content($allowed_roles, $post_id)
68 {
69 $user_roles = Utils::post_meta('_wp_adminify_user_roles');
70 $roles = is_serialized($user_roles) ? unserialize($user_roles) : $user_roles;
71 $roles = empty($roles) ? array('all') : $roles;
72 $roles = implode(', ', $roles);
73
74 return $roles;
75 }
76
77
78 // List Table Admin Pages Column Contents
79 public function adminify_column_content($column, $post_id)
80 {
81 $admin_menu_type = Utils::post_meta('_wp_adminify_menu_type');
82
83 switch ($column) {
84 case 'parent_menu':
85 $parent_menu = __('None', WP_ADMINIFY_TD);
86 if ($admin_menu_type === 'sub_level') {
87 $parent_slug = Utils::post_meta('_wp_adminify_sub_menu_item');
88
89 foreach ($GLOBALS['menu'] as $menu) {
90 if ($menu[2] === $parent_slug) {
91 $parent_menu = $menu[0];
92 break;
93 }
94 }
95 }
96 echo esc_html($parent_menu);
97 break;
98
99 case 'roles':
100 $allowed_roles = __('All', WP_ADMINIFY_TD);
101 $allowed_roles = apply_filters('adminify_admin_page_user_roles', $this->user_roles_column_content($allowed_roles, $post_id));
102 echo ucwords($allowed_roles);
103 break;
104
105
106 case 'icon':
107 $menu_icon = Utils::post_meta('_wp_adminify_menu_icon');
108
109 $icon_class = $menu_icon ? $menu_icon : 'dashicons dashicons-no is-empty';
110
111 echo ('sub_level' === $admin_menu_type ? __('None', WP_ADMINIFY_TD) : '<i class="' . esc_attr($icon_class) . '"></i>');
112 break;
113 }
114 }
115
116 public function set_submenu($submenu_file, $parent_file)
117 {
118 global $current_screen, $parent_file;
119 if (in_array($current_screen->base, array('post', 'edit')) && 'adminify_admin_page' === $current_screen->post_type) {
120
121 $parent_file = 'edit.php?post_type=adminify_widgets';
122 $submenu_file = 'edit.php?post_type=adminify_admin_page';
123 }
124 return $submenu_file;
125 }
126
127
128 public static function get_wp_admin_menus()
129 {
130 global $menu;
131
132 $options = [];
133
134 if (!empty($menu) && is_array($menu)) {
135 foreach ($menu as $item) {
136 if (!empty($item[0])) {
137 // the preg_replace removes "Comments" & "Plugins" menu spans.
138 $options[$item[2]] = (preg_replace('/\<span.*?>.*?\<\/span><\/span>/s', '', $item[0]));
139 }
140 }
141 }
142
143 return $options;
144 }
145
146 public static function get_wp_admin_submenus()
147 {
148
149 global $submenu;
150
151 $options = [];
152
153 if (!empty($submenu) && is_array($submenu)) {
154 foreach ($submenu as $items) {
155 foreach ($items as $item) {
156 if (!empty($item[0])) {
157 $options[$item[1]] = (preg_replace('/\<span.*?>.*?\<\/span><\/span>/s', '', $item[0]));
158 }
159 }
160 }
161 }
162
163 return $options;
164 }
165
166
167 public function get_menu_type_fiels(&$menu_type_fields)
168 {
169 $menu_type_fields[] = array(
170 'id' => $this->prefix . 'menu_type',
171 'type' => 'select',
172 'title' => __('Menu Type', WP_ADMINIFY_TD),
173 'options' => array(
174 'top_level' => __('Top Level Menu', WP_ADMINIFY_TD),
175 'sub_level' => __('Sub Menu', WP_ADMINIFY_TD),
176 ),
177 'default' => $this->get_default_field('_wp_adminify_menu_type')
178 );
179
180 $menu_type_fields[] = array(
181 'id' => $this->prefix . 'sub_menu_item',
182 'type' => 'select',
183 'title' => __('Select Sub Menu', WP_ADMINIFY_TD),
184 'placeholder' => __('Select a menu', WP_ADMINIFY_TD),
185 'options' => 'WPAdminify\Inc\Modules\AdminPages\AdminPages_MetaBoxes::get_wp_admin_menus',
186 'dependency' => array($this->prefix . 'menu_type', '==', 'sub_level', 'true'),
187 'default' => $this->get_default_field('_wp_adminify_sub_menu_item')
188 );
189
190 $menu_type_fields[] = array(
191 'id' => $this->prefix . 'menu_order',
192 'type' => 'text',
193 'title' => __('Menu Order', WP_ADMINIFY_TD),
194 'default' => $this->get_default_field('_wp_adminify_menu_order')
195 );
196
197 $menu_type_fields[] = array(
198 'id' => $this->prefix . 'menu_icon',
199 'type' => 'icon',
200 'title' => __('Icon', WP_ADMINIFY_TD),
201 'default' => $this->get_default_field('_wp_adminify_menu_icon')
202 );
203 }
204
205
206 public function admin_pages_metaboxes()
207 {
208 if (!class_exists('ADMINIFY')) {
209 return;
210 }
211
212 // Admin Pages Metabox
213 \ADMINIFY::createMetabox($this->prefix, array(
214 'title' => __('Menu Attributes', WP_ADMINIFY_TD),
215 'post_type' => 'adminify_admin_page',
216 'context' => 'side',
217 'priority' => 'low',
218 'data_type' => 'unserialize'
219 ));
220
221 $menu_type_fields = [];
222 $this->get_menu_type_fiels($menu_type_fields);
223
224 // Activate
225 \ADMINIFY::createSection($this->prefix, array(
226 'fields' => $menu_type_fields
227 ));
228
229 // Display Options
230 \ADMINIFY::createMetabox($this->prefix . 'admin_page_display', array(
231 'title' => __('Display Options', WP_ADMINIFY_TD),
232 'post_type' => 'adminify_admin_page',
233 'context' => 'normal',
234 'priority' => 'high',
235 'data_type' => 'unserialize'
236 ));
237
238 $remove_notice = [];
239 $this->get_remove_notice_fields($remove_notice);
240 \ADMINIFY::createSection($this->prefix . 'admin_page_display', array(
241 'title' => __('Enable/Disable', WP_ADMINIFY_TD),
242 'fields' => $remove_notice
243 ));
244
245 // User Roles
246 \ADMINIFY::createSection($this->prefix . 'admin_page_display', array(
247 'title' => 'User Roles Access',
248 'fields' => array(
249 array(
250 'id' => $this->prefix . 'user_roles',
251 'type' => 'select',
252 'title' => __('Allow users to access this page', WP_ADMINIFY_TD),
253 'placeholder' => __('Select a role', WP_ADMINIFY_TD),
254 'chosen' => true,
255 'multiple' => true,
256 'options' => 'roles',
257 'default' => $this->get_default_field('_wp_adminify_user_roles')
258 ),
259
260 )
261 ));
262
263 $custom_css_js = [];
264 $this->get_custom_css_js($custom_css_js);
265
266 // Advanced
267 \ADMINIFY::createSection($this->prefix . 'admin_page_display', array(
268 'title' => __('Custom CSS/JS', WP_ADMINIFY_TD),
269 'fields' => $custom_css_js
270 ));
271 }
272
273
274 public function get_remove_notice_fields(&$remove_notice)
275 {
276 $remove_notice[] = array(
277 'id' => $this->prefix . 'page_title',
278 'type' => 'checkbox',
279 'title' => __('Remove Page Title', WP_ADMINIFY_TD),
280 'label' => __('Remove Page Title from your created Custom Admin Page.', WP_ADMINIFY_TD),
281 'default' => $this->get_default_field('_wp_adminify_page_title')
282 );
283 $remove_notice[] = array(
284 'id' => $this->prefix . 'remove_margin',
285 'type' => 'checkbox',
286 'title' => __('Remove Page Margin', WP_ADMINIFY_TD),
287 'label' => __('Remove default Page Margin from Custom Admin Page', WP_ADMINIFY_TD),
288 'default' => $this->get_default_field('_wp_adminify_remove_margin')
289 );
290 $remove_notice[] = array(
291 'id' => $this->prefix . 'remove_notice',
292 'type' => 'checkbox',
293 'title' => __('Remove Admin Notices', WP_ADMINIFY_TD),
294 'label' => __('Remove Admin Notices from Custom Admin page', WP_ADMINIFY_TD),
295 'default' => $this->get_default_field('_wp_adminify_remove_notice')
296 );
297 }
298
299 /**
300 * Custom CSS/JS Options
301 *
302 * @param [type] $custom_css_js
303 *
304 * @return void
305 */
306 public function get_custom_css_js(&$custom_css_js)
307 {
308 $custom_css_js[] = array(
309 'id' => $this->prefix . 'script_type',
310 'type' => 'button_set',
311 'title' => __('Snippet Type', WP_ADMINIFY_TD),
312 'options' => array(
313 'css' => __('CSS', WP_ADMINIFY_TD),
314 'js' => __('JS', WP_ADMINIFY_TD),
315 ),
316 'default' => $this->get_default_field('_wp_adminify_script_type')
317 );
318
319 $custom_css_js[] = array(
320 'id' => $this->prefix . 'custom_js',
321 'type' => 'code_editor',
322 'title' => __('Custom JS', WP_ADMINIFY_TD),
323 'subtitle' => __('Add your Custom Script here', WP_ADMINIFY_TD),
324 'settings' => array(
325 'theme' => 'dracula',
326 'mode' => 'javascript',
327 ),
328 'dependency' => array($this->prefix . 'script_type', '==', 'js'),
329 'default' => $this->get_default_field('_wp_adminify_custom_js')
330 );
331
332 $custom_css_js[] = array(
333 'id' => $this->prefix . 'custom_css',
334 'type' => 'code_editor',
335 'title' => __('Custom CSS', WP_ADMINIFY_TD),
336 'subtitle' => __('Add your Custom CSS here', WP_ADMINIFY_TD),
337 'settings' => array(
338 'theme' => 'mbo',
339 'mode' => 'css',
340 ),
341 'dependency' => array($this->prefix . 'script_type', '==', 'css'),
342 'default' => $this->get_default_field('_wp_adminify_custom_css')
343 );
344 }
345 }
346