123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?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.', 'acf' ), $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 );
- }
|