Last active
March 1, 2022 18:24
-
-
Save mattkeys/01ef26935c8a0527cf9dcee71880e54d to your computer and use it in GitHub Desktop.
WPML doesn't properly handle field groups that are assigned to page parents. This filter fixes that.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make WPML compatible with ACF field groups with location set to 'page parent' | |
function filter_acf_location_rule_match_param( $result, $rule, $screen, $field_group ) { | |
$default_lang = apply_filters( 'wpml_default_language', NULL ); | |
if ( ! isset( $screen['lang'] ) || $default_lang == $screen['lang'] ) { | |
return $result; | |
} | |
if ( ! isset( $screen['post_id'] ) || empty( $screen['post_id'] ) ) { | |
return $result; | |
} | |
$default_lang_post_id = apply_filters( 'wpml_object_id', $screen['post_id'], $screen['post_type'], false, $default_lang ); | |
if ( ! $default_lang_post_id ) { | |
return $result; | |
} | |
$default_lang_post_parent_id = wp_get_post_parent_id( $default_lang_post_id ); | |
if ( ! $default_lang_post_parent_id ) { | |
return $result; | |
} | |
switch ( $rule['operator'] ) { | |
case '==': | |
if ( $default_lang_post_parent_id == $rule['value'] ) { | |
$result = true; | |
} | |
break; | |
case '!=': | |
if ( $default_lang_post_parent_id != $rule['value'] ) { | |
$result = true; | |
} | |
break; | |
} | |
return $result; | |
}; | |
add_filter( 'acf/location/match_rule/type=page_parent', 'filter_acf_location_rule_match_param', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment