third-party.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /*
  3. * ACF 3rd Party Compatibility Class
  4. *
  5. * All the logic for 3rd party functionality
  6. *
  7. * @class acf_third_party
  8. * @package ACF
  9. * @subpackage Core
  10. */
  11. if ( ! class_exists( 'acf_third_party' ) ) :
  12. class acf_third_party {
  13. /*
  14. * __construct
  15. *
  16. * This function will setup the class functionality
  17. *
  18. * @type function
  19. * @date 5/03/2014
  20. * @since 5.0.0
  21. *
  22. * @param n/a
  23. * @return n/a
  24. */
  25. function __construct() {
  26. // Tabify Edit Screen - http://wordpress.org/extend/plugins/tabify-edit-screen/
  27. if ( class_exists( 'Tabify_Edit_Screen' ) ) {
  28. add_filter( 'tabify_posttypes', array( $this, 'tabify_posttypes' ) );
  29. add_action( 'tabify_add_meta_boxes', array( $this, 'tabify_add_meta_boxes' ) );
  30. }
  31. // Post Type Switcher - http://wordpress.org/extend/plugins/post-type-switcher/
  32. if ( class_exists( 'Post_Type_Switcher' ) ) {
  33. add_filter( 'pts_allowed_pages', array( $this, 'pts_allowed_pages' ) );
  34. }
  35. // Event Espresso - https://wordpress.org/plugins/event-espresso-decaf/
  36. if ( function_exists( 'espresso_version' ) ) {
  37. add_filter( 'acf/get_post_types', array( $this, 'ee_get_post_types' ), 10, 2 );
  38. }
  39. // Dark Mode
  40. if ( class_exists( 'Dark_Mode' ) ) {
  41. add_action( 'doing_dark_mode', array( $this, 'doing_dark_mode' ) );
  42. }
  43. }
  44. /**
  45. * acf_get_post_types
  46. *
  47. * EE post types do not use the native post.php edit page, but instead render their own.
  48. * Show the EE post types in lists where 'show_ui' is used.
  49. *
  50. * @date 24/2/18
  51. * @since 5.6.9
  52. *
  53. * @param array $post_types
  54. * @param array $args
  55. * @return array
  56. */
  57. function ee_get_post_types( $post_types, $args ) {
  58. if ( ! empty( $args['show_ui'] ) ) {
  59. $ee_post_types = get_post_types( array( 'show_ee_ui' => 1 ) );
  60. $ee_post_types = array_keys( $ee_post_types );
  61. $post_types = array_merge( $post_types, $ee_post_types );
  62. $post_types = array_unique( $post_types );
  63. }
  64. // return
  65. return $post_types;
  66. }
  67. /*
  68. * tabify_posttypes
  69. *
  70. * This function removes ACF post types from the tabify edit screen (post type selection sidebar)
  71. *
  72. * @type function
  73. * @date 9/10/12
  74. * @since 3.5.1
  75. *
  76. * @param $post_id (int)
  77. * @return $post_id (int)
  78. */
  79. function tabify_posttypes( $posttypes ) {
  80. // unset
  81. unset( $posttypes['acf-field-group'] );
  82. unset( $posttypes['acf-field'] );
  83. // return
  84. return $posttypes;
  85. }
  86. /*
  87. * tabify_add_meta_boxes
  88. *
  89. * This function creates dummy metaboxes on the tabify edit screen page
  90. *
  91. * @type function
  92. * @date 9/10/12
  93. * @since 3.5.1
  94. *
  95. * @param $post_type (string)
  96. * @return n/a
  97. */
  98. function tabify_add_meta_boxes( $post_type ) {
  99. // get field groups
  100. $field_groups = acf_get_field_groups();
  101. if ( ! empty( $field_groups ) ) {
  102. foreach ( $field_groups as $field_group ) {
  103. // vars
  104. $id = "acf-{$field_group['key']}";
  105. $title = 'ACF: ' . $field_group['title'];
  106. // add meta box
  107. add_meta_box( $id, acf_esc_html( $title ), '__return_true', $post_type );
  108. }
  109. }
  110. }
  111. /*
  112. * pts_allowed_pages
  113. *
  114. * This filter will prevent PTS from running on the field group page!
  115. *
  116. * @type function
  117. * @date 25/09/2014
  118. * @since 5.0.0
  119. *
  120. * @param $pages (array)
  121. * @return $pages
  122. */
  123. function pts_allowed_pages( $pages ) {
  124. // vars
  125. $post_type = '';
  126. // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Verified elsewhere.
  127. // check $_GET because it is too early to use functions / global vars.
  128. if ( ! empty( $_GET['post_type'] ) ) {
  129. $post_type = sanitize_text_field( $_GET['post_type'] );
  130. } elseif ( ! empty( $_GET['post'] ) ) {
  131. $post_type = get_post_type( $_GET['post'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized when get_post_type() calls get_post().
  132. }
  133. // phpcs:enable WordPress.Security.NonceVerification.Recommended
  134. // check post type
  135. if ( $post_type == 'acf-field-group' ) {
  136. $pages = array();
  137. }
  138. // return
  139. return $pages;
  140. }
  141. /**
  142. * doing_dark_mode
  143. *
  144. * Runs during 'admin_enqueue_scripts' if dark mode is enabled
  145. *
  146. * @date 13/8/18
  147. * @since 5.7.3
  148. *
  149. * @param void
  150. * @return void
  151. */
  152. function doing_dark_mode() {
  153. wp_enqueue_style( 'acf-dark', acf_get_url( 'assets/css/acf-dark.css' ), array(), ACF_VERSION );
  154. }
  155. }
  156. new acf_third_party();
  157. endif;