Make WordPress Core


Ignore:
Timestamp:
12/13/2018 05:26:09 PM (8 years ago)
Author:
desrosj
Message:

Script loader: Adjust JS packages registration.

Adjusts the packages registration after [43723]:

Combine the different registration functions into one wp_default_packages function. To reach this goal move the prefix logic into a function so it can be called from different locations. Use a static variable there to prevent duplicate inclusion of version.php.

Call this function from the wp_default_scripts action by registering it as a default filter.

Combine some of the logic in _WP_Editors::print_tinymce_scripts into wp_register_tinymce_scripts. The logic to force an uncompressed TinyMCE script file stays in _WP_Editors::force_uncompressed_tinymce because that logic is very specific to the classic editor.

The script handle wp-tinymce is now a dependency of the editor script handle. In combination with the previous item, this makes the classic editor work.

Adjust the syntax of the script paths to be more consistent with other WordPress code.

Always use "production" mode for the media files to prevent people from inadvertently committing development files.

Props pento, omarreiss, atimmer.

Merges [43738] into trunk.

Fixes #45065.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/class-wp-editor.php

    r43571 r44115  
    318318                        if ( is_admin() ) {
    319319                                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
     320                                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    320321                                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
    321322                        } else {
    322323                                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
     324                                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    323325                                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
    324326                        }
     
    756758
    757759        /**
     760         *
     761         * @static
     762         *
    758763         * @param bool $default_scripts Optional. Whether default scripts should be enqueued. Default false.
    759764         */
     
    820825
    821826                if ( is_admin() ) {
     827                        add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    822828                        add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
    823829                } else {
     830                        add_action( 'wp_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    824831                        add_action( 'wp_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
    825832                }
     
    13891396
    13901397        /**
     1398         * Force uncompressed TinyMCE when a custom theme has been defined.
     1399         *
     1400         * The compressed TinyMCE file cannot deal with custom themes, so this makes
     1401         * sure that we use the uncompressed TinyMCE file if a theme is defined.
     1402         * Even if we are on a production environment.
     1403         */
     1404        public static function force_uncompressed_tinymce() {
     1405                $has_custom_theme = false;
     1406                foreach ( self::$mce_settings as $init ) {
     1407                        if ( ! empty( $init['theme_url'] ) ) {
     1408                                $has_custom_theme = true;
     1409                                break;
     1410                        }
     1411                }
     1412
     1413                if ( ! $has_custom_theme ) {
     1414                        return;
     1415                }
     1416
     1417                $wp_scripts = wp_scripts();
     1418
     1419                $wp_scripts->remove( 'wp-tinymce' );
     1420                wp_register_tinymce_scripts( $wp_scripts, true );
     1421        }
     1422
     1423        /**
    13911424         * Print (output) the main TinyMCE scripts.
    13921425         *
     
    13981431         */
    13991432        public static function print_tinymce_scripts() {
    1400                 global $tinymce_version, $concatenate_scripts, $compress_scripts;
     1433                global $concatenate_scripts;
    14011434
    14021435                if ( self::$tinymce_scripts_printed ) {
     
    14091442                        script_concat_settings();
    14101443                }
    1411 
    1412                 $suffix  = SCRIPT_DEBUG ? '' : '.min';
    1413                 $version = 'ver=' . $tinymce_version;
    1414                 $baseurl = self::get_baseurl();
    1415 
    1416                 $has_custom_theme = false;
    1417                 foreach ( self::$mce_settings as $init ) {
    1418                         if ( ! empty( $init['theme_url'] ) ) {
    1419                                 $has_custom_theme = true;
    1420                                 break;
    1421                         }
    1422                 }
    1423 
    1424                 $compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] )
    1425                         && false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $has_custom_theme;
    1426 
    1427                 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
    1428                 $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min';
    1429 
    1430                 if ( $compressed ) {
    1431                         echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
    1432                 } else {
    1433                         echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
    1434                         echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
    1435                 }
    1436 
    1437                 echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
    14381444        }
    14391445
Note: See TracChangeset for help on using the changeset viewer.