name = 'swiftling_language'; $this->label = __( 'SwiftLing language', 'swiftling' ); $this->category = 'post'; $this->object_type = 'post'; } /** * Returns the languages of the site: the original and every language it is translated into. * * @param array $rule Rule. * @return array Locale => name. */ public function get_values( $rule ) { $languages = swiftling_languages(); $values = array( /* translators: %s: name of the site's original language, e.g. English. */ $languages['source']['locale'] => sprintf( __( '%s (original)', 'swiftling' ), $languages['source']['name'] ), ); foreach ( $languages['targets'] as $language ) { $values[ $language['locale'] ] = $language['name']; } return $values; } /** * Whether the post ACF shows field groups for is in the language of the rule. * * @param array $rule Rule: operator and locale. * @param array $screen What ACF shows the field groups for. * @param array $field_group Field group. * @return bool */ public function match( $rule, $screen, $field_group ) { $post = empty( $screen['post_id'] ) || ! is_numeric( $screen['post_id'] ) ? null : get_post( (int) $screen['post_id'] ); $locale = $post && swiftling_copy_original_id( $post ) ? (string) get_post_meta( $post->ID, SWIFTLING_COPY_LANG, true ) : swiftling_languages()['source']['locale']; return $this->compare_to_rule( $locale, $rule ); } }