class-acf-location-post-status.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Location_Post_Status' ) ) :
  6. class ACF_Location_Post_Status 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_status';
  18. $this->label = __( 'Post Status', '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. // Check screen args.
  35. if ( isset( $screen['post_status'] ) ) {
  36. $post_status = $screen['post_status'];
  37. } elseif ( isset( $screen['post_id'] ) ) {
  38. $post_status = get_post_status( $screen['post_id'] );
  39. } else {
  40. return false;
  41. }
  42. // Treat "auto-draft" as "draft".
  43. if ( $post_status === 'auto-draft' ) {
  44. $post_status = 'draft';
  45. }
  46. // Compare rule against $post_status.
  47. return $this->compare_to_rule( $post_status, $rule );
  48. }
  49. /**
  50. * Returns an array of possible values for this rule type.
  51. *
  52. * @date 9/4/20
  53. * @since 5.9.0
  54. *
  55. * @param array $rule A location rule.
  56. * @return array
  57. */
  58. public function get_values( $rule ) {
  59. global $wp_post_statuses;
  60. // Append to choices.
  61. $choices = array();
  62. if ( $wp_post_statuses ) {
  63. foreach ( $wp_post_statuses as $status ) {
  64. $choices[ $status->name ] = $status->label;
  65. }
  66. }
  67. return $choices;
  68. }
  69. }
  70. // initialize
  71. acf_register_location_type( 'ACF_Location_Post_Status' );
  72. endif; // class_exists check