Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit e39f5b7

Browse files
committed
add mobile styles in admin for language switcher
fix save acf option field
1 parent 0b61aa1 commit e39f5b7

19 files changed

+127
-71
lines changed

assets/scripts/customizer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$(function () {
55

66
if ($('#wpm-language-switcher').length === 0) {
7-
var language_switcher = _.template(wpm_language_switcher_params.switcher);
7+
var language_switcher = _.template($('#tmpl-wpm-ls').text());
88
$('#customize-header-actions').append(language_switcher);
99
}
1010

assets/scripts/customizer.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/scripts/language-switcher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$(function () {
55

66
if ($('#wpm-language-switcher').length === 0) {
7-
var language_switcher = _.template(wpm_language_switcher_params.switcher);
7+
var language_switcher = _.template($('#tmpl-wpm-ls').text());
88
$('#wpbody-content .wrap').first().prepend(language_switcher);
99
}
1010

assets/scripts/language-switcher.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/styles/admin/admin.css

+16-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/styles/admin/admin.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/styles/admin/components/_lang-switcher.scss

+31-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,37 @@
5252
}
5353
}
5454

55-
.wrap {
56-
position: relative;
55+
@media screen and (max-width: 782px) {
56+
#wp-toolbar > ul > #wp-admin-bar-wpm-language-switcher {
57+
display: block;
58+
}
59+
60+
#wp-admin-bar-wpm-language-switcher-default {
61+
62+
.ab-item {
63+
min-width: 20px !important;
64+
padding: 0 !important;
65+
}
66+
67+
.ab-icon {
68+
line-height: 20px !important;
69+
}
70+
}
71+
72+
#wp-admin-bar-wpm-language-switcher {
73+
74+
.ab-icon {
75+
line-height: 20px !important;
76+
}
77+
}
78+
79+
.language-switcher {
80+
padding-top: 0;
81+
82+
a {
83+
margin-top: 0 !important;
84+
}
85+
}
5786
}
5887

5988
.language-switcher {

core/admin/class-wpm-admin-assets.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct() {
3333
public function admin_styles() {
3434

3535
// Register admin styles
36-
wp_register_style( 'wpm_language_switcher', wpm_asset_path( 'styles/admin/admin.css' ), array(), WPM_VERSION );
36+
wp_enqueue_style( 'wpm_language_switcher', wpm_asset_path( 'styles/admin/admin.css' ), array(), WPM_VERSION );
3737
}
3838

3939

@@ -79,12 +79,10 @@ public function admin_scripts() {
7979
wp_localize_script( 'wpm_translator', 'wpm_translator_params', $translator_params );
8080

8181
if ( 'customize' === $screen_id ) {
82-
wp_enqueue_style( 'wpm_language_switcher' );
8382
wp_enqueue_script( 'wpm_language_switcher_customizer' );
84-
$params = array(
85-
'switcher' => wpm_get_template_html( 'language-switcher-customizer.php' ),
86-
);
87-
wp_localize_script( 'wpm_language_switcher_customizer', 'wpm_language_switcher_params', $params );
83+
add_action('admin_print_footer_scripts', function() {
84+
echo wpm_get_template_html( 'language-switcher-customizer.php' );
85+
});
8886
}
8987

9088
$admin_pages_config = apply_filters( 'wpm_admin_pages', $config['admin_pages'] );
@@ -122,20 +120,21 @@ public function admin_scripts() {
122120
* Display language switcher for edit posts, taxonomies, options
123121
*/
124122
public function set_language_switcher() {
125-
wp_enqueue_style( 'wpm_language_switcher' );
126123
wp_enqueue_script( 'wpm_language_switcher' );
127-
$params = array(
128-
'switcher' => wpm_get_template_html( 'language-switcher.php' ),
129-
);
130-
wp_localize_script( 'wpm_language_switcher', 'wpm_language_switcher_params', $params );
124+
131125
add_action('admin_head', function() {
132126
?>
133127
<style>
134128
#wpbody-content .wrap {
135129
padding-top: 37px;
130+
position: relative;
136131
}
137132
</style>
138133
<?php
139134
});
135+
136+
add_action('admin_print_footer_scripts', function() {
137+
echo wpm_get_template_html( 'language-switcher.php' );
138+
});
140139
}
141140
}

core/admin/class-wpm-admin-menus.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ public function admin_bar_menu( \WP_Admin_Bar $wp_admin_bar ) {
6767
$wp_admin_bar->add_menu( array(
6868
'parent' => 'wpm-language-switcher',
6969
'id' => 'wpm-language-' . $language,
70-
'title' => '<img src="' . esc_url( WPM()->flag_dir() . $options[ $key ]['flag'] . '.png' ) . '" />' .
71-
'&nbsp;&nbsp;' .
72-
$options[ $key ]['name'],
70+
'title' => '<span class="ab-icon">' .
71+
'<img src="' . esc_url( WPM()->flag_dir() . $options[ $key ]['flag'] . '.png' ) . '" />' .
72+
'</span>' .
73+
'<span class="ab-label">' . $options[ $key ]['name'] . '</span>',
7374
'href' => add_query_arg( 'lang', $language, $current_url ),
7475
) );
7576
}

core/admin/class-wpm-admin-options.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public function __construct() {
3030
* Add filters for options in config
3131
*/
3232
public function init() {
33-
$config = wpm_get_config();
34-
foreach ( $config['options'] as $option => $option_config ) {
33+
$config = wpm_get_config();
34+
$options_config = apply_filters( 'wpm_options_config', $config['options'] );
35+
foreach ( $options_config as $option => $option_config ) {
3536
add_filter( "pre_update_option_{$option}", array( $this, 'wpm_update_option' ), 99, 3 );
3637
}
3738
}

core/class-wpm-options.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public function __construct() {
2727
*/
2828
public function init() {
2929

30-
$config = wpm_get_config();
30+
$config = wpm_get_config();
31+
$options_config = apply_filters( 'wpm_options_config', $config['options'] );
3132

32-
foreach ( $config['options'] as $key => $option ) {
33+
foreach ( $options_config as $key => $option ) {
3334
add_filter( "option_{$key}", 'wpm_translate_value', 0 );
3435
}
3536
}

core/vendor/class-wpm-acf.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public function save_field( $field ) {
9292
return false;
9393
}
9494

95-
$config = wpm_get_config();
96-
9795
$old_field = maybe_unserialize( get_post_field( 'post_content', $field['ID'] ) );
9896

9997
if ( ! $old_field ) {
@@ -200,6 +198,13 @@ public function save_value( $value, $post_id, $field ) {
200198
if ( isset( $acf_widget_fields[ $field['name'] ] ) && is_null( $acf_widget_fields[ $field['name'] ] ) ) {
201199
return $value;
202200
}
201+
202+
remove_filter( "acf/load_value/type={$field['type']}", 'wpm_translate_value', 0 );
203+
$old_value = get_field( $field['name'], $post_id );
204+
add_filter( "acf/load_value/type={$field['type']}", 'wpm_translate_value', 0 );
205+
$old_value = wpm_value_to_ml_array( $old_value );
206+
$new_value = wpm_set_language_value( $old_value, $value, $acf_widget_fields );
207+
$value = wpm_ml_value_to_string( $new_value );
203208
}
204209

205210
break;

languages/wpm-uk.mo

0 Bytes
Binary file not shown.

languages/wpm-uk.po

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
msgid ""
22
msgstr ""
33
"Project-Id-Version: WP Multilang\n"
4-
"POT-Creation-Date: 2017-06-22 09:46+0300\n"
5-
"PO-Revision-Date: 2017-06-22 09:46+0300\n"
4+
"POT-Creation-Date: 2017-06-24 15:21+0300\n"
5+
"PO-Revision-Date: 2017-06-24 15:21+0300\n"
66
"Last-Translator: \n"
77
"Language-Team: \n"
88
"Language: uk\n"
@@ -28,7 +28,7 @@ msgstr ""
2828
msgid "Are you sure you want to delete this language?"
2929
msgstr "Ви впевнені, що хочете видалити цю мову?"
3030

31-
#: core/admin/class-wpm-admin-posts.php:174
31+
#: core/admin/class-wpm-admin-posts.php:171
3232
#: core/admin/class-wpm-admin-taxonomies.php:259
3333
#: core/widgets/class-wpm-widget-language-switcher.php:30
3434
msgid "Languages"

languages/wpm.pot

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ msgid ""
33
msgstr ""
44
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
55
"Project-Id-Version: WP Multilang\n"
6-
"POT-Creation-Date: 2017-06-22 09:46+0300\n"
6+
"POT-Creation-Date: 2017-06-24 15:21+0300\n"
77
"PO-Revision-Date: 2017-05-22 12:43+0300\n"
88
"Last-Translator: \n"
99
"Language-Team: \n"
@@ -27,7 +27,7 @@ msgstr ""
2727
msgid "Are you sure you want to delete this language?"
2828
msgstr ""
2929

30-
#: core/admin/class-wpm-admin-posts.php:174
30+
#: core/admin/class-wpm-admin-posts.php:171
3131
#: core/admin/class-wpm-admin-taxonomies.php:259
3232
#: core/widgets/class-wpm-widget-language-switcher.php:30
3333
msgid "Languages"

readme.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: valexar
44
Tags: localization, multilanguage, multilingual, translation, multilang
55
Requires at least: 4.7
66
Tested up to: 4.8
7-
Stable tag: 1.4.0
7+
Stable tag: 1.4.1
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -134,6 +134,10 @@ Compatible with multisite not tested.
134134

135135
== Changelog ==
136136

137+
= 1.4.1 =
138+
+ add mobile styles in admin for language switcher
139+
* fix save acf option field
140+
137141
= 1.4.0 =
138142
+ add support comments and user fields
139143
+ add support ACF widget fields

templates/language-switcher-customizer.php

+24-22
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,29 @@
77
}
88
$options = wpm_get_options();
99
?>
10-
<div id="wpm-language-switcher" class="wpm-language-switcher customize-controls-close">
11-
<div class="lang-main">
12-
<?php if ( $options[ $locales[ $lang ] ]['flag'] ) { ?>
13-
<img src="<?php echo esc_url( WPM()->flag_dir() . $options[ $locales[ $lang ] ]['flag'] . '.png' ); ?>">
14-
<?php } ?>
15-
</div>
16-
<div class="lang-dropdown">
17-
<ul>
18-
<?php foreach ( $languages as $key => $language ) {
19-
if ( $language === $lang ) {
20-
continue;
21-
} ?>
22-
<li class="wpm-language-<?php esc_attr_e( $language ); ?>">
23-
<a href="<?php echo esc_url( add_query_arg( 'edit_lang', $language, home_url( $_SERVER['REQUEST_URI'] ) ) ); ?>">
24-
<?php if ( $options[ $key ]['flag'] ) { ?>
25-
<img src="<?php echo esc_url( WPM()->flag_dir() . $options[ $key ]['flag'] . '.png' ); ?>"
26-
alt="<?php esc_attr_e( $options[ $key ]['name'] ); ?>">
27-
<?php } ?>
28-
</a>
29-
</li>
10+
<script id="tmpl-wpm-ls" type="text/template">
11+
<div id="wpm-language-switcher" class="wpm-language-switcher customize-controls-close">
12+
<div class="lang-main">
13+
<?php if ( $options[ $locales[ $lang ] ]['flag'] ) { ?>
14+
<img src="<?php echo esc_url( WPM()->flag_dir() . $options[ $locales[ $lang ] ]['flag'] . '.png' ); ?>">
3015
<?php } ?>
31-
</ul>
16+
</div>
17+
<div class="lang-dropdown">
18+
<ul>
19+
<?php foreach ( $languages as $key => $language ) {
20+
if ( $language === $lang ) {
21+
continue;
22+
} ?>
23+
<li class="wpm-language-<?php esc_attr_e( $language ); ?>">
24+
<a href="<?php echo esc_url( add_query_arg( 'edit_lang', $language, home_url( $_SERVER['REQUEST_URI'] ) ) ); ?>">
25+
<?php if ( $options[ $key ]['flag'] ) { ?>
26+
<img src="<?php echo esc_url( WPM()->flag_dir() . $options[ $key ]['flag'] . '.png' ); ?>"
27+
alt="<?php esc_attr_e( $options[ $key ]['name'] ); ?>">
28+
<?php } ?>
29+
</a>
30+
</li>
31+
<?php } ?>
32+
</ul>
33+
</div>
3234
</div>
33-
</div>
35+
</script>

templates/language-switcher.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
}
77
$options = wpm_get_options();
88
?>
9-
<h3 id="wpm-language-switcher" class="nav-tab-wrapper language-switcher">
10-
<?php foreach ( $languages as $key => $language ) { ?>
11-
<a class="nav-tab<?php if ( $lang === $language ) { ?> nav-tab-active<?php } ?>"
12-
href="<?php echo esc_url( add_query_arg( 'edit_lang', $language, home_url( $_SERVER['REQUEST_URI'] ) ) ); ?>">
13-
<?php if ( $options[ $key ]['flag'] ) { ?>
14-
<img src="<?php echo esc_url( WPM()->flag_dir() . $options[ $key ]['flag'] . '.png' ); ?>"
15-
alt="<?php esc_attr_e( $options[ $key ]['name'] ) ; ?>">
16-
<?php } ?>
17-
<span><?php esc_attr_e( $options[ $key ]['name'] ); ?></span>
18-
</a>
19-
<?php } ?>
20-
</h3>
9+
<script id="tmpl-wpm-ls" type="text/template">
10+
<h3 id="wpm-language-switcher" class="nav-tab-wrapper language-switcher">
11+
<?php foreach ( $languages as $key => $language ) { ?>
12+
<a class="nav-tab<?php if ( $lang === $language ) { ?> nav-tab-active<?php } ?>" href="<?php echo esc_url( add_query_arg( 'edit_lang', $language, home_url( $_SERVER['REQUEST_URI'] ) ) ); ?>">
13+
<?php if ( $options[ $key ]['flag'] ) { ?>
14+
<img src="<?php echo esc_url( WPM()->flag_dir() . $options[ $key ]['flag'] . '.png' ); ?>" alt="<?php esc_attr_e( $options[ $key ]['name'] ) ; ?>">
15+
<?php } ?>
16+
<span><?php esc_attr_e( $options[ $key ]['name'] ); ?></span>
17+
</a>
18+
<?php } ?>
19+
</h3>
20+
</script>

wp-multilang.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
99
* Text Domain: wpm
1010
* Domain Path: /languages
11-
* Version: 1.4.0
11+
* Version: 1.4.1
1212
*
1313
* @package WPM
1414
* @category Core
@@ -42,7 +42,7 @@ final class WP_Multilang {
4242
*
4343
* @var string
4444
*/
45-
public $version = '1.4.0';
45+
public $version = '1.4.1';
4646

4747
/**
4848
* The single instance of the class.

0 commit comments

Comments
 (0)