123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Location_Post_Status' ) ) :
- class ACF_Location_Post_Status extends ACF_Location {
-
- public function initialize() {
- $this->name = 'post_status';
- $this->label = __( 'Post Status', 'acf' );
- $this->category = 'post';
- $this->object_type = 'post';
- }
-
- public function match( $rule, $screen, $field_group ) {
-
- if ( isset( $screen['post_status'] ) ) {
- $post_status = $screen['post_status'];
- } elseif ( isset( $screen['post_id'] ) ) {
- $post_status = get_post_status( $screen['post_id'] );
- } else {
- return false;
- }
-
- if ( $post_status === 'auto-draft' ) {
- $post_status = 'draft';
- }
-
- return $this->compare_to_rule( $post_status, $rule );
- }
-
- public function get_values( $rule ) {
- global $wp_post_statuses;
-
- $choices = array();
- if ( $wp_post_statuses ) {
- foreach ( $wp_post_statuses as $status ) {
- $choices[ $status->name ] = $status->label;
- }
- }
- return $choices;
- }
- }
-
- acf_register_location_type( 'ACF_Location_Post_Status' );
- endif;
|