暫無描述

html-admin-navigation.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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;
  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. }
  35. // Detect active state.
  36. if ( $submenu_file === $sub_item[2] || $plugin_page === $sub_item[2] ) {
  37. $tab['is_active'] = true;
  38. }
  39. // Special case for "Add New" page.
  40. if ( $i === 0 && $submenu_file === 'post-new.php?post_type=acf-field-group' ) {
  41. $tab['is_active'] = true;
  42. }
  43. $tabs[] = $tab;
  44. }
  45. }
  46. /**
  47. * Filters the admin navigation tabs.
  48. *
  49. * @date 27/3/20
  50. * @since 5.9.0
  51. *
  52. * @param array $tabs The array of navigation tabs.
  53. */
  54. $tabs = apply_filters( 'acf/admin/toolbar', $tabs );
  55. // Bail early if set to false.
  56. if ( $tabs === false ) {
  57. return;
  58. }
  59. ?>
  60. <div class="acf-admin-toolbar">
  61. <h2><i class="acf-tab-icon dashicons dashicons-welcome-widgets-menus"></i> <?php echo acf_get_setting( 'name' ); ?></h2>
  62. <?php
  63. foreach ( $tabs as $tab ) {
  64. printf(
  65. '<a class="acf-tab%s" href="%s">%s</a>',
  66. ! empty( $tab['is_active'] ) ? ' is-active' : '',
  67. esc_url( $tab['url'] ),
  68. acf_esc_html( $tab['text'] )
  69. );
  70. }
  71. ?>
  72. <?php if ( ! defined( 'ACF_PRO' ) || ! ACF_PRO ) : ?>
  73. <a target="_blank" href="https://www.advancedcustomfields.com/pro/?utm_source=ACF%2BFree&utm_medium=insideplugin&utm_campaign=ACF%2Bupgrade" class="btn-upgrade">
  74. <img src="<?php echo acf_get_url( 'assets/images/icon-upgrade-pro.svg' ); ?>" />
  75. <p><?php _e( 'Upgrade to Pro', 'acf' ); ?></p>
  76. </a>
  77. <?php endif; ?>
  78. </div>