Last active
July 11, 2020 20:52
-
-
Save RuslanAsadov/335cc39b094bbe87bf501f81b79e6094 to your computer and use it in GitHub Desktop.
WP Languages
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
<?php | |
// Плагин wp multilang https://ru.wordpress.org/plugins/wp-multilang/ | |
// custom switcher | |
/* | |
При вызове выводит список языков с такой вёрсткой | |
<div class="lang-header"> | |
<a href="#" class="lang-header__item active">RU</a> | |
<a href="#" class="lang-header__item">KZ</a> | |
</div> | |
*/ | |
function lang_switcher () { | |
if (function_exists('wpm_get_languages')) { | |
$languages = wpm_get_languages(); | |
$current = wpm_get_language(); | |
$out = '<div class="lang-header">'; | |
foreach ($languages as $code => $language) { | |
$toggle_url = esc_url(wpm_translate_current_url($code)); | |
$css_classes = 'lang-header__item '; | |
if ($code === $current) { | |
$css_classes .= 'active'; | |
} | |
$out .= '<a href="' . $toggle_url . '" class="' . $css_classes . '" data-lang="' . esc_attr($code) . '">'; | |
$name = $language['name']; | |
if($language['locale'] == 'ru_RU') { | |
$name = 'RU'; | |
} | |
if($language['locale'] == 'kk') { | |
$name = 'KZ'; | |
} | |
$out .= $name; | |
$out .= '</a>'; | |
$out .= ' '; | |
} | |
$out .= '</div>'; | |
return $out; | |
} | |
} | |
// проверка на язык | |
function is_kz() { | |
if(wpm_get_language() == 'kk') { | |
return true; | |
} | |
return false; | |
} | |
// Узнать id Страницы с опциями acf (toplevel_page_theme-general-settings) | |
function id_WPSE_114111() { | |
echo "<pre>"; | |
var_dump(get_current_screen()); | |
echo "</pre>"; | |
} | |
add_action( 'admin_notices', 'id_WPSE_114111' ); | |
// Пример | |
// wpm-config.json | |
{ | |
"post_types": { | |
"page": {}, | |
"post": {}, | |
"card": {}, | |
"service": {}, | |
"wp_block": {}, | |
"attachment": {}, | |
"nav_menu_item": { | |
"attr_title": {}, | |
"title": {} | |
}, | |
"any": {}, | |
"customize_changeset": null, | |
"revision": null | |
}, | |
// перечисляем тут кастомные поля для страниц и постов (всех) | |
"post_fields": { | |
"_wp_attachment_image_alt": {}, | |
"_genesis_title": {}, | |
"_genesis_description": {}, | |
"_custom_field_name": {}, | |
"_custom_field_group_name": { | |
"wpm_each": { | |
"_custom_field_in_group": {} | |
} | |
} | |
}, | |
"term_fields": { | |
"_custom_field_name": {}, | |
"_custom_field_group_name": { | |
"wpm_each": { | |
"_custom_field_in_group": {} | |
} | |
} | |
}, | |
"user_fields": {}, | |
"comment_fields": {}, | |
"admin_pages": [ | |
"upload", | |
"nav-menus", | |
"options-general", | |
"widgets", | |
"settings-network", | |
"site-settings-network", | |
"toplevel_page_theme-general-settings" | |
], | |
"options": { | |
"blogname": {}, | |
"blogdescription": {} | |
}, | |
"site_options": { | |
"site_name": {}, | |
"welcome_email": {}, | |
"first_post": {}, | |
"welcome_user_email": {}, | |
"first_page": {}, | |
"first_comment": {} | |
}, | |
"widgets": { | |
"media_image": { | |
"caption": {}, | |
"alt": {}, | |
"image_title": {} | |
}, | |
"custom_html": { | |
"content": {} | |
} | |
}, | |
"admin_html_tags": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment