| @@ -1,566 +1,566 @@ | ||
| 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 | - wp_localize_script( | |
| 335 | - 'wplingua-option-dictionary', | |
| 336 | - 'wplngDictionaryAjax', | |
| 337 | - array( | |
| 338 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 339 | - 'nonce' => wp_create_nonce( 'wplng_dictionary_update_translations' ), | |
| 340 | - 'errorMessageAjax' => esc_html__( 'Error [0]: The AJAX call failed.', 'wplingua' ), | |
| 341 | - ) | |
| 342 | - ); | |
| 343 | - | |
| 344 | - /** | |
| 345 | - * Enqueue wpLingua CSS styles | |
| 346 | - */ | |
| 347 | - | |
| 348 | - wp_enqueue_style( | |
| 349 | - 'wplingua-option-dictionary', | |
| 350 | - plugins_url() . '/wplingua/assets/css/admin/option-page-dictionary.css', | |
| 351 | - array(), | |
| 352 | - WPLNG_PLUGIN_VERSION | |
| 353 | - ); | |
| 354 | -} | |
| 355 | - | |
| 356 | - | |
| 357 | -/** | |
| 358 | - * Register wpLingua assets on translations edit pages | |
| 359 | - * | |
| 360 | - * @return void | |
| 361 | - */ | |
| 362 | -function wplng_translation_edit_assets() { | |
| 363 | - | |
| 364 | - global $post_type; | |
| 365 | - | |
| 366 | - if ( 'wplng_translation' === $post_type ) { | |
| 367 | - | |
| 368 | - /** | |
| 369 | - * Enqueue jQuery | |
| 370 | - */ | |
| 371 | - | |
| 372 | - wp_enqueue_script( 'jquery' ); | |
| 373 | - | |
| 374 | - /** | |
| 375 | - * Enqueue wpLingua JS scripts | |
| 376 | - */ | |
| 377 | - | |
| 378 | - wp_enqueue_script( | |
| 379 | - 'wplingua-edit-translation', | |
| 380 | - plugins_url() . '/wplingua/assets/js/admin/edit-translation.js', | |
| 381 | - array( 'jquery' ), | |
| 382 | - WPLNG_PLUGIN_VERSION | |
| 383 | - ); | |
| 384 | - | |
| 385 | - /** | |
| 386 | - * Localize script | |
| 387 | - */ | |
| 388 | - | |
| 389 | - wp_localize_script( | |
| 390 | - 'wplingua-edit-translation', | |
| 391 | - 'wplngI18nTranslation', | |
| 392 | - array( | |
| 393 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 394 | - 'currentLanguage' => false, | |
| 395 | - 'message' => array( | |
| 396 | - 'exitPage' => esc_html__( | |
| 397 | - '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?', | |
| 398 | - 'wplingua' | |
| 399 | - ), | |
| 400 | - 'exitEditorModal' => '', | |
| 401 | - 'buttonSave' => '', | |
| 402 | - 'buttonSaveInProgress' => '', | |
| 403 | - ), | |
| 404 | - ) | |
| 405 | - ); | |
| 406 | - | |
| 407 | - /** | |
| 408 | - * Enqueue wpLingua CSS styles | |
| 409 | - */ | |
| 410 | - | |
| 411 | - wp_enqueue_style( | |
| 412 | - 'wplingua-edit-translation', | |
| 413 | - plugins_url() . '/wplingua/assets/css/admin/edit-translation.css', | |
| 414 | - array(), | |
| 415 | - WPLNG_PLUGIN_VERSION | |
| 416 | - ); | |
| 417 | - | |
| 418 | - } | |
| 419 | -} | |
| 420 | - | |
| 421 | - | |
| 422 | - | |
| 423 | -/** | |
| 424 | - * Register wpLingua assets on translations admin list | |
| 425 | - * | |
| 426 | - * @return void | |
| 427 | - */ | |
| 428 | -function wplng_translation_list_assets() { | |
| 429 | - | |
| 430 | - global $post_type; | |
| 431 | - | |
| 432 | - if ( 'wplng_translation' === $post_type ) { | |
| 433 | - | |
| 434 | - /** | |
| 435 | - * Enqueue wpLingua CSS styles | |
| 436 | - */ | |
| 437 | - | |
| 438 | - wp_enqueue_style( | |
| 439 | - 'wplingua-list-translation', | |
| 440 | - plugins_url() . '/wplingua/assets/css/admin/list-translation.css', | |
| 441 | - array(), | |
| 442 | - WPLNG_PLUGIN_VERSION | |
| 443 | - ); | |
| 444 | - | |
| 445 | - } | |
| 446 | -} | |
| 447 | - | |
| 448 | - | |
| 449 | -/** | |
| 450 | - * Register wpLingua assets on slugs edit pages | |
| 451 | - * | |
| 452 | - * @return void | |
| 453 | - */ | |
| 454 | -function wplng_slug_edit_assets() { | |
| 455 | - | |
| 456 | - global $post_type; | |
| 457 | - | |
| 458 | - if ( 'wplng_slug' === $post_type ) { | |
| 459 | - | |
| 460 | - /** | |
| 461 | - * Enqueue jQuery | |
| 462 | - */ | |
| 463 | - | |
| 464 | - wp_enqueue_script( 'jquery' ); | |
| 465 | - | |
| 466 | - /** | |
| 467 | - * Enqueue wpLingua JS scripts | |
| 468 | - */ | |
| 469 | - | |
| 470 | - wp_enqueue_script( | |
| 471 | - 'wplingua-edit-slug', | |
| 472 | - plugins_url() . '/wplingua/assets/js/admin/edit-slug.js', | |
| 473 | - array( 'jquery' ), | |
| 474 | - WPLNG_PLUGIN_VERSION | |
| 475 | - ); | |
| 476 | - | |
| 477 | - /** | |
| 478 | - * Localize script | |
| 479 | - */ | |
| 480 | - | |
| 481 | - wp_localize_script( | |
| 482 | - 'wplingua-edit-slug', | |
| 483 | - 'wplngI18nSlug', | |
| 484 | - array( | |
| 485 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 486 | - 'currentLanguage' => false, | |
| 487 | - 'message' => array( | |
| 488 | - 'exitPage' => esc_html__( | |
| 489 | - '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?', | |
| 490 | - 'wplingua' | |
| 491 | - ), | |
| 492 | - 'exitEditorModal' => '', | |
| 493 | - 'buttonSave' => '', | |
| 494 | - 'buttonSaveInProgress' => '', | |
| 495 | - ), | |
| 496 | - ) | |
| 497 | - ); | |
| 498 | - | |
| 499 | - /** | |
| 500 | - * Enqueue wpLingua CSS styles | |
| 501 | - */ | |
| 502 | - | |
| 503 | - wp_enqueue_style( | |
| 504 | - 'wplingua-edit-slug', | |
| 505 | - plugins_url() . '/wplingua/assets/css/admin/edit-slug.css', | |
| 506 | - array(), | |
| 507 | - WPLNG_PLUGIN_VERSION | |
| 508 | - ); | |
| 509 | - | |
| 510 | - } | |
| 511 | -} | |
| 512 | - | |
| 513 | - | |
| 514 | -/** | |
| 515 | - * Register wpLingua assets on slugs admin list | |
| 516 | - * | |
| 517 | - * @return void | |
| 518 | - */ | |
| 519 | -function wplng_slug_list_assets() { | |
| 520 | - | |
| 521 | - global $post_type; | |
| 522 | - | |
| 523 | - if ( 'wplng_slug' === $post_type ) { | |
| 524 | - | |
| 525 | - /** | |
| 526 | - * Enqueue wpLingua CSS styles | |
| 527 | - */ | |
| 528 | - | |
| 529 | - wp_enqueue_style( | |
| 530 | - 'wplingua-list-slug', | |
| 531 | - plugins_url() . '/wplingua/assets/css/admin/list-slug.css', | |
| 532 | - array(), | |
| 533 | - WPLNG_PLUGIN_VERSION | |
| 534 | - ); | |
| 535 | - | |
| 536 | - } | |
| 537 | -} | |
| 538 | - | |
| 539 | - | |
| 540 | -/** | |
| 541 | - * Print wpLingua head script (JSON with all languages informations) | |
| 542 | - * | |
| 543 | - * @return void | |
| 544 | - */ | |
| 545 | -function wplng_inline_script_languages() { | |
| 546 | - | |
| 547 | - $languages = array(); | |
| 548 | - $languages_allow = wplng_get_languages_allow(); | |
| 549 | - | |
| 550 | - if ( ! empty( $languages_allow ) && is_array( $languages_allow ) ) { | |
| 551 | - | |
| 552 | - $language_website = wplng_get_language_website(); | |
| 553 | - | |
| 554 | - if ( ! in_array( $language_website, $languages_allow, true ) ) { | |
| 555 | - $languages_allow[] = $language_website; | |
| 556 | - } | |
| 557 | - | |
| 558 | - $languages = $languages_allow; | |
| 559 | - | |
| 560 | - } else { | |
| 561 | - $languages = wplng_get_languages_all(); | |
| 562 | - } | |
| 563 | - | |
| 564 | - ?><script>var wplngAllLanguages = <?php echo wp_json_encode( $languages ); ?>;</script> | |
| 565 | - <?php | |
| 566 | -} | |
| 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 | + wp_localize_script( | |
| 335 | + 'wplingua-option-dictionary', | |
| 336 | + 'wplngDictionaryAjax', | |
| 337 | + array( | |
| 338 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 339 | + 'nonce' => wp_create_nonce( 'wplng_dictionary_update_translations' ), | |
| 340 | + 'errorMessageAjax' => esc_html__( 'Error [0]: The AJAX call failed.', 'wplingua' ), | |
| 341 | + ) | |
| 342 | + ); | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * Enqueue wpLingua CSS styles | |
| 346 | + */ | |
| 347 | + | |
| 348 | + wp_enqueue_style( | |
| 349 | + 'wplingua-option-dictionary', | |
| 350 | + plugins_url() . '/wplingua/assets/css/admin/option-page-dictionary.css', | |
| 351 | + array(), | |
| 352 | + WPLNG_PLUGIN_VERSION | |
| 353 | + ); | |
| 354 | +} | |
| 355 | + | |
| 356 | + | |
| 357 | +/** | |
| 358 | + * Register wpLingua assets on translations edit pages | |
| 359 | + * | |
| 360 | + * @return void | |
| 361 | + */ | |
| 362 | +function wplng_translation_edit_assets() { | |
| 363 | + | |
| 364 | + global $post_type; | |
| 365 | + | |
| 366 | + if ( 'wplng_translation' === $post_type ) { | |
| 367 | + | |
| 368 | + /** | |
| 369 | + * Enqueue jQuery | |
| 370 | + */ | |
| 371 | + | |
| 372 | + wp_enqueue_script( 'jquery' ); | |
| 373 | + | |
| 374 | + /** | |
| 375 | + * Enqueue wpLingua JS scripts | |
| 376 | + */ | |
| 377 | + | |
| 378 | + wp_enqueue_script( | |
| 379 | + 'wplingua-edit-translation', | |
| 380 | + plugins_url() . '/wplingua/assets/js/admin/edit-translation.js', | |
| 381 | + array( 'jquery' ), | |
| 382 | + WPLNG_PLUGIN_VERSION | |
| 383 | + ); | |
| 384 | + | |
| 385 | + /** | |
| 386 | + * Localize script | |
| 387 | + */ | |
| 388 | + | |
| 389 | + wp_localize_script( | |
| 390 | + 'wplingua-edit-translation', | |
| 391 | + 'wplngI18nTranslation', | |
| 392 | + array( | |
| 393 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 394 | + 'currentLanguage' => false, | |
| 395 | + 'message' => array( | |
| 396 | + 'exitPage' => esc_html__( | |
| 397 | + '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?', | |
| 398 | + 'wplingua' | |
| 399 | + ), | |
| 400 | + 'exitEditorModal' => '', | |
| 401 | + 'buttonSave' => '', | |
| 402 | + 'buttonSaveInProgress' => '', | |
| 403 | + ), | |
| 404 | + ) | |
| 405 | + ); | |
| 406 | + | |
| 407 | + /** | |
| 408 | + * Enqueue wpLingua CSS styles | |
| 409 | + */ | |
| 410 | + | |
| 411 | + wp_enqueue_style( | |
| 412 | + 'wplingua-edit-translation', | |
| 413 | + plugins_url() . '/wplingua/assets/css/admin/edit-translation.css', | |
| 414 | + array(), | |
| 415 | + WPLNG_PLUGIN_VERSION | |
| 416 | + ); | |
| 417 | + | |
| 418 | + } | |
| 419 | +} | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | +/** | |
| 424 | + * Register wpLingua assets on translations admin list | |
| 425 | + * | |
| 426 | + * @return void | |
| 427 | + */ | |
| 428 | +function wplng_translation_list_assets() { | |
| 429 | + | |
| 430 | + global $post_type; | |
| 431 | + | |
| 432 | + if ( 'wplng_translation' === $post_type ) { | |
| 433 | + | |
| 434 | + /** | |
| 435 | + * Enqueue wpLingua CSS styles | |
| 436 | + */ | |
| 437 | + | |
| 438 | + wp_enqueue_style( | |
| 439 | + 'wplingua-list-translation', | |
| 440 | + plugins_url() . '/wplingua/assets/css/admin/list-translation.css', | |
| 441 | + array(), | |
| 442 | + WPLNG_PLUGIN_VERSION | |
| 443 | + ); | |
| 444 | + | |
| 445 | + } | |
| 446 | +} | |
| 447 | + | |
| 448 | + | |
| 449 | +/** | |
| 450 | + * Register wpLingua assets on slugs edit pages | |
| 451 | + * | |
| 452 | + * @return void | |
| 453 | + */ | |
| 454 | +function wplng_slug_edit_assets() { | |
| 455 | + | |
| 456 | + global $post_type; | |
| 457 | + | |
| 458 | + if ( 'wplng_slug' === $post_type ) { | |
| 459 | + | |
| 460 | + /** | |
| 461 | + * Enqueue jQuery | |
| 462 | + */ | |
| 463 | + | |
| 464 | + wp_enqueue_script( 'jquery' ); | |
| 465 | + | |
| 466 | + /** | |
| 467 | + * Enqueue wpLingua JS scripts | |
| 468 | + */ | |
| 469 | + | |
| 470 | + wp_enqueue_script( | |
| 471 | + 'wplingua-edit-slug', | |
| 472 | + plugins_url() . '/wplingua/assets/js/admin/edit-slug.js', | |
| 473 | + array( 'jquery' ), | |
| 474 | + WPLNG_PLUGIN_VERSION | |
| 475 | + ); | |
| 476 | + | |
| 477 | + /** | |
| 478 | + * Localize script | |
| 479 | + */ | |
| 480 | + | |
| 481 | + wp_localize_script( | |
| 482 | + 'wplingua-edit-slug', | |
| 483 | + 'wplngI18nSlug', | |
| 484 | + array( | |
| 485 | + 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 486 | + 'currentLanguage' => false, | |
| 487 | + 'message' => array( | |
| 488 | + 'exitPage' => esc_html__( | |
| 489 | + '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?', | |
| 490 | + 'wplingua' | |
| 491 | + ), | |
| 492 | + 'exitEditorModal' => '', | |
| 493 | + 'buttonSave' => '', | |
| 494 | + 'buttonSaveInProgress' => '', | |
| 495 | + ), | |
| 496 | + ) | |
| 497 | + ); | |
| 498 | + | |
| 499 | + /** | |
| 500 | + * Enqueue wpLingua CSS styles | |
| 501 | + */ | |
| 502 | + | |
| 503 | + wp_enqueue_style( | |
| 504 | + 'wplingua-edit-slug', | |
| 505 | + plugins_url() . '/wplingua/assets/css/admin/edit-slug.css', | |
| 506 | + array(), | |
| 507 | + WPLNG_PLUGIN_VERSION | |
| 508 | + ); | |
| 509 | + | |
| 510 | + } | |
| 511 | +} | |
| 512 | + | |
| 513 | + | |
| 514 | +/** | |
| 515 | + * Register wpLingua assets on slugs admin list | |
| 516 | + * | |
| 517 | + * @return void | |
| 518 | + */ | |
| 519 | +function wplng_slug_list_assets() { | |
| 520 | + | |
| 521 | + global $post_type; | |
| 522 | + | |
| 523 | + if ( 'wplng_slug' === $post_type ) { | |
| 524 | + | |
| 525 | + /** | |
| 526 | + * Enqueue wpLingua CSS styles | |
| 527 | + */ | |
| 528 | + | |
| 529 | + wp_enqueue_style( | |
| 530 | + 'wplingua-list-slug', | |
| 531 | + plugins_url() . '/wplingua/assets/css/admin/list-slug.css', | |
| 532 | + array(), | |
| 533 | + WPLNG_PLUGIN_VERSION | |
| 534 | + ); | |
| 535 | + | |
| 536 | + } | |
| 537 | +} | |
| 538 | + | |
| 539 | + | |
| 540 | +/** | |
| 541 | + * Print wpLingua head script (JSON with all languages informations) | |
| 542 | + * | |
| 543 | + * @return void | |
| 544 | + */ | |
| 545 | +function wplng_inline_script_languages() { | |
| 546 | + | |
| 547 | + $languages = array(); | |
| 548 | + $languages_allow = wplng_get_languages_allow(); | |
| 549 | + | |
| 550 | + if ( ! empty( $languages_allow ) && is_array( $languages_allow ) ) { | |
| 551 | + | |
| 552 | + $language_website = wplng_get_language_website(); | |
| 553 | + | |
| 554 | + if ( ! in_array( $language_website, $languages_allow, true ) ) { | |
| 555 | + $languages_allow[] = $language_website; | |
| 556 | + } | |
| 557 | + | |
| 558 | + $languages = $languages_allow; | |
| 559 | + | |
| 560 | + } else { | |
| 561 | + $languages = wplng_get_languages_all(); | |
| 562 | + } | |
| 563 | + | |
| 564 | + ?><script>var wplngAllLanguages = <?php echo wp_json_encode( $languages ); ?>;</script> | |
| 565 | + <?php | |
| 566 | +} | |