PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 6.5.1
Admin and Site Enhancements (ASE) v6.5.1
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
1308 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
94 if ( $hide_for_nonadmins && bwasenha_fs()->can_use_premium_code__premium_only() ) {
95 $minimum_capability = 'read';
96 } else {
97 $minimum_capability = 'manage_options';
98 }
99
100 if ( current_user_can( $minimum_capability ) ) {
101 echo '<div class="asenha-admin-notices-drawer" style="display:none;"><h2>Admin Notices</h2></div>' ;
102 }
103 }
104
105 /**
106 * Admin bar menu item for the hidden admin notices
107 *
108 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/add_menu/
109 * @link https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/
110 * @since 1.2.0
111 */
112 public function admin_notices_menu( WP_Admin_Bar $wp_admin_bar )
113 {
114 // Only show Notices menu when not in Customizer preview
115
116 if ( is_admin() ) {
117 $options = get_option( ASENHA_SLUG_U, array() );
118 $hide_for_nonadmins = ( isset( $options['hide_admin_notices_for_nonadmins'] ) ? $options['hide_admin_notices_for_nonadmins'] : false );
119
120 if ( $hide_for_nonadmins && bwasenha_fs()->can_use_premium_code__premium_only() ) {
121 $minimum_capability = 'read';
122 } else {
123 $minimum_capability = 'manage_options';
124 }
125
126 if ( current_user_can( $minimum_capability ) ) {
127 $wp_admin_bar->add_menu( array(
128 'id' => 'asenha-hide-admin-notices',
129 'parent' => 'top-secondary',
130 'grou' => null,
131 'title' => 'Notices<span class="asenha-admin-notices-counter" style="opacity:0;">0</span>',
132 'meta' => array(
133 'class' => 'asenha-admin-notices-menu',
134 'title' => 'Click to view hidden admin notices',
135 ),
136 ) );
137 }
138 }
139
140 }
141
142 /**
143 * Inline CSS for the admin bar notices menu
144 *
145 * @since 1.2.0
146 */
147 public function admin_notices_menu_inline_css()
148 {
149 $options = get_option( ASENHA_SLUG_U, array() );
150 $hide_for_nonadmins = ( isset( $options['hide_admin_notices_for_nonadmins'] ) ? $options['hide_admin_notices_for_nonadmins'] : false );
151
152 if ( $hide_for_nonadmins && bwasenha_fs()->can_use_premium_code__premium_only() ) {
153 $minimum_capability = 'read';
154 } else {
155 $minimum_capability = 'manage_options';
156 }
157
158
159 if ( current_user_can( $minimum_capability ) ) {
160 wp_add_inline_style( 'admin-bar', '
161
162 #wpadminbar .asenha-admin-notices-counter {
163 box-sizing: border-box;
164 margin: 1px 0 -1px 6px ;
165 padding: 2px 6px 3px 5px;
166 min-width: 18px;
167 height: 18px;
168 border-radius: 50%;
169 background-color: #ca4a1f;
170 color: #fff;
171 font-size: 11px;
172 line-height: 1.6;
173 text-align: center;
174 }
175
176 ' );
177 // Below we pre-emptively hide notices to avoid having them shown briefly before being moved into the notices panel via JS
178 ?>
179 <style type="text/css">
180 /* #wpbody-content .notice:not(.system-notice,.update-message),
181 #wpbody-content .notice-error,
182 #wpbody-content .error,
183 #wpbody-content .notice-info,
184 #wpbody-content .notice-information,
185 #wpbody-content #message,
186 #wpbody-content .notice-warning:not(.update-message),
187 #wpbody-content .notice-success:not(.update-message),
188 #wpbody-content .notice-updated,
189 #wpbody-content .updated:not(.active, .inactive, .plugin-update-tr),
190 #wpbody-content .update-nag, */
191 #wpbody-content > .wrap > .notice:not(.system-notice,.hidden),
192 #wpbody-content > .wrap > .notice-error,
193 #wpbody-content > .wrap > .error:not(.hidden),
194 #wpbody-content > .wrap > .notice-info,
195 #wpbody-content > .wrap > .notice-information,
196 #wpbody-content > .wrap > #message,
197 #wpbody-content > .wrap > .notice-warning:not(.hidden),
198 #wpbody-content > .wrap > .notice-success,
199 #wpbody-content > .wrap > .notice-updated,
200 #wpbody-content > .wrap > .updated,
201 #wpbody-content > .wrap > .update-nag,
202 #wpbody-content > .wrap > div > .notice:not(.system-notice,.hidden),
203 #wpbody-content > .wrap > div > .notice-error,
204 #wpbody-content > .wrap > div > .error:not(.hidden),
205 #wpbody-content > .wrap > div > .notice-info,
206 #wpbody-content > .wrap > div > .notice-information,
207 #wpbody-content > .wrap > div > #message,
208 #wpbody-content > .wrap > div > .notice-warning:not(.hidden),
209 #wpbody-content > .wrap > div > .notice-success,
210 #wpbody-content > .wrap > div > .notice-updated,
211 #wpbody-content > .wrap > div > .updated,
212 #wpbody-content > .wrap > div > .update-nag,
213 #wpbody-content > div > .wrap > .notice:not(.system-notice,.hidden),
214 #wpbody-content > div > .wrap > .notice-error,
215 #wpbody-content > div > .wrap > .error:not(.hidden),
216 #wpbody-content > div > .wrap > .notice-info,
217 #wpbody-content > div > .wrap > .notice-information,
218 #wpbody-content > div > .wrap > #message,
219 #wpbody-content > div > .wrap > .notice-warning:not(.hidden),
220 #wpbody-content > div > .wrap > .notice-success,
221 #wpbody-content > div > .wrap > .notice-updated,
222 #wpbody-content > div > .wrap > .updated,
223 #wpbody-content > div > .wrap > .update-nag,
224 #wpbody-content > .notice,
225 #wpbody-content > .error,
226 #wpbody-content > .updated,
227 #wpbody-content > .update-nag,
228 #wpbody-content > .jp-connection-banner,
229 #wpbody-content > .jitm-banner,
230 #wpbody-content > .jetpack-jitm-message,
231 #wpbody-content > .ngg_admin_notice,
232 #wpbody-content > .imagify-welcome,
233 #wpbody-content #wordfenceAutoUpdateChoice,
234 #wpbody-content #easy-updates-manager-dashnotice,
235 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice:not(.system-notice,.hidden),
236 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-error,
237 #wpbody-content > .wrap.gblocks-dashboard-wrap .error:not(.hidden),
238 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-info,
239 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-information,
240 #wpbody-content > .wrap.gblocks-dashboard-wrap #message,
241 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-warning:not(.hidden),
242 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-success,
243 #wpbody-content > .wrap.gblocks-dashboard-wrap .notice-updated,
244 #wpbody-content > .wrap.gblocks-dashboard-wrap .updated,
245 #wpbody-content > .wrap.gblocks-dashboard-wrap .update-nag {
246 position: absolute !important;
247 visibility: hidden !important;
248 }
249 </style>
250 <?php
251 }
252
253 }
254
255 /**
256 * Disable dashboard widgets
257 *
258 * @since 4.2.0
259 */
260 public function disable_dashboard_widgets()
261 {
262 global $wp_meta_boxes ;
263 // Get list of disabled widgets
264 $options = get_option( ASENHA_SLUG_U, array() );
265 $disabled_dashboard_widgets = $options['disabled_dashboard_widgets'];
266 // Store default widgets in extra options. This will be referenced from settings field.
267 $dashboard_widgets = $this->get_dashboard_widgets();
268 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
269 $options_extra['dashboard_widgets'] = $dashboard_widgets;
270 update_option( 'admin_site_enhancements_extra', $options_extra );
271 // Disable widgets
272 if ( is_array( $disabled_dashboard_widgets ) || is_object( $disabled_dashboard_widgets ) ) {
273 foreach ( $disabled_dashboard_widgets as $disabled_widget_id_context_priority => $is_disabled ) {
274 // e.g. dashboard_activity__normal__core => true/false
275
276 if ( $is_disabled ) {
277 $disabled_widget = explode( '__', $disabled_widget_id_context_priority );
278 $widget_id = $disabled_widget[0];
279 $widget_context = $disabled_widget[1];
280 $widget_priority = $disabled_widget[2];
281 // remove_meta_box( $widget_id, get_current_screen()->base, $widget_context );
282 unset( $wp_meta_boxes['dashboard'][$widget_context][$widget_priority][$widget_id] );
283 }
284
285 }
286 }
287 }
288
289 /**
290 * Get dashboard widgets
291 *
292 * @since 4.2.0
293 */
294 public function get_dashboard_widgets()
295 {
296 global $wp_meta_boxes ;
297 $dashboard_widgets = array();
298
299 if ( !isset( $wp_meta_boxes['dashboard'] ) ) {
300 $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() );
301
302 if ( !array_key_exists( 'dashboard_widgets', $options_extra ) ) {
303 require_once ABSPATH . '/wp-admin/includes/dashboard.php';
304 set_current_screen( 'dashboard' );
305 wp_dashboard_setup();
306 }
307
308 }
309
310 if ( isset( $wp_meta_boxes['dashboard'] ) ) {
311 foreach ( $wp_meta_boxes['dashboard'] as $context => $priorities ) {
312 foreach ( $priorities as $priority => $widgets ) {
313 foreach ( $widgets as $widget_id => $data ) {
314 $widget_title = ( isset( $data['title'] ) ? wp_strip_all_tags( preg_replace( '/ <span.*span>/im', '', $data['title'] ) ) : 'Undetectable' );
315 $dashboard_widgets[$widget_id] = array(
316 'id' => $widget_id,
317 'title' => $widget_title,
318 'context' => $context,
319 'priority' => $priority,
320 );
321 }
322 }
323 }
324 }
325 $dashboard_widgets = wp_list_sort(
326 $dashboard_widgets,
327 'title',
328 'ASC',
329 true
330 );
331 return $dashboard_widgets;
332 }
333
334 /**
335 * Hide admin bar on the frontend for the user roles selected
336 *
337 * @since 1.3.0
338 */
339 public function hide_admin_bar_for_roles_on_frontend()
340 {
341 $options = get_option( ASENHA_SLUG_U );
342 $hide_admin_bar = $options['hide_admin_bar'];
343 $for_roles_frontend = $options['hide_admin_bar_for'];
344 $current_user = wp_get_current_user();
345 $current_user_roles = (array) $current_user->roles;
346 // single dimensional array of role slugs
347 // User has no role, i.e. logged-out
348
349 if ( count( $current_user_roles ) == 0 ) {
350 return false;
351 // hide admin bar
352 }
353
354 // User has role(s). Do further checks.
355
356 if ( isset( $for_roles_frontend ) && count( $for_roles_frontend ) > 0 ) {
357 // Assemble single-dimensional array of roles for which admin bar would be hidden
358 $roles_admin_bar_hidden_frontend = array();
359 foreach ( $for_roles_frontend as $role_slug => $admin_bar_hidden ) {
360 if ( $admin_bar_hidden ) {
361 $roles_admin_bar_hidden_frontend[] = $role_slug;
362 }
363 }
364 // Check if any of the current user roles is one for which admin bar should be hidden
365 foreach ( $current_user_roles as $role ) {
366
367 if ( in_array( $role, $roles_admin_bar_hidden_frontend ) ) {
368 return false;
369 // hide admin bar
370 }
371
372 }
373 }
374
375 return true;
376 // show admin bar
377 }
378
379 /**
380 * Set custom admin menu width
381 *
382 * @since 5.2.0
383 */
384 public function set_custom_menu_width()
385 {
386 $options = get_option( ASENHA_SLUG_U, array() );
387 $custom_width = $options['admin_menu_width'];
388 $wp_version = get_bloginfo( 'version' );
389
390 if ( version_compare( $wp_version, '5', '>' ) ) {
391 require_once ASENHA_PATH . 'includes/admin-menu-width/wp-v5-greater.php';
392 } elseif ( version_compare( $wp_version, '4', '>=' ) ) {
393 require_once ASENHA_PATH . 'includes/admin-menu-width/wp-v4-greater.php';
394 } else {
395 }
396
397 }
398
399 /**
400 * Render custom menu order
401 *
402 * @param $menu_order array an ordered array of menu items
403 * @link https://developer.wordpress.org/reference/hooks/menu_order/
404 * @since 2.0.0
405 */
406 public function render_custom_menu_order( $menu_order )
407 {
408 global $menu ;
409 $options = get_option( ASENHA_SLUG_U );
410 // Get current menu order. We're not using the default $menu_order which uses index.php, edit.php as array values.
411 $current_menu_order = array();
412 foreach ( $menu as $menu_key => $menu_info ) {
413
414 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
415 $menu_item_id = $menu_info[2];
416 } else {
417 $menu_item_id = $menu_info[5];
418 }
419
420 $current_menu_order[] = array( $menu_item_id, $menu_info[2] );
421 }
422 // Get custom menu order
423 $custom_menu_order = $options['custom_menu_order'];
424 // comma separated
425 $custom_menu_order = explode( ",", $custom_menu_order );
426 // array of menu ID, e.g. menu-dashboard
427 // Return menu order for rendering
428 $rendered_menu_order = array();
429 // Render menu based on items saved in custom menu order
430 foreach ( $custom_menu_order as $custom_menu_item_id ) {
431 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
432 if ( $custom_menu_item_id == $current_menu_item[0] ) {
433 $rendered_menu_order[] = $current_menu_item[1];
434 }
435 }
436 }
437 // Add items from current menu not already part of custom menu order, e.g. new plugin activated and adds new menu item
438 foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) {
439 if ( !in_array( $current_menu_item[0], $custom_menu_order ) ) {
440 $rendered_menu_order[] = $current_menu_item[1];
441 }
442 }
443 return $rendered_menu_order;
444 }
445
446 /**
447 * Apply custom menu item titles
448 *
449 * @since 2.9.0
450 */
451 public function apply_custom_menu_item_titles()
452 {
453 global $menu ;
454 $options = get_option( ASENHA_SLUG_U );
455 // Get custom menu item titles
456 $custom_menu_titles = $options['custom_menu_titles'];
457 $custom_menu_titles = explode( ',', $custom_menu_titles );
458 foreach ( $menu as $menu_key => $menu_info ) {
459
460 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
461 $menu_item_id = $menu_info[2];
462 } else {
463 $menu_item_id = $menu_info[5];
464 }
465
466 // Get defaul/custom menu item title
467 foreach ( $custom_menu_titles as $custom_menu_title ) {
468 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
469 $custom_menu_title = explode( '__', $custom_menu_title );
470
471 if ( $custom_menu_title[0] == $menu_item_id ) {
472 $menu_item_title = $custom_menu_title[1];
473 // e.g. Code Snippets
474 break;
475 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
476 } else {
477 $menu_item_title = $menu_info[0];
478 }
479
480 }
481 $menu[$menu_key][0] = $menu_item_title;
482 }
483 }
484
485 /**
486 * Hide menu items by adding a class to hide them (part of WP Core's common.css)
487 *
488 * @since 2.0.0
489 */
490 public function hide_menu_items()
491 {
492 global $menu ;
493 $common_methods = new Common_Methods();
494 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
495 // indexed array
496 foreach ( $menu as $menu_key => $menu_info ) {
497
498 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
499 $menu_item_id = $menu_info[2];
500 } else {
501 $menu_item_id = $menu_info[5];
502 }
503
504 // Append 'hidden' class to hide menu item until toggled
505 if ( in_array( $menu_item_id, $menu_hidden_by_toggle ) ) {
506 $menu[$menu_key][4] = $menu_info[4] . ' hidden asenha_hidden_menu';
507 }
508 }
509 }
510
511 /**
512 * Add toggle to show hidden menu items
513 *
514 * @since 2.0.0
515 */
516 public function add_hidden_menu_toggle()
517 {
518 global $current_user ;
519 // Get menu items hidden by toggle
520 $common_methods = new Common_Methods();
521 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
522 // Get user capabilities the "Show All/Less" toggle should be shown for
523 $user_capabilities_to_show_menu_toggle_for = $common_methods->get_user_capabilities_to_show_menu_toggle_for();
524 // Get current user's capabilities from the user's role(s)
525 $current_user_capabilities = '';
526 $current_user_roles = $current_user->roles;
527 // indexed array of role slugs
528 foreach ( $current_user_roles as $current_user_role ) {
529 $current_user_role_capabilities = get_role( $current_user_role )->capabilities;
530 $current_user_role_capabilities = array_keys( $current_user_role_capabilities );
531 // indexed array
532 $current_user_role_capabilities = implode( ",", $current_user_role_capabilities );
533 $current_user_capabilities .= $current_user_role_capabilities;
534 }
535 $current_user_capabilities = array_unique( explode( ",", $current_user_capabilities ) );
536 // Maybe show "Show All/Less" toggle
537 $show_toggle_menu = false;
538 foreach ( $user_capabilities_to_show_menu_toggle_for as $user_capability_to_show_menu_toggle_for ) {
539
540 if ( in_array( $user_capability_to_show_menu_toggle_for, $current_user_capabilities ) ) {
541 $show_toggle_menu = true;
542 break;
543 }
544
545 }
546
547 if ( !empty($menu_hidden_by_toggle) && $show_toggle_menu ) {
548 add_menu_page(
549 'Show All',
550 'Show All',
551 'read',
552 'asenha_show_hidden_menu',
553 function () {
554 return false;
555 },
556 "dashicons-arrow-down-alt2",
557 300
558 );
559 add_menu_page(
560 'Show Less',
561 'Show Less',
562 'read',
563 'asenha_hide_hidden_menu',
564 function () {
565 return false;
566 },
567 "dashicons-arrow-up-alt2",
568 301
569 );
570 }
571
572 }
573
574 /**
575 * Script to toggle hidden menu itesm
576 *
577 * @since 2.0.0
578 */
579 public function enqueue_toggle_hidden_menu_script()
580 {
581 // Get menu items hidden by toggle
582 $common_methods = new Common_Methods();
583 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
584 if ( !empty($menu_hidden_by_toggle) ) {
585 // Script to set behaviour and actions of the sortable menu
586 wp_enqueue_script(
587 'asenha-toggle-hidden-menu',
588 ASENHA_URL . 'assets/js/toggle-hidden-menu.js',
589 array(),
590 ASENHA_VERSION,
591 false
592 );
593 }
594 }
595
596 /**
597 * Get and set default columns
598 *
599 * @since 6.0.9
600 */
601 public function get_default_columns( $post_type )
602 {
603 global $taxonomy_slugs ;
604 // indexed array of taxonomy slugs
605 $available_columns = array(
606 'date_published' => 'Published',
607 'postid' => 'ID',
608 'modified' => 'Last Modified',
609 'password_protected' => 'Password Protected',
610 'permalink' => 'Permalink',
611 'slug' => 'Slug',
612 'status' => 'Status',
613 'date' => 'Date',
614 );
615 if ( 'post' == $post_type ) {
616 $available_columns['sticky'] = 'Sticky';
617 }
618
619 if ( post_type_supports( $post_type, 'title' ) ) {
620 $available_columns['title'] = 'Title';
621 // $available_columns['title_raw'] = 'Title Only';
622 }
623
624 if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'excerpt' ) ) {
625 $available_columns['excerpt'] = 'Excerpt';
626 }
627 if ( post_type_supports( $post_type, 'thumbnail' ) ) {
628 $available_columns['featured_image'] = 'Featured Image';
629 }
630
631 if ( post_type_supports( $post_type, 'author' ) ) {
632 $available_columns['author'] = 'Author';
633 // $available_columns['author_name'] = 'Author';
634 // $available_columns['last_modified_author'] = 'Last Modified Author';
635 }
636
637 if ( post_type_supports( $post_type, 'post-formats' ) ) {
638 $available_columns['post_formats'] = 'Post Format';
639 }
640
641 if ( post_type_supports( $post_type, 'comments' ) ) {
642 $available_columns['comments'] = 'Comments';
643 $available_columns['comment_count'] = 'Comment Count';
644 $available_columns['comment_status'] = 'Allow Comment';
645 }
646
647 if ( post_type_supports( $post_type, 'trackbacks' ) ) {
648 $available_columns['ping_status'] = 'Ping Status';
649 }
650
651 if ( post_type_supports( $post_type, 'page-attributes' ) || is_post_type_hierarchical( $post_type ) ) {
652 $available_columns['post_parent'] = 'Post Parent';
653 $available_columns['menu_order'] = 'Menu Order';
654 }
655
656 if ( 'wp_block' == $post_type ) {
657 $available_columns['wp_pattern_sync_status'] = 'Sync Status';
658 }
659 // Add taxonomy columns according to the custom taxonomies assigned to each post type
660 $attached_taxonomies = get_object_taxonomies( $post_type );
661
662 if ( !empty($attached_taxonomies) ) {
663 $taxonomy_slugs = array();
664 foreach ( $attached_taxonomies as $taxonomy_slug ) {
665 $taxonomy_object = get_taxonomy( $taxonomy_slug );
666 $taxonomy_label = $taxonomy_object->labels->name;
667
668 if ( 'category' == $taxonomy_slug ) {
669 $taxonomy_slug = 'categories';
670 } elseif ( 'post_tag' == $taxonomy_slug ) {
671 $taxonomy_slug = 'tags';
672 }
673
674 $taxonomy_slugs[] = $taxonomy_slug;
675 $available_columns[$taxonomy_slug] = $taxonomy_label;
676 }
677 }
678
679 // Sort by array value in ascending order, so they are displayed in that order in the 'Default' pane
680 asort( $available_columns );
681 $options = get_option( ASENHA_SLUG_U . '_extra', array() );
682 $options['admin_columns_available'][$post_type] = $available_columns;
683 update_option( ASENHA_SLUG_U . '_extra', $options );
684 return $available_columns;
685 }
686
687 /**
688 * Get ACF field object data
689 *
690 * @since 6.3.0
691 */
692 public function get_acf_field_object(
693 $column_name = '',
694 $post_id = false,
695 $in_collection = false,
696 $parent_field = false,
697 $parent_type = ''
698 )
699 {
700 $field_data = array();
701
702 if ( !$in_collection ) {
703 $field_data = get_field_object( $column_name, $post_id );
704 } else {
705 $parent_field_data = get_field_object( $parent_field, $post_id );
706
707 if ( 'group' == $parent_type || 'repeater' == $parent_type ) {
708 $sub_fields = $parent_field_data['sub_fields'];
709 foreach ( $sub_fields as $sub_field ) {
710 if ( $column_name == $sub_field['name'] ) {
711 $field_data = $sub_field;
712 }
713 }
714 }
715
716
717 if ( 'flexible_content' == $parent_type ) {
718 $layouts = $parent_field_data['layouts'];
719 foreach ( $layouts as $layout ) {
720 $sub_fields = $layout['sub_fields'];
721 foreach ( $sub_fields as $sub_field ) {
722 if ( $column_name == $sub_field['name'] ) {
723 $field_data = $sub_field;
724 }
725 }
726 }
727 }
728
729 }
730
731 return $field_data;
732 }
733
734 /**
735 * Reload list table after performing Quick Edit on post types with custom admin columns
736 * This is modified from wp_ajax_inline_save() by adding a script before wp_die() at the end
737 *
738 * @link https://github.com/WordPress/wordpress-develop/blob/6.3/src/wp-admin/includes/ajax-actions.php#L2049-L2159
739 * @since 6.0.6
740 */
741 public function wp_ajax_inline_save_with_page_reload()
742 {
743 global $mode ;
744 check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
745 if ( !isset( $_POST['post_ID'] ) || !(int) $_POST['post_ID'] ) {
746 wp_die();
747 }
748 $post_id = (int) $_POST['post_ID'];
749
750 if ( 'page' === $_POST['post_type'] ) {
751 if ( !current_user_can( 'edit_page', $post_id ) ) {
752 wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
753 }
754 } else {
755 if ( !current_user_can( 'edit_post', $post_id ) ) {
756 wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
757 }
758 }
759
760 $last = wp_check_post_lock( $post_id );
761
762 if ( $last ) {
763 $last_user = get_userdata( $last );
764 $last_user_name = ( $last_user ? $last_user->display_name : __( 'Someone' ) );
765 /* translators: %s: User's display name. */
766 $msg_template = __( 'Saving is disabled: %s is currently editing this post.' );
767 if ( 'page' === $_POST['post_type'] ) {
768 /* translators: %s: User's display name. */
769 $msg_template = __( 'Saving is disabled: %s is currently editing this page.' );
770 }
771 printf( $msg_template, esc_html( $last_user_name ) );
772 wp_die();
773 }
774
775 $data =& $_POST;
776 $post = get_post( $post_id, ARRAY_A );
777 // Since it's coming from the database.
778 $post = wp_slash( $post );
779 $data['content'] = $post['post_content'];
780 $data['excerpt'] = $post['post_excerpt'];
781 // Rename.
782 $data['user_ID'] = get_current_user_id();
783 if ( isset( $data['post_parent'] ) ) {
784 $data['parent_id'] = $data['post_parent'];
785 }
786 // Status.
787
788 if ( isset( $data['keep_private'] ) && 'private' === $data['keep_private'] ) {
789 $data['visibility'] = 'private';
790 $data['post_status'] = 'private';
791 } else {
792 $data['post_status'] = $data['_status'];
793 }
794
795 if ( empty($data['comment_status']) ) {
796 $data['comment_status'] = 'closed';
797 }
798 if ( empty($data['ping_status']) ) {
799 $data['ping_status'] = 'closed';
800 }
801 // Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
802 if ( !empty($data['tax_input']) ) {
803 foreach ( $data['tax_input'] as $taxonomy => $terms ) {
804 $tax_object = get_taxonomy( $taxonomy );
805 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
806 if ( !apply_filters(
807 'quick_edit_show_taxonomy',
808 $tax_object->show_in_quick_edit,
809 $taxonomy,
810 $post['post_type']
811 ) ) {
812 unset( $data['tax_input'][$taxonomy] );
813 }
814 }
815 }
816 // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
817
818 if ( !empty($data['post_name']) && in_array( $post['post_status'], array( 'draft', 'pending' ), true ) ) {
819 $post['post_status'] = 'publish';
820 $data['post_name'] = wp_unique_post_slug(
821 $data['post_name'],
822 $post['ID'],
823 $post['post_status'],
824 $post['post_type'],
825 $post['post_parent']
826 );
827 }
828
829 // Update the post.
830 edit_post();
831 $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array(
832 'screen' => $_POST['screen'],
833 ) );
834 $mode = ( 'excerpt' === $_POST['post_view'] ? 'excerpt' : 'list' );
835 $level = 0;
836
837 if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) {
838 $request_post = array( get_post( $_POST['post_ID'] ) );
839 $parent = $request_post[0]->post_parent;
840 while ( $parent > 0 ) {
841 $parent_post = get_post( $parent );
842 $parent = $parent_post->post_parent;
843 $level++;
844 }
845 }
846
847 $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level );
848 // INTERCEPT: Add a script to reload the list table page
849 ?>
850 <script type="text/javascript">
851 jQuery('#post-<?php
852 echo $_POST['post_ID'] ;
853 ?>').css('opacity','0.3');
854 document.location.reload(true);
855 </script>
856 <?php
857 // end INTERCEPT
858 wp_die();
859 }
860
861 /**
862 * Hide the Help tab and drawer
863 *
864 * @since 4.5.0
865 */
866 public function hide_help_drawer()
867 {
868
869 if ( is_admin() ) {
870 $screen = get_current_screen();
871 $screen->remove_help_tabs();
872 }
873
874 }
875
876 /**
877 * Current post type. For Content Admin >> Show Custom Taxonomy Filters functionality.
878 */
879 public $post_type ;
880 /**
881 * Show featured images column in list tables for pages and post types that support featured image
882 *
883 * @since 1.0.0
884 */
885 public function show_featured_image_column()
886 {
887 $post_types = get_post_types( array(
888 'public' => true,
889 ), 'names' );
890 foreach ( $post_types as $post_type_key => $post_type_name ) {
891
892 if ( post_type_supports( $post_type_key, 'thumbnail' ) ) {
893 add_filter( "manage_{$post_type_name}_posts_columns", [ $this, 'add_featured_image_column' ], 999 );
894 add_action(
895 "manage_{$post_type_name}_posts_custom_column",
896 [ $this, 'add_featured_image' ],
897 10,
898 2
899 );
900 }
901
902 }
903 }
904
905 /**
906 * Add a column called Featured Image as the first column
907 *
908 * @param mixed $columns
909 * @return void
910 * @since 1.0.0
911 */
912 public function add_featured_image_column( $columns )
913 {
914 $new_columns = array();
915 foreach ( $columns as $key => $value ) {
916 if ( 'title' == $key ) {
917 // We add featured image column before the 'title' column
918 $new_columns['asenha-featured-image'] = 'Featured Image';
919 }
920 if ( 'thumb' == $key ) {
921 // For WooCommerce products, we add featured image column before it's native thumbnail column
922 $new_columns['asenha-featured-image'] = 'Product Image';
923 }
924 $new_columns[$key] = $value;
925 }
926 // Replace WooCommerce thumbnail column with ASE featured image column
927 if ( array_key_exists( 'thumb', $new_columns ) ) {
928 unset( $new_columns['thumb'] );
929 }
930 return $new_columns;
931 }
932
933 /**
934 * Echo featured image's in thumbnail size to a column
935 *
936 * @param mixed $column_name
937 * @param mixed $id
938 * @since 1.0.0
939 */
940 public function add_featured_image( $column_name, $id )
941 {
942 if ( 'asenha-featured-image' === $column_name ) {
943
944 if ( has_post_thumbnail( $id ) ) {
945 $size = 'thumbnail';
946 echo get_the_post_thumbnail( $id, $size, '' ) ;
947 } else {
948 echo '<img src="' . esc_url( plugins_url( 'assets/img/default_featured_image.jpg', __DIR__ ) ) . '" />' ;
949 }
950
951 }
952 }
953
954 /**
955 * Show excerpt column in list tables for pages and post types that support excerpt.
956 *
957 * @since 1.0.0
958 */
959 public function show_excerpt_column()
960 {
961 $post_types = get_post_types( array(
962 'public' => true,
963 ), 'names' );
964 foreach ( $post_types as $post_type_key => $post_type_name ) {
965
966 if ( post_type_supports( $post_type_key, 'excerpt' ) ) {
967 add_filter( "manage_{$post_type_name}_posts_columns", [ $this, 'add_excerpt_column' ] );
968 add_action(
969 "manage_{$post_type_name}_posts_custom_column",
970 [ $this, 'add_excerpt' ],
971 10,
972 2
973 );
974 }
975
976 }
977 }
978
979 /**
980 * Add a column called Featured Image as the first column
981 *
982 * @param mixed $columns
983 * @return void
984 * @since 1.0.0
985 */
986 public function add_excerpt_column( $columns )
987 {
988 $new_columns = array();
989 foreach ( $columns as $key => $value ) {
990 $new_columns[$key] = $value;
991 if ( $key == 'title' ) {
992 $new_columns['asenha-excerpt'] = 'Excerpt';
993 }
994 }
995 return $new_columns;
996 }
997
998 /**
999 * Echo featured image's in thumbnail size to a column
1000 *
1001 * @param mixed $column_name
1002 * @param mixed $id
1003 * @since 1.0.0
1004 */
1005 public function add_excerpt( $column_name, $id )
1006 {
1007
1008 if ( 'asenha-excerpt' === $column_name ) {
1009 $excerpt = get_the_excerpt( $id );
1010 // about 310 characters
1011 $excerpt = substr( $excerpt, 0, 160 );
1012 // truncate to 160 characters
1013 $short_excerpt = substr( $excerpt, 0, strrpos( $excerpt, ' ' ) );
1014 echo wp_kses_post( $short_excerpt ) ;
1015 }
1016
1017 }
1018
1019 /**
1020 * Add ID column list table of pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
1021 *
1022 * @since 1.0.0
1023 */
1024 public function show_id_column()
1025 {
1026 // For pages and hierarchical post types list table
1027 add_filter( 'manage_pages_columns', [ $this, 'add_id_column' ] );
1028 add_action(
1029 'manage_pages_custom_column',
1030 [ $this, 'add_id_echo_value' ],
1031 10,
1032 2
1033 );
1034 // For posts and non-hierarchical custom posts list table
1035 add_filter( 'manage_posts_columns', [ $this, 'add_id_column' ] );
1036 add_action(
1037 'manage_posts_custom_column',
1038 [ $this, 'add_id_echo_value' ],
1039 10,
1040 2
1041 );
1042 // For media list table
1043 add_filter( 'manage_media_columns', [ $this, 'add_id_column' ] );
1044 add_action(
1045 'manage_media_custom_column',
1046 [ $this, 'add_id_echo_value' ],
1047 10,
1048 2
1049 );
1050 // For list table of all taxonomies
1051 $taxonomies = get_taxonomies( [
1052 'public' => true,
1053 ], 'names' );
1054 foreach ( $taxonomies as $taxonomy ) {
1055 add_filter( 'manage_edit-' . $taxonomy . '_columns', [ $this, 'add_id_column' ] );
1056 add_action(
1057 'manage_' . $taxonomy . '_custom_column',
1058 [ $this, 'add_id_return_value' ],
1059 10,
1060 3
1061 );
1062 }
1063 // For users list table
1064 add_filter( 'manage_users_columns', [ $this, 'add_id_column' ] );
1065 add_action(
1066 'manage_users_custom_column',
1067 [ $this, 'add_id_return_value' ],
1068 10,
1069 3
1070 );
1071 // For comments list table
1072 add_filter( 'manage_edit-comments_columns', [ $this, 'add_id_column' ] );
1073 add_action(
1074 'manage_comments_custom_column',
1075 [ $this, 'add_id_echo_value' ],
1076 10,
1077 3
1078 );
1079 }
1080
1081 /**
1082 * Add a column called ID
1083 *
1084 * @param mixed $columns
1085 * @return void
1086 * @since 1.0.0
1087 */
1088 public function add_id_column( $columns )
1089 {
1090 $columns['asenha-id'] = 'ID';
1091 return $columns;
1092 }
1093
1094 /**
1095 * Echo post ID value to a column
1096 *
1097 * @param mixed $column_name
1098 * @param mixed $id
1099 * @since 1.0.0
1100 */
1101 public function add_id_echo_value( $column_name, $id )
1102 {
1103 if ( 'asenha-id' === $column_name ) {
1104 echo esc_html( $id ) ;
1105 }
1106 }
1107
1108 /**
1109 * Return post ID value to a column
1110 *
1111 * @param mixed $value
1112 * @param mixed $column_name
1113 * @param mixed $id
1114 * @since 1.0.0
1115 */
1116 public function add_id_return_value( $value, $column_name, $id )
1117 {
1118 if ( 'asenha-id' === $column_name ) {
1119 $value = $id;
1120 }
1121 return $value;
1122 }
1123
1124 /**
1125 * Add ID in the action row of list tables for pages, posts, custom post types, media, taxonomies, custom taxonomies, users amd comments
1126 *
1127 * @since 4.7.4
1128 */
1129 public function show_id_in_action_row()
1130 {
1131 add_filter(
1132 'page_row_actions',
1133 array( $this, 'add_id_in_action_row' ),
1134 10,
1135 2
1136 );
1137 add_filter(
1138 'post_row_actions',
1139 array( $this, 'add_id_in_action_row' ),
1140 10,
1141 2
1142 );
1143 add_filter(
1144 'cat_row_actions',
1145 array( $this, 'add_id_in_action_row' ),
1146 10,
1147 2
1148 );
1149 add_filter(
1150 'tag_row_actions',
1151 array( $this, 'add_id_in_action_row' ),
1152 10,
1153 2
1154 );
1155 add_filter(
1156 'media_row_actions',
1157 array( $this, 'add_id_in_action_row' ),
1158 10,
1159 2
1160 );
1161 add_filter(
1162 'comment_row_actions',
1163 array( $this, 'add_id_in_action_row' ),
1164 10,
1165 2
1166 );
1167 add_filter(
1168 'user_row_actions',
1169 array( $this, 'add_id_in_action_row' ),
1170 10,
1171 2
1172 );
1173 }
1174
1175 /**
1176 * Output the ID in the action row
1177 *
1178 * @since 4.7.4
1179 */
1180 public function add_id_in_action_row( $actions, $object )
1181 {
1182
1183 if ( current_user_can( 'edit_posts' ) ) {
1184 // For pages, posts, custom post types, media/attachments, users
1185 if ( property_exists( $object, 'ID' ) ) {
1186 $id = $object->ID;
1187 }
1188 // For taxonomies
1189 if ( property_exists( $object, 'term_id' ) ) {
1190 $id = $object->term_id;
1191 }
1192 // For comments
1193 if ( property_exists( $object, 'comment_ID' ) ) {
1194 $id = $object->comment_ID;
1195 }
1196 $actions['asenha-list-table-item-id'] = '<span class="asenha-list-table-item-id">ID: ' . $id . '</span>';
1197 }
1198
1199 return $actions;
1200 }
1201
1202 /**
1203 * Hide comments column in list tables for pages, post types that support comments, and alse media/attachments.
1204 *
1205 * @since 1.0.0
1206 */
1207 public function hide_comments_column()
1208 {
1209 $post_types = get_post_types( array(
1210 'public' => true,
1211 ), 'names' );
1212 foreach ( $post_types as $post_type_key => $post_type_name ) {
1213 if ( post_type_supports( $post_type_key, 'comments' ) ) {
1214
1215 if ( 'attachment' != $post_type_name ) {
1216 // For list tables of pages, posts and other post types
1217 add_filter( "manage_{$post_type_name}_posts_columns", [ $this, 'remove_comment_column' ] );
1218 } else {
1219 // For list table of media/attachment
1220 add_filter( 'manage_media_columns', [ $this, 'remove_comment_column' ] );
1221 }
1222
1223 }
1224 }
1225 }
1226
1227 /**
1228 * Add a column called ID
1229 *
1230 * @param mixed $columns
1231 * @return void
1232 * @since 1.0.0
1233 */
1234 public function remove_comment_column( $columns )
1235 {
1236 unset( $columns['comments'] );
1237 return $columns;
1238 }
1239
1240 /**
1241 * Hide tags column in list tables for posts.
1242 *
1243 * @since 1.0.0
1244 */
1245 public function hide_post_tags_column()
1246 {
1247 $post_types = get_post_types( array(
1248 'public' => true,
1249 ), 'names' );
1250 foreach ( $post_types as $post_type_key => $post_type_name ) {
1251 if ( $post_type_name == 'post' ) {
1252 add_filter( "manage_posts_columns", [ $this, 'remove_post_tags_column' ] );
1253 }
1254 }
1255 }
1256
1257 /**
1258 * Add a column called ID
1259 *
1260 * @param mixed $columns
1261 * @return void
1262 * @since 1.0.0
1263 */
1264 public function remove_post_tags_column( $columns )
1265 {
1266 unset( $columns['tags'] );
1267 return $columns;
1268 }
1269
1270 /**
1271 * Show custom (hierarchical) taxonomy filter(s) for all post types.
1272 *
1273 * @since 1.0.0
1274 */
1275 public function show_custom_taxonomy_filters( $post_type )
1276 {
1277 $post_taxonomies = get_object_taxonomies( $post_type, 'objects' );
1278 // Only show custom taxonomy filters for post types other than 'post'
1279 if ( 'post' != $post_type && 'attachment' != $post_type && 'asenha_code_snippet' != $post_type ) {
1280 array_walk( $post_taxonomies, [ $this, 'output_taxonomy_filter' ] );
1281 }
1282 }
1283
1284 /**
1285 * Output filter on the post type's list table for a taxonomy
1286 *
1287 * @since 1.0.0
1288 */
1289 public function output_taxonomy_filter( $post_taxonomy )
1290 {
1291 // Only show taxonomy filter when the taxonomy is hierarchical
1292 if ( true === $post_taxonomy->hierarchical ) {
1293 wp_dropdown_categories( array(
1294 'show_option_all' => sprintf( 'All %s', $post_taxonomy->label ),
1295 'orderby' => 'name',
1296 'order' => 'ASC',
1297 'hide_empty' => false,
1298 'hide_if_empty' => true,
1299 'selected' => sanitize_text_field( ( isset( $_GET[$post_taxonomy->query_var] ) && !empty($_GET[$post_taxonomy->query_var]) ? $_GET[$post_taxonomy->query_var] : '' ) ),
1300 'hierarchical' => true,
1301 'name' => $post_taxonomy->query_var,
1302 'taxonomy' => $post_taxonomy->name,
1303 'value_field' => 'slug',
1304 ) );
1305 }
1306 }
1307
1308 }