PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.16.7
Translate and Go multilingual – Automatic AI translation – wpLingua v2.16.7
2.16.7 2.16.6 2.16.5 2.16.4 2.16.3 2.16.2 2.16.1 2.16.0 2.15.2 2.15.1 2.15.0 2.14.3 2.14.2 2.14.1 2.14.0 2.13.1 2.13.0 2.12.3 2.12.2 2.12.1 trunk 1.0.3 1.0.4 1.0.5 1.1.0 All 112 releases
wplingua / inc / dom / replace-body-class.php

replace-body-class.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.16.7, at inc/dom/replace-body-class.php

54 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8
9 /**
10 * Modify the body class in dom for translated pages
11 *
12 * @param object $dom
13 * @param array $args
14 * @return object
15 */
16 function wplng_dom_replace_body_class( $dom, $args ) {
17
18 wplng_args_setup( $args );
19
20 // Replace languages IDs in <body> class
21 foreach ( $dom->find( 'body' ) as $element ) {
22
23 $class_array = ! empty( $element->class ) ? explode( ' ', $element->class ) : array();
24
25 foreach ( $class_array as $key => $class ) {
26 if ( wplng_str_is_locale_id( $class ) ) {
27 $class_array[ $key ] = $args['language_target'];
28 } elseif ( 'ltr' === $class || 'rtl' === $class ) {
29 $class_array[ $key ] = $args['language_target_dir'];
30 }
31 }
32
33 $class_array[] = 'wplingua-translated';
34
35 global $wplng_class_reload;
36
37 if ( true === $wplng_class_reload ) {
38 $class_array[] = 'wplingua-reload';
39 }
40
41 $class_array = array_unique( $class_array ); // Remove duplicate
42 $class_str = '';
43
44 foreach ( $class_array as $class ) {
45 $class_str .= $class . ' ';
46 }
47
48 $class_str = trim( $class_str );
49 $element->class = esc_attr( $class_str );
50 }
51
52 return $dom;
53 }
54