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

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