PluginProbe
Translate and Go multilingual – Automatic AI translation – wpLingua / 2.13.0
Translate and Go multilingual – Automatic AI translation – wpLingua v2.13.0
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.13.0, at inc/admin/assets.php

552 lines 10.4 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( 'type' => 'text/css' )
183 );
184
185 wp_localize_script( 'jquery', 'cm_settings', $cm_settings );
186 wp_enqueue_script( 'wp-theme-plugin-editor' );
187 wp_enqueue_style( 'wp-codemirror' );
188 }
189
190 /**
191 * Add inline style for wpLingua custom CSS
192 */
193
194 $custom_css = get_option( 'wplng_custom_css' );
195
196 if ( ! empty( $custom_css )
197 && is_string( $custom_css )
198 ) {
199 $custom_css = wp_strip_all_tags( $custom_css );
200 // Prevent breaking out of the <style> context
201 $custom_css = str_replace( '</style', '', $custom_css );
202 wp_add_inline_style( 'wplingua', $custom_css );
203 }
204 }
205
206
207 /**
208 * Register wpLingua assets for option page : Exclusions
209 *
210 * @param string $hook
211 * @return void
212 */
213 function wplng_option_page_exclusions_assets( $hook ) {
214
215 if ( ! is_admin()
216 || $hook !== 'wplingua_page_wplingua-exclusions'
217 ) {
218 return;
219 }
220
221 /**
222 * Enqueue jQuery
223 */
224
225 wp_enqueue_script( 'jquery' );
226
227 /**
228 * Enqueue wpLingua CSS styles
229 */
230
231 wp_enqueue_style(
232 'wplingua-option-exclusions',
233 plugins_url() . '/wplingua/assets/css/admin/option-page-exclusions.css',
234 array(),
235 WPLNG_PLUGIN_VERSION
236 );
237 }
238
239
240 /**
241 * Register wpLingua assets for option page : Links & Medias
242 *
243 * @param string $hook
244 * @return void
245 */
246 function wplng_option_page_link_media_assets( $hook ) {
247
248 if ( ! is_admin()
249 || $hook !== 'wplingua_page_wplingua-link-media'
250 ) {
251 return;
252 }
253
254 /**
255 * Enqueue jQuery
256 */
257
258 wp_enqueue_script( 'jquery' );
259
260 /**
261 * Enqueue wpLingua JS scripts
262 */
263
264 wp_enqueue_script(
265 'wplingua-option',
266 plugins_url() . '/wplingua/assets/js/admin/option-page.js',
267 array( 'jquery' ),
268 WPLNG_PLUGIN_VERSION
269 );
270
271 wp_enqueue_script(
272 'wplingua-option-link-media',
273 plugins_url() . '/wplingua/assets/js/admin/option-page-link-media.js',
274 array( 'jquery' ),
275 WPLNG_PLUGIN_VERSION
276 );
277
278 /**
279 * Enqueue wpLingua CSS styles
280 */
281
282 wp_enqueue_style(
283 'wplingua-option-link-media',
284 plugins_url() . '/wplingua/assets/css/admin/option-page-link-media.css',
285 array(),
286 WPLNG_PLUGIN_VERSION
287 );
288 }
289
290
291 /**
292 * Register wpLingua assets for option page : Dictionary
293 *
294 * @param string $hook
295 * @return void
296 */
297 function wplng_option_page_dictionary_assets( $hook ) {
298
299 if ( ! is_admin()
300 || $hook !== 'wplingua_page_wplingua-dictionary'
301 ) {
302 return;
303 }
304
305 /**
306 * Enqueue jQuery
307 */
308
309 wp_enqueue_script( 'jquery' );
310
311 /**
312 * Enqueue wpLingua JS scripts
313 */
314
315 wp_enqueue_script(
316 'wplingua-option',
317 plugins_url() . '/wplingua/assets/js/admin/option-page.js',
318 array( 'jquery' ),
319 WPLNG_PLUGIN_VERSION
320 );
321
322 wp_enqueue_script(
323 'wplingua-option-dictionary',
324 plugins_url() . '/wplingua/assets/js/admin/option-page-dictionary.js',
325 array( 'jquery' ),
326 WPLNG_PLUGIN_VERSION
327 );
328
329 /**
330 * Enqueue wpLingua CSS styles
331 */
332
333 wp_enqueue_style(
334 'wplingua-option-dictionary',
335 plugins_url() . '/wplingua/assets/css/admin/option-page-dictionary.css',
336 array(),
337 WPLNG_PLUGIN_VERSION
338 );
339 }
340
341
342 /**
343 * Register wpLingua assets on translations edit pages
344 *
345 * @return void
346 */
347 function wplng_translation_edit_assets() {
348
349 global $post_type;
350
351 if ( 'wplng_translation' === $post_type ) {
352
353 /**
354 * Enqueue jQuery
355 */
356
357 wp_enqueue_script( 'jquery' );
358
359 /**
360 * Enqueue wpLingua JS scripts
361 */
362
363 wp_enqueue_script(
364 'wplingua-edit-translation',
365 plugins_url() . '/wplingua/assets/js/admin/edit-translation.js',
366 array( 'jquery' ),
367 WPLNG_PLUGIN_VERSION
368 );
369
370 /**
371 * Localize script
372 */
373
374 wp_localize_script(
375 'wplingua-edit-translation',
376 'wplngI18nTranslation',
377 array(
378 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
379 'currentLanguage' => false,
380 'message' => array(
381 'exitPage' => esc_html__(
382 '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?',
383 'wplingua'
384 ),
385 'exitEditorModal' => '',
386 'buttonSave' => '',
387 'buttonSaveInProgress' => '',
388 ),
389 )
390 );
391
392 /**
393 * Enqueue wpLingua CSS styles
394 */
395
396 wp_enqueue_style(
397 'wplingua-edit-translation',
398 plugins_url() . '/wplingua/assets/css/admin/edit-translation.css',
399 array(),
400 WPLNG_PLUGIN_VERSION
401 );
402
403 }
404 }
405
406
407
408 /**
409 * Register wpLingua assets on translations admin list
410 *
411 * @return void
412 */
413 function wplng_translation_list_assets() {
414
415 global $post_type;
416
417 if ( 'wplng_translation' === $post_type ) {
418
419 /**
420 * Enqueue wpLingua CSS styles
421 */
422
423 wp_enqueue_style(
424 'wplingua-list-translation',
425 plugins_url() . '/wplingua/assets/css/admin/list-translation.css',
426 array(),
427 WPLNG_PLUGIN_VERSION
428 );
429
430 }
431 }
432
433
434 /**
435 * Register wpLingua assets on slugs edit pages
436 *
437 * @return void
438 */
439 function wplng_slug_edit_assets() {
440
441 global $post_type;
442
443 if ( 'wplng_slug' === $post_type ) {
444
445 /**
446 * Enqueue jQuery
447 */
448
449 wp_enqueue_script( 'jquery' );
450
451 /**
452 * Enqueue wpLingua JS scripts
453 */
454
455 wp_enqueue_script(
456 'wplingua-edit-slug',
457 plugins_url() . '/wplingua/assets/js/admin/edit-slug.js',
458 array( 'jquery' ),
459 WPLNG_PLUGIN_VERSION
460 );
461
462 /**
463 * Localize script
464 */
465
466 wp_localize_script(
467 'wplingua-edit-slug',
468 'wplngI18nSlug',
469 array(
470 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
471 'currentLanguage' => false,
472 'message' => array(
473 'exitPage' => esc_html__(
474 '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?',
475 'wplingua'
476 ),
477 'exitEditorModal' => '',
478 'buttonSave' => '',
479 'buttonSaveInProgress' => '',
480 ),
481 )
482 );
483
484 /**
485 * Enqueue wpLingua CSS styles
486 */
487
488 wp_enqueue_style(
489 'wplingua-edit-slug',
490 plugins_url() . '/wplingua/assets/css/admin/edit-slug.css',
491 array(),
492 WPLNG_PLUGIN_VERSION
493 );
494
495 }
496 }
497
498
499 /**
500 * Register wpLingua assets on slugs admin list
501 *
502 * @return void
503 */
504 function wplng_slug_list_assets() {
505
506 global $post_type;
507
508 if ( 'wplng_slug' === $post_type ) {
509
510 /**
511 * Enqueue wpLingua CSS styles
512 */
513
514 wp_enqueue_style(
515 'wplingua-list-slug',
516 plugins_url() . '/wplingua/assets/css/admin/list-slug.css',
517 array(),
518 WPLNG_PLUGIN_VERSION
519 );
520
521 }
522 }
523
524
525 /**
526 * Print wpLingua head script (JSON with all languages informations)
527 *
528 * @return void
529 */
530 function wplng_inline_script_languages() {
531
532 $languages = array();
533 $languages_allow = wplng_get_languages_allow();
534
535 if ( ! empty( $languages_allow ) && is_array( $languages_allow ) ) {
536
537 $language_website = wplng_get_language_website();
538
539 if ( ! in_array( $language_website, $languages_allow, true ) ) {
540 $languages_allow[] = $language_website;
541 }
542
543 $languages = $languages_allow;
544
545 } else {
546 $languages = wplng_get_languages_all();
547 }
548
549 ?><script>var wplngAllLanguages = <?php echo wp_json_encode( $languages ); ?>;</script>
550 <?php
551 }
552