admin.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Admin' ) ) :
  6. class ACF_Admin {
  7. /**
  8. * Constructor.
  9. *
  10. * @date 23/06/12
  11. * @since 5.0.0
  12. *
  13. * @param void
  14. * @return void
  15. */
  16. function __construct() {
  17. // Add actions.
  18. add_action( 'admin_menu', array( $this, 'admin_menu' ) );
  19. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
  20. add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
  21. add_action( 'current_screen', array( $this, 'current_screen' ) );
  22. }
  23. /**
  24. * Adds the ACF menu item.
  25. *
  26. * @date 28/09/13
  27. * @since 5.0.0
  28. *
  29. * @param void
  30. * @return void
  31. */
  32. function admin_menu() {
  33. // Bail early if ACF is hidden.
  34. if ( ! acf_get_setting( 'show_admin' ) ) {
  35. return;
  36. }
  37. // Vars.
  38. $slug = 'edit.php?post_type=acf-field-group';
  39. $cap = acf_get_setting( 'capability' );
  40. // Add menu items.
  41. add_menu_page( __( 'Custom Fields', 'acf' ), __( 'Custom Fields', 'acf' ), $cap, $slug, false, 'dashicons-welcome-widgets-menus', 80 );
  42. add_submenu_page( $slug, __( 'Field Groups', 'acf' ), __( 'Field Groups', 'acf' ), $cap, $slug );
  43. add_submenu_page( $slug, __( 'Add New', 'acf' ), __( 'Add New', 'acf' ), $cap, 'post-new.php?post_type=acf-field-group' );
  44. }
  45. /**
  46. * Enqueues global admin styling.
  47. *
  48. * @date 28/09/13
  49. * @since 5.0.0
  50. *
  51. * @param void
  52. * @return void
  53. */
  54. function admin_enqueue_scripts() {
  55. wp_enqueue_style( 'acf-global' );
  56. }
  57. /**
  58. * Appends custom admin body classes.
  59. *
  60. * @date 5/11/19
  61. * @since 5.8.7
  62. *
  63. * @param string $classes Space-separated list of CSS classes.
  64. * @return string
  65. */
  66. function admin_body_class( $classes ) {
  67. global $wp_version;
  68. // Determine body class version.
  69. $wp_minor_version = floatval( $wp_version );
  70. if ( $wp_minor_version >= 5.3 ) {
  71. $classes .= ' acf-admin-5-3';
  72. } else {
  73. $classes .= ' acf-admin-3-8';
  74. }
  75. // Add browser for specific CSS.
  76. $classes .= ' acf-browser-' . acf_get_browser();
  77. // Return classes.
  78. return $classes;
  79. }
  80. /**
  81. * Adds custom functionality to "ACF" admin pages.
  82. *
  83. * @date 7/4/20
  84. * @since 5.9.0
  85. *
  86. * @param void
  87. * @return void
  88. */
  89. function current_screen( $screen ) {
  90. // Determine if the current page being viewed is "ACF" related.
  91. if ( isset( $screen->post_type ) && $screen->post_type === 'acf-field-group' ) {
  92. add_action( 'in_admin_header', array( $this, 'in_admin_header' ) );
  93. add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
  94. $this->setup_help_tab();
  95. }
  96. }
  97. /**
  98. * Sets up the admin help tab.
  99. *
  100. * @date 20/4/20
  101. * @since 5.9.0
  102. *
  103. * @param void
  104. * @return void
  105. */
  106. public function setup_help_tab() {
  107. $screen = get_current_screen();
  108. // Overview tab.
  109. $screen->add_help_tab(
  110. array(
  111. 'id' => 'overview',
  112. 'title' => __( 'Overview', 'acf' ),
  113. 'content' =>
  114. '<p><strong>' . __( 'Overview', 'acf' ) . '</strong></p>' .
  115. '<p>' . __( 'The Advanced Custom Fields plugin provides a visual form builder to customize WordPress edit screens with extra fields, and an intuitive API to display custom field values in any theme template file.', 'acf' ) . '</p>' .
  116. '<p>' . sprintf(
  117. __( 'Before creating your first Field Group, we recommend first reading our <a href="%s" target="_blank">Getting started</a> guide to familiarize yourself with the plugin\'s philosophy and best practises.', 'acf' ),
  118. acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/getting-started-with-acf/', 'docs', 'help-tab' )
  119. ) . '</p>' .
  120. '<p>' . __( 'Please use the Help & Support tab to get in touch should you find yourself requiring assistance.', 'acf' ) . '</p>' .
  121. '',
  122. )
  123. );
  124. // Help tab.
  125. $screen->add_help_tab(
  126. array(
  127. 'id' => 'help',
  128. 'title' => __( 'Help & Support', 'acf' ),
  129. 'content' =>
  130. '<p><strong>' . __( 'Help & Support', 'acf' ) . '</strong></p>' .
  131. '<p>' . __( 'We are fanatical about support, and want you to get the best out of your website with ACF. If you run into any difficulties, there are several places you can find help:', 'acf' ) . '</p>' .
  132. '<ul>' .
  133. '<li>' . sprintf(
  134. __( '<a href="%s" target="_blank">Documentation</a>. Our extensive documentation contains references and guides for most situations you may encounter.', 'acf' ),
  135. acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/', 'docs', 'help-tab' )
  136. ) . '</li>' .
  137. '<li>' . sprintf(
  138. __( '<a href="%s" target="_blank">Discussions</a>. We have an active and friendly community on our Community Forums who may be able to help you figure out the ‘how-tos’ of the ACF world.', 'acf' ),
  139. acf_add_url_utm_tags( 'https://support.advancedcustomfields.com/', 'docs', 'help-tab' )
  140. ) . '</li>' .
  141. '<li>' . sprintf(
  142. __( '<a href="%s" target="_blank">Help Desk</a>. The support professionals on our Help Desk will assist with your more in depth, technical challenges.', 'acf' ),
  143. acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/support/', 'docs', 'help-tab' )
  144. ) . '</li>' .
  145. '</ul>',
  146. )
  147. );
  148. // Sidebar.
  149. $screen->set_help_sidebar(
  150. '<p><strong>' . __( 'Information', 'acf' ) . '</strong></p>' .
  151. '<p><span class="dashicons dashicons-admin-plugins"></span> ' . sprintf( __( 'Version %s', 'acf' ), ACF_VERSION ) . '</p>' .
  152. '<p><span class="dashicons dashicons-wordpress"></span> <a href="https://wordpress.org/plugins/advanced-custom-fields/" target="_blank">' . __( 'View details', 'acf' ) . '</a></p>' .
  153. '<p><span class="dashicons dashicons-admin-home"></span> <a href="' . acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/', 'docs', 'help-tab' ) . '" target="_blank" target="_blank">' . __( 'Visit website', 'acf' ) . '</a></p>' .
  154. ''
  155. );
  156. }
  157. /**
  158. * Renders the admin navigation element.
  159. *
  160. * @date 27/3/20
  161. * @since 5.9.0
  162. *
  163. * @param void
  164. * @return void
  165. */
  166. function in_admin_header() {
  167. acf_get_view( 'html-admin-navigation' );
  168. $screen = get_current_screen();
  169. if ( isset( $screen->base ) && 'post' === $screen->base ) {
  170. acf_get_view( 'html-admin-form-top' );
  171. }
  172. }
  173. /**
  174. * Modifies the admin footer text.
  175. *
  176. * @date 7/4/20
  177. * @since 5.9.0
  178. *
  179. * @param string $text The admin footer text.
  180. * @return string
  181. */
  182. function admin_footer_text( $text ) {
  183. // Use RegExp to append "ACF" after the <a> element allowing translations to read correctly.
  184. return preg_replace( '/(<a[\S\s]+?\/a>)/', '$1 ' . __( 'and', 'acf' ) . ' <a href="' . acf_add_url_utm_tags( 'https://www.advancedcustomfields.com', 'footer', 'footer' ) . '" target="_blank">ACF</a>', $text, 1 );
  185. }
  186. }
  187. // Instantiate.
  188. acf_new_instance( 'ACF_Admin' );
  189. endif; // class_exists check