wp/wp-includes/script-loader.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    52 	$suffix     = wp_scripts_get_suffix();
    52 	$suffix     = wp_scripts_get_suffix();
    53 	$dev_suffix = wp_scripts_get_suffix( 'dev' );
    53 	$dev_suffix = wp_scripts_get_suffix( 'dev' );
    54 
    54 
    55 	script_concat_settings();
    55 	script_concat_settings();
    56 
    56 
    57 	$compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] )
    57 	$compressed = $compress_scripts && $concatenate_scripts && ! $force_uncompressed;
    58 		&& false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $force_uncompressed;
       
    59 
    58 
    60 	/*
    59 	/*
    61 	 * Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production)
    60 	 * Load tinymce.js when running from /src, otherwise load wp-tinymce.js (in production)
    62 	 * or tinymce.min.js (when SCRIPT_DEBUG is true).
    61 	 * or tinymce.min.js (when SCRIPT_DEBUG is true).
    63 	 */
    62 	 */
    64 	if ( $compressed ) {
    63 	if ( $compressed ) {
    65 		$scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version );
    64 		$scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version );
    66 	} else {
    65 	} else {
    95 		'regenerator-runtime',
    94 		'regenerator-runtime',
    96 		'moment',
    95 		'moment',
    97 		'lodash',
    96 		'lodash',
    98 		'wp-polyfill-fetch',
    97 		'wp-polyfill-fetch',
    99 		'wp-polyfill-formdata',
    98 		'wp-polyfill-formdata',
   100 		'wp-polyfill-importmap',
       
   101 		'wp-polyfill-node-contains',
    99 		'wp-polyfill-node-contains',
   102 		'wp-polyfill-url',
   100 		'wp-polyfill-url',
   103 		'wp-polyfill-dom-rect',
   101 		'wp-polyfill-dom-rect',
   104 		'wp-polyfill-element-closest',
   102 		'wp-polyfill-element-closest',
   105 		'wp-polyfill-object-fit',
   103 		'wp-polyfill-object-fit',
   106 		'wp-polyfill-inert',
   104 		'wp-polyfill-inert',
   107 		'wp-polyfill',
   105 		'wp-polyfill',
   108 	);
   106 	);
   109 
   107 
   110 	$vendor_scripts_versions = array(
   108 	$vendor_scripts_versions = array(
   111 		'react'                       => '18.3.1',
   109 		'react'                       => '18.3.1.1', // Final .1 due to switch to UMD build, can be removed in the next update.
   112 		'react-dom'                   => '18.3.1',
   110 		'react-dom'                   => '18.3.1.1', // Final .1 due to switch to UMD build, can be removed in the next update.
   113 		'react-jsx-runtime'           => '18.3.1',
   111 		'react-jsx-runtime'           => '18.3.1',
   114 		'regenerator-runtime'         => '0.14.0',
   112 		'regenerator-runtime'         => '0.14.1',
   115 		'moment'                      => '2.29.4',
   113 		'moment'                      => '2.30.1',
   116 		'lodash'                      => '4.17.21',
   114 		'lodash'                      => '4.17.21',
   117 		'wp-polyfill-fetch'           => '3.6.17',
   115 		'wp-polyfill-fetch'           => '3.6.20',
   118 		'wp-polyfill-formdata'        => '4.0.10',
   116 		'wp-polyfill-formdata'        => '4.0.10',
   119 		'wp-polyfill-node-contains'   => '4.8.0',
   117 		'wp-polyfill-node-contains'   => '4.8.0',
   120 		'wp-polyfill-url'             => '3.6.4',
   118 		'wp-polyfill-url'             => '3.6.4',
   121 		'wp-polyfill-dom-rect'        => '4.8.0',
   119 		'wp-polyfill-dom-rect'        => '4.8.0',
   122 		'wp-polyfill-element-closest' => '3.0.2',
   120 		'wp-polyfill-element-closest' => '3.0.2',
   123 		'wp-polyfill-object-fit'      => '2.3.5',
   121 		'wp-polyfill-object-fit'      => '2.3.5',
   124 		'wp-polyfill-inert'           => '3.1.2',
   122 		'wp-polyfill-inert'           => '3.1.3',
   125 		'wp-polyfill'                 => '3.15.0',
   123 		'wp-polyfill'                 => '3.15.0',
   126 		'wp-polyfill-importmap'       => '1.8.2',
       
   127 	);
   124 	);
   128 
   125 
   129 	foreach ( $vendor_scripts as $handle => $dependencies ) {
   126 	foreach ( $vendor_scripts as $handle => $dependencies ) {
   130 		if ( is_string( $dependencies ) ) {
   127 		if ( is_string( $dependencies ) ) {
   131 			$handle       = $dependencies;
   128 			$handle       = $dependencies;
   611 	if ( $disable_captions ) {
   608 	if ( $disable_captions ) {
   612 		$tinymce_settings['wpeditimage_disable_captions'] = true;
   609 		$tinymce_settings['wpeditimage_disable_captions'] = true;
   613 	}
   610 	}
   614 
   611 
   615 	if ( ! empty( $editor_settings['tinymce'] ) && is_array( $editor_settings['tinymce'] ) ) {
   612 	if ( ! empty( $editor_settings['tinymce'] ) && is_array( $editor_settings['tinymce'] ) ) {
   616 		array_merge( $tinymce_settings, $editor_settings['tinymce'] );
   613 		$tinymce_settings = array_merge( $tinymce_settings, $editor_settings['tinymce'] );
   617 	}
   614 	}
   618 
   615 
   619 	/** This filter is documented in wp-includes/class-wp-editor.php */
   616 	/** This filter is documented in wp-includes/class-wp-editor.php */
   620 	$tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' );
   617 	$tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' );
   621 
   618 
   682  */
   679  */
   683 function wp_scripts_get_suffix( $type = '' ) {
   680 function wp_scripts_get_suffix( $type = '' ) {
   684 	static $suffixes;
   681 	static $suffixes;
   685 
   682 
   686 	if ( null === $suffixes ) {
   683 	if ( null === $suffixes ) {
   687 		// Include an unmodified $wp_version.
   684 		/*
       
   685 		 * Include an unmodified $wp_version.
       
   686 		 *
       
   687 		 * Note: wp_get_wp_version() is not used here, as this file can be included
       
   688 		 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
       
   689 		 * wp-includes/functions.php is not loaded.
       
   690 		 */
   688 		require ABSPATH . WPINC . '/version.php';
   691 		require ABSPATH . WPINC . '/version.php';
   689 
   692 
   690 		/*
   693 		/*
   691 		 * Note: str_contains() is not used here, as this file can be included
   694 		 * Note: str_contains() is not used here, as this file can be included
   692 		 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
   695 		 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
   749 			'time'   => (string) time(),
   752 			'time'   => (string) time(),
   750 			'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ),
   753 			'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ),
   751 		)
   754 		)
   752 	);
   755 	);
   753 
   756 
   754 	$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 );
   757 	$scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils', 'wp-a11y' ), false, 1 );
   755 	$scripts->set_translations( 'common' );
   758 	$scripts->set_translations( 'common' );
       
   759 
       
   760 	$bulk_action_observer_ids = array(
       
   761 		'bulk_action' => 'action',
       
   762 		'changeit'    => 'new_role',
       
   763 	);
       
   764 	did_action( 'init' ) && $scripts->localize(
       
   765 		'common',
       
   766 		'bulkActionObserverIds',
       
   767 		/**
       
   768 		 * Filters the array of field name attributes for bulk actions.
       
   769 		 *
       
   770 		 * @since 6.8.1
       
   771 		 *
       
   772 		 * @param array $bulk_action_observer_ids {
       
   773 		 *      An array of field name attributes for bulk actions.
       
   774 		 *
       
   775 		 *      @type string $bulk_action The bulk action field name. Default 'action'.
       
   776 		 *      @type string $changeit    The new role field name. Default 'new_role'.
       
   777 		 * }
       
   778 		 */
       
   779 		apply_filters( 'bulk_action_observer_ids', $bulk_action_observer_ids )
       
   780 	);
   756 
   781 
   757 	$scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
   782 	$scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
   758 
   783 
   759 	$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
   784 	$scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
   760 
   785 
   805 	did_action( 'init' ) && $scripts->localize(
   830 	did_action( 'init' ) && $scripts->localize(
   806 		'wp-ajax-response',
   831 		'wp-ajax-response',
   807 		'wpAjax',
   832 		'wpAjax',
   808 		array(
   833 		array(
   809 			'noPerm' => __( 'Sorry, you are not allowed to do that.' ),
   834 			'noPerm' => __( 'Sorry, you are not allowed to do that.' ),
   810 			'broken' => __( 'Something went wrong.' ),
   835 			'broken' => __( 'An error occurred while processing your request. Please try again later.' ),
   811 		)
   836 		)
   812 	);
   837 	);
   813 
   838 
   814 	$scripts->add( 'wp-api-request', "/wp-includes/js/api-request$suffix.js", array( 'jquery' ), false, 1 );
   839 	$scripts->add( 'wp-api-request', "/wp-includes/js/api-request$suffix.js", array( 'jquery' ), false, 1 );
   815 	// `wpApiSettings` is also used by `wp-api`, which depends on this script.
   840 	// `wpApiSettings` is also used by `wp-api`, which depends on this script.
   933 
   958 
   934 	// Deprecated, not used in core, most functionality is included in jQuery 1.3.
   959 	// Deprecated, not used in core, most functionality is included in jQuery 1.3.
   935 	$scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.3.0', 1 );
   960 	$scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.3.0', 1 );
   936 
   961 
   937 	// jQuery plugins.
   962 	// jQuery plugins.
   938 	$scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '2.2.0', 1 );
   963 	$scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '3.0.0', 1 );
   939 	$scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 );
   964 	$scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 );
   940 	$scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.2.3', 1 );
   965 	$scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.2.3', 1 );
   941 	$scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2-wp', 1 );
   966 	$scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2-wp', 1 );
   942 	$scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 );
   967 	$scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 );
   943 	$scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 );
   968 	$scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 );
   978 	$uploader_l10n = array(
  1003 	$uploader_l10n = array(
   979 		'queue_limit_exceeded'      => __( 'You have attempted to queue too many files.' ),
  1004 		'queue_limit_exceeded'      => __( 'You have attempted to queue too many files.' ),
   980 		/* translators: %s: File name. */
  1005 		/* translators: %s: File name. */
   981 		'file_exceeds_size_limit'   => __( '%s exceeds the maximum upload size for this site.' ),
  1006 		'file_exceeds_size_limit'   => __( '%s exceeds the maximum upload size for this site.' ),
   982 		'zero_byte_file'            => __( 'This file is empty. Please try another.' ),
  1007 		'zero_byte_file'            => __( 'This file is empty. Please try another.' ),
   983 		'invalid_filetype'          => __( 'Sorry, you are not allowed to upload this file type.' ),
  1008 		'invalid_filetype'          => __( 'This file cannot be processed by the web server.' ),
   984 		'not_an_image'              => __( 'This file is not an image. Please try another.' ),
  1009 		'not_an_image'              => __( 'This file is not an image. Please try another.' ),
   985 		'image_memory_exceeded'     => __( 'Memory exceeded. Please try another smaller file.' ),
  1010 		'image_memory_exceeded'     => __( 'Memory exceeded. Please try another smaller file.' ),
   986 		'image_dimensions_exceeded' => __( 'This is larger than the maximum size. Please try another.' ),
  1011 		'image_dimensions_exceeded' => __( 'This is larger than the maximum size. Please try another.' ),
   987 		'default_error'             => __( 'An error occurred in the upload. Please try again later.' ),
  1012 		'default_error'             => __( 'An error occurred in the upload. Please try again later.' ),
   988 		'missing_upload_url'        => __( 'There was a configuration error. Please contact the server administrator.' ),
  1013 		'missing_upload_url'        => __( 'There was a configuration error. Please contact the server administrator.' ),
  1002 		'crunching'                 => __( 'Crunching…' ),
  1027 		'crunching'                 => __( 'Crunching…' ),
  1003 		'deleted'                   => __( 'moved to the Trash.' ),
  1028 		'deleted'                   => __( 'moved to the Trash.' ),
  1004 		/* translators: %s: File name. */
  1029 		/* translators: %s: File name. */
  1005 		'error_uploading'           => __( '“%s” has failed to upload.' ),
  1030 		'error_uploading'           => __( '“%s” has failed to upload.' ),
  1006 		'unsupported_image'         => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ),
  1031 		'unsupported_image'         => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ),
  1007 		'noneditable_image'         => __( 'This image cannot be processed by the web server. Convert it to JPEG or PNG before uploading.' ),
  1032 		'noneditable_image'         => __( 'The web server cannot generate responsive image sizes for this image. Convert it to JPEG or PNG before uploading.' ),
  1008 		'file_url_copied'           => __( 'The file URL has been copied to your clipboard' ),
  1033 		'file_url_copied'           => __( 'The file URL has been copied to your clipboard' ),
  1009 	);
  1034 	);
  1010 
  1035 
  1011 	$scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' );
  1036 	$scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5.1' );
  1012 	$scripts->add( 'plupload', "/wp-includes/js/plupload/plupload$suffix.js", array( 'moxiejs' ), '2.1.9' );
  1037 	$scripts->add( 'plupload', "/wp-includes/js/plupload/plupload$suffix.js", array( 'moxiejs' ), '2.1.9' );
  1013 	// Back compat handles:
  1038 	// Back compat handles:
  1014 	foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) {
  1039 	foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) {
  1015 		$scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' );
  1040 		$scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' );
  1016 	}
  1041 	}
  1031 	did_action( 'init' ) && $scripts->add_data( 'comment-reply', 'strategy', 'async' );
  1056 	did_action( 'init' ) && $scripts->add_data( 'comment-reply', 'strategy', 'async' );
  1032 
  1057 
  1033 	$scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' );
  1058 	$scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' );
  1034 	did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' );
  1059 	did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' );
  1035 
  1060 
  1036 	$scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.13.4', 1 );
  1061 	$scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.13.7', 1 );
  1037 	$scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.5.0', 1 );
  1062 	$scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.6.0', 1 );
  1038 
  1063 
  1039 	$scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 );
  1064 	$scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 );
  1040 	did_action( 'init' ) && $scripts->localize(
  1065 	did_action( 'init' ) && $scripts->localize(
  1041 		'wp-util',
  1066 		'wp-util',
  1042 		'_wpUtilSettings',
  1067 		'_wpUtilSettings',
  1212 	$scripts->set_translations( 'application-passwords' );
  1237 	$scripts->set_translations( 'application-passwords' );
  1213 
  1238 
  1214 	$scripts->add( 'auth-app', "/wp-admin/js/auth-app$suffix.js", array( 'jquery', 'wp-api-request', 'wp-i18n', 'wp-hooks' ), false, 1 );
  1239 	$scripts->add( 'auth-app', "/wp-admin/js/auth-app$suffix.js", array( 'jquery', 'wp-api-request', 'wp-i18n', 'wp-hooks' ), false, 1 );
  1215 	$scripts->set_translations( 'auth-app' );
  1240 	$scripts->set_translations( 'auth-app' );
  1216 
  1241 
  1217 	$scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
  1242 	$scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'clipboard', 'jquery', 'password-strength-meter', 'wp-util', 'wp-a11y' ), false, 1 );
  1218 	$scripts->set_translations( 'user-profile' );
  1243 	$scripts->set_translations( 'user-profile' );
  1219 	$user_id = isset( $_GET['user_id'] ) ? (int) $_GET['user_id'] : 0;
  1244 	$user_id = isset( $_GET['user_id'] ) ? (int) $_GET['user_id'] : 0;
  1220 	did_action( 'init' ) && $scripts->localize(
  1245 	did_action( 'init' ) && $scripts->localize(
  1221 		'user-profile',
  1246 		'user-profile',
  1222 		'userProfileL10n',
  1247 		'userProfileL10n',
  1287 			'saved'                   => __( 'Saved' ),
  1312 			'saved'                   => __( 'Saved' ),
  1288 			'cancel'                  => __( 'Cancel' ),
  1313 			'cancel'                  => __( 'Cancel' ),
  1289 			'close'                   => __( 'Close' ),
  1314 			'close'                   => __( 'Close' ),
  1290 			'action'                  => __( 'Action' ),
  1315 			'action'                  => __( 'Action' ),
  1291 			'discardChanges'          => __( 'Discard changes' ),
  1316 			'discardChanges'          => __( 'Discard changes' ),
  1292 			'cheatin'                 => __( 'Something went wrong.' ),
  1317 			'cheatin'                 => __( 'An error occurred. Please try again later.' ),
  1293 			'notAllowedHeading'       => __( 'You need a higher level of permission.' ),
  1318 			'notAllowedHeading'       => __( 'You need a higher level of permission.' ),
  1294 			'notAllowed'              => __( 'Sorry, you are not allowed to customize this site.' ),
  1319 			'notAllowed'              => __( 'Sorry, you are not allowed to customize this site.' ),
  1295 			'previewIframeTitle'      => __( 'Site Preview' ),
  1320 			'previewIframeTitle'      => __( 'Site Preview' ),
  1296 			'loginIframeTitle'        => __( 'Session expired' ),
  1321 			'loginIframeTitle'        => __( 'Session expired' ),
  1297 			'collapseSidebar'         => _x( 'Hide Controls', 'label for hide controls button without length constraints' ),
  1322 			'collapseSidebar'         => _x( 'Hide Controls', 'label for hide controls button without length constraints' ),
  1390 
  1415 
  1391 	if ( is_admin() ) {
  1416 	if ( is_admin() ) {
  1392 		$scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );
  1417 		$scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );
  1393 		$scripts->set_translations( 'admin-tags' );
  1418 		$scripts->set_translations( 'admin-tags' );
  1394 
  1419 
  1395 		$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 );
  1420 		$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query', 'wp-a11y' ), false, 1 );
  1396 		$scripts->set_translations( 'admin-comments' );
  1421 		$scripts->set_translations( 'admin-comments' );
  1397 		did_action( 'init' ) && $scripts->localize(
  1422 		did_action( 'init' ) && $scripts->localize(
  1398 			'admin-comments',
  1423 			'admin-comments',
  1399 			'adminCommentsSettings',
  1424 			'adminCommentsSettings',
  1400 			array(
  1425 			array(
  1520  * @param WP_Styles $styles
  1545  * @param WP_Styles $styles
  1521  */
  1546  */
  1522 function wp_default_styles( $styles ) {
  1547 function wp_default_styles( $styles ) {
  1523 	global $editor_styles;
  1548 	global $editor_styles;
  1524 
  1549 
  1525 	// Include an unmodified $wp_version.
  1550 	/*
       
  1551 	 * Include an unmodified $wp_version.
       
  1552 	 *
       
  1553 	 * Note: wp_get_wp_version() is not used here, as this file can be included
       
  1554 	 * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
       
  1555 	 * wp-includes/functions.php is not loaded.
       
  1556 	 */
  1526 	require ABSPATH . WPINC . '/version.php';
  1557 	require ABSPATH . WPINC . '/version.php';
  1527 
  1558 
  1528 	if ( ! defined( 'SCRIPT_DEBUG' ) ) {
  1559 	if ( ! defined( 'SCRIPT_DEBUG' ) ) {
  1529 		/*
  1560 		/*
  1530 		 * Note: str_contains() is not used here, as this file can be included
  1561 		 * Note: str_contains() is not used here, as this file can be included
  1616 	$styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css", array( 'dashicons' ) );
  1647 	$styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css", array( 'dashicons' ) );
  1617 	$styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons', 'dashicons', 'wp-mediaelement' ) );
  1648 	$styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons', 'dashicons', 'wp-mediaelement' ) );
  1618 	$styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array( 'dashicons' ) );
  1649 	$styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array( 'dashicons' ) );
  1619 	$styles->add( 'customize-preview', "/wp-includes/css/customize-preview$suffix.css", array( 'dashicons' ) );
  1650 	$styles->add( 'customize-preview', "/wp-includes/css/customize-preview$suffix.css", array( 'dashicons' ) );
  1620 	$styles->add( 'wp-embed-template-ie', "/wp-includes/css/wp-embed-template-ie$suffix.css" );
  1651 	$styles->add( 'wp-embed-template-ie', "/wp-includes/css/wp-embed-template-ie$suffix.css" );
       
  1652 	$styles->add( 'wp-empty-template-alert', "/wp-includes/css/wp-empty-template-alert$suffix.css" );
  1621 	$styles->add_data( 'wp-embed-template-ie', 'conditional', 'lte IE 8' );
  1653 	$styles->add_data( 'wp-embed-template-ie', 'conditional', 'lte IE 8' );
  1622 
  1654 
  1623 	// External libraries and friends.
  1655 	// External libraries and friends.
  1624 	$styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' );
  1656 	$styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' );
  1625 	$styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array( 'dashicons' ) );
  1657 	$styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array( 'dashicons' ) );
  1650 	$styles->add( 'wp-editor-font', $fonts_url ); // No longer used in core as of 5.7.
  1682 	$styles->add( 'wp-editor-font', $fonts_url ); // No longer used in core as of 5.7.
  1651 	$block_library_theme_path = WPINC . "/css/dist/block-library/theme$suffix.css";
  1683 	$block_library_theme_path = WPINC . "/css/dist/block-library/theme$suffix.css";
  1652 	$styles->add( 'wp-block-library-theme', "/$block_library_theme_path" );
  1684 	$styles->add( 'wp-block-library-theme', "/$block_library_theme_path" );
  1653 	$styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path );
  1685 	$styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path );
  1654 
  1686 
       
  1687 	$classic_theme_styles_path = WPINC . "/css/classic-themes$suffix.css";
       
  1688 	$styles->add( 'classic-theme-styles', "/$classic_theme_styles_path" );
       
  1689 	$styles->add_data( 'classic-theme-styles', 'path', ABSPATH . $classic_theme_styles_path );
       
  1690 
  1655 	$styles->add(
  1691 	$styles->add(
  1656 		'wp-reset-editor-styles',
  1692 		'wp-reset-editor-styles',
  1657 		"/wp-includes/css/dist/block-library/reset$suffix.css",
  1693 		"/wp-includes/css/dist/block-library/reset$suffix.css",
  1658 		array( 'common', 'forms' ) // Make sure the reset is loaded after the default WP Admin styles.
  1694 		array( 'common', 'forms' ) // Make sure the reset is loaded after the default WP Admin styles.
  1659 	);
  1695 	);
  1668 		'wp-block-editor-content',
  1704 		'wp-block-editor-content',
  1669 		"/wp-includes/css/dist/block-editor/content$suffix.css",
  1705 		"/wp-includes/css/dist/block-editor/content$suffix.css",
  1670 		array( 'wp-components' )
  1706 		array( 'wp-components' )
  1671 	);
  1707 	);
  1672 
  1708 
       
  1709 	// Only add CONTENT styles here that should be enqueued in the iframe!
  1673 	$wp_edit_blocks_dependencies = array(
  1710 	$wp_edit_blocks_dependencies = array(
  1674 		'wp-components',
  1711 		'wp-components',
  1675 		'wp-editor',
       
  1676 		/*
  1712 		/*
  1677 		 * This needs to be added before the block library styles,
  1713 		 * This needs to be added before the block library styles,
  1678 		 * The block library styles override the "reset" styles.
  1714 		 * The block library styles override the "reset" styles.
  1679 		 */
  1715 		 */
  1680 		'wp-reset-editor-styles',
  1716 		'wp-reset-editor-styles',
  1681 		'wp-block-library',
  1717 		'wp-block-library',
  1682 		'wp-reusable-blocks',
       
  1683 		'wp-block-editor-content',
  1718 		'wp-block-editor-content',
  1684 		'wp-patterns',
       
  1685 	);
  1719 	);
  1686 
  1720 
  1687 	// Only load the default layout and margin styles for themes without theme.json file.
  1721 	// Only load the default layout and margin styles for themes without theme.json file.
  1688 	if ( ! wp_theme_has_theme_json() ) {
  1722 	if ( ! wp_theme_has_theme_json() ) {
  1689 		$wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
  1723 		$wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
  1738 			'wp-components',
  1772 			'wp-components',
  1739 		),
  1773 		),
  1740 		'edit-widgets'         => array(
  1774 		'edit-widgets'         => array(
  1741 			'wp-widgets',
  1775 			'wp-widgets',
  1742 			'wp-block-editor',
  1776 			'wp-block-editor',
       
  1777 			'wp-editor',
  1743 			'wp-edit-blocks',
  1778 			'wp-edit-blocks',
  1744 			'wp-block-library',
  1779 			'wp-block-library',
  1745 			'wp-reusable-blocks',
       
  1746 			'wp-patterns',
  1780 			'wp-patterns',
  1747 			'wp-preferences',
  1781 			'wp-preferences',
  1748 		),
  1782 		),
  1749 		'customize-widgets'    => array(
  1783 		'customize-widgets'    => array(
  1750 			'wp-widgets',
  1784 			'wp-widgets',
  1751 			'wp-block-editor',
  1785 			'wp-block-editor',
       
  1786 			'wp-editor',
  1752 			'wp-edit-blocks',
  1787 			'wp-edit-blocks',
  1753 			'wp-block-library',
  1788 			'wp-block-library',
  1754 			'wp-reusable-blocks',
       
  1755 			'wp-patterns',
  1789 			'wp-patterns',
  1756 			'wp-preferences',
  1790 			'wp-preferences',
  1757 		),
  1791 		),
  1758 		'edit-site'            => array(
  1792 		'edit-site'            => array(
  1759 			'wp-components',
  1793 			'wp-components',
  1760 			'wp-block-editor',
  1794 			'wp-block-editor',
       
  1795 			'wp-editor',
  1761 			'wp-edit-blocks',
  1796 			'wp-edit-blocks',
  1762 			'wp-commands',
  1797 			'wp-commands',
  1763 			'wp-preferences',
  1798 			'wp-preferences',
  1764 		),
  1799 		),
  1765 	);
  1800 	);
  1798 		'customize-widgets',
  1833 		'customize-widgets',
  1799 		'customize-nav-menus',
  1834 		'customize-nav-menus',
  1800 		'customize-preview',
  1835 		'customize-preview',
  1801 		'login',
  1836 		'login',
  1802 		'site-health',
  1837 		'site-health',
       
  1838 		'wp-empty-template-alert',
  1803 		// Includes CSS.
  1839 		// Includes CSS.
  1804 		'buttons',
  1840 		'buttons',
  1805 		'admin-bar',
  1841 		'admin-bar',
  1806 		'wp-auth-check',
  1842 		'wp-auth-check',
  1807 		'editor-buttons',
  1843 		'editor-buttons',
  2083  *
  2119  *
  2084  * @see wp_print_scripts()
  2120  * @see wp_print_scripts()
  2085  *
  2121  *
  2086  * @global bool $concatenate_scripts
  2122  * @global bool $concatenate_scripts
  2087  *
  2123  *
  2088  * @return array
  2124  * @return string[] Handles of the scripts that were printed.
  2089  */
  2125  */
  2090 function print_head_scripts() {
  2126 function print_head_scripts() {
  2091 	global $concatenate_scripts;
  2127 	global $concatenate_scripts;
  2092 
  2128 
  2093 	if ( ! did_action( 'wp_print_scripts' ) ) {
  2129 	if ( ! did_action( 'wp_print_scripts' ) ) {
  2122  * @since 2.8.0
  2158  * @since 2.8.0
  2123  *
  2159  *
  2124  * @global WP_Scripts $wp_scripts
  2160  * @global WP_Scripts $wp_scripts
  2125  * @global bool       $concatenate_scripts
  2161  * @global bool       $concatenate_scripts
  2126  *
  2162  *
  2127  * @return array
  2163  * @return string[] Handles of the scripts that were printed.
  2128  */
  2164  */
  2129 function print_footer_scripts() {
  2165 function print_footer_scripts() {
  2130 	global $wp_scripts, $concatenate_scripts;
  2166 	global $wp_scripts, $concatenate_scripts;
  2131 
  2167 
  2132 	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
  2168 	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
  2203  *
  2239  *
  2204  * @since 2.8.0
  2240  * @since 2.8.0
  2205  *
  2241  *
  2206  * @global WP_Scripts $wp_scripts
  2242  * @global WP_Scripts $wp_scripts
  2207  *
  2243  *
  2208  * @return array
  2244  * @return string[] Handles of the scripts that were printed.
  2209  */
  2245  */
  2210 function wp_print_head_scripts() {
  2246 function wp_print_head_scripts() {
  2211 	global $wp_scripts;
  2247 	global $wp_scripts;
  2212 
  2248 
  2213 	if ( ! did_action( 'wp_print_scripts' ) ) {
  2249 	if ( ! did_action( 'wp_print_scripts' ) ) {
  2268  *
  2304  *
  2269  * @since 2.8.0
  2305  * @since 2.8.0
  2270  *
  2306  *
  2271  * @global bool $concatenate_scripts
  2307  * @global bool $concatenate_scripts
  2272  *
  2308  *
  2273  * @return array
  2309  * @return string[] Handles of the styles that were printed.
  2274  */
  2310  */
  2275 function print_admin_styles() {
  2311 function print_admin_styles() {
  2276 	global $concatenate_scripts;
  2312 	global $concatenate_scripts;
  2277 
  2313 
  2278 	$wp_styles = wp_styles();
  2314 	$wp_styles = wp_styles();
  2475  * Enqueues the global styles defined via theme.json.
  2511  * Enqueues the global styles defined via theme.json.
  2476  *
  2512  *
  2477  * @since 5.8.0
  2513  * @since 5.8.0
  2478  */
  2514  */
  2479 function wp_enqueue_global_styles() {
  2515 function wp_enqueue_global_styles() {
  2480 	$separate_assets  = wp_should_load_separate_core_block_assets();
  2516 	$assets_on_demand = wp_should_load_block_assets_on_demand();
  2481 	$is_block_theme   = wp_is_block_theme();
  2517 	$is_block_theme   = wp_is_block_theme();
  2482 	$is_classic_theme = ! $is_block_theme;
  2518 	$is_classic_theme = ! $is_block_theme;
  2483 
  2519 
  2484 	/*
  2520 	/*
  2485 	 * Global styles should be printed in the head when loading all styles combined.
  2521 	 * Global styles should be printed in the head for block themes, or for classic themes when loading assets on
  2486 	 * The footer should only be used to print global styles for classic themes with separate core assets enabled.
  2522 	 * demand is disabled, which is the default.
  2487 	 *
  2523 	 * The footer should only be used for classic themes when loading assets on demand is enabled.
  2488 	 * See https://core.trac.wordpress.org/ticket/53494.
  2524 	 *
       
  2525 	 * See https://core.trac.wordpress.org/ticket/53494 and https://core.trac.wordpress.org/ticket/61965.
  2489 	 */
  2526 	 */
  2490 	if (
  2527 	if (
  2491 		( $is_block_theme && doing_action( 'wp_footer' ) ) ||
  2528 		( $is_block_theme && doing_action( 'wp_footer' ) ) ||
  2492 		( $is_classic_theme && doing_action( 'wp_footer' ) && ! $separate_assets ) ||
  2529 		( $is_classic_theme && doing_action( 'wp_footer' ) && ! $assets_on_demand ) ||
  2493 		( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) && $separate_assets )
  2530 		( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) && $assets_on_demand )
  2494 	) {
  2531 	) {
  2495 		return;
  2532 		return;
  2496 	}
  2533 	}
  2497 
  2534 
  2498 	/*
  2535 	/*
  2502 	 */
  2539 	 */
  2503 	add_filter( 'wp_theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );
  2540 	add_filter( 'wp_theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );
  2504 
  2541 
  2505 	$stylesheet = wp_get_global_stylesheet();
  2542 	$stylesheet = wp_get_global_stylesheet();
  2506 
  2543 
       
  2544 	if ( $is_block_theme ) {
       
  2545 		/*
       
  2546 		 * Dequeue the Customizer's custom CSS
       
  2547 		 * and add it before the global styles custom CSS.
       
  2548 		 */
       
  2549 		remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
       
  2550 		// Get the custom CSS from the Customizer and add it to the global stylesheet.
       
  2551 		$custom_css  = wp_get_custom_css();
       
  2552 		$stylesheet .= $custom_css;
       
  2553 
       
  2554 		// Add the global styles custom CSS at the end.
       
  2555 		$stylesheet .= wp_get_global_stylesheet( array( 'custom-css' ) );
       
  2556 	}
       
  2557 
  2507 	if ( empty( $stylesheet ) ) {
  2558 	if ( empty( $stylesheet ) ) {
  2508 		return;
  2559 		return;
  2509 	}
  2560 	}
  2510 
  2561 
  2511 	wp_register_style( 'global-styles', false );
  2562 	wp_register_style( 'global-styles', false );
  2515 	// Add each block as an inline css.
  2566 	// Add each block as an inline css.
  2516 	wp_add_global_styles_for_blocks();
  2567 	wp_add_global_styles_for_blocks();
  2517 }
  2568 }
  2518 
  2569 
  2519 /**
  2570 /**
  2520  * Enqueues the global styles custom css defined via theme.json.
       
  2521  *
       
  2522  * @since 6.2.0
       
  2523  */
       
  2524 function wp_enqueue_global_styles_custom_css() {
       
  2525 	if ( ! wp_is_block_theme() ) {
       
  2526 		return;
       
  2527 	}
       
  2528 
       
  2529 	// Don't enqueue Customizer's custom CSS separately.
       
  2530 	remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
       
  2531 
       
  2532 	$custom_css  = wp_get_custom_css();
       
  2533 	$custom_css .= wp_get_global_styles_custom_css();
       
  2534 
       
  2535 	if ( ! empty( $custom_css ) ) {
       
  2536 		wp_add_inline_style( 'global-styles', $custom_css );
       
  2537 	}
       
  2538 }
       
  2539 
       
  2540 /**
       
  2541  * Checks if the editor scripts and styles for all registered block types
  2571  * Checks if the editor scripts and styles for all registered block types
  2542  * should be enqueued on the current screen.
  2572  * should be enqueued on the current screen.
  2543  *
  2573  *
  2544  * @since 5.6.0
  2574  * @since 5.6.0
  2545  *
  2575  *
  2562 	 */
  2592 	 */
  2563 	return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen );
  2593 	return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen );
  2564 }
  2594 }
  2565 
  2595 
  2566 /**
  2596 /**
  2567  * Checks whether separate styles should be loaded for core blocks on-render.
  2597  * Checks whether separate styles should be loaded for core blocks.
  2568  *
  2598  *
  2569  * When this function returns true, other functions ensure that core blocks
  2599  * When this function returns true, other functions ensure that core blocks use their own separate stylesheets.
  2570  * only load their assets on-render, and each block loads its own, individual
  2600  * When this function returns false, all core blocks will use the single combined 'wp-block-library' stylesheet.
  2571  * assets. Third-party blocks only load their assets when rendered.
  2601  *
  2572  *
  2602  * As a side effect, the return value will by default result in block assets to be loaded on demand, via the
  2573  * When this function returns false, all core block assets are loaded regardless
  2603  * {@see wp_should_load_block_assets_on_demand()} function. This behavior can be separately altered via that function.
  2574  * of whether they are rendered in a page or not, because they are all part of
       
  2575  * the `block-library/style.css` file. Assets for third-party blocks are always
       
  2576  * enqueued regardless of whether they are rendered or not.
       
  2577  *
  2604  *
  2578  * This only affects front end and not the block editor screens.
  2605  * This only affects front end and not the block editor screens.
  2579  *
  2606  *
       
  2607  * @since 5.8.0
       
  2608  * @see @see wp_should_load_block_assets_on_demand()
  2580  * @see wp_enqueue_registered_block_scripts_and_styles()
  2609  * @see wp_enqueue_registered_block_scripts_and_styles()
  2581  * @see register_block_style_handle()
  2610  * @see register_block_style_handle()
  2582  *
  2611  *
  2583  * @since 5.8.0
  2612  * @return bool Whether separate core block assets will be loaded.
  2584  *
       
  2585  * @return bool Whether separate assets will be loaded.
       
  2586  */
  2613  */
  2587 function wp_should_load_separate_core_block_assets() {
  2614 function wp_should_load_separate_core_block_assets() {
  2588 	if ( is_admin() || is_feed() || wp_is_rest_endpoint() ) {
  2615 	if ( is_admin() || is_feed() || wp_is_rest_endpoint() ) {
  2589 		return false;
  2616 		return false;
  2590 	}
  2617 	}
  2602 	 */
  2629 	 */
  2603 	return apply_filters( 'should_load_separate_core_block_assets', false );
  2630 	return apply_filters( 'should_load_separate_core_block_assets', false );
  2604 }
  2631 }
  2605 
  2632 
  2606 /**
  2633 /**
       
  2634  * Checks whether block styles should be loaded only on-render.
       
  2635  *
       
  2636  * When this function returns true, other functions ensure that blocks only load their assets on-render.
       
  2637  * When this function returns false, all block assets are loaded regardless of whether they are rendered in a page.
       
  2638  *
       
  2639  * The default return value depends on the result of {@see wp_should_load_separate_core_block_assets()}, which controls
       
  2640  * whether Core block stylesheets should be loaded separately or via a combined 'wp-block-library' stylesheet.
       
  2641  *
       
  2642  * This only affects front end and not the block editor screens.
       
  2643  *
       
  2644  * @since 6.8.0
       
  2645  * @see wp_should_load_separate_core_block_assets()
       
  2646  *
       
  2647  * @return bool Whether to load block assets only when they are rendered.
       
  2648  */
       
  2649 function wp_should_load_block_assets_on_demand() {
       
  2650 	if ( is_admin() || is_feed() || wp_is_rest_endpoint() ) {
       
  2651 		return false;
       
  2652 	}
       
  2653 
       
  2654 	/*
       
  2655 	 * For backward compatibility, the default return value for this function is based on the return value of
       
  2656 	 * `wp_should_load_separate_core_block_assets()`. Initially, this function used to control both of these concerns.
       
  2657 	 */
       
  2658 	$load_assets_on_demand = wp_should_load_separate_core_block_assets();
       
  2659 
       
  2660 	/**
       
  2661 	 * Filters whether block styles should be loaded on demand.
       
  2662 	 *
       
  2663 	 * Returning false loads all block assets, regardless of whether they are rendered in a page or not.
       
  2664 	 * Returning true loads block assets only when they are rendered.
       
  2665 	 *
       
  2666 	 * The default value of the filter depends on the result of {@see wp_should_load_separate_core_block_assets()},
       
  2667 	 * which controls whether Core block stylesheets should be loaded separately or via a combined 'wp-block-library'
       
  2668 	 * stylesheet.
       
  2669 	 *
       
  2670 	 * @since 6.8.0
       
  2671 	 *
       
  2672 	 * @param bool $load_assets_on_demand Whether to load block assets only when they are rendered.
       
  2673 	 */
       
  2674 	return apply_filters( 'should_load_block_assets_on_demand', $load_assets_on_demand );
       
  2675 }
       
  2676 
       
  2677 /**
  2607  * Enqueues registered block scripts and styles, depending on current rendered
  2678  * Enqueues registered block scripts and styles, depending on current rendered
  2608  * context (only enqueuing editor scripts while in context of the editor).
  2679  * context (only enqueuing editor scripts while in context of the editor).
  2609  *
  2680  *
  2610  * @since 5.0.0
  2681  * @since 5.0.0
  2611  *
  2682  *
  2612  * @global WP_Screen $current_screen WordPress current screen object.
  2683  * @global WP_Screen $current_screen WordPress current screen object.
  2613  */
  2684  */
  2614 function wp_enqueue_registered_block_scripts_and_styles() {
  2685 function wp_enqueue_registered_block_scripts_and_styles() {
  2615 	global $current_screen;
  2686 	global $current_screen;
  2616 
  2687 
  2617 	if ( wp_should_load_separate_core_block_assets() ) {
  2688 	if ( wp_should_load_block_assets_on_demand() ) {
  2618 		return;
  2689 		return;
  2619 	}
  2690 	}
  2620 
  2691 
  2621 	$load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();
  2692 	$load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();
  2622 
  2693 
  2623 	$block_registry = WP_Block_Type_Registry::get_instance();
  2694 	$block_registry = WP_Block_Type_Registry::get_instance();
       
  2695 
       
  2696 	/*
       
  2697 	 * Block styles are only enqueued if they're registered. For core blocks, this is only the case if
       
  2698 	 * `wp_should_load_separate_core_block_assets()` returns true. Otherwise they use the single combined
       
  2699 	 * 'wp-block-library` stylesheet. See also `register_core_block_style_handles()`.
       
  2700 	 * Since `wp_enqueue_style()` does not trigger warnings if the style is not registered, it is okay to not cater for
       
  2701 	 * this behavior here and simply call `wp_enqueue_style()` unconditionally.
       
  2702 	 */
  2624 	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
  2703 	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
  2625 		// Front-end and editor styles.
  2704 		// Front-end and editor styles.
  2626 		foreach ( $block_type->style_handles as $style_handle ) {
  2705 		foreach ( $block_type->style_handles as $style_handle ) {
  2627 			wp_enqueue_style( $style_handle );
  2706 			wp_enqueue_style( $style_handle );
  2628 		}
  2707 		}
  2660 
  2739 
  2661 	foreach ( $block_styles as $block_name => $styles ) {
  2740 	foreach ( $block_styles as $block_name => $styles ) {
  2662 		foreach ( $styles as $style_properties ) {
  2741 		foreach ( $styles as $style_properties ) {
  2663 			if ( isset( $style_properties['style_handle'] ) ) {
  2742 			if ( isset( $style_properties['style_handle'] ) ) {
  2664 
  2743 
  2665 				// If the site loads separate styles per-block, enqueue the stylesheet on render.
  2744 				// If the site loads block styles on demand, enqueue the stylesheet on render.
  2666 				if ( wp_should_load_separate_core_block_assets() ) {
  2745 				if ( wp_should_load_block_assets_on_demand() ) {
  2667 					add_filter(
  2746 					add_filter(
  2668 						'render_block',
  2747 						'render_block',
  2669 						static function ( $html, $block ) use ( $block_name, $style_properties ) {
  2748 						static function ( $html, $block ) use ( $block_name, $style_properties ) {
  2670 							if ( $block['blockName'] === $block_name ) {
  2749 							if ( $block['blockName'] === $block_name ) {
  2671 								wp_enqueue_style( $style_properties['style_handle'] );
  2750 								wp_enqueue_style( $style_properties['style_handle'] );
  2682 			if ( isset( $style_properties['inline_style'] ) ) {
  2761 			if ( isset( $style_properties['inline_style'] ) ) {
  2683 
  2762 
  2684 				// Default to "wp-block-library".
  2763 				// Default to "wp-block-library".
  2685 				$handle = 'wp-block-library';
  2764 				$handle = 'wp-block-library';
  2686 
  2765 
  2687 				// If the site loads separate styles per-block, check if the block has a stylesheet registered.
  2766 				// If the site loads block styles on demand, check if the block has a stylesheet registered.
  2688 				if ( wp_should_load_separate_core_block_assets() ) {
  2767 				if ( wp_should_load_block_assets_on_demand() ) {
  2689 					$block_stylesheet_handle = generate_block_asset_handle( $block_name, 'style' );
  2768 					$block_stylesheet_handle = generate_block_asset_handle( $block_name, 'style' );
  2690 
  2769 
  2691 					if ( isset( $wp_styles->registered[ $block_stylesheet_handle ] ) ) {
  2770 					if ( isset( $wp_styles->registered[ $block_stylesheet_handle ] ) ) {
  2692 						$handle = $block_stylesheet_handle;
  2771 						$handle = $block_stylesheet_handle;
  2693 					}
  2772 					}
  3050 
  3129 
  3051 			// Short-circuit if the URL does not require normalization.
  3130 			// Short-circuit if the URL does not require normalization.
  3052 			if (
  3131 			if (
  3053 				str_starts_with( $url, 'http:' ) ||
  3132 				str_starts_with( $url, 'http:' ) ||
  3054 				str_starts_with( $url, 'https:' ) ||
  3133 				str_starts_with( $url, 'https:' ) ||
  3055 				str_starts_with( $url, '//' ) ||
  3134 				str_starts_with( $url, '/' ) ||
  3056 				str_starts_with( $url, '#' ) ||
  3135 				str_starts_with( $url, '#' ) ||
  3057 				str_starts_with( $url, 'data:' )
  3136 				str_starts_with( $url, 'data:' )
  3058 			) {
  3137 			) {
  3059 				return $matches[0];
  3138 				return $matches[0];
  3060 			}
  3139 			}
  3182 }
  3261 }
  3183 
  3262 
  3184 /**
  3263 /**
  3185  * Enqueues a stylesheet for a specific block.
  3264  * Enqueues a stylesheet for a specific block.
  3186  *
  3265  *
  3187  * If the theme has opted-in to separate-styles loading,
  3266  * If the theme has opted-in to load block styles on demand,
  3188  * then the stylesheet will be enqueued on-render,
  3267  * then the stylesheet will be enqueued on-render,
  3189  * otherwise when the block inits.
  3268  * otherwise when the block inits.
  3190  *
  3269  *
  3191  * @since 5.9.0
  3270  * @since 5.9.0
  3192  *
  3271  *
  3250 
  3329 
  3251 		return $content;
  3330 		return $content;
  3252 	};
  3331 	};
  3253 
  3332 
  3254 	$hook = did_action( 'wp_enqueue_scripts' ) ? 'wp_footer' : 'wp_enqueue_scripts';
  3333 	$hook = did_action( 'wp_enqueue_scripts' ) ? 'wp_footer' : 'wp_enqueue_scripts';
  3255 	if ( wp_should_load_separate_core_block_assets() ) {
  3334 	if ( wp_should_load_block_assets_on_demand() ) {
  3256 		/**
  3335 		/**
  3257 		 * Callback function to register and enqueue styles.
  3336 		 * Callback function to register and enqueue styles.
  3258 		 *
  3337 		 *
  3259 		 * @param string $content The block content.
  3338 		 * @param string $content The block content.
  3260 		 * @param array  $block   The full block, including name and attributes.
  3339 		 * @param array  $block   The full block, including name and attributes.
  3296 }
  3375 }
  3297 
  3376 
  3298 /**
  3377 /**
  3299  * Loads classic theme styles on classic themes in the frontend.
  3378  * Loads classic theme styles on classic themes in the frontend.
  3300  *
  3379  *
  3301  * This is needed for backwards compatibility for button blocks specifically.
  3380  * This is used for backwards compatibility for Button and File blocks specifically.
  3302  *
  3381  *
  3303  * @since 6.1.0
  3382  * @since 6.1.0
       
  3383  * @since 6.2.0 Added File block styles.
       
  3384  * @since 6.8.0 Moved stylesheet registration outside of this function.
  3304  */
  3385  */
  3305 function wp_enqueue_classic_theme_styles() {
  3386 function wp_enqueue_classic_theme_styles() {
  3306 	if ( ! wp_theme_has_theme_json() ) {
  3387 	if ( ! wp_theme_has_theme_json() ) {
  3307 		$suffix = wp_scripts_get_suffix();
       
  3308 		wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css" );
       
  3309 		wp_style_add_data( 'classic-theme-styles', 'path', ABSPATH . WPINC . "/css/classic-themes$suffix.css" );
       
  3310 		wp_enqueue_style( 'classic-theme-styles' );
  3388 		wp_enqueue_style( 'classic-theme-styles' );
  3311 	}
  3389 	}
  3312 }
       
  3313 
       
  3314 /**
       
  3315  * Loads classic theme styles on classic themes in the editor.
       
  3316  *
       
  3317  * This is needed for backwards compatibility for button blocks specifically.
       
  3318  *
       
  3319  * @since 6.1.0
       
  3320  *
       
  3321  * @param array $editor_settings The array of editor settings.
       
  3322  * @return array A filtered array of editor settings.
       
  3323  */
       
  3324 function wp_add_editor_classic_theme_styles( $editor_settings ) {
       
  3325 	if ( wp_theme_has_theme_json() ) {
       
  3326 		return $editor_settings;
       
  3327 	}
       
  3328 
       
  3329 	$suffix               = wp_scripts_get_suffix();
       
  3330 	$classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
       
  3331 
       
  3332 	/*
       
  3333 	 * This follows the pattern of get_block_editor_theme_styles,
       
  3334 	 * but we can't use get_block_editor_theme_styles directly as it
       
  3335 	 * only handles external files or theme files.
       
  3336 	 */
       
  3337 	$classic_theme_styles_settings = array(
       
  3338 		'css'            => file_get_contents( $classic_theme_styles ),
       
  3339 		'__unstableType' => 'core',
       
  3340 		'isGlobalStyles' => false,
       
  3341 	);
       
  3342 
       
  3343 	// Add these settings to the start of the array so that themes can override them.
       
  3344 	array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
       
  3345 
       
  3346 	return $editor_settings;
       
  3347 }
  3390 }
  3348 
  3391 
  3349 /**
  3392 /**
  3350  * Removes leading and trailing _empty_ script tags.
  3393  * Removes leading and trailing _empty_ script tags.
  3351  *
  3394  *