PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.14.2
Translate and Go multilingual – Automatic AI translation – wpLingua v2.14.2
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 / admin / assets.php

assets.php in Translate and Go multilingual – Automatic AI translation – wpLingua 2.14.2, at inc/admin/assets.php

557 lines 10.5 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 * Register wpLingua assets for option page : Settings
11 *
12 * @param string $hook
13 * @return void
14 */
15 function wplng_option_page_settings_assets( $hook ) {
16
17 if ( ! is_admin()
18 || $hook !== 'toplevel_page_wplingua-settings'
19 || empty( wplng_get_api_key() )
20 ) {
21 return;
22 }
23
24 /**
25 * Enqueue jQuery
26 */
27
28 wp_enqueue_script( 'jquery' );
29
30 /**
31 * Enqueue wpLingua JS scripts
32 */
33
34 wp_enqueue_script(
35 'wplingua-option',
36 plugins_url() . '/wplingua/assets/js/admin/option-page.js',
37 array( 'jquery' ),
38 WPLNG_PLUGIN_VERSION
39 );
40
41 wp_enqueue_script(
42 'wplingua-option-settings',
43 plugins_url() . '/wplingua/assets/js/admin/option-page-settings.js',
44 array( 'jquery' ),
45 WPLNG_PLUGIN_VERSION
46 );
47
48 /**
49 * Enqueue wpLingua CSS styles
50 */
51
52 wp_enqueue_style(
53 'wplingua-option-settings',
54 plugins_url() . '/wplingua/assets/css/admin/option-page-settings.css',
55 array(),
56 WPLNG_PLUGIN_VERSION
57 );
58 }
59
60
61 /**
62 * Register wpLingua assets for option page : Register
63 *
64 * @param string $hook
65 * @return void
66 */
67 function wplng_option_page_register_assets( $hook ) {
68
69 if ( ! is_admin()
70 || $hook !== 'toplevel_page_wplingua-settings'
71 ) {
72 return;
73 }
74
75 /**
76 * Enqueue jQuery
77 */
78
79 wp_enqueue_script( 'jquery' );
80
81 /**
82 * Enqueue wpLingua JS scripts
83 */
84
85 wp_enqueue_script(
86 'wplingua-option',
87 plugins_url() . '/wplingua/assets/js/admin/option-page.js',
88 array( 'jquery' ),
89 WPLNG_PLUGIN_VERSION
90 );
91
92 wp_enqueue_script(
93 'wplingua-option-register',
94 plugins_url() . '/wplingua/assets/js/admin/option-page-register.js',
95 array( 'jquery' ),
96 WPLNG_PLUGIN_VERSION
97 );
98
99 /**
100 * Enqueue wpLingua CSS styles
101 */
102
103 wp_enqueue_style(
104 'wplingua-option-register',
105 plugins_url() . '/wplingua/assets/css/admin/option-page-register.css',
106 array(),
107 WPLNG_PLUGIN_VERSION
108 );
109 }
110
111
112 /**
113 * Register wpLingua assets for option page : Switcher
114 *
115 * @param string $hook The current admin page hook.
116 * @return void
117 */
118 function wplng_option_page_switcher_assets( $hook ) {
119
120 if ( ! is_admin()
121 || $hook !== 'wplingua_page_wplingua-switcher'
122 ) {
123 return;
124 }
125
126 /**
127 * Enqueue jQuery
128 */
129
130 wp_enqueue_script( 'jquery' );
131
132 /**
133 * Enqueue wpLingua JS scripts
134 */
135
136 wp_enqueue_script(
137 'wplingua-option-switcher',
138 plugins_url() . '/wplingua/assets/js/admin/option-page-switcher.js',
139 array( 'jquery' ),
140 WPLNG_PLUGIN_VERSION
141 );
142
143 wp_enqueue_script(
144 'wplingua-option',
145 plugins_url() . '/wplingua/assets/js/admin/option-page.js',
146 array( 'jquery' ),
147 WPLNG_PLUGIN_VERSION
148 );
149
150 wp_enqueue_script(
151 'wplingua-script',
152 plugins_url() . '/wplingua/assets/js/front.js',
153 array(),
154 WPLNG_PLUGIN_VERSION
155 );
156
157 /**
158 * Enqueue wpLingua CSS styles
159 */
160
161 wp_enqueue_style(
162 'wplingua-option-switcher',
163 plugins_url() . '/wplingua/assets/css/admin/option-page-switcher.css',
164 array(),
165 WPLNG_PLUGIN_VERSION
166 );
167
168 wp_enqueue_style(
169 'wplingua',
170 plugins_url() . '/wplingua/assets/css/front.css',
171 array(),
172 WPLNG_PLUGIN_VERSION
173 );
174
175 /**
176 * Enqueue CSS and JS for the code editor
177 */
178
179 if ( function_exists( 'wp_enqueue_code_editor' ) ) {
180 $cm_settings = array();
181 $cm_settings['codeEditor'] = wp_enqueue_code_editor(
182 array(
183 'type' => 'text/css',
184 'codemirror' => array(
185 'lineWrapping' => true,
186 ),
187 )
188 );
189
190 wp_localize_script( 'jquery', 'cm_settings', $cm_settings );
191 wp_enqueue_script( 'wp-theme-plugin-editor' );
192 wp_enqueue_style( 'wp-codemirror' );
193 }
194
195 /**
196 * Add inline style for wpLingua custom CSS
197 */
198
199 $custom_css = get_option( 'wplng_custom_css' );
200
201 if ( ! empty( $custom_css )
202 && is_string( $custom_css )
203 ) {
204 $custom_css = wp_strip_all_tags( $custom_css );
205 // Prevent breaking out of the <style> context
206 $custom_css = str_replace( '</style', '', $custom_css );
207 wp_add_inline_style( 'wplingua', $custom_css );
208 }
209 }
210
211
212 /**
213 * Register wpLingua assets for option page : Exclusions
214 *
215 * @param string $hook
216 * @return void
217 */
218 function wplng_option_page_exclusions_assets( $hook ) {
219
220 if ( ! is_admin()
221 || $hook !== 'wplingua_page_wplingua-exclusions'
222 ) {
223 return;
224 }
225
226 /**
227 * Enqueue jQuery
228 */
229
230 wp_enqueue_script( 'jquery' );
231
232 /**
233 * Enqueue wpLingua CSS styles
234 */
235
236 wp_enqueue_style(
237 'wplingua-option-exclusions',
238 plugins_url() . '/wplingua/assets/css/admin/option-page-exclusions.css',
239 array(),
240 WPLNG_PLUGIN_VERSION
241 );
242 }
243
244
245 /**
246 * Register wpLingua assets for option page : Links & Medias
247 *
248 * @param string $hook
249 * @return void
250 */
251 function wplng_option_page_link_media_assets( $hook ) {
252
253 if ( ! is_admin()
254 || $hook !== 'wplingua_page_wplingua-link-media'
255 ) {
256 return;
257 }
258
259 /**
260 * Enqueue jQuery
261 */
262
263 wp_enqueue_script( 'jquery' );
264
265 /**
266 * Enqueue wpLingua JS scripts
267 */
268
269 wp_enqueue_script(
270 'wplingua-option',
271 plugins_url() . '/wplingua/assets/js/admin/option-page.js',
272 array( 'jquery' ),
273 WPLNG_PLUGIN_VERSION
274 );
275
276 wp_enqueue_script(
277 'wplingua-option-link-media',
278 plugins_url() . '/wplingua/assets/js/admin/option-page-link-media.js',
279 array( 'jquery' ),
280 WPLNG_PLUGIN_VERSION
281 );
282
283 /**
284 * Enqueue wpLingua CSS styles
285 */
286
287 wp_enqueue_style(
288 'wplingua-option-link-media',
289 plugins_url() . '/wplingua/assets/css/admin/option-page-link-media.css',
290 array(),
291 WPLNG_PLUGIN_VERSION
292 );
293 }
294
295
296 /**
297 * Register wpLingua assets for option page : Dictionary
298 *
299 * @param string $hook
300 * @return void
301 */
302 function wplng_option_page_dictionary_assets( $hook ) {
303
304 if ( ! is_admin()
305 || $hook !== 'wplingua_page_wplingua-dictionary'
306 ) {
307 return;
308 }
309
310 /**
311 * Enqueue jQuery
312 */
313
314 wp_enqueue_script( 'jquery' );
315
316 /**
317 * Enqueue wpLingua JS scripts
318 */
319
320 wp_enqueue_script(
321 'wplingua-option',
322 plugins_url() . '/wplingua/assets/js/admin/option-page.js',
323 array( 'jquery' ),
324 WPLNG_PLUGIN_VERSION
325 );
326
327 wp_enqueue_script(
328 'wplingua-option-dictionary',
329 plugins_url() . '/wplingua/assets/js/admin/option-page-dictionary.js',
330 array( 'jquery' ),
331 WPLNG_PLUGIN_VERSION
332 );
333
334 /**
335 * Enqueue wpLingua CSS styles
336 */
337
338 wp_enqueue_style(
339 'wplingua-option-dictionary',
340 plugins_url() . '/wplingua/assets/css/admin/option-page-dictionary.css',
341 array(),
342 WPLNG_PLUGIN_VERSION
343 );
344 }
345
346
347 /**
348 * Register wpLingua assets on translations edit pages
349 *
350 * @return void
351 */
352 function wplng_translation_edit_assets() {
353
354 global $post_type;
355
356 if ( 'wplng_translation' === $post_type ) {
357
358 /**
359 * Enqueue jQuery
360 */
361
362 wp_enqueue_script( 'jquery' );
363
364 /**
365 * Enqueue wpLingua JS scripts
366 */
367
368 wp_enqueue_script(
369 'wplingua-edit-translation',
370 plugins_url() . '/wplingua/assets/js/admin/edit-translation.js',
371 array( 'jquery' ),
372 WPLNG_PLUGIN_VERSION
373 );
374
375 /**
376 * Localize script
377 */
378
379 wp_localize_script(
380 'wplingua-edit-translation',
381 'wplngI18nTranslation',
382 array(
383 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
384 'currentLanguage' => false,
385 'message' => array(
386 'exitPage' => esc_html__(
387 'You are about to leave the page without saving your changes. They will be lost if you continue. Would you like to leave the page anyway?',
388 'wplingua'
389 ),
390 'exitEditorModal' => '',
391 'buttonSave' => '',
392 'buttonSaveInProgress' => '',
393 ),
394 )
395 );
396
397 /**
398 * Enqueue wpLingua CSS styles
399 */
400
401 wp_enqueue_style(
402 'wplingua-edit-translation',
403 plugins_url() . '/wplingua/assets/css/admin/edit-translation.css',
404 array(),
405 WPLNG_PLUGIN_VERSION
406 );
407
408 }
409 }
410
411
412
413 /**
414 * Register wpLingua assets on translations admin list
415 *
416 * @return void
417 */
418 function wplng_translation_list_assets() {
419
420 global $post_type;
421
422 if ( 'wplng_translation' === $post_type ) {
423
424 /**
425 * Enqueue wpLingua CSS styles
426 */
427
428 wp_enqueue_style(
429 'wplingua-list-translation',
430 plugins_url() . '/wplingua/assets/css/admin/list-translation.css',
431 array(),
432 WPLNG_PLUGIN_VERSION
433 );
434
435 }
436 }
437
438
439 /**
440 * Register wpLingua assets on slugs edit pages
441 *
442 * @return void
443 */
444 function wplng_slug_edit_assets() {
445
446 global $post_type;
447
448 if ( 'wplng_slug' === $post_type ) {
449
450 /**
451 * Enqueue jQuery
452 */
453
454 wp_enqueue_script( 'jquery' );
455
456 /**
457 * Enqueue wpLingua JS scripts
458 */
459
460 wp_enqueue_script(
461 'wplingua-edit-slug',
462 plugins_url() . '/wplingua/assets/js/admin/edit-slug.js',
463 array( 'jquery' ),
464 WPLNG_PLUGIN_VERSION
465 );
466
467 /**
468 * Localize script
469 */
470
471 wp_localize_script(
472 'wplingua-edit-slug',
473 'wplngI18nSlug',
474 array(
475 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
476 'currentLanguage' => false,
477 'message' => array(
478 'exitPage' => esc_html__(
479 'You are about to leave the page without saving your changes. They will be lost if you continue. Would you like to leave the page anyway?',
480 'wplingua'
481 ),
482 'exitEditorModal' => '',
483 'buttonSave' => '',
484 'buttonSaveInProgress' => '',
485 ),
486 )
487 );
488
489 /**
490 * Enqueue wpLingua CSS styles
491 */
492
493 wp_enqueue_style(
494 'wplingua-edit-slug',
495 plugins_url() . '/wplingua/assets/css/admin/edit-slug.css',
496 array(),
497 WPLNG_PLUGIN_VERSION
498 );
499
500 }
501 }
502
503
504 /**
505 * Register wpLingua assets on slugs admin list
506 *
507 * @return void
508 */
509 function wplng_slug_list_assets() {
510
511 global $post_type;
512
513 if ( 'wplng_slug' === $post_type ) {
514
515 /**
516 * Enqueue wpLingua CSS styles
517 */
518
519 wp_enqueue_style(
520 'wplingua-list-slug',
521 plugins_url() . '/wplingua/assets/css/admin/list-slug.css',
522 array(),
523 WPLNG_PLUGIN_VERSION
524 );
525
526 }
527 }
528
529
530 /**
531 * Print wpLingua head script (JSON with all languages informations)
532 *
533 * @return void
534 */
535 function wplng_inline_script_languages() {
536
537 $languages = array();
538 $languages_allow = wplng_get_languages_allow();
539
540 if ( ! empty( $languages_allow ) && is_array( $languages_allow ) ) {
541
542 $language_website = wplng_get_language_website();
543
544 if ( ! in_array( $language_website, $languages_allow, true ) ) {
545 $languages_allow[] = $language_website;
546 }
547
548 $languages = $languages_allow;
549
550 } else {
551 $languages = wplng_get_languages_all();
552 }
553
554 ?><script>var wplngAllLanguages = <?php echo wp_json_encode( $languages ); ?>;</script>
555 <?php
556 }
557