Skip to content

Instantly share code, notes, and snippets.

@campusboy87
Created July 8, 2020 12:39
Show Gist options
  • Save campusboy87/e445db294de5816ef5cc0992bbac2b72 to your computer and use it in GitHub Desktop.
Save campusboy87/e445db294de5816ef5cc0992bbac2b72 to your computer and use it in GitHub Desktop.
Добавляет условие отображения как "Главный" и "Региональный" сайта в сети сайтов WordPress
<?php
function acf_add_location_site() {
$key = 'site-location';
add_filter( 'acf/location/rule_types', function ( $choices ) use ( $key ) {
$choices['Мультисайт'][ $key ] = 'Месторасположение';
return $choices;
} );
add_filter( "acf/location/rule_values/$key", function ( $choices ) {
return [
'main' => 'Головной',
'region' => 'Региональный',
];
} );
add_filter( "acf/location/rule_match/$key", function ( $match, $rule, $options ) {
$current_site = is_main_site() ? 'main' : 'region';
$selected_site = $rule['value'];
if ( $rule['operator'] == "==" ) {
$match = ( $current_site == $selected_site );
} elseif ( $rule['operator'] == "!=" ) {
$match = ( $current_site != $selected_site );
}
return $match;
}, 10, 3 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment