navigation.php
186 lines
| 1 | <?php |
| 2 | //phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- included template file. |
| 3 | /** |
| 4 | * The template for displaying admin navigation. |
| 5 | * |
| 6 | * @date 27/3/20 |
| 7 | * @since ACF 5.9.0 |
| 8 | */ |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; |
| 12 | } |
| 13 | |
| 14 | global $submenu, $submenu_file, $plugin_page, $acf_page_title; |
| 15 | |
| 16 | // Setup default vars and generate array of navigation items. |
| 17 | $parent_slug = 'edit.php?post_type=acf-field-group'; |
| 18 | $core_tabs = array(); |
| 19 | $acf_more_items = array(); |
| 20 | $more_items = array(); |
| 21 | |
| 22 | // Hardcoded since future ACF post types will likely live in the "More" menu. |
| 23 | $core_tabs_classes = array( 'acf-field-group', 'acf-post-type', 'acf-taxonomy' ); |
| 24 | $acf_more_items_classes = array( 'acf-ui-options-page', 'acf-tools', 'acf-settings-updates' ); |
| 25 | |
| 26 | if ( isset( $submenu[ $parent_slug ] ) ) { |
| 27 | foreach ( $submenu[ $parent_slug ] as $i => $sub_item ) { |
| 28 | |
| 29 | // Check user can access page. |
| 30 | if ( ! current_user_can( $sub_item[1] ) ) { |
| 31 | continue; |
| 32 | } |
| 33 | |
| 34 | // Define tab. |
| 35 | $menu_item = array( |
| 36 | 'text' => $sub_item[0], |
| 37 | 'url' => $sub_item[2], |
| 38 | ); |
| 39 | |
| 40 | // Convert submenu slug "test" to "$parent_slug&page=test". |
| 41 | if ( ! strpos( $sub_item[2], '.php' ) ) { |
| 42 | $menu_item['url'] = add_query_arg( array( 'page' => $sub_item[2] ), $parent_slug ); |
| 43 | $menu_item['class'] = $sub_item[2]; |
| 44 | } else { |
| 45 | // Build class from URL. |
| 46 | $menu_item['class'] = str_replace( 'edit.php?post_type=', '', $sub_item[2] ); |
| 47 | } |
| 48 | |
| 49 | // Detect active state. |
| 50 | if ( $submenu_file === $sub_item[2] || $plugin_page === $sub_item[2] ) { |
| 51 | $menu_item['is_active'] = true; |
| 52 | } |
| 53 | |
| 54 | // Handle "Add New" versions of edit page. |
| 55 | if ( str_replace( 'edit', 'post-new', $sub_item[2] ) === $submenu_file ) { |
| 56 | $menu_item['is_active'] = true; |
| 57 | } |
| 58 | |
| 59 | // Organize the menu items. |
| 60 | if ( in_array( $menu_item['class'], $core_tabs_classes, true ) ) { |
| 61 | // Main ACF tabs. |
| 62 | $core_tabs[] = $menu_item; |
| 63 | |
| 64 | // Add post types & taxonomies to the more menu as well so we can show them there on smaller screens. |
| 65 | if ( in_array( $menu_item['class'], array( 'acf-post-type', 'acf-taxonomy' ), true ) ) { |
| 66 | $acf_more_items[] = $menu_item; |
| 67 | } |
| 68 | } elseif ( in_array( $menu_item['class'], $acf_more_items_classes, true ) ) { |
| 69 | // ACF tabs moved to the "More" menu. |
| 70 | $acf_more_items[] = $menu_item; |
| 71 | } else { |
| 72 | // Third party tabs placed into the "More" menu. |
| 73 | $more_items[] = $menu_item; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Filters the admin navigation more items. |
| 80 | * |
| 81 | * @since ACF 5.9.0 |
| 82 | * |
| 83 | * @param array $more_items The array of navigation tabs. |
| 84 | */ |
| 85 | $more_items = apply_filters( 'acf/admin/toolbar', $more_items ); |
| 86 | |
| 87 | // Bail early if set to false. |
| 88 | if ( $core_tabs === false ) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Helper function for looping over the provided menu items |
| 94 | * and echoing out the necessary markup. |
| 95 | * |
| 96 | * @since ACF 6.2 |
| 97 | * |
| 98 | * @param array $menu_items An array of menu items to print. |
| 99 | * @param string $section The section being printed. |
| 100 | * @return void |
| 101 | */ |
| 102 | function acf_print_menu_section( $menu_items, $section = '' ) { |
| 103 | // Bail if no menu items. |
| 104 | if ( ! is_array( $menu_items ) || empty( $menu_items ) ) { |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | $section_html = ''; |
| 109 | |
| 110 | foreach ( $menu_items as $menu_item ) { |
| 111 | $class = ! empty( $menu_item['class'] ) ? $menu_item['class'] : $menu_item['text']; |
| 112 | $target = ! empty( $menu_item['target'] ) ? ' target="' . esc_attr( $menu_item['target'] ) . '"' : ''; |
| 113 | $aria_label = ! empty( $menu_item['aria-label'] ) ? ' aria-label="' . esc_attr( $menu_item['aria-label'] ) . '"' : ''; |
| 114 | $li_class = ! empty( $menu_item['li_class'] ) ? esc_attr( $menu_item['li_class'] ) : ''; |
| 115 | |
| 116 | $html = sprintf( |
| 117 | '<a class="acf-tab%s %s" href="%s"%s%s><i class="acf-icon"></i>%s</a>', |
| 118 | ! empty( $menu_item['is_active'] ) ? ' is-active' : '', |
| 119 | 'acf-header-tab-' . esc_attr( acf_slugify( $class ) ), |
| 120 | esc_url( $menu_item['url'] ), |
| 121 | $target, |
| 122 | $aria_label, |
| 123 | acf_esc_html( $menu_item['text'] ) |
| 124 | ); |
| 125 | |
| 126 | if ( 'core' !== $section ) { |
| 127 | if ( $li_class === '' ) { |
| 128 | $html = '<li>' . $html . '</li>'; |
| 129 | } else { |
| 130 | $html = sprintf( '<li class="%s">', $li_class ) . $html . '</li>'; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | $section_html .= $html; |
| 135 | } |
| 136 | |
| 137 | echo $section_html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- safely built and escaped HTML above. |
| 138 | } |
| 139 | ?> |
| 140 | <div class="acf-admin-toolbar"> |
| 141 | <div class="acf-admin-toolbar-inner"> |
| 142 | <div class="acf-nav-wrap"> |
| 143 | <a href="<?php echo esc_url( admin_url( 'edit.php?post_type=acf-field-group' ) ); ?>" class="acf-logo" aria-label="<?php esc_attr_e( 'Edit SCF Field Groups', 'secure-custom-fields' ); ?>"> |
| 144 | <img src="<?php echo esc_url( acf_get_url( 'assets/images/scf-logo.svg' ) ); ?>" alt="<?php esc_attr_e( 'Secure Custom Fields logo', 'secure-custom-fields' ); ?>"> |
| 145 | </a> |
| 146 | |
| 147 | <h2><?php echo esc_html( acf_get_setting( 'name' ) ); ?></h2> |
| 148 | <?php acf_print_menu_section( $core_tabs, 'core' ); ?> |
| 149 | <?php if ( $acf_more_items || $more_items ) { ?> |
| 150 | <div class="acf-more acf-header-tab-acf-more" tabindex="0"> |
| 151 | <span class="acf-tab acf-more-tab"><i class="acf-icon acf-icon-more"></i><?php esc_html_e( 'More', 'secure-custom-fields' ); ?> <i class="acf-icon acf-icon-dropdown"></i></span> |
| 152 | <ul> |
| 153 | <?php |
| 154 | if ( $acf_more_items ) { |
| 155 | if ( $more_items ) { |
| 156 | echo '<li class="acf-more-section-header"><span class="acf-tab acf-tab-header">SCF</span></li>'; |
| 157 | } |
| 158 | acf_print_menu_section( $acf_more_items, 'acf' ); |
| 159 | } |
| 160 | if ( $more_items ) { |
| 161 | echo '<li class="acf-more-section-header"><span class="acf-tab acf-tab-header">' . esc_html__( 'Other', 'secure-custom-fields' ) . ' </span></li>'; |
| 162 | acf_print_menu_section( $more_items ); |
| 163 | } |
| 164 | ?> |
| 165 | </ul> |
| 166 | </div> |
| 167 | <?php } ?> |
| 168 | </div> |
| 169 | </div> |
| 170 | </div> |
| 171 | |
| 172 | <?php |
| 173 | |
| 174 | global $plugin_page; |
| 175 | $screen = get_current_screen(); |
| 176 | |
| 177 | if ( ! in_array( $screen->id, acf_get_internal_post_types(), true ) ) { |
| 178 | if ( 'acf-tools' === $plugin_page ) { |
| 179 | $acf_page_title = __( 'Tools', 'secure-custom-fields' ); |
| 180 | } elseif ( 'scf-beta-features' === $plugin_page ) { |
| 181 | $acf_page_title = __( 'Beta Features', 'secure-custom-fields' ); |
| 182 | } |
| 183 | acf_get_view( 'global/header' ); |
| 184 | } |
| 185 | ?> |
| 186 |