PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 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 All 502 releases
jetpack / 3rd-party / wpml.php

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

66 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 if ( ! defined( 'ABSPATH' ) ) {
9 exit( 0 );
10 }
11
12 /**
13 * Load routines only if WPML is loaded.
14 *
15 * @since 4.4.0
16 */
17 function wpml_jetpack_init() {
18 add_action( 'jetpack_widget_get_top_posts', 'wpml_jetpack_widget_get_top_posts', 10, 3 );
19 add_filter( 'grunion_contact_form_field_html', 'grunion_contact_form_field_html_filter', 10, 3 );
20 }
21 add_action( 'wpml_loaded', 'wpml_jetpack_init' );
22
23 /**
24 * Filter the Top Posts and Pages by language.
25 *
26 * @param array $posts Array of the most popular posts.
27 *
28 * @return array
29 */
30 function wpml_jetpack_widget_get_top_posts( $posts ) {
31 global $sitepress;
32
33 foreach ( $posts as $k => $post ) {
34 $lang_information = wpml_get_language_information( $post['post_id'] );
35 if ( ! is_wp_error( $lang_information ) ) {
36 $post_language = substr( $lang_information['locale'], 0, 2 );
37 if ( $post_language !== $sitepress->get_current_language() ) {
38 unset( $posts[ $k ] );
39 }
40 }
41 }
42
43 return $posts;
44 }
45
46 /**
47 * Filter the HTML of the Contact Form and output the one requested by language.
48 *
49 * @param string $r Contact Form HTML output.
50 * @param string $field_label Field label.
51 *
52 * @return string
53 */
54 function grunion_contact_form_field_html_filter( $r, $field_label ) {
55 global $sitepress;
56
57 if ( function_exists( 'icl_translate' ) ) {
58 if ( $sitepress->get_current_language() !== $sitepress->get_default_language() ) {
59 $label_translation = icl_translate( 'jetpack ', $field_label . '_label', $field_label );
60 $r = str_replace( $field_label, $label_translation, $r );
61 }
62 }
63
64 return $r;
65 }
66