PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 1.0.5
Translate and Go multilingual – Automatic AI translation – wpLingua v1.0.5
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 / shortcode.php

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

110 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 ), $atts
42 );
43
44 switch ( $attributes['lang'] ) {
45 case false:
46 return '';
47 break;
48
49 case 'translated':
50 $languages = wplng_get_languages_target_ids();
51 break;
52
53 case 'original':
54 $languages = array( wplng_get_language_website_id() );
55 break;
56
57 default:
58 $languages_attr = explode( ',', $attributes['lang'] );
59
60 foreach ( $languages_attr as $language ) {
61 $language = trim( $language );
62 if ( wplng_is_valid_language_id( $language ) ) {
63 $languages[] = $language;
64 }
65 }
66 break;
67 }
68
69 if ( empty( $languages )
70 || ! in_array( $language_current, $languages )
71 ) {
72 return '';
73 }
74
75 $html = '<span class="notranslate">';
76 $html .= wp_kses_post( $content );
77 $html .= '</span>';
78
79 return $html;
80 }
81
82
83 /**
84 * wpLingua Shortcode : [wplng_switcher]
85 *
86 * @param array $atts
87 * @return string
88 */
89 function wplng_shortcode_switcher( $atts ) {
90
91 $attributes = shortcode_atts(
92 array(
93 'insert' => false,
94 'style' => false,
95 'title' => false,
96 'theme' => false,
97 'flags' => false,
98 'class' => false,
99 ), $atts
100 );
101
102 if ( ! empty( $attributes['class'] ) ) {
103 $attributes['class'] .= ' insert-shortcode';
104 } else {
105 $attributes['class'] = 'insert-shortcode';
106 }
107
108 return wplng_get_switcher_html( $attributes );
109 }
110