class-activation.php
7 months ago
class-admin-menu-organizer.php
7 months ago
class-admin-menu-svg-icon-mask.php
7 months ago
class-auto-publish-posts-with-missed-schedule.php
7 months ago
class-avif-upload.php
7 months ago
class-captcha-protection.php
7 months ago
class-change-login-url.php
7 months ago
class-cleanup-admin-bar.php
7 months ago
class-common-methods.php
7 months ago
class-content-duplication.php
7 months ago
class-content-order.php
7 months ago
class-custom-admin-footer-text.php
7 months ago
class-custom-body-class.php
7 months ago
class-custom-css.php
7 months ago
class-custom-nav-menu-items-in-new-tab.php
7 months ago
class-deactivation.php
7 months ago
class-disable-author-archives.php
7 months ago
class-disable-comments.php
7 months ago
class-disable-dashboard-widgets.php
7 months ago
class-disable-embeds.php
7 months ago
class-disable-feeds.php
7 months ago
class-disable-gutenberg.php
7 months ago
class-disable-rest-api.php
7 months ago
class-disable-smaller-components.php
7 months ago
class-disable-updates.php
7 months ago
class-disable-xml-rpc.php
7 months ago
class-display-system-summary.php
7 months ago
class-email-address-obfuscator.php
7 months ago
class-email-delivery.php
7 months ago
class-enhance-list-tables.php
7 months ago
class-external-permalinks.php
7 months ago
class-heartbeat-control.php
7 months ago
class-hide-admin-bar.php
7 months ago
class-hide-admin-notices.php
7 months ago
class-image-sizes-panel.php
7 months ago
class-image-upload-control.php
7 months ago
class-insert-head-body-footer-code.php
7 months ago
class-last-login-column.php
7 months ago
class-limit-login-attempts.php
7 months ago
class-login-id-type.php
7 months ago
class-login-logout-menu.php
7 months ago
class-maintenance-mode.php
7 months ago
class-manage-ads-appads-txt.php
7 months ago
class-manage-robots-txt.php
7 months ago
class-media-replacement.php
7 months ago
class-multiple-user-roles.php
7 months ago
class-obfuscate-author-slugs.php
7 months ago
class-open-external-links-in-new-tab.php
7 months ago
class-password-protection.php
7 months ago
class-redirect-after-login.php
7 months ago
class-redirect-after-logout.php
7 months ago
class-redirect-fourofour.php
7 months ago
class-registration-date-column.php
7 months ago
class-revisions-control.php
7 months ago
class-search-engines-visibility.php
7 months ago
class-settings-fields-render.php
7 months ago
class-settings-sanitization.php
7 months ago
class-settings-sections-fields.php
7 months ago
class-show-custom-taxonomy-filters.php
7 months ago
class-site-identity-on-login-page.php
7 months ago
class-svg-upload.php
7 months ago
class-various-admin-ui-enhancements.php
7 months ago
class-view-admin-as-role.php
7 months ago
class-wider-admin-menu.php
7 months ago
class-wp-config-transformer.php
7 months ago
class-admin-menu-organizer.php
447 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class for Admin Menu Organizer module |
| 7 | * |
| 8 | * @since 6.9.5 |
| 9 | */ |
| 10 | class Admin_Menu_Organizer { |
| 11 | /** |
| 12 | * Add Admin Menu item under Settings menu |
| 13 | * |
| 14 | * @since 7.8.5 |
| 15 | */ |
| 16 | public function add_menu_item() { |
| 17 | add_submenu_page( |
| 18 | 'options-general.php', |
| 19 | // Parent page/menu |
| 20 | __( 'Admin Menu Settings', 'admin-site-enhancements' ), |
| 21 | // Browser tab/window title |
| 22 | __( 'Admin Menu', 'admin-site-enhancements' ), |
| 23 | // Sube menu title |
| 24 | 'manage_options', |
| 25 | // Minimal user capabililty |
| 26 | 'admin-menu-organizer', |
| 27 | // Page slug. Shows up in URL. |
| 28 | array($this, 'add_admin_menu_settings_page') |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Create settings page for Admin Menu |
| 34 | * |
| 35 | * @since 7.8.5 |
| 36 | */ |
| 37 | public function add_admin_menu_settings_page() { |
| 38 | $render_field = new Settings_Fields_Render(); |
| 39 | ?> |
| 40 | <div class="wrap admin-menu-organizer"> |
| 41 | <h1 class="wp-heading-inline"><?php |
| 42 | echo __( 'Admin Menu Organizer', 'admin-site-enhancements' ); |
| 43 | ?></h1> |
| 44 | <div class="admin-menu-organizer-main"> |
| 45 | <div class="admin-menu-sortables-wrapper"> |
| 46 | <?php |
| 47 | $render_field->render_sortable_menu(); |
| 48 | ?> |
| 49 | </div> |
| 50 | <div class="admin-menu-actions"> |
| 51 | <button id="amo-save-changes" class="button button-primary button-large"><?php |
| 52 | echo __( 'Save Changes', 'admin-site-enhancements' ); |
| 53 | ?></button> |
| 54 | <div class="asenha-saving-changes" style="display:none;"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="#2271b1" d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z" opacity=".25"/><path fill="#2271b1" d="M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"><animateTransform attributeName="transform" dur="0.75s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></svg></div> |
| 55 | <div class="asenha-changes-saved" style="display:none;"><svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24"><path fill="seagreen" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10s10-4.48 10-10S17.52 2 12 2zM9.29 16.29L5.7 12.7a.996.996 0 1 1 1.41-1.41L10 14.17l6.88-6.88a.996.996 0 1 1 1.41 1.41l-7.59 7.59a.996.996 0 0 1-1.41 0z"/></svg></div> |
| 56 | </div> |
| 57 | </div> |
| 58 | </div> |
| 59 | <?php |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Render custom menu order |
| 64 | * |
| 65 | * @param $menu_order array an ordered array of menu items |
| 66 | * @link https://developer.wordpress.org/reference/hooks/menu_order/ |
| 67 | * @since 2.0.0 |
| 68 | */ |
| 69 | public function render_custom_menu_order( $menu_order ) { |
| 70 | global $menu; |
| 71 | $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 72 | $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() ); |
| 73 | // Get current menu order. We're not using the default $menu_order which uses index.php, edit.php as array values. |
| 74 | $current_menu_order = array(); |
| 75 | foreach ( $menu as $menu_key => $menu_info ) { |
| 76 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 77 | $menu_item_id = $menu_info[2]; |
| 78 | } else { |
| 79 | $menu_item_id = $menu_info[5]; |
| 80 | } |
| 81 | $current_menu_order[] = array($menu_item_id, $menu_info[2]); |
| 82 | } |
| 83 | // Get custom menu order |
| 84 | $custom_menu_order = $options['custom_menu_order']; |
| 85 | // comma separated |
| 86 | $custom_menu_order = explode( ",", $custom_menu_order ); |
| 87 | // array of menu ID, e.g. menu-dashboard |
| 88 | // Return menu order for rendering |
| 89 | $rendered_menu_order = array(); |
| 90 | // Render menu based on items saved in custom menu order |
| 91 | foreach ( $custom_menu_order as $custom_menu_item_id ) { |
| 92 | foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) { |
| 93 | if ( $custom_menu_item_id == $current_menu_item[0] ) { |
| 94 | $rendered_menu_order[] = $current_menu_item[1]; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | // Add items from current menu not already part of custom menu order, e.g. new plugin activated and adds new menu item |
| 99 | foreach ( $current_menu_order as $current_menu_item_id => $current_menu_item ) { |
| 100 | if ( !in_array( $current_menu_item[0], $custom_menu_order ) ) { |
| 101 | $rendered_menu_order[] = $current_menu_item[1]; |
| 102 | } |
| 103 | } |
| 104 | return $rendered_menu_order; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Apply custom menu item titles |
| 109 | * |
| 110 | * @since 2.9.0 |
| 111 | */ |
| 112 | public function apply_custom_menu_item_titles() { |
| 113 | global $menu; |
| 114 | $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 115 | $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() ); |
| 116 | // Get custom menu item titles |
| 117 | $custom_menu_titles = $options['custom_menu_titles']; |
| 118 | $custom_menu_titles = explode( ',', $custom_menu_titles ); |
| 119 | foreach ( $menu as $menu_key => $menu_info ) { |
| 120 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 121 | $menu_item_id = $menu_info[2]; |
| 122 | } else { |
| 123 | $menu_item_id = $menu_info[5]; |
| 124 | } |
| 125 | // Get defaul/custom menu item title |
| 126 | foreach ( $custom_menu_titles as $custom_menu_title ) { |
| 127 | // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets |
| 128 | $custom_menu_title = explode( '__', $custom_menu_title ); |
| 129 | if ( $custom_menu_title[0] == $menu_item_id ) { |
| 130 | $menu_item_title = $custom_menu_title[1]; |
| 131 | // e.g. Code Snippets |
| 132 | break; |
| 133 | // stop foreach loop so $menu_item_title is not overwritten in the next iteration |
| 134 | } else { |
| 135 | $menu_item_title = $menu_info[0]; |
| 136 | } |
| 137 | } |
| 138 | $menu[$menu_key][0] = $menu_item_title; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Apply custom menu item titles |
| 144 | * |
| 145 | * @since 7.9.7 |
| 146 | */ |
| 147 | public function apply_custom_title_for_posts_menu() { |
| 148 | global $wp_post_types; |
| 149 | $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 150 | $admin_menu_options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() ); |
| 151 | // $admin_menu_organizer = new ASENHA\Classes\Admin_Menu_Organizer(); |
| 152 | // For 'Posts' menu, if the title has been changed, try changing the labels for it everywhere |
| 153 | $custom_menu_titles = explode( ',', $admin_menu_options['custom_menu_titles'] ); |
| 154 | foreach ( $custom_menu_titles as $custom_menu_title ) { |
| 155 | if ( false !== strpos( $custom_menu_title, 'menu-posts__' ) ) { |
| 156 | $custom_menu_title = explode( '__', $custom_menu_title ); |
| 157 | $posts_custom_title = $custom_menu_title[1]; |
| 158 | $posts_default_title = __( 'Posts', 'admin-site-enhancements' ); |
| 159 | if ( is_array( $wp_post_types ) ) { |
| 160 | if ( isset( $wp_post_types['post'] ) && property_exists( $wp_post_types['post'], 'label' ) ) { |
| 161 | $posts_default_title = $wp_post_types['post']->label; |
| 162 | } |
| 163 | } |
| 164 | if ( $posts_default_title != $posts_custom_title ) { |
| 165 | add_filter( 'post_type_labels_post', [$this, 'change_post_labels'] ); |
| 166 | add_action( 'init', [$this, 'change_post_object_label'] ); |
| 167 | add_action( 'admin_menu', [$this, 'change_post_menu_label'], PHP_INT_MAX ); |
| 168 | add_action( 'admin_bar_menu', [$this, 'change_wp_admin_bar'], 80 ); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Get custom title for 'Posts' menu item |
| 176 | * |
| 177 | * @since 6.9.13 |
| 178 | */ |
| 179 | public function get_posts_custom_title() { |
| 180 | $post_object = get_post_type_object( 'post' ); |
| 181 | // object |
| 182 | $posts_default_title = ''; |
| 183 | if ( is_object( $post_object ) ) { |
| 184 | if ( property_exists( $post_object, 'label' ) ) { |
| 185 | $posts_default_title = $post_object->label; |
| 186 | } else { |
| 187 | $posts_default_title = $post_object->labels->name; |
| 188 | } |
| 189 | } |
| 190 | $posts_custom_title = $posts_default_title; |
| 191 | $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 192 | $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() ); |
| 193 | $custom_menu_titles = ( isset( $options['custom_menu_titles'] ) ? explode( ',', $options['custom_menu_titles'] ) : array() ); |
| 194 | if ( !empty( $custom_menu_titles ) ) { |
| 195 | foreach ( $custom_menu_titles as $custom_menu_title ) { |
| 196 | if ( false !== strpos( $custom_menu_title, 'menu-posts__' ) ) { |
| 197 | $custom_menu_title = explode( '__', $custom_menu_title ); |
| 198 | $posts_custom_title = $custom_menu_title[1]; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | return $posts_custom_title; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * For 'Posts', apply custom label |
| 207 | * |
| 208 | * @link https://developer.wordpress.org/reference/hooks/post_type_labels_post_type/ |
| 209 | * @since 6.9.13 |
| 210 | */ |
| 211 | public function change_post_labels( $labels ) { |
| 212 | $post_object = get_post_type_object( 'post' ); |
| 213 | // object |
| 214 | $posts_default_title_plural = ''; |
| 215 | if ( is_object( $post_object ) ) { |
| 216 | if ( property_exists( $post_object, 'label' ) ) { |
| 217 | $posts_default_title_plural = $post_object->label; |
| 218 | } else { |
| 219 | $posts_default_title_plural = $post_object->labels->name; |
| 220 | } |
| 221 | $posts_default_title_singular = $post_object->labels->singular_name; |
| 222 | $posts_custom_title = $this->get_posts_custom_title(); |
| 223 | foreach ( $labels as $key => $label ) { |
| 224 | if ( null === $label ) { |
| 225 | continue; |
| 226 | } |
| 227 | $labels->{$key} = str_replace( [$posts_default_title_plural, $posts_default_title_singular], $posts_custom_title, $label ); |
| 228 | } |
| 229 | } |
| 230 | return $labels; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * For 'Posts', apply custom label in post object |
| 235 | * |
| 236 | * @since 6.9.12 |
| 237 | */ |
| 238 | public function change_post_object_label() { |
| 239 | global $wp_post_types; |
| 240 | $posts_custom_title = $this->get_posts_custom_title(); |
| 241 | $labels =& $wp_post_types['post']->labels; |
| 242 | $labels->name = $posts_custom_title; |
| 243 | $labels->singular_name = $posts_custom_title; |
| 244 | $labels->all_items = sprintf( |
| 245 | /* translators: %s is post type or taxonomy label */ |
| 246 | __( 'All %s', 'admin-site-enhancements' ), |
| 247 | $posts_custom_title |
| 248 | ); |
| 249 | $labels->add_new = __( 'Add New', 'admin-site-enhancements' ); |
| 250 | $labels->add_new_item = __( 'Add New', 'admin-site-enhancements' ); |
| 251 | $labels->edit_item = __( 'Edit', 'admin-site-enhancements' ); |
| 252 | $labels->new_item = $posts_custom_title; |
| 253 | $labels->view_item = __( 'View', 'admin-site-enhancements' ); |
| 254 | $labels->search_items = sprintf( |
| 255 | /* translators: %s is post type or taxonomy label */ |
| 256 | __( 'Search %s', 'admin-site-enhancements' ), |
| 257 | $posts_custom_title |
| 258 | ); |
| 259 | $labels->not_found = sprintf( |
| 260 | /* translators: %s is the post type label */ |
| 261 | __( 'No %s found', 'admin-site-enhancements' ), |
| 262 | strtolower( $posts_custom_title ) |
| 263 | ); |
| 264 | $labels->not_found_in_trash = sprintf( |
| 265 | /* translators: %s is the post type label */ |
| 266 | __( 'No %s found in Trash', 'admin-site-enhancements' ), |
| 267 | strtolower( $posts_custom_title ) |
| 268 | ); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * For 'Posts', apply custom label in menu and submenu |
| 273 | * |
| 274 | * @since 6.9.12 |
| 275 | */ |
| 276 | public function change_post_menu_label() { |
| 277 | global $submenu; |
| 278 | $posts_custom_title = $this->get_posts_custom_title(); |
| 279 | if ( !empty( $posts_custom_title ) ) { |
| 280 | $submenu['edit.php'][5][0] = sprintf( |
| 281 | /* translators: %s is post type or taxonomy label */ |
| 282 | __( 'All %s', 'admin-site-enhancements' ), |
| 283 | $posts_custom_title |
| 284 | ); |
| 285 | } else { |
| 286 | $submenu['edit.php'][5][0] = sprintf( |
| 287 | /* translators: %s is post type or taxonomy label */ |
| 288 | __( 'All %s', 'admin-site-enhancements' ), |
| 289 | $posts_default_title |
| 290 | ); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * For 'Posts', apply custom label in admin bar |
| 296 | * |
| 297 | * @since 6.9.12 |
| 298 | */ |
| 299 | public function change_wp_admin_bar( $wp_admin_bar ) { |
| 300 | $posts_custom_title = $this->get_posts_custom_title(); |
| 301 | $new_post_node = $wp_admin_bar->get_node( 'new-post' ); |
| 302 | if ( $new_post_node ) { |
| 303 | $new_post_node->title = $posts_custom_title; |
| 304 | $wp_admin_bar->add_node( $new_post_node ); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Hide parent menu items by adding class(es) to hide them |
| 310 | * |
| 311 | * @since 2.0.0 |
| 312 | */ |
| 313 | public function hide_menu_items() { |
| 314 | global $menu; |
| 315 | $common_methods = new Common_Methods(); |
| 316 | $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle(); |
| 317 | // indexed array |
| 318 | foreach ( $menu as $menu_key => $menu_info ) { |
| 319 | if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) { |
| 320 | $menu_item_id = $menu_info[2]; |
| 321 | } else { |
| 322 | $menu_item_id = $menu_info[5]; |
| 323 | } |
| 324 | // Append 'hidden' class to hide menu item until toggled |
| 325 | if ( in_array( $menu_item_id, $menu_hidden_by_toggle ) ) { |
| 326 | $menu[$menu_key][4] = $menu_info[4] . ' hidden asenha_hidden_menu'; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Add toggle to show hidden menu items |
| 333 | * |
| 334 | * @since 2.0.0 |
| 335 | */ |
| 336 | public function add_hidden_menu_toggle() { |
| 337 | global $current_user; |
| 338 | // Get menu items hidden by toggle |
| 339 | $common_methods = new Common_Methods(); |
| 340 | $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle(); |
| 341 | $submenu_hidden_by_toggle = array(); |
| 342 | // Get user capabilities the "Show All/Less" toggle should be shown for |
| 343 | $user_capabilities_to_show_menu_toggle_for = $common_methods->get_user_capabilities_to_show_menu_toggle_for(); |
| 344 | // Get current user's capabilities from the user's role(s) |
| 345 | $current_user_capabilities = ''; |
| 346 | $current_user_roles = $current_user->roles; |
| 347 | // indexed array of role slugs |
| 348 | foreach ( $current_user_roles as $current_user_role ) { |
| 349 | $current_user_role_capabilities = get_role( $current_user_role )->capabilities; |
| 350 | if ( is_array( $current_user_role_capabilities ) ) { |
| 351 | $current_user_role_capabilities = array_keys( $current_user_role_capabilities ); |
| 352 | // indexed array |
| 353 | $current_user_role_capabilities = implode( ",", $current_user_role_capabilities ); |
| 354 | $current_user_capabilities .= ',' . $current_user_role_capabilities; |
| 355 | } |
| 356 | } |
| 357 | // Maybe show "Show All/Less" toggle |
| 358 | $show_toggle_menu = false; |
| 359 | if ( !empty( $current_user_capabilities ) ) { |
| 360 | $current_user_capabilities = array_unique( explode( ",", $current_user_capabilities ) ); |
| 361 | foreach ( $user_capabilities_to_show_menu_toggle_for as $user_capability_to_show_menu_toggle_for ) { |
| 362 | if ( in_array( $user_capability_to_show_menu_toggle_for, $current_user_capabilities ) ) { |
| 363 | $show_toggle_menu = true; |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | if ( (!empty( $menu_hidden_by_toggle ) || !empty( $submenu_hidden_by_toggle )) && $show_toggle_menu ) { |
| 369 | add_menu_page( |
| 370 | __( 'Show All', 'admin-site-enhancements' ), |
| 371 | __( 'Show All', 'admin-site-enhancements' ), |
| 372 | 'read', |
| 373 | 'asenha_show_hidden_menu', |
| 374 | function () { |
| 375 | return false; |
| 376 | }, |
| 377 | "dashicons-arrow-down-alt2", |
| 378 | 300 |
| 379 | ); |
| 380 | add_menu_page( |
| 381 | __( 'Show Less', 'admin-site-enhancements' ), |
| 382 | __( 'Show Less', 'admin-site-enhancements' ), |
| 383 | 'read', |
| 384 | 'asenha_hide_hidden_menu', |
| 385 | function () { |
| 386 | return false; |
| 387 | }, |
| 388 | "dashicons-arrow-up-alt2", |
| 389 | 301 |
| 390 | ); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Script to toggle hidden menu itesm |
| 396 | * |
| 397 | * @since 2.0.0 |
| 398 | */ |
| 399 | public function enqueue_toggle_hidden_menu_script() { |
| 400 | // Get menu items hidden by toggle |
| 401 | $common_methods = new Common_Methods(); |
| 402 | $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle(); |
| 403 | $submenu_hidden_by_toggle = array(); |
| 404 | if ( !empty( $menu_hidden_by_toggle ) || !empty( $submenu_hidden_by_toggle ) ) { |
| 405 | // Script to set behaviour and actions of the sortable menu |
| 406 | wp_enqueue_script( |
| 407 | 'asenha-toggle-hidden-menu', |
| 408 | ASENHA_URL . 'assets/js/toggle-hidden-menu.js', |
| 409 | array(), |
| 410 | ASENHA_VERSION, |
| 411 | false |
| 412 | ); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Save admin menu via AJAX |
| 418 | * |
| 419 | * @since 6.3.1 |
| 420 | */ |
| 421 | public function save_admin_menu() { |
| 422 | if ( isset( $_REQUEST ) ) { |
| 423 | if ( check_ajax_referer( 'save-menu-nonce', 'nonce', false ) ) { |
| 424 | $options_extra = get_option( ASENHA_SLUG_U . '_extra', array() ); |
| 425 | $options = ( isset( $options_extra['admin_menu'] ) ? $options_extra['admin_menu'] : array() ); |
| 426 | $options['custom_menu_order'] = ( isset( $_REQUEST['custom_menu_order'] ) ? $_REQUEST['custom_menu_order'] : $options['custom_menu_order'] ); |
| 427 | $options['custom_menu_titles'] = ( isset( $_REQUEST['custom_menu_titles'] ) ? wp_unslash( $_REQUEST['custom_menu_titles'] ) : $options['custom_menu_titles'] ); |
| 428 | $options['custom_menu_hidden'] = ( isset( $_REQUEST['custom_menu_hidden'] ) ? $_REQUEST['custom_menu_hidden'] : $options['custom_menu_hidden'] ); |
| 429 | $options_extra['admin_menu'] = $options; |
| 430 | // vi( $options_extra, '', 'save menu' ); |
| 431 | $updated = update_option( ASENHA_SLUG_U . '_extra', $options_extra, true ); |
| 432 | if ( $updated ) { |
| 433 | $response = array( |
| 434 | 'status' => 'success', |
| 435 | ); |
| 436 | } else { |
| 437 | $response = array( |
| 438 | 'status' => 'failed', |
| 439 | ); |
| 440 | } |
| 441 | echo json_encode( $response ); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | } |
| 447 |