123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly
- }
- if ( ! class_exists( 'ACF_Location' ) ) :
- abstract class ACF_Location extends ACF_Legacy_Location {
- /**
- * The location rule name.
- *
- * @since 5.9.0
- * @var string
- */
- public $name = '';
- /**
- * The location rule label.
- *
- * @since 5.9.0
- * @var string
- */
- public $label = '';
- /**
- * The location rule category.
- *
- * Accepts "post", "page", "user", "forms" or a custom label.
- *
- * @since 5.9.0
- * @var string
- */
- public $category = 'post';
- /**
- * Whether or not the location rule is publicly accessible.
- *
- * @since 5.0.0
- * @var bool
- */
- public $public = true;
- /**
- * The object type related to this location rule.
- *
- * Accepts an object type discoverable by `acf_get_object_type()`.
- *
- * @since 5.9.0
- * @var string
- */
- public $object_type = '';
- /**
- * The object subtype related to this location rule.
- *
- * Accepts a custom post type or custom taxonomy.
- *
- * @since 5.9.0
- * @var string
- */
- public $object_subtype = '';
- /**
- * Constructor.
- *
- * @date 8/4/20
- * @since 5.9.0
- *
- * @param void
- * @return void
- */
- public function __construct() {
- $this->initialize();
- // Call legacy constructor.
- parent::__construct();
- }
- /**
- * Initializes props.
- *
- * @date 5/03/2014
- * @since 5.0.0
- *
- * @param void
- * @return void
- */
- public function initialize() {
- // Set props here.
- }
- /**
- * Returns an array of operators for this location.
- *
- * @date 9/4/20
- * @since 5.9.0
- *
- * @param array $rule A location rule.
- * @return array
- */
- public static function get_operators( $rule ) {
- return array(
- '==' => __( 'is equal to', 'acf' ),
- '!=' => __( 'is not equal to', 'acf' ),
- );
- }
- /**
- * Returns an array of possible values for this location.
- *
- * @date 9/4/20
- * @since 5.9.0
- *
- * @param array $rule A location rule.
- * @return array
- */
- public function get_values( $rule ) {
- return array();
- }
- /**
- * Returns the object_type connected to this location.
- *
- * @date 1/4/20
- * @since 5.9.0
- *
- * @param array $rule A location rule.
- * @return string
- */
- public function get_object_type( $rule ) {
- return $this->object_type;
- }
- /**
- * Returns the object_subtype connected to this location.
- *
- * @date 1/4/20
- * @since 5.9.0
- *
- * @param array $rule A location rule.
- * @return string|array
- */
- public function get_object_subtype( $rule ) {
- return $this->object_subtype;
- }
- /**
- * Matches the provided rule against the screen args returning a bool result.
- *
- * @date 9/4/20
- * @since 5.9.0
- *
- * @param array $rule The location rule.
- * @param array $screen The screen args.
- * @param array $field_group The field group settings.
- * @return bool
- */
- public function match( $rule, $screen, $field_group ) {
- return false;
- }
- /**
- * Compares the given value and rule params returning true when they match.
- *
- * @date 17/9/19
- * @since 5.8.1
- *
- * @param array $rule The location rule data.
- * @param mixed $value The value to compare against.
- * @return bool
- */
- public function compare_to_rule( $value, $rule ) {
- $result = ( $value == $rule['value'] );
- // Allow "all" to match any value.
- if ( $rule['value'] === 'all' ) {
- $result = true;
- }
- // Reverse result for "!=" operator.
- if ( $rule['operator'] === '!=' ) {
- return ! $result;
- }
- return $result;
- }
- }
- endif; // class_exists check
|