Brak opisu

class-acf-location-taxonomy.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Location_Taxonomy' ) ) :
  6. class ACF_Location_Taxonomy 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 = 'taxonomy';
  18. $this->label = __( 'Taxonomy', 'acf' );
  19. $this->category = 'forms';
  20. $this->object_type = 'term';
  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. // Check screen args.
  35. if ( isset( $screen['taxonomy'] ) ) {
  36. $taxonomy = $screen['taxonomy'];
  37. } else {
  38. return false;
  39. }
  40. // Compare rule against $taxonomy.
  41. return $this->compare_to_rule( $taxonomy, $rule );
  42. }
  43. /**
  44. * Returns an array of possible values for this rule type.
  45. *
  46. * @date 9/4/20
  47. * @since 5.9.0
  48. *
  49. * @param array $rule A location rule.
  50. * @return array
  51. */
  52. public function get_values( $rule ) {
  53. return array_merge(
  54. array(
  55. 'all' => __( 'All', 'acf' ),
  56. ),
  57. acf_get_taxonomy_labels()
  58. );
  59. }
  60. /**
  61. * Returns the object_subtype connected to this location.
  62. *
  63. * @date 1/4/20
  64. * @since 5.9.0
  65. *
  66. * @param array $rule A location rule.
  67. * @return string|array
  68. */
  69. function get_object_subtype( $rule ) {
  70. if ( $rule['operator'] === '==' ) {
  71. return $rule['value'];
  72. }
  73. return '';
  74. }
  75. }
  76. // initialize
  77. acf_register_location_type( 'ACF_Location_Taxonomy' );
  78. endif; // class_exists check