123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Compatibility' ) ) :
- class ACF_Compatibility {
-
- function __construct() {
-
- add_filter( 'acf/validate_field', array( $this, 'validate_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=textarea', array( $this, 'validate_textarea_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=relationship', array( $this, 'validate_relationship_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=post_object', array( $this, 'validate_relationship_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=page_link', array( $this, 'validate_relationship_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=image', array( $this, 'validate_image_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=file', array( $this, 'validate_image_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=wysiwyg', array( $this, 'validate_wysiwyg_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=date_picker', array( $this, 'validate_date_picker_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=taxonomy', array( $this, 'validate_taxonomy_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=date_time_picker', array( $this, 'validate_date_time_picker_field' ), 20, 1 );
- add_filter( 'acf/validate_field/type=user', array( $this, 'validate_user_field' ), 20, 1 );
- add_filter( 'acf/validate_field_group', array( $this, 'validate_field_group' ), 20, 1 );
-
- add_filter( 'acf/field_wrapper_attributes', array( $this, 'field_wrapper_attributes' ), 20, 2 );
-
- add_filter( 'acf/location/validate_rule/type=post_taxonomy', array( $this, 'validate_post_taxonomy_location_rule' ), 20, 1 );
- add_filter( 'acf/location/validate_rule/type=post_category', array( $this, 'validate_post_taxonomy_location_rule' ), 20, 1 );
-
- add_action( 'acf/init', array( $this, 'init' ) );
- }
-
- function init() {
-
- if ( defined( 'ACF_LITE' ) && ACF_LITE ) {
- acf_update_setting( 'show_admin', false );
- }
- }
-
- function field_wrapper_attributes( $wrapper, $field ) {
-
- if ( acf_get_compatibility( 'field_wrapper_class' ) ) {
- $wrapper['class'] .= " field_type-{$field['type']}";
- if ( $field['key'] ) {
- $wrapper['class'] .= " field_key-{$field['key']}";
- }
- }
-
- return $wrapper;
- }
-
- function validate_field( $field ) {
-
-
- if ( isset( $field['conditional_logic']['status'] ) ) {
-
- if ( $field['conditional_logic']['status'] ) {
- $field['conditional_logic'] = acf_convert_rules_to_groups( $field['conditional_logic']['rules'], $field['conditional_logic']['allorany'] );
- } else {
- $field['conditional_logic'] = 0;
- }
- }
-
- return $field;
- }
-
- function validate_textarea_field( $field ) {
-
- $formatting = acf_extract_var( $field, 'formatting' );
- if ( $formatting === 'br' ) {
- $field['new_lines'] = 'br';
- }
-
- return $field;
- }
-
- function validate_relationship_field( $field ) {
-
- if ( acf_in_array( 'all', $field['post_type'] ) ) {
- $field['post_type'] = array();
- }
-
- if ( acf_in_array( 'all', $field['taxonomy'] ) ) {
- $field['taxonomy'] = array();
- }
-
- if ( isset( $field['result_elements'] ) ) {
- $field['elements'] = acf_extract_var( $field, 'result_elements' );
- }
-
- return $field;
- }
-
- function validate_image_field( $field ) {
-
- if ( isset( $field['save_format'] ) ) {
- $field['return_format'] = acf_extract_var( $field, 'save_format' );
- }
-
- if ( $field['return_format'] == 'object' ) {
- $field['return_format'] = 'array';
- }
-
- return $field;
- }
-
- function validate_wysiwyg_field( $field ) {
-
- if ( $field['media_upload'] === 'yes' ) {
- $field['media_upload'] = 1;
- } elseif ( $field['media_upload'] === 'no' ) {
- $field['media_upload'] = 0;
- }
-
- return $field;
- }
-
- function validate_date_picker_field( $field ) {
-
- if ( isset( $field['date_format'] ) ) {
-
- $date_format = $field['date_format'];
- $display_format = $field['display_format'];
-
- $display_format = acf_convert_date_to_php( $display_format );
-
- $field['display_format'] = $display_format;
- $field['save_format'] = $date_format;
-
- unset( $field['date_format'] );
- }
-
- return $field;
- }
-
- function validate_taxonomy_field( $field ) {
-
- if ( isset( $field['load_save_terms'] ) ) {
- $field['save_terms'] = acf_extract_var( $field, 'load_save_terms' );
- }
-
- return $field;
- }
-
- function validate_date_time_picker_field( $field ) {
-
-
- if ( ! empty( $field['time_format'] ) ) {
-
- $time_format = acf_extract_var( $field, 'time_format' );
- $date_format = acf_extract_var( $field, 'date_format' );
- $get_as_timestamp = acf_extract_var( $field, 'get_as_timestamp' );
-
- $time_format = acf_convert_time_to_php( $time_format );
- $date_format = acf_convert_date_to_php( $date_format );
-
- $field['return_format'] = $date_format . ' ' . $time_format;
- $field['display_format'] = $date_format . ' ' . $time_format;
-
- if ( $get_as_timestamp === 'true' ) {
- $field['return_format'] = 'U';
- }
- }
-
- return $field;
- }
-
- function validate_user_field( $field ) {
-
- if ( acf_in_array( 'all', $field['role'] ) ) {
- $field['role'] = '';
- }
-
- if ( isset( $field['field_type'] ) ) {
-
- $field_type = acf_extract_var( $field, 'field_type' );
-
- if ( $field_type === 'multi_select' ) {
- $field['multiple'] = true;
- }
- }
-
- return $field;
- }
-
- function validate_field_group( $field_group ) {
-
- $version = 5;
-
-
- if ( ! $field_group['key'] ) {
- $version = 4;
- $field_group['key'] = isset( $field_group['id'] ) ? "group_{$field_group['id']}" : uniqid( 'group_' );
- }
-
-
- if ( isset( $field_group['options'] ) ) {
- $options = acf_extract_var( $field_group, 'options' );
- $field_group = array_merge( $field_group, $options );
- }
-
-
- if ( isset( $field_group['location']['rules'] ) ) {
- $field_group['location'] = acf_convert_rules_to_groups( $field_group['location']['rules'], $field_group['location']['allorany'] );
- }
-
-
- $replace = array(
- 'taxonomy' => 'post_taxonomy',
- 'ef_media' => 'attachment',
- 'ef_taxonomy' => 'taxonomy',
- 'ef_user' => 'user_role',
- 'user_type' => 'current_user_role',
- );
-
- if ( $version > 4 ) {
- unset( $replace['taxonomy'] );
- }
-
- if ( $field_group['location'] ) {
- foreach ( $field_group['location'] as $i => $group ) {
-
- if ( $group ) {
- foreach ( $group as $j => $rule ) {
-
- if ( isset( $replace[ $rule['param'] ] ) ) {
- $field_group['location'][ $i ][ $j ]['param'] = $replace[ $rule['param'] ];
- }
- }
- }
- }
- }
-
- if ( isset( $field_group['layout'] ) ) {
- $field_group['style'] = acf_extract_var( $field_group, 'layout' );
- }
-
- if ( $field_group['style'] === 'no_box' ) {
- $field_group['style'] = 'seamless';
- }
-
- return $field_group;
- }
-
- function validate_post_taxonomy_location_rule( $rule ) {
-
-
- if ( is_numeric( $rule['value'] ) ) {
- $term = acf_get_term( $rule['value'] );
- if ( $term ) {
- $rule['value'] = acf_encode_term( $term );
- }
- }
-
- return $rule;
- }
- }
- acf_new_instance( 'ACF_Compatibility' );
- endif;
- function acf_get_compatibility( $name ) {
- return apply_filters( "acf/compatibility/{$name}", false );
- }
|