PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 6.9.2
Admin and Site Enhancements (ASE) v6.9.2
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-admin-interface.php
admin-site-enhancements / classes Last commit date
class-activation.php 2 years ago class-admin-interface.php 2 years ago class-common-methods.php 2 years ago class-content-management.php 2 years ago class-custom-code.php 2 years ago class-deactivation.php 2 years ago class-disable-components.php 2 years ago class-login-logout.php 2 years ago class-optimizations.php 2 years ago class-security.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-utilities.php 2 years ago
class-admin-interface.php
1374 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 use WP_Admin_Bar ;
6 use ArrayObject ;
7 use NumberFormatter ;
8 /**
9 * Class related to Admin Interface features
10 *
11 * @since 1.2.0
12 */
13 class Admin_Interface
14 {
15 /**
16 * Modify admin bar menu for Admin Interface >> Hide or Modify Elements feature
17 *
18 * @param $wp_admin_bar object The admin bar.
19 * @since 1.9.0
20 */
21 public function modify_admin_bar_menu( $wp_admin_bar )
22 {
23 $options = get_option( ASENHA_SLUG_U, array() );
24 // Hide WP Logo Menu
25
26 if ( array_key_exists( 'hide_ab_wp_logo_menu', $options ) && $options['hide_ab_wp_logo_menu'] ) {
27 remove_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
28 // priority needs to match default value. Use QM to reference.
29 }
30
31 // Hide Customize Menu
32
33 if ( array_key_exists( 'hide_ab_customize_menu', $options ) && $options['hide_ab_customize_menu'] ) {
34 remove_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 );
35 // priority needs to match default value. Use QM to reference.
36 }
37
38 // Hide Updates Counter/Link
39
40 if ( array_key_exists( 'hide_ab_updates_menu', $options ) && $options['hide_ab_updates_menu'] ) {
41 remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 );
42 // priority needs to match default value. Use QM to reference.
43 }
44
45 // Hide Comments Counter/Link
46
47 if ( array_key_exists( 'hide_ab_comments_menu', $options ) && $options['hide_ab_comments_menu'] ) {
48 remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
49 // priority needs to match default value. Use QM to reference.
50 }
51
52 // Hide New Content Menu
53
54 if ( array_key_exists( 'hide_ab_new_content_menu', $options ) && $options['hide_ab_new_content_menu'] ) {
55 remove_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 );
56 // priority needs to match default value. Use QM to reference.
57 }
58
59 // Hide 'Howdy' text
60
61 if ( array_key_exists( 'hide_ab_howdy', $options ) && $options['hide_ab_howdy'] ) {
62 // Remove the whole my account sectino and later rebuild it
63 remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 );
64 $current_user = wp_get_current_user();
65 $user_id = get_current_user_id();
66 $profile_url = get_edit_profile_url( $user_id );
67 $avatar = get_avatar( $user_id, 26 );
68 // size 26x26 pixels
69 $display_name = $current_user->display_name;
70 $class = ( $avatar ? 'with-avatar' : 'no-avatar' );
71 $wp_admin_bar->add_menu( array(
72 'id' => 'my-account',
73 'parent' => 'top-secondary',
74 'title' => $display_name . $avatar,
75 'href' => $profile_url,
76 'meta' => array(
77 'class' => $class,
78 ),
79 ) );
80 }
81
82 }
83
84 /**
85 * Wrapper for admin notices being output on admin screens
86 *
87 * @since 1.2.0
88 */
89 public function admin_notices_wrapper()
90 {
91 $options = get_option( ASENHA_SLUG_U, array() );
92 $hide_for_nonadmins = ( isset( $options['hide_admin_notices_for_nonadmins'] ) ? $options['hide_admin_notices_for_nonadmins'] : false );
93 $minimum_capability = 'manage_options';
94 if ( function_exists( 'bwasenha_fs' ) ) {
95 if ( $hide_for_nonadmins && bwasenha_fs()->can_use_premium_code__premium_only() ) {
96 $minimum_capability = 'read';
97 }
98 }
99 if ( current_user_can( $minimum_capability ) ) {
100 echo '<div class="asenha-admin-notices-drawer" style="display:none;"><h2>Admin Notices</h2></div>' ;
101 }
102 }
103
104 /**
105 * Admin bar menu item for the hidden admin notices
106 *
107 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/add_menu/
108 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/
109 * @since 1.2.0
110 */
111 public function admin_notices_menu( WP_Admin_Bar $wp_admin_bar )
112 {
113 // Only show Notices menu in wp-admin but when not in Customizer preview
114
115 if ( is_admin() && !is_customize_preview() ) {
116 $options = get_option( ASENHA_SLUG_U, array() );
117 $hide_for_nonadmins = ( isset( $options['hide_admin_notices_for_nonadmins'] ) ? $options['hide_admin_notices_for_nonadmins'] : false );
118 $minimum_capability = 'manage_options';
119 if ( function_exists( 'bwasenha_fs' ) ) {
120 if ( $hide_for_nonadmins && bwasenha_fs()->can_use_premium_code__premium_only() ) {
121 $minimum_capability = 'read';
122 }
123 }
124 if ( current_user_can( $minimum_capability ) ) {
125 $wp_admin_bar->add_menu( array(
126 'id' => 'asenha-hide-admin-notices',
127 'parent' => 'top-secondary',
128 'grou' => null,
129 'title' => 'Notices<span class="asenha-admin-notices-counter" style="opacity:0;">0</span>',
130 'meta' => array(
131 'class' => 'asenha-admin-notices-menu',
132 'title' => 'Click to view hidden admin notices',
133 ),
134 ) );
135 }
136 }
137
138 }
139
140 /**
141 * Inline CSS for the hiding notices on page load in wp admin pages
142 *
143 * @since 1.2.0
144 */
145 public function admin_notices_menu_inline_css()
146 {
147 $options = get_option( ASENHA_SLUG_U, array() );
148 $hide_for_nonadmins = ( isset( $options['hide_admin_notices_for_nonadmins'] ) ? $options['hide_admin_notices_for_nonadmins'] : false );
149 $minimum_capability = 'manage_options';
150 if ( function_exists( 'bwasenha_fs' ) ) {
151 if ( $hide_for_nonadmins && bwasenha_fs()->can_use_premium_code__premium_only() ) {
152 $minimum_capability = 'read';
153 }
154 }
155
156 if ( is_admin() && !is_customize_preview() && current_user_can( $minimum_capability ) ) {
157 // Below we pre-emptively hide notices to avoid having them shown briefly before being moved into the notices panel via JS
158 ?>
159 <style type="text/css">
160 #wpadminbar .asenha-admin-notices-menu .ab-empty-item {
161 cursor: pointer;
162 }
163
164 #wpadminbar .asenha-admin-notices-counter {
165 box-sizing: border-box;
166 margin: 1px 0 -1px 6px ;
167 padding: 2px 6px 3px 5px;
168 min-width: 18px;
169 height: 18px;
170 border-radius: 50%;
171 background-color: #ca4a1f;
172 color: #fff;
173 font-size: 11px;
174 line-height: 1.6;
175 text-align: center;
176 }
177
178 /* #wpbody-content .notice:not(.system-notice,.update-message),
179 #wpbody-content .notice-error,
180 #wpbody-content .error,
181 #wpbody-content .notice-info,
182 #wpbody-content .notice-information,
183 #wpbody-content #message,
184 #wpbody-content .notice-warning:not(.update-message),
185 #wpbody-content .notice-success:not(.update-message),
186 #wpbody-content .notice-updated,
187 #wpbody-content .updated:not(.active, .inactive, .plugin-update-tr),
188 #wpbody-content .update-nag, */
189 #wpbody-content > .wrap > .notice:not(.system-notice,.hidden),
190 #wpbody-content > .wrap > .notice-error,
191 #wpbody-content > .wrap > .error:not(.hidden),
192 #wpbody-content > .wrap > .notice-info,
193 #wpbody-content > .wrap > .notice-information,
194 #wpbody-content > .wrap > #message,
195 #wpbody-content > .wrap > .notice-warning:not(.hidden),
196 #wpbody-content > .wrap > .notice-success,
197 #wpbody-content > .wrap > .notice-updated,
198 #wpbody-content > .wrap > .updated,
199 #wpbody-content > .wrap > .update-nag,
200 #wpbody-content > .wrap > div > .notice:not(.system-notice,.hidden),
201 #wpbody-content > .wrap > div > .notice-error,
202 #wpbody-content > .wrap > div > .error:not(.hidden),
203 #wpbody-content > .wrap > div > .notice-info,
204 #wpbody-content > .wrap > div > .notice-information,
205 #wpbody-content > .wrap > div > #message,
206 #wpbody-content > .wrap > div > .notice-warning:not(.hidden),
207 #wpbody-content > .wrap > div > .notice-success,
208 #wpbody-content > .wrap > div > .notice-updated,
209 #wpbody-content > .wrap > div > .updated,
210 #wpbody-content > .wrap > div > .update-nag,
211 #wpbody-content > div > .wrap > .notice:not(.system-notice,.hidden),
212 #wpbody-content > div > .wrap > .notice-error,
213 #wpbody-content > div > .wrap > .error:not(.hidden),
214 #wpbody-content > div > .wrap > .notice-info,
215 #wpbody-content > div > .wrap > .notice-information,
216 #wpbody-content > div > .wrap > #message,
217 #wpbody-content > div > .wrap > .notice-warning:not(.hidden),
218 #wpbody-content > div > .wrap > .notice-success,
219 #wpbody-content > div > .wrap > .notice-updated,
220 #wpbody-content > div > .wrap > .updated,
221 #wpbody-content > div > .wrap > .update-nag,
222 #wpbody-content > .notice,
223 #wpbody-content > .error,
224 #wpbody-content > .updated,
225 #wpbody-content > .update-nag,
226 #wpbody-content > .jp-connection-banner,
227 #wpbody-content > .jitm-banner,
228 #wpbody-content > .jetpack-jitm-message,
229 #wpbody-content > .ngg_admin_notice,
230 #wpbody-content > .imagify-welcome,
231 #wpbody-content #wordfenceAutoUpdateChoice,
232 #wpbody-content #easy-updates-manager-dashnotice,
233 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice:not(.system-notice,.hidden),
234 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-error,
235 #wpbody-content > .wrap.gblocks-dashboard-wrap .error:not(.hidden),
236 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-info,
237 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-information,
238 #wpbody-content > .wrap.gblocks-dashboard-wrap #message,
239 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-warning:not(.hidden),
240 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-success,
241 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-updated,
242 #wpbody-content > .wrap.gblocks-dashboard-wrap .updated,
243 #wpbody-content > .wrap.gblocks-dashboard-wrap .update-nag {
244 position: absolute !important;
245 visibility: hidden !important;
246 }
247 </style>
248 <?php
249 }
250
251 }
252
253 /**
254 * Disable dashboard widgets
255 *
256 * @since 4.2.0
257 */
258 public function disable_dashboard_widgets()
259 {
260 global $wp_meta_boxes ;
261 // Get list of disabled widgets
262 $options = get_option( ASENHA_SLUG_U, array() );
263 $disabled_dashboard_widgets = $options['disabled_dashboard_widgets'];
264 // Store default widgets in extra options. This will be referenced from settings field.
265 $dashboard_widgets = $this->get_dashboard_widgets();
266 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
267 $options_extra['dashboard_widgets'] = $dashboard_widgets;
268 update_option( 'admin_site_enhancements_extra', $options_extra );
269 // Disable widgets
270 if ( is_array( $disabled_dashboard_widgets ) || is_object( $disabled_dashboard_widgets ) ) {
271 foreach ( $disabled_dashboard_widgets as $disabled_widget_id_context_priority => $is_disabled ) {
272 // e.g. dashboard_activity__normal__core => true/false
273
274 if ( $is_disabled ) {
275 $disabled_widget = explode( '__', $disabled_widget_id_context_priority );
276 $widget_id = $disabled_widget[0];
277 $widget_context = $disabled_widget[1];
278 $widget_priority = $disabled_widget[2];
279 // remove_meta_box( $widget_id, get_current_screen()->base, $widget_context );
280 unset( $wp_meta_boxes['dashboard'][$widget_context][$widget_priority][$widget_id] );
281 }
282
283 }
284 }
285 }
286
287 /**
288 * Get dashboard widgets
289 *
290 * @since 4.2.0
291 */
292 public function get_dashboard_widgets()
293 {
294 global $wp_meta_boxes ;
295 $dashboard_widgets = array();
296
297 if ( !isset( $wp_meta_boxes['dashboard'] ) ) {
298 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
299
300 if ( !array_key_exists( 'dashboard_widgets', $options_extra ) ) {
301 require_once ABSPATH . '/wp-admin/includes/dashboard.php';
302 set_current_screen( 'dashboard' );
303 wp_dashboard_setup();
304 }
305
306 }
307
308 if ( isset( $wp_meta_boxes['dashboard'] ) ) {
309 foreach ( $wp_meta_boxes['dashboard'] as $context => $priorities ) {
310 foreach ( $priorities as $priority => $widgets ) {
311 foreach ( $widgets as $widget_id => $data ) {
312 $widget_title = ( isset( $data['title'] ) ? wp_strip_all_tags( preg_replace( '/ <span.*span>/im', '', $data['title'] ) ) : 'Undetectable' );
313 $dashboard_widgets[$widget_id] = array(
314 'id' => $widget_id,
315 'title' => $widget_title,
316 'context' => $context,
317 'priority' => $priority,
318 );
319 }
320 }
321 }
322 }
323 $dashboard_widgets = wp_list_sort(
324 $dashboard_widgets,
325 'title',
326 'ASC',
327 true
328 );
329 return $dashboard_widgets;
330 }
331
332 /**
333 * Hide admin bar on the frontend for the user roles selected
334 *
335 * @since 1.3.0
336 */
337 public function hide_admin_bar_for_roles_on_frontend()
338 {
339 $options = get_option( ASENHA_SLUG_U );
340 $hide_admin_bar = $options['hide_admin_bar'];
341 $for_roles_frontend = $options['hide_admin_bar_for'];
342 $current_user = wp_get_current_user();
343 $current_user_roles = (array) $current_user->roles;
344 // single dimensional array of role slugs
345 // User has no role, i.e. logged-out
346
347 if ( count( $current_user_roles ) == 0 ) {
348 return false;
349 // hide admin bar
350 }
351
352 // User has role(s). Do further checks.
353
354 if ( isset( $for_roles_frontend ) && count( $for_roles_frontend ) > 0 ) {
355 // Assemble single-dimensional array of roles for which admin bar would be hidden
356 $roles_admin_bar_hidden_frontend = array();
357 foreach ( $for_roles_frontend as $role_slug => $admin_bar_hidden ) {
358 if ( $admin_bar_hidden ) {
359 $roles_admin_bar_hidden_frontend[] = $role_slug;
360 }
361 }
362 // Check if any of the current user roles is one for which admin bar should be hidden
363 foreach ( $current_user_roles as $role ) {
364
365 if ( in_array( $role, $roles_admin_bar_hidden_frontend ) ) {
366 return false;
367 // hide admin bar
368 }
369
370 }
371 }
372
373 return true;
374 // show admin bar
375 }
376
377 /**
378 * Set custom admin menu width
379 *
380 * @since 5.2.0
381 */
382 public function set_custom_menu_width()
383 {
384 $options = get_option( ASENHA_SLUG_U, array() );
385 $custom_width = $options['admin_menu_width'];
386 $wp_version = get_bloginfo( 'version' );
387
388 if ( version_compare( $wp_version, '5', '>' ) ) {
389 require_once ASENHA_PATH . 'includes/admin-menu-width/wp-v5-greater.php';
390 } elseif ( version_compare( $wp_version, '4', '>=' ) ) {
391 require_once ASENHA_PATH . 'includes/admin-menu-width/wp-v4-greater.php';
392 } else {
393 }
394
395 }
396
397 /**
398 * Render custom menu order
399 *
400 * @param $menu_order array an ordered array of menu items
401 * @link https://developer.wordpress.org/reference/hooks/menu_order/
402 * @since 2.0.0
403 */
404 public function render_custom_menu_order( $menu_order )
405 {
406 global $menu ;
407 $options = get_option( ASENHA_SLUG_U );
408 // Get current menu order. We're not using the default $menu_order which uses index.php, edit.php as array values.
409 $current_menu_order = array();
410 foreach ( $menu as $menu_key => $menu_info ) {
411
412 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
413 $menu_item_id = $menu_info[2];
414 } else {
415 $menu_item_id = $menu_info[5];
416 }
417
418 $current_menu_order[] = array( $menu_item_id, $menu_info[2] );
419 }
420 // Get custom menu order
421 $custom_menu_order = $options['custom_menu_order'];
422 // comma separated
423 $custom_menu_order = explode( ",", $custom_menu_order );
424 // array of menu ID, e.g. menu-dashboard
425 // Return menu order for rendering
426 $rendered_menu_order = array();
427 // Render menu based on items saved in custom menu order
428 foreach ( $custom_menu_order as $custom_menu_item_id ) {
429 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
430 if ( $custom_menu_item_id == $current_menu_item[0] ) {
431 $rendered_menu_order[] = $current_menu_item[1];
432 }
433 }
434 }
435 // Add items from current menu not already part of custom menu order, e.g. new plugin activated and adds new menu item
436 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
437 if ( !in_array( $current_menu_item[0], $custom_menu_order ) ) {
438 $rendered_menu_order[] = $current_menu_item[1];
439 }
440 }
441 return $rendered_menu_order;
442 }
443
444 /**
445 * Apply custom menu item titles
446 *
447 * @since 2.9.0
448 */
449 public function apply_custom_menu_item_titles()
450 {
451 global $menu ;
452 $options = get_option( ASENHA_SLUG_U );
453 // Get custom menu item titles
454 $custom_menu_titles = $options['custom_menu_titles'];
455 $custom_menu_titles = explode( ',', $custom_menu_titles );
456 foreach ( $menu as $menu_key => $menu_info ) {
457
458 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
459 $menu_item_id = $menu_info[2];
460 } else {
461 $menu_item_id = $menu_info[5];
462 }
463
464 // Get defaul/custom menu item title
465 foreach ( $custom_menu_titles as $custom_menu_title ) {
466 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
467 $custom_menu_title = explode( '__', $custom_menu_title );
468
469 if ( $custom_menu_title[0] == $menu_item_id ) {
470 $menu_item_title = $custom_menu_title[1];
471 // e.g. Code Snippets
472 break;
473 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
474 } else {
475 $menu_item_title = $menu_info[0];
476 }
477
478 }
479 $menu[$menu_key][0] = $menu_item_title;
480 }
481 }
482
483 /**
484 * Hide menu items by adding a class to hide them (part of WP Core's common.css)
485 *
486 * @since 2.0.0
487 */
488 public function hide_menu_items()
489 {
490 global $menu ;
491 $common_methods = new Common_Methods();
492 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
493 // indexed array
494 foreach ( $menu as $menu_key => $menu_info ) {
495
496 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
497 $menu_item_id = $menu_info[2];
498 } else {
499 $menu_item_id = $menu_info[5];
500 }
501
502 // Append 'hidden' class to hide menu item until toggled
503 if ( in_array( $menu_item_id, $menu_hidden_by_toggle ) ) {
504 $menu[$menu_key][4] = $menu_info[4] . ' hidden asenha_hidden_menu';
505 }
506 }
507 }
508
509 /**
510 * Add toggle to show hidden menu items
511 *
512 * @since 2.0.0
513 */
514 public function add_hidden_menu_toggle()
515 {
516 global $current_user ;
517 // Get menu items hidden by toggle
518 $common_methods = new Common_Methods();
519 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
520 // Get user capabilities the "Show All/Less" toggle should be shown for
521 $user_capabilities_to_show_menu_toggle_for = $common_methods->get_user_capabilities_to_show_menu_toggle_for();
522 // Get current user's capabilities from the user's role(s)
523 $current_user_capabilities = '';
524 $current_user_roles = $current_user->roles;
525 // indexed array of role slugs
526 foreach ( $current_user_roles as $current_user_role ) {
527 $current_user_role_capabilities = get_role( $current_user_role )->capabilities;
528 $current_user_role_capabilities = array_keys( $current_user_role_capabilities );
529 // indexed array
530 $current_user_role_capabilities = implode( ",", $current_user_role_capabilities );
531 $current_user_capabilities .= $current_user_role_capabilities;
532 }
533 $current_user_capabilities = array_unique( explode( ",", $current_user_capabilities ) );
534 // Maybe show "Show All/Less" toggle
535 $show_toggle_menu = false;
536 foreach ( $user_capabilities_to_show_menu_toggle_for as $user_capability_to_show_menu_toggle_for ) {
537
538 if ( in_array( $user_capability_to_show_menu_toggle_for, $current_user_capabilities ) ) {
539 $show_toggle_menu = true;
540 break;
541 }
542
543 }
544
545 if ( !empty($menu_hidden_by_toggle) && $show_toggle_menu ) {
546 add_menu_page(
547 'Show All',
548 'Show All',
549 'read',
550 'asenha_show_hidden_menu',
551 function () {
552 return false;
553 },
554 "dashicons-arrow-down-alt2",
555 300
556 );
557 add_menu_page(
558 'Show Less',
559 'Show Less',
560 'read',
561 'asenha_hide_hidden_menu',
562 function () {
563 return false;
564 },
565 "dashicons-arrow-up-alt2",
566 301
567 );
568 }
569
570 }
571
572 /**
573 * Script to toggle hidden menu itesm
574 *
575 * @since 2.0.0
576 */
577 public function enqueue_toggle_hidden_menu_script()
578 {
579 // Get menu items hidden by toggle
580 $common_methods = new Common_Methods();
581 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
582 if ( !empty($menu_hidden_by_toggle) ) {
583 // Script to set behaviour and actions of the sortable menu
584 wp_enqueue_script(
585 'asenha-toggle-hidden-menu',
586 ASENHA_URL . 'assets/js/toggle-hidden-menu.js',
587 array(),
588 ASENHA_VERSION,
589 false
590 );
591 }
592 }
593
594 /**
595 * Get and set default columns
596 *
597 * @since 6.0.9
598 */
599 public function get_default_columns( $post_type )
600 {
601 global $taxonomy_slugs ;
602 // indexed array of taxonomy slugs
603 $available_columns = array(
604 'date_published' => 'Published',
605 'postid' => 'ID',
606 'modified' => 'Last Modified',
607 'password_protected' => 'Password Protected',
608 'permalink' => 'Permalink',
609 'slug' => 'Slug',
610 'status' => 'Status',
611 'date' => 'Date',
612 );
613 if ( 'post' == $post_type ) {
614 $available_columns['sticky'] = 'Sticky';
615 }
616
617 if ( post_type_supports( $post_type, 'title' ) ) {
618 $available_columns['title'] = 'Title';
619 // $available_columns['title_raw'] = 'Title Only';
620 }
621
622 if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'excerpt' ) ) {
623 $available_columns['excerpt'] = 'Excerpt';
624 }
625 if ( post_type_supports( $post_type, 'thumbnail' ) ) {
626 $available_columns['featured_image'] = 'Featured Image';
627 }
628
629 if ( post_type_supports( $post_type, 'author' ) ) {
630 $available_columns['author'] = 'Author';
631 // $available_columns['author_name'] = 'Author';
632 // $available_columns['last_modified_author'] = 'Last Modified Author';
633 }
634
635 if ( post_type_supports( $post_type, 'post-formats' ) ) {
636 $available_columns['post_formats'] = 'Post Format';
637 }
638
639 if ( post_type_supports( $post_type, 'comments' ) ) {
640 $available_columns['comments'] = 'Comments';
641 $available_columns['comment_count'] = 'Comment Count';
642 $available_columns['comment_status'] = 'Allow Comment';
643 }
644
645 if ( post_type_supports( $post_type, 'trackbacks' ) ) {
646 $available_columns['ping_status'] = 'Ping Status';
647 }
648
649 if ( post_type_supports( $post_type, 'page-attributes' ) || is_post_type_hierarchical( $post_type ) ) {
650 $available_columns['post_parent'] = 'Post Parent';
651 $available_columns['menu_order'] = 'Menu Order';
652 }
653
654 if ( 'wp_block' == $post_type ) {
655 $available_columns['wp_pattern_sync_status'] = 'Sync Status';
656 }
657 if ( 'shop_order' == $post_type ) {
658 $available_columns['products_ordered'] = 'Products';
659 }
660 // Add taxonomy columns according to the custom taxonomies assigned to each post type
661 $attached_taxonomies = get_object_taxonomies( $post_type );
662
663 if ( !empty($attached_taxonomies) ) {
664 $taxonomy_slugs = array();
665 foreach ( $attached_taxonomies as $taxonomy_slug ) {
666 $taxonomy_object = get_taxonomy( $taxonomy_slug );
667 $taxonomy_label = $taxonomy_object->labels->name;
668
669 if ( 'category' == $taxonomy_slug ) {
670 $taxonomy_slug = 'categories';
671 } elseif ( 'post_tag' == $taxonomy_slug ) {
672 $taxonomy_slug = 'tags';
673 }
674
675 $taxonomy_slugs[] = $taxonomy_slug;
676 $available_columns[$taxonomy_slug] = $taxonomy_label;
677 }
678 }
679
680 // Sort by array value in ascending order, so they are displayed in that order in the 'Default' pane
681 asort( $available_columns );
682 $options = get_option( ASENHA_SLUG_U . '_extra', array() );
683 $options['admin_columns_available'][$post_type] = $available_columns;
684 update_option( ASENHA_SLUG_U . '_extra', $options );
685 return $available_columns;
686 }
687
688 /**
689 * Get ACF field object data
690 *
691 * @since 6.3.0
692 */
693 public function get_acf_field_object(
694 $column_name = '',
695 $post_id = false,
696 $in_collection = false,
697 $parent_field = false,
698 $parent_type = ''
699 )
700 {
701 $field_data = array();
702
703 if ( !$in_collection ) {
704 $field_data = get_field_object( $column_name, $post_id );
705 } else {
706 $parent_field_data = get_field_object( $parent_field, $post_id );
707
708 if ( 'group' == $parent_type || 'repeater' == $parent_type ) {
709 $sub_fields = $parent_field_data['sub_fields'];
710 foreach ( $sub_fields as $sub_field ) {
711 if ( $column_name == $sub_field['name'] ) {
712 $field_data = $sub_field;
713 }
714 }
715 }
716
717
718 if ( 'flexible_content' == $parent_type ) {
719 $layouts = $parent_field_data['layouts'];
720 foreach ( $layouts as $layout ) {
721 $sub_fields = $layout['sub_fields'];
722 foreach ( $sub_fields as $sub_field ) {
723 if ( $column_name == $sub_field['name'] ) {
724 $field_data = $sub_field;
725 }
726 }
727 }
728 }
729
730 }
731
732 return $field_data;
733 }
734
735 /**
736 * Reload list table after performing Quick Edit on post types with custom admin columns
737 * This is modified from wp_ajax_inline_save() by adding a script before wp_die() at the end
738 *
739 * @link https://github.com/WordPress/wordpress-develop/blob/6.3/src/wp-admin/includes/ajax-actions.php#L2049-L2159
740 * @since 6.0.6
741 */
742 public function wp_ajax_inline_save_with_page_reload()
743 {
744 global $mode ;
745 check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
746 if ( !isset( $_POST['post_ID'] ) || !(int) $_POST['post_ID'] ) {
747 wp_die();
748 }
749 $post_id = (int) $_POST['post_ID'];
750
751 if ( 'page' === $_POST['post_type'] ) {
752 if ( !current_user_can( 'edit_page', $post_id ) ) {
753 wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
754 }
755 } else {
756 if ( !current_user_can( 'edit_post', $post_id ) ) {
757 wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
758 }
759 }
760
761 $last = wp_check_post_lock( $post_id );
762
763 if ( $last ) {
764 $last_user = get_userdata( $last );
765 $last_user_name = ( $last_user ? $last_user->display_name : __( 'Someone' ) );
766 /* translators: %s: User's display name. */
767 $msg_template = __( 'Saving is disabled: %s is currently editing this post.' );
768 if ( 'page' === $_POST['post_type'] ) {
769 /* translators: %s: User's display name. */
770 $msg_template = __( 'Saving is disabled: %s is currently editing this page.' );
771 }
772 printf( $msg_template, esc_html( $last_user_name ) );
773 wp_die();
774 }
775
776 $data =& $_POST;
777 $post = get_post( $post_id, ARRAY_A );
778 // Since it's coming from the database.
779 $post = wp_slash( $post );
780 $data['content'] = $post['post_content'];
781 $data['excerpt'] = $post['post_excerpt'];
782 // Rename.
783 $data['user_ID'] = get_current_user_id();
784 if ( isset( $data['post_parent'] ) ) {
785 $data['parent_id'] = $data['post_parent'];
786 }
787 // Status.
788
789 if ( isset( $data['keep_private'] ) && 'private' === $data['keep_private'] ) {
790 $data['visibility'] = 'private';
791 $data['post_status'] = 'private';
792 } else {
793 $data['post_status'] = $data['_status'];
794 }
795
796 if ( empty($data['comment_status']) ) {
797 $data['comment_status'] = 'closed';
798 }
799 if ( empty($data['ping_status']) ) {
800 $data['ping_status'] = 'closed';
801 }
802 // Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
803 if ( !empty($data['tax_input']) ) {
804 foreach ( $data['tax_input'] as $taxonomy => $terms ) {
805 $tax_object = get_taxonomy( $taxonomy );
806 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
807 if ( !apply_filters(
808 'quick_edit_show_taxonomy',
809 $tax_object->show_in_quick_edit,
810 $taxonomy,
811 $post['post_type']
812 ) ) {
813 unset( $data['tax_input'][$taxonomy] );
814 }
815 }
816 }
817 // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
818
819 if ( !empty($data['post_name']) && in_array( $post['post_status'], array( 'draft', 'pending' ), true ) ) {
820 $post['post_status'] = 'publish';
821 $data['post_name'] = wp_unique_post_slug(
822 $data['post_name'],
823 $post['ID'],
824 $post['post_status'],
825 $post['post_type'],
826 $post['post_parent']
827 );
828 }
829
830 // Update the post.
831 edit_post();
832 $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array(
833 'screen' => $_POST['screen'],
834 ) );
835 $mode = ( 'excerpt' === $_POST['post_view'] ? 'excerpt' : 'list' );
836 $level = 0;
837
838 if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) {
839 $request_post = array( get_post( $_POST['post_ID'] ) );
840 $parent = $request_post[0]->post_parent;
841 while ( $parent > 0 ) {
842 $parent_post = get_post( $parent );
843 $parent = $parent_post->post_parent;
844 $level++;
845 }
846 }
847
848 $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level );
849 // INTERCEPT: Add a script to reload the list table page
850 ?>
851 <script type="text/javascript">
852 jQuery('#post-<?php
853 echo $_POST['post_ID'] ;
854 ?>').css('opacity','0.3');
855 document.location.reload(true);
856 </script>
857 <?php
858 // end INTERCEPT
859 wp_die();
860 }
861
862 /**
863 * Hide the Help tab and drawer
864 *
865 * @since 4.5.0
866 */
867 public function hide_help_drawer()
868 {
869
870 if ( is_admin() ) {
871 $screen = get_current_screen();
872 $screen->remove_help_tabs();
873 }
874
875 }
876
877 /**
878 * Current post type. For Content Admin >> Show Custom Taxonomy Filters functionality.
879 */
880 public $post_type ;
881 /**
882 * Show featured images column in list tables for pages and post types that support featured image
883 *
884 * @since 1.0.0
885 */
886 public function show_featured_image_column()
887 {
888 $post_types = get_post_types( array(
889 'public' => true,
890 ), 'names' );
891 foreach ( $post_types as $post_type_key => $post_type_name ) {
892
893 if ( post_type_supports( $post_type_key, 'thumbnail' ) ) {
894 add_filter( "manage_{$post_type_name}_posts_columns", [ $this, 'add_featured_image_column' ], 999 );
895 add_action(
896 "manage_{$post_type_name}_posts_custom_column",
897 [ $this, 'add_featured_image' ],
898 10,
899 2
900 );
901 }
902
903 }
904 }
905
906 /**
907 * Add a column called Featured Image as the first column
908 *
909 * @param mixed $columns
910 * @return void
911 * @since 1.0.0
912 */
913 public function add_featured_image_column( $columns )
914 {
915 $new_columns = array();
916 foreach ( $columns as $key => $value ) {
917 if ( 'title' == $key ) {
918 // We add featured image column before the 'title' column
919 $new_columns['asenha-featured-image'] = 'Featured Image';
920 }
921 if ( 'thumb' == $key ) {
922 // For WooCommerce products, we add featured image column before it's native thumbnail column
923 $new_columns['asenha-featured-image'] = 'Product Image';
924 }
925 $new_columns[$key] = $value;
926 }
927 // Replace WooCommerce thumbnail column with ASE featured image column
928 if ( array_key_exists( 'thumb', $new_columns ) ) {
929 unset( $new_columns['thumb'] );
930 }
931 return $new_columns;
932 }
933
934 /**
935 * Echo featured image's in thumbnail size to a column
936 *
937 * @param mixed $column_name
938 * @param mixed $id
939 * @since 1.0.0
940 */
941 public function add_featured_image( $column_name, $id )
942 {
943 if ( 'asenha-featured-image' === $column_name ) {
944
945 if ( has_post_thumbnail( $id ) ) {
946 $size = 'thumbnail';
947 echo get_the_post_thumbnail( $id, $size, '' ) ;
948 } else {
949 echo '<img src="' . esc_url( plugins_url( 'assets/img/default_featured_image.jpg', __DIR__ ) ) . '" />' ;
950 }
951
952 }
953 }
954
955 /**
956 * Show excerpt column in list tables for pages and post types that support excerpt.
957 *
958 * @since 1.0.0
959 */
960 public function show_excerpt_column()
961 {
962 $post_types = get_post_types( array(
963 'public' => true,
964 ), 'names' );
965 foreach ( $post_types as $post_type_key => $post_type_name ) {
966
967 if ( post_type_supports( $post_type_key, 'excerpt' ) ) {
968 add_filter( "manage_{$post_type_name}_posts_columns", [ $this, 'add_excerpt_column' ] );
969 add_action(
970 "manage_{$post_type_name}_posts_custom_column",
971 [ $this, 'add_excerpt' ],
972 10,
973 2
974 );
975 }
976
977 }
978 }
979
980 /**
981 * Add a column called Featured Image as the first column
982 *
983 * @param mixed $columns
984 * @return void
985 * @since 1.0.0
986 */
987 public function add_excerpt_column( $columns )
988 {
989 $new_columns = array();
990 foreach ( $columns as $key => $value ) {
991 $new_columns[$key] = $value;
992 if ( $key == 'title' ) {
993 $new_columns['asenha-excerpt'] = 'Excerpt';
994 }
995 }
996 return $new_columns;
997 }
998
999 /**
1000 * Echo featured image's in thumbnail size to a column
1001 *
1002 * @param mixed $column_name
1003 * @param mixed $id
1004 * @since 1.0.0
1005 */
1006 public function add_excerpt( $column_name, $id )
1007 {
1008
1009 if ( 'asenha-excerpt' === $column_name ) {
1010 $excerpt = get_the_excerpt( $id );
1011 // about 310 characters
1012 $excerpt = substr( $excerpt, 0, 160 );
1013 // truncate to 160 characters
1014 $short_excerpt = substr( $excerpt, 0, strrpos( $excerpt, ' ' ) );
1015 echo wp_kses_post( $short_excerpt ) ;
1016 }
1017
1018 }
1019
1020 /**
1021 * Add ID column list table of pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
1022 *
1023 * @since 1.0.0
1024 */
1025 public function show_id_column()
1026 {
1027 // For pages and hierarchical post types list table
1028 add_filter( 'manage_pages_columns', [ $this, 'add_id_column' ] );
1029 add_action(
1030 'manage_pages_custom_column',
1031 [ $this, 'add_id_echo_value' ],
1032 10,
1033 2
1034 );
1035 // For posts and non-hierarchical custom posts list table
1036 add_filter( 'manage_posts_columns', [ $this, 'add_id_column' ] );
1037 add_action(
1038 'manage_posts_custom_column',
1039 [ $this, 'add_id_echo_value' ],
1040 10,
1041 2
1042 );
1043 // For media list table
1044 add_filter( 'manage_media_columns', [ $this, 'add_id_column' ] );
1045 add_action(
1046 'manage_media_custom_column',
1047 [ $this, 'add_id_echo_value' ],
1048 10,
1049 2
1050 );
1051 // For list table of all taxonomies
1052 $taxonomies = get_taxonomies( [
1053 'public' => true,
1054 ], 'names' );
1055 foreach ( $taxonomies as $taxonomy ) {
1056 add_filter( 'manage_edit-' . $taxonomy . '_columns', [ $this, 'add_id_column' ] );
1057 add_action(
1058 'manage_' . $taxonomy . '_custom_column',
1059 [ $this, 'add_id_return_value' ],
1060 10,
1061 3
1062 );
1063 }
1064 // For users list table
1065 add_filter( 'manage_users_columns', [ $this, 'add_id_column' ] );
1066 add_action(
1067 'manage_users_custom_column',
1068 [ $this, 'add_id_return_value' ],
1069 10,
1070 3
1071 );
1072 // For comments list table
1073 add_filter( 'manage_edit-comments_columns', [ $this, 'add_id_column' ] );
1074 add_action(
1075 'manage_comments_custom_column',
1076 [ $this, 'add_id_echo_value' ],
1077 10,
1078 3
1079 );
1080 }
1081
1082 /**
1083 * Add a column called ID
1084 *
1085 * @param mixed $columns
1086 * @return void
1087 * @since 1.0.0
1088 */
1089 public function add_id_column( $columns )
1090 {
1091 $columns['asenha-id'] = 'ID';
1092 return $columns;
1093 }
1094
1095 /**
1096 * Echo post ID value to a column
1097 *
1098 * @param mixed $column_name
1099 * @param mixed $id
1100 * @since 1.0.0
1101 */
1102 public function add_id_echo_value( $column_name, $id )
1103 {
1104 if ( 'asenha-id' === $column_name ) {
1105 echo esc_html( $id ) ;
1106 }
1107 }
1108
1109 /**
1110 * Return post ID value to a column
1111 *
1112 * @param mixed $value
1113 * @param mixed $column_name
1114 * @param mixed $id
1115 * @since 1.0.0
1116 */
1117 public function add_id_return_value( $value, $column_name, $id )
1118 {
1119 if ( 'asenha-id' === $column_name ) {
1120 $value = $id;
1121 }
1122 return $value;
1123 }
1124
1125 /**
1126 * Add ID in the action row of list tables for pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
1127 *
1128 * @since 4.7.4
1129 */
1130 public function show_id_in_action_row()
1131 {
1132 add_filter(
1133 'page_row_actions',
1134 array( $this, 'add_id_in_action_row' ),
1135 10,
1136 2
1137 );
1138 add_filter(
1139 'post_row_actions',
1140 array( $this, 'add_id_in_action_row' ),
1141 10,
1142 2
1143 );
1144 add_filter(
1145 'cat_row_actions',
1146 array( $this, 'add_id_in_action_row' ),
1147 10,
1148 2
1149 );
1150 add_filter(
1151 'tag_row_actions',
1152 array( $this, 'add_id_in_action_row' ),
1153 10,
1154 2
1155 );
1156 add_filter(
1157 'media_row_actions',
1158 array( $this, 'add_id_in_action_row' ),
1159 10,
1160 2
1161 );
1162 add_filter(
1163 'comment_row_actions',
1164 array( $this, 'add_id_in_action_row' ),
1165 10,
1166 2
1167 );
1168 add_filter(
1169 'user_row_actions',
1170 array( $this, 'add_id_in_action_row' ),
1171 10,
1172 2
1173 );
1174 }
1175
1176 /**
1177 * Output the ID in the action row
1178 *
1179 * @since 4.7.4
1180 */
1181 public function add_id_in_action_row( $actions, $object )
1182 {
1183
1184 if ( current_user_can( 'edit_posts' ) ) {
1185 // For pages, posts, custom post types, media/attachments, users
1186 if ( property_exists( $object, 'ID' ) ) {
1187 $id = $object->ID;
1188 }
1189 // For taxonomies
1190 if ( property_exists( $object, 'term_id' ) ) {
1191 $id = $object->term_id;
1192 }
1193 // For comments
1194 if ( property_exists( $object, 'comment_ID' ) ) {
1195 $id = $object->comment_ID;
1196 }
1197 $actions['asenha-list-table-item-id'] = '<span class="asenha-list-table-item-id">ID: ' . $id . '</span>';
1198 }
1199
1200 return $actions;
1201 }
1202
1203 /**
1204 * Hide comments column in list tables for pages, post types that support comments, and alse media/attachments.
1205 *
1206 * @since 1.0.0
1207 */
1208 public function hide_comments_column()
1209 {
1210 $post_types = get_post_types( array(
1211 'public' => true,
1212 ), 'names' );
1213 foreach ( $post_types as $post_type_key => $post_type_name ) {
1214 if ( post_type_supports( $post_type_key, 'comments' ) ) {
1215
1216 if ( 'attachment' != $post_type_name ) {
1217 // For list tables of pages, posts and other post types
1218 add_filter( "manage_{$post_type_name}_posts_columns", [ $this, 'remove_comment_column' ] );
1219 } else {
1220 // For list table of media/attachment
1221 add_filter( 'manage_media_columns', [ $this, 'remove_comment_column' ] );
1222 }
1223
1224 }
1225 }
1226 }
1227
1228 /**
1229 * Add a column called ID
1230 *
1231 * @param mixed $columns
1232 * @return void
1233 * @since 1.0.0
1234 */
1235 public function remove_comment_column( $columns )
1236 {
1237 unset( $columns['comments'] );
1238 return $columns;
1239 }
1240
1241 /**
1242 * Hide tags column in list tables for posts.
1243 *
1244 * @since 1.0.0
1245 */
1246 public function hide_post_tags_column()
1247 {
1248 $post_types = get_post_types( array(
1249 'public' => true,
1250 ), 'names' );
1251 foreach ( $post_types as $post_type_key => $post_type_name ) {
1252 if ( $post_type_name == 'post' ) {
1253 add_filter( "manage_posts_columns", [ $this, 'remove_post_tags_column' ] );
1254 }
1255 }
1256 }
1257
1258 /**
1259 * Custom sort on the plugins listing to show active plugins first
1260 *
1261 * @link https://plugins.trac.wordpress.org/browser/display-active-plugins-first/tags/1.1/display-active-plugins-first.php
1262 * @since 6.7.0
1263 */
1264 public function show_active_plugins_first()
1265 {
1266 global $wp_list_table, $status ;
1267 if ( !in_array( $status, array(
1268 'active',
1269 'inactive',
1270 'recently_activated',
1271 'mustuse'
1272 ), true ) ) {
1273 uksort( $wp_list_table->items, array( $this, 'plugins_order_callback' ) );
1274 }
1275 }
1276
1277 /**
1278 * Modify footer text
1279 *
1280 * @since 6.9.0
1281 */
1282 public function custom_admin_footer_text_left()
1283 {
1284 $options = get_option( ASENHA_SLUG_U, array() );
1285 $custom_admin_footer_left = ( isset( $options['custom_admin_footer_left'] ) ? $options['custom_admin_footer_left'] : '' );
1286 echo wp_kses_post( $custom_admin_footer_left ) ;
1287 }
1288
1289 /**
1290 * Change WP version number text in footer
1291 *
1292 * @since 6.9.0
1293 */
1294 public function custom_admin_footer_text_right()
1295 {
1296 $options = get_option( ASENHA_SLUG_U, array() );
1297 $custom_admin_footer_right = ( isset( $options['custom_admin_footer_right'] ) ? $options['custom_admin_footer_right'] : '' );
1298 echo wp_kses_post( $custom_admin_footer_right ) ;
1299 }
1300
1301 /**
1302 * Reorder plugins list to show active ones first
1303 *
1304 * @link https://plugins.trac.wordpress.org/browser/display-active-plugins-first/tags/1.1/display-active-plugins-first.php
1305 * @since 6.7.0
1306 */
1307 public function plugins_order_callback( $a, $b )
1308 {
1309 global $wp_list_table ;
1310 $a_active = is_plugin_active( $a );
1311 $b_active = is_plugin_active( $b );
1312
1313 if ( $a_active && !$b_active ) {
1314 return -1;
1315 } elseif ( !$a_active && $b_active ) {
1316 return 1;
1317 } else {
1318 return @strcasecmp( $wp_list_table->items[$a]['Name'], $wp_list_table->items[$b]['Name'] );
1319 }
1320
1321 }
1322
1323 /**
1324 * Add a column called ID
1325 *
1326 * @param mixed $columns
1327 * @return void
1328 * @since 1.0.0
1329 */
1330 public function remove_post_tags_column( $columns )
1331 {
1332 unset( $columns['tags'] );
1333 return $columns;
1334 }
1335
1336 /**
1337 * Show custom (hierarchical) taxonomy filter(s) for all post types.
1338 *
1339 * @since 1.0.0
1340 */
1341 public function show_custom_taxonomy_filters( $post_type )
1342 {
1343 $post_taxonomies = get_object_taxonomies( $post_type, 'objects' );
1344 // Only show custom taxonomy filters for post types other than 'post'
1345 if ( 'post' != $post_type && 'attachment' != $post_type && 'asenha_code_snippet' != $post_type ) {
1346 array_walk( $post_taxonomies, [ $this, 'output_taxonomy_filter' ] );
1347 }
1348 }
1349
1350 /**
1351 * Output filter on the post type's list table for a taxonomy
1352 *
1353 * @since 1.0.0
1354 */
1355 public function output_taxonomy_filter( $post_taxonomy )
1356 {
1357 // Only show taxonomy filter when the taxonomy is hierarchical
1358 if ( true === $post_taxonomy->hierarchical ) {
1359 wp_dropdown_categories( array(
1360 'show_option_all' => sprintf( 'All %s', $post_taxonomy->label ),
1361 'orderby' => 'name',
1362 'order' => 'ASC',
1363 'hide_empty' => false,
1364 'hide_if_empty' => true,
1365 'selected' => sanitize_text_field( ( isset( $_GET[$post_taxonomy->query_var] ) && !empty($_GET[$post_taxonomy->query_var]) ? $_GET[$post_taxonomy->query_var] : '' ) ),
1366 'hierarchical' => true,
1367 'name' => $post_taxonomy->query_var,
1368 'taxonomy' => $post_taxonomy->name,
1369 'value_field' => 'slug',
1370 ) );
1371 }
1372 }
1373
1374 }