menu.php
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_admin_menu')): |
| 8 | |
| 9 | class acfe_admin_menu{ |
| 10 | |
| 11 | /** |
| 12 | * Construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_action('current_screen', array($this, 'current_screen')); |
| 17 | add_action('admin_menu', array($this, 'admin_menu'), 999); |
| 18 | |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * current_screen |
| 23 | * |
| 24 | * @param $screen |
| 25 | */ |
| 26 | function current_screen($screen){ |
| 27 | |
| 28 | // check version |
| 29 | if(acf_version_compare(acf_get_setting('version'), '>=', '5.9')){ |
| 30 | |
| 31 | // allowed screens |
| 32 | $allowed = array( |
| 33 | 'edit-acf-field-group-category', |
| 34 | 'edit-acfe-dbt', |
| 35 | 'acfe-dbt', |
| 36 | 'edit-acfe-template', |
| 37 | 'acfe-template', |
| 38 | 'edit-acfe-form', |
| 39 | 'acfe-form' |
| 40 | ); |
| 41 | |
| 42 | // chgeck allowed |
| 43 | if(acf_is_screen($allowed)){ |
| 44 | add_action('in_admin_header', array($this, 'in_admin_header')); |
| 45 | } |
| 46 | |
| 47 | } |
| 48 | |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /** |
| 53 | * in_admin_header |
| 54 | */ |
| 55 | function in_admin_header(){ |
| 56 | acf_get_view('html-admin-navigation'); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | /** |
| 61 | * admin_menu |
| 62 | * |
| 63 | * Swap menu items to the correct order |
| 64 | */ |
| 65 | function admin_menu(){ |
| 66 | |
| 67 | // global |
| 68 | global $submenu; |
| 69 | |
| 70 | // bail early |
| 71 | if(!acf_maybe_get($submenu, 'edit.php?post_type=acf-field-group')){ |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | // vars |
| 76 | $new_menu = array(); |
| 77 | $all_menu = $submenu['edit.php?post_type=acf-field-group']; |
| 78 | |
| 79 | // order |
| 80 | $order = array( |
| 81 | 'edit.php?post_type=acf-field-group', |
| 82 | 'post-new.php?post_type=acf-field-group', |
| 83 | 'edit-tags.php?taxonomy=acf-field-group-category', |
| 84 | 'edit.php?post_type=acfe-dbt', |
| 85 | 'edit.php?post_type=acfe-form', |
| 86 | 'edit.php?post_type=acfe-dop', |
| 87 | 'edit.php?post_type=acf-post-type', |
| 88 | 'acfe-settings', |
| 89 | 'edit.php?post_type=acf-taxonomy', |
| 90 | 'edit.php?post_type=acf-ui-options-page', |
| 91 | 'acf-tools', |
| 92 | 'acf-settings-updates', |
| 93 | ); |
| 94 | |
| 95 | // loop |
| 96 | foreach($submenu['edit.php?post_type=acf-field-group'] as $k => $item){ |
| 97 | |
| 98 | //name |
| 99 | $name = $item[2]; |
| 100 | |
| 101 | // search |
| 102 | $position = array_search($name, $order); |
| 103 | |
| 104 | // found position |
| 105 | if($position !== false){ |
| 106 | $this->assign_submenu($new_menu, $position, $item, $all_menu, $k); |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | |
| 111 | // sort new menu |
| 112 | ksort($new_menu); |
| 113 | |
| 114 | // assign new menu |
| 115 | $submenu['edit.php?post_type=acf-field-group'] = $new_menu; |
| 116 | |
| 117 | // add menu items that are left |
| 118 | if(!empty($all_menu)){ |
| 119 | $submenu['edit.php?post_type=acf-field-group'] = array_merge($new_menu, $all_menu); |
| 120 | } |
| 121 | |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /** |
| 126 | * assign_submenu |
| 127 | * |
| 128 | * @param $new_menu |
| 129 | * @param $new_menu_key |
| 130 | * @param $item |
| 131 | * @param $all_menu |
| 132 | * @param $all_menu_key |
| 133 | */ |
| 134 | function assign_submenu(&$new_menu, $new_menu_key, $item, &$all_menu, $all_menu_key){ |
| 135 | |
| 136 | $new_menu[ $new_menu_key ] = $item; |
| 137 | unset($all_menu[ $all_menu_key ]); |
| 138 | |
| 139 | } |
| 140 | |
| 141 | } |
| 142 | |
| 143 | new acfe_admin_menu(); |
| 144 | |
| 145 | endif; |