| @@ -31,12 +31,19 @@ | ||
| 31 | 31 | * Enqueue wpLingua JS scripts |
| 32 | 32 | */ |
| 33 | 33 | |
| 34 | 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( | |
| 35 | 42 | 'wplingua-option-settings', |
| 36 | 43 | plugins_url() . '/wplingua/assets/js/admin/option-page-settings.js', |
| 37 | 44 | array( 'jquery' ), |
| 38 | - WPLNG_API_VERSION | |
| 45 | + WPLNG_PLUGIN_VERSION | |
| 39 | 46 | ); |
| 40 | 47 | |
| 41 | 48 | /** |
| 42 | 49 | * Enqueue wpLingua CSS styles |
| @@ -45,17 +52,10 @@ | ||
| 45 | 52 | wp_enqueue_style( |
| 46 | 53 | 'wplingua-option-settings', |
| 47 | 54 | plugins_url() . '/wplingua/assets/css/admin/option-page-settings.css', |
| 48 | 55 | array(), |
| 49 | - WPLNG_API_VERSION | |
| 56 | + WPLNG_PLUGIN_VERSION | |
| 50 | 57 | ); |
| 51 | - | |
| 52 | - wp_enqueue_style( | |
| 53 | - 'wplingua-option-pages', | |
| 54 | - plugins_url() . '/wplingua/assets/css/admin/option-page.css', | |
| 55 | - array(), | |
| 56 | - WPLNG_API_VERSION | |
| 57 | - ); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | /** |
| @@ -82,12 +82,19 @@ | ||
| 82 | 82 | * Enqueue wpLingua JS scripts |
| 83 | 83 | */ |
| 84 | 84 | |
| 85 | 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( | |
| 86 | 93 | 'wplingua-option-register', |
| 87 | 94 | plugins_url() . '/wplingua/assets/js/admin/option-page-register.js', |
| 88 | 95 | array( 'jquery' ), |
| 89 | - WPLNG_API_VERSION | |
| 96 | + WPLNG_PLUGIN_VERSION | |
| 90 | 97 | ); |
| 91 | 98 | |
| 92 | 99 | /** |
| 93 | 100 | * Enqueue wpLingua CSS styles |
| @@ -96,17 +103,10 @@ | ||
| 96 | 103 | wp_enqueue_style( |
| 97 | 104 | 'wplingua-option-register', |
| 98 | 105 | plugins_url() . '/wplingua/assets/css/admin/option-page-register.css', |
| 99 | 106 | array(), |
| 100 | - WPLNG_API_VERSION | |
| 107 | + WPLNG_PLUGIN_VERSION | |
| 101 | 108 | ); |
| 102 | - | |
| 103 | - wp_enqueue_style( | |
| 104 | - 'wplingua-option-pages', | |
| 105 | - plugins_url() . '/wplingua/assets/css/admin/option-page.css', | |
| 106 | - array(), | |
| 107 | - WPLNG_API_VERSION | |
| 108 | - ); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | /** |
| @@ -111,9 +111,9 @@ | ||
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * Register wpLingua assets for option page : Switcher |
| 114 | 114 | * |
| 115 | - * @param string $hook | |
| 115 | + * @param string $hook The current admin page hook. | |
| 116 | 116 | * @return void |
| 117 | 117 | */ |
| 118 | 118 | function wplng_option_page_switcher_assets( $hook ) { |
| 119 | 119 | |
| @@ -136,16 +136,23 @@ | ||
| 136 | 136 | wp_enqueue_script( |
| 137 | 137 | 'wplingua-option-switcher', |
| 138 | 138 | plugins_url() . '/wplingua/assets/js/admin/option-page-switcher.js', |
| 139 | 139 | array( 'jquery' ), |
| 140 | - WPLNG_API_VERSION | |
| 140 | + WPLNG_PLUGIN_VERSION | |
| 141 | 141 | ); |
| 142 | 142 | |
| 143 | 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( | |
| 144 | 151 | 'wplingua-script', |
| 145 | - plugins_url() . '/wplingua/assets/js/script.js', | |
| 146 | - array( 'jquery' ), | |
| 147 | - WPLNG_API_VERSION | |
| 152 | + plugins_url() . '/wplingua/assets/js/front.js', | |
| 153 | + array(), | |
| 154 | + WPLNG_PLUGIN_VERSION | |
| 148 | 155 | ); |
| 149 | 156 | |
| 150 | 157 | /** |
| 151 | 158 | * Enqueue wpLingua CSS styles |
| @@ -154,23 +161,16 @@ | ||
| 154 | 161 | wp_enqueue_style( |
| 155 | 162 | 'wplingua-option-switcher', |
| 156 | 163 | plugins_url() . '/wplingua/assets/css/admin/option-page-switcher.css', |
| 157 | 164 | array(), |
| 158 | - WPLNG_API_VERSION | |
| 165 | + WPLNG_PLUGIN_VERSION | |
| 159 | 166 | ); |
| 160 | 167 | |
| 161 | 168 | wp_enqueue_style( |
| 162 | - 'wplingua-option-pages', | |
| 163 | - plugins_url() . '/wplingua/assets/css/admin/option-page.css', | |
| 164 | - array(), | |
| 165 | - WPLNG_API_VERSION | |
| 166 | - ); | |
| 167 | - | |
| 168 | - wp_enqueue_style( | |
| 169 | 169 | 'wplingua', |
| 170 | 170 | plugins_url() . '/wplingua/assets/css/front.css', |
| 171 | 171 | array(), |
| 172 | - WPLNG_API_VERSION | |
| 172 | + WPLNG_PLUGIN_VERSION | |
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | 176 | * Enqueue CSS and JS for the code editor |
| @@ -178,9 +178,14 @@ | ||
| 178 | 178 | |
| 179 | 179 | if ( function_exists( 'wp_enqueue_code_editor' ) ) { |
| 180 | 180 | $cm_settings = array(); |
| 181 | 181 | $cm_settings['codeEditor'] = wp_enqueue_code_editor( |
| 182 | - array( 'type' => 'text/css' ) | |
| 182 | + array( | |
| 183 | + 'type' => 'text/css', | |
| 184 | + 'codemirror' => array( | |
| 185 | + 'lineWrapping' => true, | |
| 186 | + ), | |
| 187 | + ) | |
| 183 | 188 | ); |
| 184 | 189 | |
| 185 | 190 | wp_localize_script( 'jquery', 'cm_settings', $cm_settings ); |
| 186 | 191 | wp_enqueue_script( 'wp-theme-plugin-editor' ); |
| @@ -196,8 +201,10 @@ | ||
| 196 | 201 | if ( ! empty( $custom_css ) |
| 197 | 202 | && is_string( $custom_css ) |
| 198 | 203 | ) { |
| 199 | 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 ); | |
| 200 | 207 | wp_add_inline_style( 'wplingua', $custom_css ); |
| 201 | 208 | } |
| 202 | 209 | } |
| 203 | 210 | |
| @@ -229,18 +236,122 @@ | ||
| 229 | 236 | wp_enqueue_style( |
| 230 | 237 | 'wplingua-option-exclusions', |
| 231 | 238 | plugins_url() . '/wplingua/assets/css/admin/option-page-exclusions.css', |
| 232 | 239 | array(), |
| 233 | - WPLNG_API_VERSION | |
| 240 | + WPLNG_PLUGIN_VERSION | |
| 234 | 241 | ); |
| 242 | +} | |
| 235 | 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 | + | |
| 236 | 287 | wp_enqueue_style( |
| 237 | - 'wplingua-option-pages', | |
| 238 | - plugins_url() . '/wplingua/assets/css/admin/option-page.css', | |
| 288 | + 'wplingua-option-link-media', | |
| 289 | + plugins_url() . '/wplingua/assets/css/admin/option-page-link-media.css', | |
| 239 | 290 | array(), |
| 240 | - WPLNG_API_VERSION | |
| 291 | + WPLNG_PLUGIN_VERSION | |
| 241 | 292 | ); |
| 293 | +} | |
| 242 | 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 | + ); | |
| 243 | 354 | } |
| 244 | 355 | |
| 245 | 356 | |
| 246 | 357 | /** |
| @@ -247,9 +358,9 @@ | ||
| 247 | 358 | * Register wpLingua assets on translations edit pages |
| 248 | 359 | * |
| 249 | 360 | * @return void |
| 250 | 361 | */ |
| 251 | -function wplng_translation_assets() { | |
| 362 | +function wplng_translation_edit_assets() { | |
| 252 | 363 | |
| 253 | 364 | global $post_type; |
| 254 | 365 | |
| 255 | 366 | if ( 'wplng_translation' === $post_type ) { |
| @@ -264,23 +375,33 @@ | ||
| 264 | 375 | * Enqueue wpLingua JS scripts |
| 265 | 376 | */ |
| 266 | 377 | |
| 267 | 378 | wp_enqueue_script( |
| 268 | - 'wplingua-translation', | |
| 269 | - plugins_url() . '/wplingua/assets/js/admin/translation.js', | |
| 379 | + 'wplingua-edit-translation', | |
| 380 | + plugins_url() . '/wplingua/assets/js/admin/edit-translation.js', | |
| 270 | 381 | array( 'jquery' ), |
| 271 | - WPLNG_API_VERSION | |
| 382 | + WPLNG_PLUGIN_VERSION | |
| 272 | 383 | ); |
| 273 | 384 | |
| 274 | 385 | /** |
| 275 | - * Localize script for AJAX | |
| 386 | + * Localize script | |
| 276 | 387 | */ |
| 277 | 388 | |
| 278 | 389 | wp_localize_script( |
| 279 | - 'wplingua-translation', | |
| 280 | - 'adminAjax', | |
| 390 | + 'wplingua-edit-translation', | |
| 391 | + 'wplngI18nTranslation', | |
| 281 | 392 | array( |
| 282 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 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 | + ), | |
| 283 | 404 | ) |
| 284 | 405 | ); |
| 285 | 406 | |
| 286 | 407 | /** |
| @@ -287,16 +408,133 @@ | ||
| 287 | 408 | * Enqueue wpLingua CSS styles |
| 288 | 409 | */ |
| 289 | 410 | |
| 290 | 411 | wp_enqueue_style( |
| 291 | - 'wplingua-translation', | |
| 292 | - plugins_url() . '/wplingua/assets/css/admin/translation.css', | |
| 412 | + 'wplingua-edit-translation', | |
| 413 | + plugins_url() . '/wplingua/assets/css/admin/edit-translation.css', | |
| 293 | 414 | array(), |
| 294 | - WPLNG_API_VERSION | |
| 415 | + WPLNG_PLUGIN_VERSION | |
| 295 | 416 | ); |
| 296 | 417 | |
| 297 | 418 | } |
| 419 | +} | |
| 298 | 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 | + } | |
| 299 | 537 | } |
| 300 | 538 | |
| 301 | 539 | |
| 302 | 540 | /** |