PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.16.6
Translate and Go multilingual – Automatic AI translation – wpLingua v2.16.6
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 1.1.1 All 111 releases
wplingua / inc / dom / replace-links.php

replace-links.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.16.6, at inc/dom/replace-links.php

76 lines 1.3 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 links in dom for translated pages
11 *
12 * @param object $dom
13 * @param array $args
14 * @return object
15 */
16 function wplng_dom_replace_links( $dom, $args ) {
17
18 wplng_args_setup( $args );
19
20 /**
21 * Translate and replace links
22 */
23
24 $attr_url_to_translate = wplng_data_attr_url_to_translate();
25
26 foreach ( $attr_url_to_translate as $attr ) {
27
28 foreach ( $dom->find( $attr['selector'] ) as $element ) {
29
30 if ( empty( $element->attr[ $attr['attr'] ] ) ) {
31 continue;
32 }
33
34 $link = sanitize_url( $element->attr[ $attr['attr'] ] );
35
36 $translated_url = wplng_url_translate(
37 $link,
38 $args['language_target']
39 );
40
41 $element->setAttribute(
42 $attr['attr'],
43 esc_url( $translated_url )
44 );
45
46 }
47 }
48
49 /**
50 * Apply "link & media" rules and replace links
51 */
52
53 foreach ( $dom->find( 'img[srcset]' ) as $element ) {
54
55 if ( empty( $element->attr['srcset'] ) ) {
56 continue;
57 }
58
59 $link = $element->attr['srcset'];
60
61 $url_link_media_applied = wplng_link_media_apply_rules(
62 $link,
63 $args['language_target']
64 );
65
66 if ( $url_link_media_applied !== $link ) {
67 $element->setAttribute(
68 'srcset',
69 esc_attr( $url_link_media_applied )
70 );
71 }
72 }
73
74 return $dom;
75 }
76