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 / shortcode.php

shortcode.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.16.6, at inc/shortcode.php

115 lines 2.0 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 * wpLingua Shortcode : [wplng_notranslate]
11 *
12 * @param array $atts
13 * @param string $content
14 * @return string
15 */
16 function wplng_shortcode_notranslate( $atts, $content ) {
17
18 $html = '<span class="notranslate">';
19 $html .= wp_kses_post( $content );
20 $html .= '</span>';
21
22 return $html;
23 }
24
25
26 /**
27 * wpLingua Shortcode : [wplng_only]
28 *
29 * @param array $atts
30 * @param string $content
31 * @return string
32 */
33 function wplng_shortcode_only( $atts, $content ) {
34
35 $languages = array();
36 $language_current = wplng_get_language_current_id();
37
38 $attributes = shortcode_atts(
39 array(
40 'lang' => false,
41 ),
42 $atts
43 );
44
45 switch ( $attributes['lang'] ) {
46 case false:
47 return '';
48 break;
49
50 case 'translated':
51 $languages = wplng_get_languages_target_ids();
52 break;
53
54 case 'original':
55 $languages = array( wplng_get_language_website_id() );
56 break;
57
58 default:
59 $languages_attr = explode( ',', $attributes['lang'] );
60
61 foreach ( $languages_attr as $language ) {
62 $language = trim( $language );
63 if ( wplng_is_valid_language_id( $language ) ) {
64 $languages[] = $language;
65 }
66 }
67 break;
68 }
69
70 if ( empty( $languages )
71 || ! in_array( $language_current, $languages )
72 ) {
73 return '';
74 }
75
76 $content = wp_kses_post( $content );
77 $content = do_shortcode( $content );
78
79 $html = '<span class="notranslate">';
80 $html .= $content;
81 $html .= '</span>';
82
83 return $html;
84 }
85
86
87 /**
88 * wpLingua Shortcode : [wplng_switcher]
89 *
90 * @param array $atts
91 * @return string
92 */
93 function wplng_shortcode_switcher( $atts ) {
94
95 $attributes = shortcode_atts(
96 array(
97 'insert' => false,
98 'style' => false,
99 'title' => false,
100 'theme' => false,
101 'flags' => false,
102 'class' => false,
103 ),
104 $atts
105 );
106
107 if ( ! empty( $attributes['class'] ) ) {
108 $attributes['class'] .= ' insert-shortcode';
109 } else {
110 $attributes['class'] = 'insert-shortcode';
111 }
112
113 return wplng_get_switcher_html( $attributes );
114 }
115