PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 14.4
Jetpack – WP Security, Backup, Speed, & Growth v14.4
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / 3rd-party / wpml.php

wpml.php in Jetpack – WP Security, Backup, Speed, & Growth 14.4, at 3rd-party/wpml.php

62 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Only load these if WPML plugin is installed and active.
4 *
5 * @package automattic/jetpack
6 */
7
8 /**
9 * Load routines only if WPML is loaded.
10 *
11 * @since 4.4.0
12 */
13 function wpml_jetpack_init() {
14 add_action( 'jetpack_widget_get_top_posts', 'wpml_jetpack_widget_get_top_posts', 10, 3 );
15 add_filter( 'grunion_contact_form_field_html', 'grunion_contact_form_field_html_filter', 10, 3 );
16 }
17 add_action( 'wpml_loaded', 'wpml_jetpack_init' );
18
19 /**
20 * Filter the Top Posts and Pages by language.
21 *
22 * @param array $posts Array of the most popular posts.
23 *
24 * @return array
25 */
26 function wpml_jetpack_widget_get_top_posts( $posts ) {
27 global $sitepress;
28
29 foreach ( $posts as $k => $post ) {
30 $lang_information = wpml_get_language_information( $post['post_id'] );
31 if ( ! is_wp_error( $lang_information ) ) {
32 $post_language = substr( $lang_information['locale'], 0, 2 );
33 if ( $post_language !== $sitepress->get_current_language() ) {
34 unset( $posts[ $k ] );
35 }
36 }
37 }
38
39 return $posts;
40 }
41
42 /**
43 * Filter the HTML of the Contact Form and output the one requested by language.
44 *
45 * @param string $r Contact Form HTML output.
46 * @param string $field_label Field label.
47 *
48 * @return string
49 */
50 function grunion_contact_form_field_html_filter( $r, $field_label ) {
51 global $sitepress;
52
53 if ( function_exists( 'icl_translate' ) ) {
54 if ( $sitepress->get_current_language() !== $sitepress->get_default_language() ) {
55 $label_translation = icl_translate( 'jetpack ', $field_label . '_label', $field_label );
56 $r = str_replace( $field_label, $label_translation, $r );
57 }
58 }
59
60 return $r;
61 }
62