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

Commit 6ca0e34

Browse files
committed
Merge branch 'release/1.7.6'
2 parents ccaeee6 + 42c8a6c commit 6ca0e34

12 files changed

+150
-50
lines changed

configs/newsletter.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
"admin_page_newsletter_subscription_forms",
7676
"admin_page_newsletter_subscription_template",
7777
"newsletter_page_newsletter_main_main",
78-
"admin_page_newsletter_main_info"
78+
"admin_page_newsletter_main_info",
79+
"newsletter_page_newsletter_wpusers_index",
80+
"newsletter_page_newsletter_lock_index"
7981
]
8082
}

configs/woocommerce.json

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"woocommerce_page_wc-settings"
1818
],
1919
"options": {
20+
"woocommerce_store_address": {},
21+
"woocommerce_store_address_2": {},
22+
"woocommerce_store_city": {},
2023
"woocommerce_email_footer_text": {},
2124
"woocommerce_demo_store_notice": {},
2225
"woocommerce_price_thousand_sep": {},

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function language_columns( $columns ) {
7979
public function render_language_column( $columns, $column, $term_id ) {
8080

8181
if ( 'languages' === $column ) {
82-
remove_filter( 'get_term', 'wpm_translate_object', 0 );
82+
remove_filter( 'get_term', 'wpm_translate_term', 0 );
8383
$term = get_term( $term_id );
84-
add_filter( 'get_term', 'wpm_translate_object', 0 );
84+
add_filter( 'get_term', 'wpm_translate_term', 0, 2 );
8585
$output = array();
8686
$text = $term->name . $term->description;
8787
$strings = wpm_value_to_ml_array( $text );

core/class-wpm-posts.php

+2-18
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct() {
4545
add_filter( 'get_pages', array( $this, 'translate_posts' ), 0 );
4646
add_filter( 'posts_results', array( $this, 'translate_posts' ), 0 );
4747
add_action( 'parse_query', array( $this, 'filter_posts_by_language' ) );
48-
add_filter( 'the_post', array( $this, 'translate_post' ), 0 );
48+
add_filter( 'the_post', 'wpm_translate_post', 0 );
4949
add_filter( 'the_title', 'wpm_translate_string', 0 );
5050
add_filter( 'the_content', 'wpm_translate_string', 0 );
5151
add_filter( 'the_excerpt', 'wpm_translate_string', 0 );
@@ -64,22 +64,6 @@ public function __construct() {
6464
}
6565

6666

67-
/**
68-
* Translate post
69-
*
70-
* @param $post
71-
*
72-
* @return object
73-
*/
74-
public function translate_post( $post ) {
75-
if ( ! is_object( $post ) || ! isset( $this->post_config[ $post->post_type ] ) || is_null( $this->post_config[ $post->post_type ] ) ) {
76-
return $post;
77-
}
78-
79-
return wpm_translate_object( $post );
80-
}
81-
82-
8367
/**
8468
* Translate all posts
8569
*
@@ -88,7 +72,7 @@ public function translate_post( $post ) {
8872
* @return array
8973
*/
9074
public function translate_posts( $posts ) {
91-
return array_map( array( $this, 'translate_post' ), $posts );
75+
return array_map( 'wpm_translate_post', $posts );
9276
}
9377

9478

core/class-wpm-taxonomies.php

+17-20
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class WPM_Taxonomies extends \WPM_Object {
4949
public function __construct() {
5050
parent::__construct();
5151
$this->term_config = $this->config['taxonomies'];
52-
add_filter( 'get_term', array( $this, 'translate_term' ), 0 );
52+
add_filter( 'get_term', 'wpm_translate_term', 0, 2 );
5353
add_filter( 'get_terms', array( $this, 'translate_terms' ), 0 );
5454
add_filter( 'get_terms_args', array( $this, 'filter_terms_by_language' ), 10, 2 );
5555
add_filter( "get_{$this->object_type}_metadata", array( $this, 'get_meta_field' ), 0, 3 );
@@ -64,22 +64,6 @@ public function __construct() {
6464
}
6565

6666

67-
/**
68-
* Translate term
69-
*
70-
* @param $term
71-
*
72-
* @return object
73-
*/
74-
public function translate_term( $term ) {
75-
if ( ! is_object( $term ) || ! isset( $this->term_config[ $term->taxonomy ] ) || is_null( $this->term_config[ $term->taxonomy ] ) ) {
76-
return $term;
77-
}
78-
79-
return wpm_translate_object( $term );
80-
}
81-
82-
8367
/**
8468
* Translate all terms
8569
*
@@ -88,7 +72,20 @@ public function translate_term( $term ) {
8872
* @return array
8973
*/
9074
public function translate_terms( $terms ) {
91-
return array_map( array( $this, 'translate_term' ), $terms );
75+
76+
if ( is_array( $terms ) ) {
77+
$_terms = array();
78+
foreach ( $terms as $term ) {
79+
if ( is_object( $term ) ) {
80+
$_terms[] = $term;
81+
} else {
82+
$_terms[] = wpm_translate_value( $term );
83+
}
84+
}
85+
$terms = $_terms;
86+
}
87+
88+
return $terms;
9289
}
9390

9491

@@ -253,10 +250,10 @@ public function update_term( $data, $term_id, $taxonomy, $args ) {
253250
return $data;
254251
}
255252

256-
remove_filter( 'get_term', 'wpm_translate_object', 0 );
253+
remove_filter( 'get_term', 'wpm_translate_term', 0 );
257254
$old_name = get_term_field( 'name', $term_id, $taxonomy, 'edit' );
258255
$old_description = get_term_field( 'description', $term_id, $taxonomy, 'edit' );
259-
add_filter( 'get_term', 'wpm_translate_object', 0 );
256+
add_filter( 'get_term', 'wpm_translate_term', 0, 2 );
260257

261258
if ( ! wpm_is_ml_value( $data['name'] ) ) {
262259
$strings = wpm_value_to_ml_array( $old_name );

core/vendor/class-wpm-buddypress.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function save_field_description( $description ) {
216216
* @return array
217217
*/
218218
public function remove_filter( $children ) {
219-
remove_filter( 'attribute_escape', 'WPM\Core\WPM_Posts::escaping_text', 0 );
219+
remove_filter( 'attribute_escape', array( 'WPM\Core\WPM_Posts', 'escaping_text' ), 0 );
220220

221221
return $children;
222222
}

core/vendor/class-wpm-newsletter.php

+20-3
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,33 @@ public function add_notice() {
5252
$screen_id = $screen ? $screen->id : '';
5353

5454
if ( 'admin_page_newsletter_emails_edit' === $screen_id ) {
55-
remove_filter( 'attribute_escape', 'WPM\Core\WPM_Posts::escaping_text', 0 );
56-
remove_filter( 'esc_textarea', 'WPM\Core\WPM_Posts::escaping_text', 0 );
57-
remove_filter( 'esc_html', 'WPM\Core\WPM_Posts::escaping_text', 0 );
55+
remove_filter( 'attribute_escape', array( 'WPM\Core\WPM_Posts', 'escaping_text' ), 0 );
56+
remove_filter( 'esc_textarea', array( 'WPM\Core\WPM_Posts', 'escaping_text' ), 0 );
57+
remove_filter( 'esc_html', array( 'WPM\Core\WPM_Posts', 'escaping_text' ), 0 );
5858
wpm_show_notice();
5959
}
6060
}
6161

6262

63+
/**
64+
* Translate options
65+
*/
6366
public function translate_options(){
6467
\NewsletterSubscription::instance()->options = wpm_translate_value( \NewsletterSubscription::instance()->options );
68+
69+
/**
70+
* Compatibility with extension WP Users Integration
71+
*/
72+
if ( class_exists( 'NewsletterWpUsers' ) ) {
73+
\NewsletterWpUsers::$instance->options = wpm_translate_value( \NewsletterWpUsers::$instance->options );
74+
}
75+
76+
/**
77+
* Compatibility with extension Locked Content
78+
*/
79+
if (class_exists( 'NewsletterLock')) {
80+
\NewsletterLock::$instance->options = wpm_translate_value( \NewsletterLock::$instance->options );
81+
}
6582
}
6683
}
6784

core/vendor/class-wpm-yoast-seo.php

+30
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,25 @@ public function __construct() {
3030
add_filter( 'wpm_option_wpseo_titles_config', array( $this, 'set_posts_config' ) );
3131
add_filter( 'wpseo_title', 'wpm_translate_string', 0 );
3232
remove_filter( 'update_post_metadata', array( 'WPSEO_Meta', 'remove_meta_if_default' ), 10 );
33+
add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_false' );
3334
add_filter( 'wpseo_sitemap_url', array( $this, 'add_alternate_sitemaplinks' ), 10, 2 );
35+
add_filter( 'wpseo_sitemap_entry', function($url, $type, $object){
36+
switch ($type) {
37+
case 'post':
38+
$languages = get_post_meta( $object->ID, '_languages', true );
39+
if ($languages) {
40+
$url['languages'] = $languages;
41+
}
42+
break;
43+
case 'term':
44+
$languages = get_term_meta( $object->term_id, '_languages', true );
45+
if ($languages) {
46+
$url['languages'] = $languages;
47+
}
48+
break;
49+
}
50+
return $url;
51+
},10,3);
3452
}
3553

3654

@@ -83,12 +101,24 @@ public function set_posts_config( $config ) {
83101
public function add_alternate_sitemaplinks( $output, $url ) {
84102
$loc = $output;
85103
$new_output = '';
104+
86105
foreach ( wpm_get_languages() as $locale => $language ) {
106+
107+
if ( isset( $url['languages'] ) && ! in_array( $language, $url['languages'] ) ) {
108+
continue;
109+
}
110+
87111
$alternate = '';
88112
$new_loc = str_replace( $url['loc'], esc_url( wpm_translate_url( $url['loc'], $language ) ), $loc );
113+
89114
foreach ( wpm_get_languages() as $lc => $lg ) {
115+
if ( isset( $url['languages'] ) && ! in_array( $lg, $url['languages'] ) ) {
116+
continue;
117+
}
118+
90119
$alternate .= sprintf( "\t<xhtml:link rel=\"alternate\" hreflang=\"%s\" href=\"%s\" />\n\t", esc_attr( str_replace( '_', '-', strtolower( $lc ) ) ), esc_url( wpm_translate_url( $url['loc'], $lg ) ) );
91120
}
121+
92122
$alternate .= '</url>';
93123
$new_loc = str_replace( '</url>', $alternate, $new_loc );
94124
$new_output .= $new_loc;

core/wpm-template-functions.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,29 @@ function wpm_language_switcher( $args = array(), $echo = true ) {
128128
*/
129129
function wpm_set_meta_languages() {
130130
$current_url = wpm_get_current_url();
131+
132+
$languages = array();
133+
if ( is_single() ) {
134+
$languages = get_post_meta( get_the_ID(), '_languages', true );
135+
}
136+
137+
if ( is_category() || is_tag() || is_tax() ) {
138+
$languages = get_term_meta( get_queried_object_id(), '_languages', true );
139+
}
140+
131141
foreach ( wpm_get_languages() as $locale => $language ) {
132-
if ( get_locale() != $locale ) {
133-
printf( '<link rel="alternate" hreflang="%s" href="%s"/>', esc_attr( str_replace( '_', '-', strtolower( $locale ) ) ), esc_url( wpm_translate_url( $current_url, $language ) ) );
142+
143+
if ( $languages && ! in_array( $language, $languages ) ) {
144+
continue;
134145
}
135146

136147
if ( wpm_get_default_locale() == $locale ) {
137148
printf( '<link rel="alternate" hreflang="x-default" href="%s"/>', esc_url( wpm_translate_url( $current_url, $language ) ) );
138149
}
150+
151+
if ( get_locale() != $locale ) {
152+
printf( '<link rel="alternate" hreflang="%s" href="%s"/>', esc_attr( str_replace( '_', '-', strtolower( $locale ) ) ), esc_url( wpm_translate_url( $current_url, $language ) ) );
153+
}
139154
}
140155
}
141156

core/wpm-translation-functions.php

+46
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,52 @@ function wpm_translate_object( $object, $lang = '' ) {
392392
return $object;
393393
}
394394

395+
396+
/**
397+
* Translate post
398+
*
399+
* @param $post
400+
*
401+
* @return object WP_Post
402+
*/
403+
function wpm_translate_post( $post ) {
404+
$config = wpm_get_config();
405+
$post_config = $config['post_types'];
406+
407+
if ( ! is_object( $post ) || ! isset( $post_config[ $post->post_type ] ) || is_null( $post_config[ $post->post_type ] ) ) {
408+
return $post;
409+
}
410+
411+
return wpm_translate_object( $post );
412+
}
413+
414+
415+
/**
416+
* Translate term
417+
*
418+
* @param $term
419+
*
420+
* @param $taxonomy
421+
*
422+
* @return object WP_Term
423+
*/
424+
function wpm_translate_term( $term, $taxonomy ) {
425+
$config = wpm_get_config();
426+
$term_config = $config['taxonomies'];
427+
428+
if ( ! isset( $term_config[ $taxonomy ] ) || is_null( $term_config[ $taxonomy ] ) ) {
429+
return $term;
430+
}
431+
432+
if ( is_object( $term ) ) {
433+
return wpm_translate_object( $term );
434+
}
435+
436+
return wpm_translate_value( $term );
437+
438+
}
439+
440+
395441
/**
396442
* Untranslate WP_Post object
397443
*

readme.txt

+7-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.2
7-
Stable tag: 1.7.5
7+
Stable tag: 1.7.6
88
Requires PHP: 5.6
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -169,6 +169,12 @@ If you have opened several browser tabs for editing this post in different langu
169169

170170
== Changelog ==
171171

172+
= 1.7.6 =
173+
+ add check for alternate metalinks in head for separated term and posts
174+
+ add separating posts and terms by language in Yoast Sitemap
175+
+ added compatibility with Newsletter free extensions
176+
* fix save terms translation
177+
172178
= 1.7.5 =
173179
+ add links on other languages to Yoast Sitemap
174180
+ add translating gallery widget from WP4.9

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.7.5
11+
* Version: 1.7.6
1212
*
1313
* @package WPM
1414
* @category Core
@@ -40,7 +40,7 @@ final class WP_Multilang {
4040
*
4141
* @var string
4242
*/
43-
public $version = '1.7.5';
43+
public $version = '1.7.6';
4444

4545
/**
4646
* The single instance of the class.

0 commit comments

Comments
 (0)