Ticket #35760: 35760.patch
File 35760.patch, 28.1 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
1497 1497 1498 1498 $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; 1499 1499 1500 require(ABSPATH . WPINC . '/class-wp-editor.php'); 1500 if ( ! class_exists( '_WP_Editors', false ) ) { 1501 require( ABSPATH . WPINC . '/class-wp-editor.php' ); 1502 } 1503 1501 1504 $results = _WP_Editors::wp_link_query( $args ); 1502 1505 1503 1506 if ( ! isset( $results ) ) -
src/wp-admin/js/editor.js
1 window.wp = window.wp || {}; 1 2 2 ( function( $ ) { 3 ( function( $, wp ) { 4 wp.editor = wp.editor || {}; 5 3 6 /** 4 7 * @summary Utility functions for the editor. 5 8 * … … 484 487 } ); 485 488 } 486 489 487 window.wp = window.wp || {}; 488 window.wp.editor = window.wp.editor || {}; 489 window.wp.editor.autop = wpautop; 490 window.wp.editor.removep = pre_wpautop; 490 wp.editor.autop = wpautop; 491 wp.editor.removep = pre_wpautop; 491 492 492 493 exports = { 493 494 go: switchEditor, … … 505 506 * Expose the switch editors to be used globally. 506 507 */ 507 508 window.switchEditors = new SwitchEditors(); 508 }( window.jQuery )); 509 510 /** 511 * Initialize TinyMCE and/or Quicktags. For use with wp_enqueue_editor() (PHP). 512 * 513 * Intended for use with an existing textarea that will become the Text editor tab. 514 * The editor width will be the width of the textarea container, height will be adjustable. 515 * 516 * Settings for both TinyMCE and Quicktags can be passed on initialization, and are "filtered" 517 * with custom jQuery events on the document element, wp-before-tinymce-init and wp-before-quicktags-init. 518 * 519 * @since 4.8 520 * 521 * @param {string} id The HTML id of the textarea that is used for the editor. 522 * Has to be jQuery compliant. No brackets, special chars, etc. 523 * @param {object} settings Example: 524 * settings = { 525 * // See https://www.tinymce.com/docs/configure/integration-and-setup/. 526 * // Alternatively set to `true` to use the defaults. 527 * tinymce: { 528 * setup: function( editor ) { 529 * console.log( 'Editor initialized', editor ); 530 * } 531 * } 532 * 533 * // Alternatively set to `true` to use the defaults. 534 * quicktags: { 535 * buttons: 'strong,em,link' 536 * } 537 * } 538 */ 539 wp.editor.initialize = function( id, settings ) { 540 var init; 541 var defaults; 542 543 if ( ! $ || ! id || ! wp.editor.getDefaultSettings ) { 544 return; 545 } 546 547 defaults = wp.editor.getDefaultSettings(); 548 549 // Add wrap and the Visual|Text tabs. 550 if ( settings.tinymce && settings.quicktags ) { 551 var $textarea = $( '#' + id ); 552 var $wrap = $( '<div>' ).attr( { 553 'class': 'wp-core-ui wp-editor-wrap tmce-active', 554 id: 'wp-' + id + '-wrap' 555 } ); 556 var $button = $( '<button>' ).attr( { 557 type: 'button', 558 'data-wp-editor-id': id 559 } ); 560 561 $wrap.append( 562 $( '<div class="wp-editor-tools">' ) 563 .append( $( '<div class="wp-editor-tabs">' ) 564 .append( $button.clone().attr({ 565 id: id + '-tmce', 566 'class': 'wp-switch-editor switch-tmce' 567 }).text( window.tinymce.translate( 'Visual' ) ) ) 568 .append( $button.clone().attr({ 569 id: id + '-html', 570 'class': 'wp-switch-editor switch-html' 571 }).text( window.tinymce.translate( 'Text' ) ) ) 572 ) 573 ); 574 575 $textarea.after( $wrap ); 576 $wrap.append( $textarea ); 577 } 578 579 if ( window.tinymce && settings.tinymce ) { 580 if ( typeof settings.tinymce !== 'object' ) { 581 settings.tinymce = {}; 582 } 583 584 init = $.extend( {}, defaults.tinymce, settings.tinymce ); 585 init.selector = '#' + id; 586 587 $( document ).trigger( 'wp-before-tinymce-init', init ); 588 window.tinymce.init( init ); 589 590 if ( ! window.wpActiveEditor ) { 591 window.wpActiveEditor = id; 592 } 593 } 594 595 if ( window.quicktags && settings.quicktags ) { 596 if ( typeof settings.quicktags !== 'object' ) { 597 settings.quicktags = {}; 598 } 599 600 init = $.extend( {}, defaults.quicktags, settings.quicktags ); 601 init.id = id; 602 603 $( document ).trigger( 'wp-before-quicktags-init', init ); 604 window.quicktags( init ); 605 606 if ( ! window.wpActiveEditor ) { 607 window.wpActiveEditor = init.id; 608 } 609 } 610 }; 611 612 /** 613 * Get the editor content. 614 * 615 * Intended for use with editors that were initialized with wp.editor.initialize(). 616 * 617 * @since 4.8 618 * 619 * @param {string} id The HTML id of the editor textarea. 620 * @return The editor content. 621 */ 622 wp.editor.getContent = function( id ) { 623 var editor; 624 625 if ( ! $ || ! id ) { 626 return; 627 } 628 629 if ( window.tinymce ) { 630 editor = window.tinymce.get( id ); 631 632 if ( editor && ! editor.isHidden() ) { 633 editor.save(); 634 } 635 } 636 637 return $( '#' + id ).val(); 638 }; 639 640 }( window.jQuery, window.wp )); -
src/wp-includes/class-wp-editor.php
27 27 private static $drag_drop_upload = false; 28 28 private static $old_dfw_compat = false; 29 29 private static $translation; 30 private static $tinymce_scripts_printed = false; 31 private static $link_dialog_printed = false; 30 32 31 33 private function __construct() {} 32 34 … … 350 352 if ( self::$this_tinymce ) { 351 353 352 354 if ( empty( self::$first_init ) ) { 353 self::$baseurl = includes_url( 'js/tinymce' ); 354 355 $mce_locale = get_user_locale(); 356 self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1 357 358 /** This filter is documented in wp-admin/includes/media.php */ 359 $no_captions = (bool) apply_filters( 'disable_captions', '' ); 355 $baseurl = self::get_baseurl(); 356 $mce_locale = self::get_mce_locale(); 360 357 $ext_plugins = ''; 361 $shortcut_labels = array();362 358 363 foreach ( self::get_translation() as $name => $value ) {364 if ( is_array( $value ) ) {365 $shortcut_labels[$name] = $value[1];366 }367 }368 369 359 if ( $set['teeny'] ) { 370 360 371 361 /** … … 376 366 * @param array $plugins An array of teenyMCE plugins. 377 367 * @param string $editor_id Unique editor identifier, e.g. 'content'. 378 368 */ 379 self::$plugins =$plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );369 $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id ); 380 370 } else { 381 371 382 372 /** … … 521 511 self::$plugins = $plugins; 522 512 self::$ext_plugins = $ext_plugins; 523 513 524 self::$first_init = array( 525 'theme' => 'modern', 526 'skin' => 'lightgray', 527 'language' => self::$mce_locale, 528 'formats' => '{' . 529 'alignleft: [' . 530 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' . 531 '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' . 532 '],' . 533 'aligncenter: [' . 534 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' . 535 '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' . 536 '],' . 537 'alignright: [' . 538 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' . 539 '{selector: "img,table,dl.wp-caption", classes: "alignright"}' . 540 '],' . 541 'strikethrough: {inline: "del"}' . 542 '}', 543 'relative_urls' => false, 544 'remove_script_host' => false, 545 'convert_urls' => false, 546 'browser_spellcheck' => true, 547 'fix_list_elements' => true, 548 'entities' => '38,amp,60,lt,62,gt', 549 'entity_encoding' => 'raw', 550 'keep_styles' => false, 551 'cache_suffix' => 'wp-mce-' . $tinymce_version, 514 $settings = self::default_settings(); 515 $settings['plugins'] = implode( ',', $plugins ); 552 516 553 // Limit the preview styles in the menu/toolbar554 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',555 556 'end_container_on_empty_block' => true,557 'wpeditimage_disable_captions' => $no_captions,558 'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),559 'plugins' => implode( ',', $plugins ),560 'wp_lang_attr' => get_bloginfo( 'language' ),561 'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ),562 );563 564 517 if ( ! empty( $mce_external_plugins ) ) { 565 self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );518 $settings['external_plugins'] = wp_json_encode( $mce_external_plugins ); 566 519 } 567 520 568 $suffix = SCRIPT_DEBUG ? '' : '.min'; 569 $version = 'ver=' . get_bloginfo( 'version' ); 570 $dashicons = includes_url( "css/dashicons$suffix.css?$version" ); 521 /** This filter is documented in wp-admin/includes/media.php */ 522 if ( apply_filters( 'disable_captions', '' ) ) { 523 $settings['wpeditimage_disable_captions'] = true; 524 } 571 525 572 // WordPress default stylesheet and dashicons 573 $mce_css = array( 574 $dashicons, 575 self::$baseurl . '/skins/wordpress/wp-content.css?' . $version 576 ); 526 $mce_css = $settings['content_css']; 527 $editor_styles = get_editor_stylesheets(); 577 528 578 $editor_styles = get_editor_stylesheets();579 529 if ( ! empty( $editor_styles ) ) { 580 foreach ( $editor_styles as $style ) { 581 $mce_css[] = $style; 582 } 530 $mce_css .= ',' . implode( ',', $editor_styles ); 583 531 } 584 532 585 533 /** … … 589 537 * 590 538 * @param string $stylesheets Comma-delimited list of stylesheets. 591 539 */ 592 $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css )), ' ,' );540 $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' ); 593 541 594 if ( ! empty($mce_css) ) 595 self::$first_init['content_css'] = $mce_css; 542 if ( ! empty( $mce_css ) ) { 543 $settings['content_css'] = $mce_css; 544 } else { 545 unset( $settings['content_css'] ); 546 } 547 548 self::$first_init = $settings; 596 549 } 597 550 598 551 if ( $set['teeny'] ) { … … 690 643 691 644 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) ); 692 645 693 if ( ! empty($set['tinymce']['body_class']) ) {646 if ( ! empty( $set['tinymce']['body_class'] ) ) { 694 647 $body_class .= ' ' . $set['tinymce']['body_class']; 695 unset( $set['tinymce']['body_class']);648 unset( $set['tinymce']['body_class'] ); 696 649 } 697 650 698 651 $mceInit = array ( 699 652 'selector' => "#$editor_id", 700 'resize' => 'vertical',701 'menubar' => false,702 653 'wpautop' => (bool) $set['wpautop'], 703 654 'indent' => ! $set['wpautop'], 704 'toolbar1' => implode( $mce_buttons, ','),705 'toolbar2' => implode( $mce_buttons_2, ','),706 'toolbar3' => implode( $mce_buttons_3, ','),707 'toolbar4' => implode( $mce_buttons_4, ','),655 'toolbar1' => implode( ',', $mce_buttons ), 656 'toolbar2' => implode( ',', $mce_buttons_2 ), 657 'toolbar3' => implode( ',', $mce_buttons_3 ), 658 'toolbar4' => implode( ',', $mce_buttons_4 ), 708 659 'tabfocus_elements' => $set['tabfocus_elements'], 709 660 'body_class' => $body_class 710 661 ); … … 762 713 * @param array $init 763 714 * @return string 764 715 */ 765 private static function _parse_init( $init) {716 private static function _parse_init( $init ) { 766 717 $options = ''; 767 718 768 foreach ( $init as $k => $v) {769 if ( is_bool( $v) ) {770 $val = $v ? 'true' : 'false';771 $options .= $k . ':' . $val . ',';719 foreach ( $init as $key => $value ) { 720 if ( is_bool( $value ) ) { 721 $val = $value ? 'true' : 'false'; 722 $options .= $key . ':' . $val . ','; 772 723 continue; 773 } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) { 774 $options .= $k . ':' . $v . ','; 724 } elseif ( ! empty( $value ) && is_string( $value ) && ( 725 ( '{' == $value{0} && '}' == $value{strlen( $value ) - 1} ) || 726 ( '[' == $value{0} && ']' == $value{strlen( $value ) - 1} ) || 727 preg_match( '/^\(?function ?\(/', $value ) ) ) { 728 729 $options .= $key . ':' . $value . ','; 775 730 continue; 776 731 } 777 $options .= $k . ':"' . $v. '",';732 $options .= $key . ':"' . $value . '",'; 778 733 } 779 734 780 735 return '{' . trim( $options, ' ,' ) . '}'; … … 784 739 * 785 740 * @static 786 741 */ 787 public static function enqueue_scripts() { 788 if ( self::$has_tinymce ) 789 wp_enqueue_script('editor'); 742 public static function enqueue_scripts( $default_scripts = false ) { 743 if ( $default_scripts || self::$has_tinymce ) { 744 wp_enqueue_script( 'editor' ); 745 } 790 746 791 if ( self::$has_quicktags ) {747 if ( $default_scripts || self::$has_quicktags ) { 792 748 wp_enqueue_script( 'quicktags' ); 793 749 wp_enqueue_style( 'buttons' ); 794 750 } 795 751 796 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {797 wp_enqueue_script( 'wplink');752 if ( $default_scripts || in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) { 753 wp_enqueue_script( 'wplink' ); 798 754 wp_enqueue_script( 'jquery-ui-autocomplete' ); 799 755 } 800 756 801 757 if ( self::$old_dfw_compat ) { 802 wp_enqueue_script( 'wp-fullscreen-stub');758 wp_enqueue_script( 'wp-fullscreen-stub' ); 803 759 } 804 760 805 761 if ( self::$has_medialib ) { … … 806 762 add_thickbox(); 807 763 wp_enqueue_script( 'media-upload' ); 808 764 wp_enqueue_script( 'wp-embed' ); 765 } elseif ( $default_scripts ) { 766 wp_enqueue_script( 'media-upload' ); 809 767 } 810 768 811 769 /** … … 817 775 * and Quicktags are being loaded. 818 776 */ 819 777 do_action( 'wp_enqueue_editor', array( 820 'tinymce' => self::$has_tinymce,821 'quicktags' => self::$has_quicktags,778 'tinymce' => ( $default_scripts || self::$has_tinymce ), 779 'quicktags' => ( $default_scripts || self::$has_quicktags ), 822 780 ) ); 823 781 } 824 782 783 public static function enqueue_default_editor() { 784 // We are past the point where scripts can be enqueued properly. 785 if ( did_action( 'wp_enqueue_editor' ) ) { 786 return; 787 } 788 789 self::enqueue_scripts( true ); 790 791 // Also add wp-includes/css/editor.css 792 wp_enqueue_style( 'editor-buttons' ); 793 794 if ( is_admin() ) { 795 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 ); 796 } else { 797 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 ); 798 } 799 } 800 801 public static function print_default_editor_scripts() { 802 $settings = self::default_settings(); 803 804 $settings['toolbar1'] = 'bold,italic,bullist,numlist,link'; 805 $settings['wpautop'] = false; 806 $settings['indent'] = true; 807 $settings['elementpath'] = false; 808 809 // In production all plugins are loaded (they are in wp-editor.js.gz) 810 // but only these will be initialized by default. 811 $settings['plugins'] = implode( ',', array( 812 'charmap', 813 'colorpicker', 814 'hr', 815 'lists', 816 // 'media', 817 'paste', 818 'tabfocus', 819 'textcolor', 820 'fullscreen', 821 'wordpress', 822 // 'wpautoresize', 823 'wpeditimage', 824 'wpemoji', 825 'wpgallery', 826 'wplink', 827 // 'wpdialogs', 828 'wptextpattern', 829 // 'wpview', 830 ) ); 831 832 $settings = self::_parse_init( $settings ); 833 834 $suffix = SCRIPT_DEBUG ? '' : '.min'; 835 $baseurl = self::get_baseurl(); 836 837 ?> 838 <script type="text/javascript"> 839 window.wp = window.wp || {}; 840 window.wp.editor = window.wp.editor || {}; 841 window.wp.editor.getDefaultSettings = function() { 842 return { 843 tinymce: <?php echo $settings; ?>, 844 quicktags: { 845 buttons: 'strong,em,link,ul,ol,li,code' 846 } 847 }; 848 }; 849 850 var tinyMCEPreInit = { 851 baseURL: "<?php echo $baseurl; ?>", 852 suffix: "<?php echo $suffix; ?>", 853 mceInit: {}, 854 qtInit: {}, 855 load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');} 856 }; 857 </script> 858 <?php 859 860 self::print_tinymce_scripts(); 861 862 self::wp_link_dialog(); 863 } 864 865 public static function get_mce_locale() { 866 if ( empty( self::$mce_locale ) ) { 867 $mce_locale = get_user_locale(); 868 self::$mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1 869 } 870 871 return self::$mce_locale; 872 } 873 874 public static function get_baseurl() { 875 if ( empty( self::$baseurl ) ) { 876 self::$baseurl = includes_url( 'js/tinymce' ); 877 } 878 879 return self::$baseurl; 880 } 881 882 // Only default settings. Doesn't include plugins, buttons, editor selector. 883 private static function default_settings() { 884 global $tinymce_version; 885 886 $shortcut_labels = array(); 887 888 foreach ( self::get_translation() as $name => $value ) { 889 if ( is_array( $value ) ) { 890 $shortcut_labels[$name] = $value[1]; 891 } 892 } 893 894 $settings = array( 895 'theme' => 'modern', 896 'skin' => 'lightgray', 897 'language' => self::get_mce_locale(), 898 'formats' => '{' . 899 'alignleft: [' . 900 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' . 901 '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' . 902 '],' . 903 'aligncenter: [' . 904 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' . 905 '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' . 906 '],' . 907 'alignright: [' . 908 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' . 909 '{selector: "img,table,dl.wp-caption", classes: "alignright"}' . 910 '],' . 911 'strikethrough: {inline: "del"}' . 912 '}', 913 'relative_urls' => false, 914 'remove_script_host' => false, 915 'convert_urls' => false, 916 'browser_spellcheck' => true, 917 'fix_list_elements' => true, 918 'entities' => '38,amp,60,lt,62,gt', 919 'entity_encoding' => 'raw', 920 'keep_styles' => false, 921 'cache_suffix' => 'wp-mce-' . $tinymce_version, 922 'resize' => 'vertical', 923 'menubar' => false, 924 925 // Limit the preview styles in the menu/toolbar 926 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform', 927 928 'end_container_on_empty_block' => true, 929 'wpeditimage_html5_captions' => true, 930 'wp_lang_attr' => get_bloginfo( 'language' ), 931 'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ), 932 ); 933 934 $suffix = SCRIPT_DEBUG ? '' : '.min'; 935 $version = 'ver=' . get_bloginfo( 'version' ); 936 937 // Default stylesheets 938 $settings['content_css'] = includes_url( "css/dashicons$suffix.css?$version" ) . ',' . 939 includes_url( "js/tinymce/skins/wordpress/wp-content.css?$version" ); 940 941 return $settings; 942 } 943 825 944 private static function get_translation() { 826 945 if ( empty( self::$translation ) ) { 827 946 self::$translation = array( … … 1028 1147 1029 1148 /* translators: word count */ 1030 1149 'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ), 1031 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' => __( 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' ) . "\n\n" . __( 'If you’re looking to paste rich content from Microsoft Word, try turning this option off. The editor will clean up text pasted from Word automatically.' ), 1032 'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' => __( 'Rich Text Area. Press Alt-Shift-H for help.' ), 1150 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' => 1151 __( 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' ) . "\n\n" . 1152 __( 'If you’re looking to paste rich content from Microsoft Word, try turning this option off. The editor will clean up text pasted from Word automatically.' ), 1153 'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' => 1154 __( 'Rich Text Area. Press Alt-Shift-H for help.' ), 1033 1155 'Rich Text Area. Press Control-Option-H for help.' => __( 'Rich Text Area. Press Control-Option-H for help.' ), 1034 'You have unsaved changes are you sure you want to navigate away?' => __( 'The changes you made will be lost if you navigate away from this page.' ), 1035 'Your browser doesn\'t support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.' => __( 'Your browser does not support direct access to the clipboard. Please use keyboard shortcuts or your browser’s edit menu instead.' ), 1156 'You have unsaved changes are you sure you want to navigate away?' => 1157 __( 'The changes you made will be lost if you navigate away from this page.' ), 1158 'Your browser doesn\'t support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.' => 1159 __( 'Your browser does not support direct access to the clipboard. Please use keyboard shortcuts or your browser’s edit menu instead.' ), 1036 1160 1037 1161 // TinyMCE menus 1038 1162 'Insert' => _x( 'Insert', 'TinyMCE menu' ), … … 1055 1179 'Paste URL or type to search' => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog 1056 1180 'Apply' => __( 'Apply' ), // Tooltip for the 'apply' button in the inline link dialog 1057 1181 'Link options' => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog 1182 'Visual' => __( 'Visual' ), // Editor switch tab label 1183 'Text' => __( 'Text' ), // Editor switch tab label 1058 1184 1059 1185 // Shortcuts help modal 1060 1186 'Keyboard Shortcuts' => array( __( 'Keyboard Shortcuts' ), 'accessH' ), … … 1098 1224 } 1099 1225 1100 1226 /** 1101 * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n() .1102 * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.1227 * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(), 1228 * or as JS snippet that should run after tinymce.js is loaded. 1103 1229 * 1104 1230 * @static 1105 1231 * @param string $mce_locale The locale used for the editor. … … 1108 1234 */ 1109 1235 public static function wp_mce_translation( $mce_locale = '', $json_only = false ) { 1110 1236 if ( ! $mce_locale ) { 1111 $mce_locale = self:: $mce_locale;1237 $mce_locale = self::get_mce_locale(); 1112 1238 } 1113 1239 1114 1240 $mce_translation = self::get_translation(); 1115 1241 1116 1242 foreach ( $mce_translation as $name => $value ) { 1117 1243 if ( is_array( $value ) ) { 1118 1244 $mce_translation[$name] = $value[0]; … … 1150 1276 return wp_json_encode( $mce_translation ); 1151 1277 } 1152 1278 1153 $baseurl = self:: $baseurl ? self::$baseurl : includes_url( 'js/tinymce');1279 $baseurl = self::get_baseurl(); 1154 1280 1155 1281 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" . 1156 1282 "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n"; 1157 1283 } 1158 1284 1285 public static function print_tinymce_scripts() { 1286 global $tinymce_version, $concatenate_scripts, $compress_scripts; 1287 1288 if ( self::$tinymce_scripts_printed ) { 1289 return; 1290 } 1291 1292 self::$tinymce_scripts_printed = true; 1293 1294 if ( ! isset( $concatenate_scripts ) ) { 1295 script_concat_settings(); 1296 } 1297 1298 $version = 'ver=' . $tinymce_version; 1299 $baseurl = self::get_baseurl(); 1300 1301 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING']) 1302 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); 1303 1304 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG) 1305 $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min'; 1306 1307 if ( $compressed ) { 1308 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&$version'></script>\n"; 1309 } else { 1310 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n"; 1311 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n"; 1312 } 1313 1314 echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n"; 1315 } 1316 1159 1317 /** 1160 1318 * 1161 1319 * @static … … 1166 1324 public static function editor_js() { 1167 1325 global $tinymce_version, $concatenate_scripts, $compress_scripts; 1168 1326 1169 /** 1170 * Filters "tiny_mce_version" is deprecated 1171 * 1172 * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE. 1173 * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter. 1174 * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code). 1175 */ 1176 $version = 'ver=' . $tinymce_version; 1177 $tmce_on = !empty(self::$mce_settings); 1327 $tmce_on = ! empty( self::$mce_settings ); 1328 $mceInit = $qtInit = ''; 1178 1329 1179 if ( ! isset($concatenate_scripts) )1180 script_concat_settings();1181 1182 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])1183 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');1184 1185 $mceInit = $qtInit = '';1186 1330 if ( $tmce_on ) { 1187 1331 foreach ( self::$mce_settings as $editor_id => $init ) { 1188 1332 $options = self::_parse_init( $init ); 1189 1333 $mceInit .= "'$editor_id':{$options},"; 1190 1334 } 1191 $mceInit = '{' . trim( $mceInit, ',') . '}';1335 $mceInit = '{' . trim( $mceInit, ',' ) . '}'; 1192 1336 } else { 1193 1337 $mceInit = '{}'; 1194 1338 } 1195 1339 1196 if ( ! empty(self::$qt_settings) ) {1340 if ( ! empty( self::$qt_settings ) ) { 1197 1341 foreach ( self::$qt_settings as $editor_id => $init ) { 1198 1342 $options = self::_parse_init( $init ); 1199 1343 $qtInit .= "'$editor_id':{$options},"; 1200 1344 } 1201 $qtInit = '{' . trim( $qtInit, ',') . '}';1345 $qtInit = '{' . trim( $qtInit, ',' ) . '}'; 1202 1346 } else { 1203 1347 $qtInit = '{}'; 1204 1348 } … … 1210 1354 ); 1211 1355 1212 1356 $suffix = SCRIPT_DEBUG ? '' : '.min'; 1357 $baseurl = self::get_baseurl(); 1213 1358 1214 1359 /** 1215 1360 * Fires immediately before the TinyMCE settings are printed. … … 1223 1368 1224 1369 <script type="text/javascript"> 1225 1370 tinyMCEPreInit = { 1226 baseURL: "<?php echo self::$baseurl; ?>",1371 baseURL: "<?php echo $baseurl; ?>", 1227 1372 suffix: "<?php echo $suffix; ?>", 1228 1373 <?php 1229 1374 … … 1240 1385 </script> 1241 1386 <?php 1242 1387 1243 $baseurl = self::$baseurl;1244 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)1245 $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min';1246 1247 1388 if ( $tmce_on ) { 1248 if ( $compressed ) { 1249 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&$version'></script>\n"; 1250 } else { 1251 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n"; 1252 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n"; 1253 } 1389 self::print_tinymce_scripts(); 1254 1390 1255 echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";1256 1257 1391 if ( self::$ext_plugins ) { 1258 1392 // Load the old-format English strings to prevent unsightly labels in old style popups 1259 1393 echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n"; … … 1434 1568 * @static 1435 1569 */ 1436 1570 public static function wp_link_dialog() { 1571 // Run once 1572 if ( self::$link_dialog_printed ) { 1573 return; 1574 } 1575 1576 self::$link_dialog_printed = true; 1577 1437 1578 // display: none is required here, see #WP27605 1438 1579 ?> 1439 1580 <div id="wp-link-backdrop" style="display: none"></div> -
src/wp-includes/general-template.php
3057 3057 } 3058 3058 3059 3059 /** 3060 * Outputs the editor scripts, stylesheets, and default settings. 3061 * 3062 * The editor can be initialized when needed after page load. 3063 * See wp.editor.initialize() in wp-admin/js/editor.js for initialization options. 3064 * 3065 * @uses _WP_Editors 3066 * @since 4.8.0 3067 */ 3068 function wp_enqueue_editor() { 3069 if ( ! class_exists( '_WP_Editors', false ) ) { 3070 require( ABSPATH . WPINC . '/class-wp-editor.php' ); 3071 } 3072 3073 _WP_Editors::enqueue_default_editor(); 3074 } 3075 3076 /** 3060 3077 * Retrieves the contents of the search WordPress query variable. 3061 3078 * 3062 3079 * The search query string is passed through esc_attr() to ensure that it is safe