Make WordPress Core


Ignore:
Timestamp:
10/17/2018 03:28:33 PM (6 years ago)
Author:
atimmer
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.
Fixes #45065.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/class-wp-editor.php

    r43482 r43738  
    310310            if ( is_admin() ) {
    311311                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
     312                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    312313                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
    313314            } else {
    314315                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
     316                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    315317                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
    316318            }
     
    744746     *
    745747     * @static
    746      * 
     748     *
    747749     * @param bool $default_scripts Optional. Whether default scripts should be enqueued. Default false.
    748750     */
     
    806808
    807809        if ( is_admin() ) {
     810            add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    808811            add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
    809812        } else {
     813            add_action( 'wp_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    810814            add_action( 'wp_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
    811815        }
     
    13741378
    13751379    /**
     1380     * Force uncompressed TinyMCE when a custom theme has been defined.
     1381     *
     1382     * The compressed TinyMCE file cannot deal with custom themes, so this makes
     1383     * sure that we use the uncompressed TinyMCE file if a theme is defined.
     1384     * Even if we are on a production environment.
     1385     */
     1386    public static function force_uncompressed_tinymce() {
     1387        $has_custom_theme = false;
     1388        foreach ( self::$mce_settings as $init ) {
     1389            if ( ! empty( $init['theme_url'] ) ) {
     1390                $has_custom_theme = true;
     1391                break;
     1392            }
     1393        }
     1394
     1395        if ( ! $has_custom_theme ) {
     1396            return;
     1397        }
     1398
     1399        $wp_scripts = wp_scripts();
     1400
     1401        $wp_scripts->remove( 'wp-tinymce' );
     1402        wp_register_tinymce_scripts( $wp_scripts, true );
     1403    }
     1404
     1405    /**
    13761406     * Print (output) the main TinyMCE scripts.
    13771407     *
     
    13841414     */
    13851415    public static function print_tinymce_scripts() {
    1386         global $tinymce_version, $concatenate_scripts, $compress_scripts;
     1416        global $concatenate_scripts;
    13871417
    13881418        if ( self::$tinymce_scripts_printed ) {
     
    13941424        if ( ! isset( $concatenate_scripts ) ) {
    13951425            script_concat_settings();
    1396         }
    1397 
    1398         $suffix = SCRIPT_DEBUG ? '' : '.min';
    1399         $version = 'ver=' . $tinymce_version;
    1400         $baseurl = self::get_baseurl();
    1401 
    1402         $has_custom_theme = false;
    1403         foreach ( self::$mce_settings as $init ) {
    1404             if ( ! empty( $init['theme_url'] ) ) {
    1405                 $has_custom_theme = true;
    1406                 break;
    1407             }
    1408         }
    1409 
    1410         $compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] )
    1411             && false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $has_custom_theme;
    1412 
    1413         // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
    1414         $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min';
    1415 
    1416         if ( $compressed ) {
    1417             echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
    1418         } else {
    1419             echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
    1420             echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
    14211426        }
    14221427
Note: See TracChangeset for help on using the changeset viewer.