class-acf-location-page.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Location_Page' ) ) :
  6. class ACF_Location_Page extends ACF_Location {
  7. /**
  8. * Initializes props.
  9. *
  10. * @date 5/03/2014
  11. * @since 5.0.0
  12. *
  13. * @param void
  14. * @return void
  15. */
  16. public function initialize() {
  17. $this->name = 'page';
  18. $this->label = __( 'Page', 'acf' );
  19. $this->category = 'page';
  20. $this->object_type = 'post';
  21. $this->object_subtype = 'page';
  22. }
  23. /**
  24. * Matches the provided rule against the screen args returning a bool result.
  25. *
  26. * @date 9/4/20
  27. * @since 5.9.0
  28. *
  29. * @param array $rule The location rule.
  30. * @param array $screen The screen args.
  31. * @param array $field_group The field group settings.
  32. * @return bool
  33. */
  34. public function match( $rule, $screen, $field_group ) {
  35. return acf_get_location_type( 'post' )->match( $rule, $screen, $field_group );
  36. }
  37. /**
  38. * Returns an array of possible values for this rule type.
  39. *
  40. * @date 9/4/20
  41. * @since 5.9.0
  42. *
  43. * @param array $rule A location rule.
  44. * @return array
  45. */
  46. public function get_values( $rule ) {
  47. $choices = array();
  48. // Get grouped posts.
  49. $groups = acf_get_grouped_posts(
  50. array(
  51. 'post_type' => array( 'page' ),
  52. )
  53. );
  54. // Get first group.
  55. $posts = reset( $groups );
  56. // Append to choices.
  57. if ( $posts ) {
  58. foreach ( $posts as $post ) {
  59. $choices[ $post->ID ] = acf_get_post_title( $post );
  60. }
  61. }
  62. return $choices;
  63. }
  64. }
  65. // Register.
  66. acf_register_location_type( 'ACF_Location_Page' );
  67. endif; // class_exists check