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

Commit 6a8687f

Browse files
committed
Merge branch 'release/2.1.9'
2 parents 617c995 + 41058d4 commit 6a8687f

15 files changed

+111
-59
lines changed

configs/plugins/woocommerce.json

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@
9696
"title" : {},
9797
"description" : {},
9898
"instructions" : {}
99+
},
100+
"woocommerce_bacs_accounts": {
101+
"wpm_each": {
102+
"account_name": {},
103+
"bank_name": {}
104+
}
99105
}
100106
},
101107
"admin_html_tags": {

includes/class-wp-multilang.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class WP_Multilang {
2121
*
2222
* @var string
2323
*/
24-
public $version = '2.1.8';
24+
public $version = '2.1.9';
2525

2626
/**
2727
* The single instance of the class.

includes/class-wpm-ajax.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,13 @@ private static function set_default_language_for_object( $object, $object_config
489489
case 'description':
490490
case 'post_content':
491491
if ( is_serialized_string( $content ) ) {
492-
$content = unserialize( $content );
492+
$content = unserialize( $content );
493493
$object->$key = serialize( wpm_set_new_value( $content, wpm_translate_value( $content, $lang ), $object_config[ $key ], $lang ) );
494494
break;
495495
}
496496

497497
if ( json_decode( $content ) ) {
498-
$content = json_decode( $content, true );
498+
$content = json_decode( $content, true );
499499
$object->$key = wp_json_encode( wpm_set_new_value( $content, wpm_translate_value( $content, $lang ), $object_config[ $key ], $lang ) );
500500
break;
501501
}

includes/class-wpm-menus.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,14 @@ public function add_languages_to_menu( $items ) {
199199
$first_lang = null;
200200

201201
foreach ( $languages as $code => $language ) {
202-
$new_item = clone $item;
203-
$new_item->ID = 'language-' . $code;
204-
$new_item->db_id = 'language-' . $code;
205-
$new_item->object = 'language';
206-
$new_item->object_id = $code;
207-
$language_title = '';
202+
$new_item = new \stdClass();
203+
$new_item->ID = 'language-' . $code;
204+
$new_item->db_id = 'language-' . $code;
205+
$new_item->classes = $item->classes;
206+
$new_item->type = 'language';
207+
$new_item->menu_item_parent = $item->menu_item_parent;
208+
$new_item->parent_submenu_type = $item->parent_submenu_type;
209+
$language_title = '';
208210

209211
if ( $lang == $code ) {
210212
$was_current = true;
@@ -258,7 +260,9 @@ public function add_languages_to_menu( $items ) {
258260
$sorted_array = array();
259261

260262
foreach ( $items as $k => $v ) {
261-
$sorted_array[ $k + 1 ] = $v;
263+
$order = $k + 1;
264+
$v->menu_order = $order;
265+
$sorted_array[ $order ] = $v;
262266
}
263267

264268
$items = $sorted_array;
@@ -267,7 +271,6 @@ public function add_languages_to_menu( $items ) {
267271
}// End if().
268272
}// End foreach().
269273

270-
271274
return $items;
272275
}
273276
}

includes/class-wpm-posts.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public function __construct() {
6464
*/
6565
public function translate_posts( $posts ) {
6666
foreach ( $posts as &$post ) {
67-
if ( ! is_null( wpm_get_post_config( $post->post_type ) ) ) {
68-
$post = wpm_translate_post( $post );
69-
}
67+
$post = wpm_translate_post( $post );
7068
}
7169

7270
return $posts;

includes/class-wpm-setup.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,6 @@ private function set_user_language() {
342342
if ( $url_lang = $this->get_lang_from_url() ) {
343343
$user_language = $url_lang;
344344
}
345-
346-
if ( $user_language && ! is_admin() && ! isset( $languages[ $user_language ] ) ) {
347-
add_action( 'template_redirect', array( $this, 'set_not_found' ) );
348-
}
349345
}
350346

351347
if ( isset( $_REQUEST['lang'] ) ) {
@@ -402,7 +398,7 @@ public function redirect_default_url() {
402398
}
403399
} else {
404400
if ( $url_lang && $user_language === $default_language ) {
405-
wp_redirect( home_url( preg_replace( '!^/([a-z]{2})(/|$)!i', '/', $this->get_original_request_uri() ) ) );
401+
wp_redirect( home_url( preg_replace( '!^/' . $url_lang . '(/|$)!i', '/', $this->get_original_request_uri() ) ) );
406402
exit;
407403
}
408404
}
@@ -554,7 +550,7 @@ public function load_integrations() {
554550
/**
555551
* Set 404 headers for not available language
556552
*/
557-
private function set_not_found() {
553+
public function set_not_found() {
558554
global $wp_query;
559555
$wp_query->set_404();
560556
status_header( 404 );
@@ -816,9 +812,11 @@ public function set_html_locale( $translation, $text ) {
816812
private function get_lang_from_url() {
817813
if ( ! $this->url_language ) {
818814
$url_lang = '';
815+
$parts = explode( '/', ltrim( trailingslashit( $this->get_original_request_uri() ), '/' ) );
816+
$lang = $parts[0];
819817

820-
if ( preg_match( '!^/([a-z]{2})(/|$)!i', $this->get_original_request_uri(), $match ) ) {
821-
$url_lang = $match[1];
818+
if ( isset( $this->languages[ $lang ] ) ) {
819+
$url_lang = $lang;
822820
}
823821

824822
$this->url_language = $url_lang;

includes/class-wpm-taxonomies.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,12 @@ public function __construct() {
6666
* @return array
6767
*/
6868
public function translate_terms( $terms ) {
69-
70-
if ( is_array( $terms ) ) {
71-
$_terms = array();
72-
foreach ( $terms as $term ) {
73-
if ( is_object( $term ) ) {
74-
$_terms[] = wpm_translate_term( $term, $term->taxonomy );
75-
} else {
76-
$_terms[] = wpm_translate_value( $term );
77-
}
69+
foreach ( $terms as &$term ) {
70+
if ( is_object( $term ) ) {
71+
$term = wpm_translate_term( $term, $term->taxonomy );
72+
} else {
73+
$term = wpm_translate_value( $term );
7874
}
79-
$terms = $_terms;
8075
}
8176

8277
return $terms;

includes/integrations/class-wpm-acf.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class WPM_Acf {
2222
*/
2323
public function __construct() {
2424
add_action( 'init', array( $this, 'init_filters' ), 5 );
25-
add_filter( 'acf/load_field', 'wpm_translate_value', 5 );
26-
add_filter( 'acf/load_value', 'wpm_translate_value', 5 );
25+
add_filter( 'acf/load_field', 'wpm_translate_value', 6 );
26+
add_filter( 'acf/load_value', 'wpm_translate_value', 6 );
2727
add_filter( 'wpm_acf_field_text_config', array( $this, 'add_text_field_config' ) );
2828
add_filter( 'wpm_acf_field_textarea_config', array( $this, 'add_text_field_config' ) );
2929
add_filter( 'wpm_acf_field_wysiwyg_config', array( $this, 'add_text_field_config' ) );
@@ -38,13 +38,13 @@ public function __construct() {
3838
public function init_filters() {
3939
if ( version_compare( acf()->settings['version'], 5, 'ge' ) ) {
4040
add_filter( 'wpm_post_acf-field-group_config', array( $this, 'add_config' ) );
41-
add_filter( 'acf/get_field_group', 'wpm_translate_value', 5 );
42-
add_filter( 'acf/get_field_label', 'wpm_translate_string', 5 );
41+
add_filter( 'acf/get_field_group', 'wpm_translate_value', 6 );
42+
add_filter( 'acf/get_field_label', 'wpm_translate_string', 6 );
4343
add_filter( 'acf/update_field', array( $this, 'update_field_pro' ), 99 );
4444
add_filter( 'acf/update_value', array( $this, 'update_value_pro' ), 99, 3 );
4545
} else {
4646
add_filter( 'wpm_post_acf_config', array( $this, 'add_config' ) );
47-
add_filter( 'acf/field_group/get_fields', 'wpm_translate_value', 5 );
47+
add_filter( 'acf/field_group/get_fields', 'wpm_translate_value', 6 );
4848
remove_class_action( 'acf/update_field', 'acf_field_functions', 'update_field', 5 );
4949
add_action( 'acf/update_field', array( $this, 'update_field' ), 5, 2 );
5050
remove_class_action( 'acf/update_value', 'acf_field_functions', 'update_value', 5 );

includes/integrations/class-wpm-gutenberg.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function add_language_switcher() {
3232
$screen = get_current_screen();
3333
$screen_id = $screen ? $screen->id : '';
3434

35-
if ( is_null( $screen ) || ! $screen->post_type || is_null( wpm_get_post_config( $screen->post_type ) ) || ( $screen_id !== $screen->post_type ) ) {
35+
if ( is_null( $screen ) || ! $screen->post_type || is_null( wpm_get_post_config( $screen->post_type ) ) || ( $screen_id !== $screen->post_type ) || ! gutenberg_can_edit_post_type( $screen->post_type ) ) {
3636
return;
3737
}
3838

@@ -41,15 +41,14 @@ public function add_language_switcher() {
4141
}
4242

4343
add_action( 'admin_print_footer_scripts', 'wpm_admin_language_switcher_customizer' );
44-
4544
wpm_enqueue_js( "
46-
wp.api.init().done( function() {
45+
wp.api.init().then( function() {
4746
if ($('#wpm-language-switcher').length === 0) {
4847
var language_switcher = wp.template( 'wpm-ls-customizer' );
4948
$('.editor-header-toolbar').prepend(language_switcher);
5049
}
5150
});
52-
51+
5352
$(document).on('click', '#wpm-language-switcher .lang-dropdown a', function(){
5453
var location = String(document.location);
5554
var lang = $(this).data('lang');

includes/integrations/class-wpm-megamenu.php

+27-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ class WPM_Megamenu {
2222
*/
2323
public function __construct() {
2424
add_action( 'admin_print_scripts-mega-menu_page_maxmegamenu_theme_editor', array( $this, 'add_language_switcher' ), 11 );
25+
add_filter( 'widget_update_callback', array( $this, 'pre_save_widget' ), 100, 3 );
2526
}
2627

2728

2829
/**
2930
* Add language switcher
30-
*
31-
* @param $hook
3231
*/
3332
public function add_language_switcher() {
3433

@@ -45,4 +44,30 @@ public function add_language_switcher() {
4544
}
4645
" );
4746
}
47+
48+
/**
49+
* Fix save widgets in menu item
50+
*
51+
* @param $instance
52+
* @param $new_instance
53+
* @param $old_instance
54+
*
55+
* @return array
56+
*/
57+
public function pre_save_widget( $instance, $new_instance, $old_instance ) {
58+
59+
if ( isset( $old_instance['mega_menu_columns'] ) && ! isset( $new_instance['mega_menu_columns'] ) ) {
60+
$instance['mega_menu_columns'] = $old_instance['mega_menu_columns'];
61+
}
62+
63+
if ( isset( $old_instance['mega_menu_order'] ) && ! isset( $new_instance['mega_menu_order'] ) ) {
64+
$instance['mega_menu_order'] = $old_instance['mega_menu_order'];
65+
}
66+
67+
if ( isset( $old_instance['mega_menu_parent_menu_id'] ) && ! isset( $new_instance['mega_menu_parent_menu_id'] ) ) {
68+
$instance['mega_menu_parent_menu_id'] = $old_instance['mega_menu_parent_menu_id'];
69+
}
70+
71+
return $instance;
72+
}
4873
}

includes/integrations/class-wpm-tablepress.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function save_table( $data, $postarr ) {
6363
),
6464
);
6565

66-
$old_table = json_decode( get_post_field( 'post_content', wpm_clean( $postarr['ID'] ), 'edit' ) );
67-
$new_table = json_decode( stripslashes_from_strings_only( $data['post_content'] ) );
66+
$old_table = json_decode( get_post_field( 'post_content', wpm_clean( $postarr['ID'] ), 'edit' ), true );
67+
$new_table = json_decode( stripslashes_from_strings_only( $data['post_content'] ), true );
6868
$value = wpm_set_new_value( $old_table, $new_table, $options );
6969
$data['post_content'] = addslashes_gpc( wp_json_encode( $value ) );
7070

includes/integrations/class-wpm-woocommerce.php

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct() {
2626
add_filter( 'woocommerce_product_get_name', 'wpm_translate_string' );
2727
add_filter( 'woocommerce_product_get_description', 'wpm_translate_string' );
2828
add_filter( 'woocommerce_product_get_short_description', 'wpm_translate_string' );
29+
add_filter( 'woocommerce_product_title', 'wpm_translate_string' );
2930
add_filter( 'woocommerce_shortcode_products_query', array( $this, 'remove_filter' ) );
3031
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_js_frontend' ) );
3132
add_filter( 'woocommerce_cart_shipping_method_full_label', 'wpm_translate_string' );
@@ -54,6 +55,7 @@ public function __construct() {
5455
add_filter( 'woocommerce_attribute_taxonomies', array( $this, 'translate_attribute_taxonomies' ) );
5556
add_action( 'admin_head', array( $this, 'set_translation_for_attribute_taxonomies' ) );
5657
add_filter( 'woocommerce_product_get_review_count', array( $this, 'fix_product_review_count' ), 10, 2 );
58+
add_action( 'admin_action_duplicate_product', array( $this, 'remove_filters' ), 9 );
5759
}
5860

5961

@@ -295,4 +297,14 @@ public function fix_product_review_count( $count, $product ) {
295297

296298
return $count;
297299
}
300+
301+
/**
302+
* Remove filters when product is duplication
303+
*/
304+
public function remove_filters() {
305+
remove_filter( 'woocommerce_product_get_name', 'wpm_translate_string' );
306+
remove_filter( 'woocommerce_product_get_description', 'wpm_translate_string' );
307+
remove_filter( 'woocommerce_product_get_short_description', 'wpm_translate_string' );
308+
remove_filter( 'woocommerce_product_title', 'wpm_translate_string' );
309+
}
298310
}

includes/wpm-translation-functions.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ function wpm_translate_url( $url, $language = '' ) {
4747
$url = remove_query_arg( 'lang', $url );
4848
$default_uri = str_replace( $host, '', $url );
4949
$default_uri = $default_uri ? $default_uri : '/';
50-
$pattern = '!^/([a-z]{2})(/|$)!i';
50+
$languages = wpm_get_languages();
51+
$parts = explode( '/', ltrim( trailingslashit( $default_uri ), '/' ) );
52+
$url_lang = $parts[0];
5153

52-
if ( preg_match( $pattern, $default_uri ) ) {
53-
$default_uri = preg_replace( $pattern, '/', $default_uri );
54+
if ( isset( $languages[ $url_lang ] ) ) {
55+
$default_uri = preg_replace( '!^/' . $url_lang . '(/|$)!i', '/', $default_uri );
5456
}
5557

5658
$default_language = wpm_get_default_language();
@@ -83,7 +85,7 @@ function wpm_translate_url( $url, $language = '' ) {
8385
*/
8486
function wpm_translate_string( $string, $language = '' ) {
8587

86-
if ( is_serialized_string( $string ) || json_decode( $string ) ) {
88+
if ( ! is_string( $string ) || is_serialized_string( $string ) || json_decode( $string ) ) {
8789
return $string;
8890
}
8991

@@ -160,7 +162,7 @@ function wpm_string_to_ml_array( $string ) {
160162
}
161163

162164
$string = htmlspecialchars_decode( $string );
163-
$blocks = preg_split( '#(<!--:[a-z]{2}-->|<!--:-->|\[:[a-z]{2}\]|\[:\]|\{:[a-z]{2}\}|\{:\})#ism', $string, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
165+
$blocks = preg_split( '#(<!--:[a-z-]+-->|<!--:-->|\[:[a-z-]+\]|\[:\]|\{:[a-z-]+\}|\{:\})#ism', $string, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
164166

165167
if ( empty( $blocks ) || count( $blocks ) === 1 ) {
166168
return $string;
@@ -177,15 +179,15 @@ function wpm_string_to_ml_array( $string ) {
177179
$language = '';
178180
foreach ( $blocks as $block ) {
179181

180-
if ( preg_match( '#^<!--:([a-z]{2})-->$#ism', $block, $matches ) ) {
182+
if ( preg_match( '#^<!--:([a-z-]+)-->$#ism', $block, $matches ) ) {
181183
$language = $matches[1];
182184
continue;
183185

184-
} elseif ( preg_match( '#^\[:([a-z]{2})\]$#ism', $block, $matches ) ) {
186+
} elseif ( preg_match( '#^\[:([a-z-]+)\]$#ism', $block, $matches ) ) {
185187
$language = $matches[1];
186188
continue;
187189

188-
} elseif ( preg_match( '#^\{:([a-z]{2})\}$#ism', $block, $matches ) ) {
190+
} elseif ( preg_match( '#^\{:([a-z-]+)\}$#ism', $block, $matches ) ) {
189191
$language = $matches[1];
190192
continue;
191193
}
@@ -434,8 +436,11 @@ function wpm_translate_term( $term, $taxonomy, $lang = '' ) {
434436
return wpm_translate_object( $term, $lang );
435437
}
436438

437-
return wpm_translate_value( $term, $lang );
439+
if ( is_array( $term ) ) {
440+
return wpm_translate_value( $term, $lang );
441+
}
438442

443+
return $term;
439444
}
440445

441446

@@ -497,7 +502,7 @@ function wpm_is_ml_array( $array ) {
497502
*/
498503
function wpm_is_ml_string( $string ) {
499504

500-
if ( is_array( $string ) || is_bool( $string ) || is_serialized_string( $string ) || json_decode( $string ) ) {
505+
if ( ! is_string( $string ) || is_serialized_string( $string ) || json_decode( $string ) ) {
501506
return false;
502507
}
503508

@@ -547,7 +552,7 @@ function wpm_is_ml_value( $value ) {
547552
*/
548553
function wpm_set_new_value( $old_value, $new_value, $config = array(), $lang = '' ) {
549554

550-
if ( is_bool( $old_value ) || is_serialized_string( $old_value ) || json_decode( $old_value ) ) {
555+
if ( is_bool( $old_value ) || is_serialized_string( $old_value ) || ( is_string( $old_value ) && json_decode( $old_value ) ) ) {
551556
return $old_value;
552557
}
553558

0 commit comments

Comments
 (0)