class-acf-location-post-category.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Location_Post_Category' ) ) :
  6. class ACF_Location_Post_Category 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 = 'post_category';
  18. $this->label = __( 'Post Category', 'acf' );
  19. $this->category = 'post';
  20. $this->object_type = 'post';
  21. }
  22. /**
  23. * Matches the provided rule against the screen args returning a bool result.
  24. *
  25. * @date 9/4/20
  26. * @since 5.9.0
  27. *
  28. * @param array $rule The location rule.
  29. * @param array $screen The screen args.
  30. * @param array $field_group The field group settings.
  31. * @return bool
  32. */
  33. public function match( $rule, $screen, $field_group ) {
  34. return acf_get_location_type( 'post_taxonomy' )->match( $rule, $screen, $field_group );
  35. }
  36. /**
  37. * Returns an array of possible values for this rule type.
  38. *
  39. * @date 9/4/20
  40. * @since 5.9.0
  41. *
  42. * @param array $rule A location rule.
  43. * @return array
  44. */
  45. public function get_values( $rule ) {
  46. $choices = acf_get_taxonomy_terms( array( 'category' ) );
  47. if ( $choices ) {
  48. return reset( $choices );
  49. }
  50. return array();
  51. }
  52. /**
  53. * Returns the object_subtype connected to this location.
  54. *
  55. * @date 1/4/20
  56. * @since 5.9.0
  57. *
  58. * @param array $rule A location rule.
  59. * @return string|array
  60. */
  61. public function get_object_subtype( $rule ) {
  62. return acf_get_location_type( 'post_taxonomy' )->get_object_subtype( $rule );
  63. }
  64. }
  65. // initialize
  66. acf_register_location_rule( 'ACF_Location_Post_Category' );
  67. endif; // class_exists check