debug-bar
5 years ago
3rd-party.php
5 years ago
bbpress.php
5 years ago
beaverbuilder.php
5 years ago
bitly.php
5 years ago
buddypress.php
5 years ago
class-domain-mapping.php
5 years ago
class-jetpack-bbpress-rest-api.php
5 years ago
class-jetpack-crm-data.php
5 years ago
class-jetpack-modules-overrides.php
5 years ago
class.jetpack-amp-support.php
5 years ago
creative-mail.php
5 years ago
crowdsignal.php
5 years ago
debug-bar.php
5 years ago
qtranslate-x.php
5 years ago
vaultpress.php
5 years ago
web-stories.php
5 years ago
woocommerce-services.php
5 years ago
woocommerce.php
5 years ago
wpml.php
5 years ago
wpml.php
62 lines
| 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 |