html-admin-navigation.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * The template for displaying admin navigation.
  4. *
  5. * @date 27/3/20
  6. * @since 5.9.0
  7. */
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. exit;
  10. }
  11. global $submenu, $parent_file, $submenu_file, $plugin_page, $pagenow, $acf_page_title;
  12. // Vars.
  13. $parent_slug = 'edit.php?post_type=acf-field-group';
  14. // Generate array of navigation items.
  15. $tabs = array();
  16. if ( isset( $submenu[ $parent_slug ] ) ) {
  17. foreach ( $submenu[ $parent_slug ] as $i => $sub_item ) {
  18. // Check user can access page.
  19. if ( ! current_user_can( $sub_item[1] ) ) {
  20. continue;
  21. }
  22. // Ignore "Add New".
  23. if ( $i === 1 ) {
  24. continue;
  25. }
  26. // Define tab.
  27. $tab = array(
  28. 'text' => $sub_item[0],
  29. 'url' => $sub_item[2],
  30. );
  31. // Convert submenu slug "test" to "$parent_slug&page=test".
  32. if ( ! strpos( $sub_item[2], '.php' ) ) {
  33. $tab['url'] = add_query_arg( array( 'page' => $sub_item[2] ), $parent_slug );
  34. $tab['class'] = $sub_item[2];
  35. } else {
  36. // Build class from URL.
  37. $tab['class'] = str_replace( 'edit.php?post_type=', '', $sub_item[2] );
  38. }
  39. // Detect active state.
  40. if ( $submenu_file === $sub_item[2] || $plugin_page === $sub_item[2] ) {
  41. $tab['is_active'] = true;
  42. }
  43. // Special case for "Add New" page.
  44. if ( $i === 0 && $submenu_file === 'post-new.php?post_type=acf-field-group' ) {
  45. $tab['is_active'] = true;
  46. }
  47. $tabs[] = $tab;
  48. }
  49. }
  50. /**
  51. * Filters the admin navigation tabs.
  52. *
  53. * @date 27/3/20
  54. * @since 5.9.0
  55. *
  56. * @param array $tabs The array of navigation tabs.
  57. */
  58. $tabs = apply_filters( 'acf/admin/toolbar', $tabs );
  59. // Bail early if set to false.
  60. if ( $tabs === false ) {
  61. return;
  62. }
  63. ?>
  64. <div class="acf-admin-toolbar">
  65. <a href="<?php echo admin_url( 'edit.php?post_type=acf-field-group' ); ?>" class="acf-logo"><img src="<?php echo acf_get_url( 'assets/images/acf-logo.svg' ); ?>" alt="<?php esc_attr_e( 'Advanced Custom Fields logo', 'acf' ); ?>"></a>
  66. <h2><?php echo acf_get_setting( 'name' ); ?></h2>
  67. <?php
  68. foreach ( $tabs as $tab ) {
  69. $classname = ! empty( $tab['class'] ) ? $tab['class'] : $tab['text'];
  70. printf(
  71. '<a class="acf-tab%s %s" href="%s"><i class="acf-icon"></i>%s</a>',
  72. ! empty( $tab['is_active'] ) ? ' is-active' : '',
  73. 'acf-header-tab-' . acf_slugify( $classname ),
  74. esc_url( $tab['url'] ),
  75. acf_esc_html( $tab['text'] )
  76. );
  77. }
  78. ?>
  79. <?php if ( ! defined( 'ACF_PRO' ) || ! ACF_PRO ) : ?>
  80. <a target="_blank" href="<?php echo acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/pro/', 'ACF upgrade', 'header' ); ?>" class="btn-upgrade acf-admin-toolbar-upgrade-btn">
  81. <i class="acf-icon acf-icon-stars"></i>
  82. <p><?php _e( 'Unlock Extra Features with ACF PRO', 'acf' ); ?></p>
  83. </a>
  84. <?php endif; ?>
  85. </div>
  86. <?php
  87. global $plugin_page;
  88. $screen = get_current_screen();
  89. if ( $screen->id !== 'acf-field-group' ) {
  90. if ( $plugin_page == 'acf-tools' ) {
  91. $acf_page_title = __( 'Tools', 'acf' );
  92. } elseif ( $plugin_page == 'acf-settings-updates' ) {
  93. $acf_page_title = __( 'Updates', 'acf' );
  94. }
  95. acf_get_view( 'html-admin-acf-header' );
  96. }
  97. ?>