1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Only load these if WPML plugin is installed and active. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Load routines only if WPML is loaded. |
8
|
|
|
* |
9
|
|
|
* @since 4.4.0 |
10
|
|
|
*/ |
11
|
|
|
function wpml_jetpack_init() { |
12
|
|
|
add_action( 'jetpack_widget_get_top_posts', 'wpml_jetpack_widget_get_top_posts', 10, 3 ); |
13
|
|
|
add_filter( 'grunion_contact_form_field_html', 'grunion_contact_form_field_html_filter', 10, 3 ); |
14
|
|
|
} |
15
|
|
|
add_action( 'wpml_loaded', 'wpml_jetpack_init' ); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Filter the Top Posts and Pages by language. |
19
|
|
|
* |
20
|
|
|
* @param array $posts Array of the most popular posts. |
21
|
|
|
* @param array $post_ids Array of Post IDs. |
22
|
|
|
* @param string $count Number of Top Posts we want to display. |
23
|
|
|
* |
24
|
|
|
* @return array |
25
|
|
|
*/ |
26
|
|
|
function wpml_jetpack_widget_get_top_posts( $posts, $post_ids, $count ) { |
|
|
|
|
27
|
|
|
global $sitepress; |
28
|
|
|
|
29
|
|
|
foreach ( $posts as $k => $post ) { |
30
|
|
|
$lang_information = wpml_get_language_information( $post['post_id'] ); |
31
|
|
|
$post_language = substr( $lang_information['locale'], 0, 2 ); |
32
|
|
|
if ( $post_language !== $sitepress->get_current_language() ) { |
33
|
|
|
unset( $posts[ $k ] ); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return $posts; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Filter the HTML of the Contact Form and output the one requested by language. |
42
|
|
|
* |
43
|
|
|
* @param string $r Contact Form HTML output. |
44
|
|
|
* @param string $field_label Field label. |
45
|
|
|
* @param int|null $id Post ID. |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
function grunion_contact_form_field_html_filter( $r, $field_label, $id ){ |
|
|
|
|
50
|
|
|
global $sitepress; |
51
|
|
|
|
52
|
|
|
if ( function_exists( 'icl_translate' ) ) { |
53
|
|
|
if ( $sitepress->get_current_language() !== $sitepress->get_default_language() ) { |
54
|
|
|
$label_translation = icl_translate( 'jetpack ', $field_label . '_label', $field_label ); |
55
|
|
|
$r = str_replace( $field_label, $label_translation, $r ); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $r; |
60
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.