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

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

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