<?php if (!defined('ABSPATH')) { exit; } acf_register_store('location-types'); function acf_register_location_type($class_name) { $store = acf_get_store('location-types'); if (!class_exists($class_name)) { $message = sprintf(__('Class "%s" does not exist.', 'acf'), $class_name); _doing_it_wrong(__FUNCTION__, $message, '5.9.0'); return false; } $location_type = new $class_name(); $name = $location_type->name; if ($store->has($name)) { $message = sprintf(__('Location type "%s" is already registered.'), $name); _doing_it_wrong(__FUNCTION__, $message, '5.9.0'); return false; } $store->set($name, $location_type); do_action('acf/registered_location_type', $name, $location_type); return $location_type; } function acf_get_location_types() { return acf_get_store('location-types')->get(); } function acf_get_location_type($name) { return acf_get_store('location-types')->get($name); } function acf_get_location_rule_types() { $types = array(); $categories = array('post' => __('Post', 'acf'), 'page' => __('Page', 'acf'), 'user' => __('User', 'acf'), 'forms' => __('Forms', 'acf')); $location_types = acf_get_location_types(); foreach ($location_types as $location_type) { if (!$location_type->public) { continue; } $category = $location_type->category; if (isset($categories[$category])) { $category = $categories[$category]; } $types[$category][$location_type->name] = esc_html($location_type->label); } return apply_filters('acf/location/rule_types', $types); } function acf_validate_location_rule($rule = array()) { $rule = wp_parse_args($rule, array('id' => '', 'group' => '', 'param' => '', 'operator' => '==', 'value' => '')); $rule = apply_filters("acf/location/validate_rule/type={$rule['param']}", $rule); $rule = apply_filters('acf/location/validate_rule', $rule); return $rule; } function acf_get_location_rule_operators($rule) { $operators = ACF_Location::get_operators($rule); $location_type = acf_get_location_type($rule['param']); if ($location_type) { $operators = $location_type->get_operators($rule); } $operators = apply_filters("acf/location/rule_operators/type={$rule['param']}", $operators, $rule); $operators = apply_filters("acf/location/rule_operators/{$rule['param']}", $operators, $rule); $operators = apply_filters('acf/location/rule_operators', $operators, $rule); return $operators; } function acf_get_location_rule_values($rule) { $values = array(); $location_type = acf_get_location_type($rule['param']); if ($location_type) { $values = $location_type->get_values($rule); } $values = apply_filters("acf/location/rule_values/type={$rule['param']}", $values, $rule); $values = apply_filters("acf/location/rule_values/{$rule['param']}", $values, $rule); $values = apply_filters('acf/location/rule_values', $values, $rule); return $values; } function acf_match_location_rule($rule, $screen, $field_group) { $result = false; $location_type = acf_get_location_type($rule['param']); if ($location_type) { $result = $location_type->match($rule, $screen, $field_group); } $result = apply_filters("acf/location/match_rule/type={$rule['param']}", $result, $rule, $screen, $field_group); $result = apply_filters('acf/location/match_rule', $result, $rule, $screen, $field_group); $result = apply_filters("acf/location/rule_match/{$rule['param']}", $result, $rule, $screen, $field_group); $result = apply_filters('acf/location/rule_match', $result, $rule, $screen, $field_group); return $result; } function acf_get_location_screen($screen = array(), $deprecated = false) { $screen = wp_parse_args($screen, array('lang' => acf_get_setting('current_language'), 'ajax' => false)); return apply_filters('acf/location/screen', $screen, $deprecated); } function acf_register_location_rule($class_name) { return acf_register_location_type($class_name); } function acf_get_location_rule($name) { return acf_get_location_type($name); } function acf_get_valid_location_rule($rule) { return acf_validate_location_rule($rule); }