html-admin-navigation.php
| 1 | <?php |
| 2 | /** |
| 3 | * The template for displaying admin navigation. |
| 4 | * |
| 5 | * @date 27/3/20 |
| 6 | * @since 5.9.0 |
| 7 | */ |
| 8 | |
| 9 | if( ! defined( 'ABSPATH' ) ) exit; |
| 10 | |
| 11 | global $submenu, $parent_file, $submenu_file, $plugin_page, $pagenow; |
| 12 | |
| 13 | // Vars. |
| 14 | $parent_slug = 'edit.php?post_type=acf-field-group'; |
| 15 | |
| 16 | // Generate array of navigation items. |
| 17 | $tabs = array(); |
| 18 | if( isset($submenu[ $parent_slug ]) ) { |
| 19 | foreach( $submenu[ $parent_slug ] as $i => $sub_item ) { |
| 20 | |
| 21 | // Check user can access page. |
| 22 | if ( !current_user_can( $sub_item[1] ) ) { |
| 23 | continue; |
| 24 | } |
| 25 | |
| 26 | // Ignore "Add New". |
| 27 | if( $i === 1 ) { |
| 28 | continue; |
| 29 | } |
| 30 | |
| 31 | // Define tab. |
| 32 | $tab = array( |
| 33 | 'text' => $sub_item[0], |
| 34 | 'url' => $sub_item[2] |
| 35 | ); |
| 36 | |
| 37 | // Convert submenu slug "test" to "$parent_slug&page=test". |
| 38 | if( !strpos($sub_item[2], '.php') ) { |
| 39 | $tab['url'] = add_query_arg( array( 'page' => $sub_item[2] ), $parent_slug ); |
| 40 | } |
| 41 | |
| 42 | // Detect active state. |
| 43 | if( $submenu_file === $sub_item[2] || $plugin_page === $sub_item[2] ) { |
| 44 | $tab['is_active'] = true; |
| 45 | } |
| 46 | |
| 47 | // Special case for "Add New" page. |
| 48 | if( $i === 0 && $submenu_file === 'post-new.php?post_type=acf-field-group' ) { |
| 49 | $tab['is_active'] = true; |
| 50 | } |
| 51 | $tabs[] = $tab; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Filters the admin navigation tabs. |
| 57 | * |
| 58 | * @date 27/3/20 |
| 59 | * @since 5.9.0 |
| 60 | * |
| 61 | * @param array $tabs The array of navigation tabs. |
| 62 | */ |
| 63 | $tabs = apply_filters( 'acf/admin/toolbar', $tabs ); |
| 64 | |
| 65 | // Bail early if set to false. |
| 66 | if( $tabs === false ) { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | ?> |
| 71 | <div class="acf-admin-toolbar"> |
| 72 | <h2><i class="acf-tab-icon dashicons dashicons-welcome-widgets-menus"></i> <?php echo acf_get_setting('name'); ?></h2> |
| 73 | <?php foreach( $tabs as $tab ) { |
| 74 | printf( |
| 75 | '<a class="acf-tab%s" href="%s">%s</a>', |
| 76 | !empty( $tab['is_active'] ) ? ' is-active' : '', |
| 77 | esc_url( $tab['url'] ), |
| 78 | acf_esc_html( $tab['text'] ) |
| 79 | ); |
| 80 | } ?> |
| 81 | </div> |