class-acf-location-page-parent.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Location_Page_Parent' ) ) :
  6. class ACF_Location_Page_Parent 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_parent';
  18. $this->label = __( 'Page Parent', '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. // Check screen args.
  36. if ( isset( $screen['page_parent'] ) ) {
  37. $page_parent = $screen['page_parent'];
  38. } elseif ( isset( $screen['post_id'] ) ) {
  39. $post = get_post( $screen['post_id'] );
  40. $page_parent = $post ? $post->post_parent : false;
  41. } else {
  42. return false;
  43. }
  44. // Compare rule against $page_parent.
  45. return $this->compare_to_rule( $page_parent, $rule );
  46. }
  47. /**
  48. * Returns an array of possible values for this rule type.
  49. *
  50. * @date 9/4/20
  51. * @since 5.9.0
  52. *
  53. * @param array $rule A location rule.
  54. * @return array
  55. */
  56. public function get_values( $rule ) {
  57. return acf_get_location_type( 'page' )->get_values( $rule );
  58. }
  59. }
  60. // Register.
  61. acf_register_location_type( 'ACF_Location_Page_Parent' );
  62. endif; // class_exists check