wp_default_packages_inline_scripts

The timeline below displays how wordpress function wp_default_packages_inline_scripts has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 * @since 6.4.0 Added relative time strings for the `wp-date` inline script output.
 *
 * @global WP_Locale $wp_locale WordPress date and time locale object.
 * @global wpdb      $wpdb      WordPress database abstraction object.
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts($scripts)
{
    global $wp_locale, $wpdb;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', sanitize_url(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', wp_installing() ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences';
    $user_id = get_current_user_id();
    $preload_data = get_user_meta($user_id, $meta_key, true);
    $scripts->add_inline_script('wp-preferences', sprintf('( function() {
				var serverData = %s;
				var userId = "%d";
				var persistenceLayer = wp.preferencesPersistence.__unstableCreatePersistenceLayer( serverData, userId );
				var preferencesStore = wp.preferences.store;
				wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer );
			} ) ();', wp_json_encode($preload_data), $user_id));
    // Backwards compatibility - configure the old wp-data persistence system.
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '} )();')));
    // Calculate the timezone abbr (EDT, PST) if possible.
    $timezone_string = get_option('timezone_string', 'UTC');
    $timezone_abbr = '';
    if (!empty($timezone_string)) {
        $timezone_date = new DateTime('now', new DateTimeZone($timezone_string));
        $timezone_abbr = $timezone_date->format('T');
    }
    $gmt_offset = get_option('gmt_offset', 0);
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
        /* translators: One second from or to a particular datetime, e.g., "a second ago" or "a second from now". */
        's' => __('a second'),
        /* translators: %d: Duration in seconds from or to a particular datetime, e.g., "4 seconds ago" or "4 seconds from now". */
        'ss' => __('%d seconds'),
        /* translators: One minute from or to a particular datetime, e.g., "a minute ago" or "a minute from now". */
        'm' => __('a minute'),
        /* translators: %d: Duration in minutes from or to a particular datetime, e.g., "4 minutes ago" or "4 minutes from now". */
        'mm' => __('%d minutes'),
        /* translators: One hour from or to a particular datetime, e.g., "an hour ago" or "an hour from now". */
        'h' => __('an hour'),
        /* translators: %d: Duration in hours from or to a particular datetime, e.g., "4 hours ago" or "4 hours from now". */
        'hh' => __('%d hours'),
        /* translators: One day from or to a particular datetime, e.g., "a day ago" or "a day from now". */
        'd' => __('a day'),
        /* translators: %d: Duration in days from or to a particular datetime, e.g., "4 days ago" or "4 days from now". */
        'dd' => __('%d days'),
        /* translators: One month from or to a particular datetime, e.g., "a month ago" or "a month from now". */
        'M' => __('a month'),
        /* translators: %d: Duration in months from or to a particular datetime, e.g., "4 months ago" or "4 months from now". */
        'MM' => __('%d months'),
        /* translators: One year from or to a particular datetime, e.g., "a year ago" or "a year from now". */
        'y' => __('a year'),
        /* translators: %d: Duration in years from or to a particular datetime, e.g., "4 years ago" or "4 years from now". */
        'yy' => __('%d years'),
    ), 'startOfWeek' => (int) get_option('start_of_week', 0)), 'formats' => array(
        /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => (float) $gmt_offset, 'offsetFormatted' => str_replace(array('.25', '.5', '.75'), array(':15', ':30', ':45'), (string) $gmt_offset), 'string' => $timezone_string, 'abbr' => $timezone_abbr)))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
    /*
     * wp-editor module is exposed as window.wp.editor.
     * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
     * Solution: fuse the two objects together to maintain backward compatibility.
     * For more context, see https://github.com/WordPress/gutenberg/issues/33203.
     */
    $scripts->add_inline_script('wp-editor', 'Object.assign( window.wp.editor, window.wp.oldEditor );', 'after');
}

WordPress Version: 6.4

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 * @since 6.4.0 Added relative time strings for the `wp-date` inline script output.
 *
 * @global WP_Locale $wp_locale WordPress date and time locale object.
 * @global wpdb      $wpdb      WordPress database abstraction object.
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts($scripts)
{
    global $wp_locale, $wpdb;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', sanitize_url(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', wp_installing() ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences';
    $user_id = get_current_user_id();
    $preload_data = get_user_meta($user_id, $meta_key, true);
    $scripts->add_inline_script('wp-preferences', sprintf('( function() {
				var serverData = %s;
				var userId = "%d";
				var persistenceLayer = wp.preferencesPersistence.__unstableCreatePersistenceLayer( serverData, userId );
				var preferencesStore = wp.preferences.store;
				wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer );
			} ) ();', wp_json_encode($preload_data), $user_id));
    // Backwards compatibility - configure the old wp-data persistence system.
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '} )();')));
    // Calculate the timezone abbr (EDT, PST) if possible.
    $timezone_string = get_option('timezone_string', 'UTC');
    $timezone_abbr = '';
    if (!empty($timezone_string)) {
        $timezone_date = new DateTime('now', new DateTimeZone($timezone_string));
        $timezone_abbr = $timezone_date->format('T');
    }
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
        /* translators: One second from or to a particular datetime, e.g., "a second ago" or "a second from now". */
        's' => __('a second'),
        /* translators: %s: Duration in seconds from or to a particular datetime, e.g., "4 seconds ago" or "4 seconds from now". */
        'ss' => __('%d seconds'),
        /* translators: One minute from or to a particular datetime, e.g., "a minute ago" or "a minute from now". */
        'm' => __('a minute'),
        /* translators: %s: Duration in minutes from or to a particular datetime, e.g., "4 minutes ago" or "4 minutes from now". */
        'mm' => __('%d minutes'),
        /* translators: %s: One hour from or to a particular datetime, e.g., "an hour ago" or "an hour from now". */
        'h' => __('an hour'),
        /* translators: %s: Duration in hours from or to a particular datetime, e.g., "4 hours ago" or "4 hours from now". */
        'hh' => __('%d hours'),
        /* translators: %s: One day from or to a particular datetime, e.g., "a day ago" or "a day from now". */
        'd' => __('a day'),
        /* translators: %s: Duration in days from or to a particular datetime, e.g., "4 days ago" or "4 days from now". */
        'dd' => __('%d days'),
        /* translators: %s: One month from or to a particular datetime, e.g., "a month ago" or "a month from now". */
        'M' => __('a month'),
        /* translators: %s: Duration in months from or to a particular datetime, e.g., "4 months ago" or "4 months from now". */
        'MM' => __('%d months'),
        /* translators: %s: One year from or to a particular datetime, e.g., "a year ago" or "a year from now". */
        'y' => __('a year'),
        /* translators: %s: Duration in years from or to a particular datetime, e.g., "4 years ago" or "4 years from now". */
        'yy' => __('%d years'),
    ), 'startOfWeek' => (int) get_option('start_of_week', 0)), 'formats' => array(
        /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => (float) get_option('gmt_offset', 0), 'string' => $timezone_string, 'abbr' => $timezone_abbr)))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
    /*
     * wp-editor module is exposed as window.wp.editor.
     * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
     * Solution: fuse the two objects together to maintain backward compatibility.
     * For more context, see https://github.com/WordPress/gutenberg/issues/33203.
     */
    $scripts->add_inline_script('wp-editor', 'Object.assign( window.wp.editor, window.wp.oldEditor );', 'after');
}

WordPress Version: 6.1

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @global WP_Locale $wp_locale WordPress date and time locale object.
 * @global wpdb      $wpdb      WordPress database abstraction object.
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts($scripts)
{
    global $wp_locale, $wpdb;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', sanitize_url(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', wp_installing() ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences';
    $user_id = get_current_user_id();
    $preload_data = get_user_meta($user_id, $meta_key, true);
    $scripts->add_inline_script('wp-preferences', sprintf('( function() {
				var serverData = %s;
				var userId = "%d";
				var persistenceLayer = wp.preferencesPersistence.__unstableCreatePersistenceLayer( serverData, userId );
				var preferencesStore = wp.preferences.store;
				wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer );
			} ) ();', wp_json_encode($preload_data), $user_id));
    // Backwards compatibility - configure the old wp-data persistence system.
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '} )();')));
    // Calculate the timezone abbr (EDT, PST) if possible.
    $timezone_string = get_option('timezone_string', 'UTC');
    $timezone_abbr = '';
    if (!empty($timezone_string)) {
        $timezone_date = new DateTime('now', new DateTimeZone($timezone_string));
        $timezone_abbr = $timezone_date->format('T');
    }
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
    ), 'startOfWeek' => (int) get_option('start_of_week', 0)), 'formats' => array(
        /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => (float) get_option('gmt_offset', 0), 'string' => $timezone_string, 'abbr' => $timezone_abbr)))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
    /*
     * wp-editor module is exposed as window.wp.editor.
     * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
     * Solution: fuse the two objects together to maintain backward compatibility.
     * For more context, see https://github.com/WordPress/gutenberg/issues/33203.
     */
    $scripts->add_inline_script('wp-editor', 'Object.assign( window.wp.editor, window.wp.oldEditor );', 'after');
}

WordPress Version: 5.9

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @global WP_Locale $wp_locale WordPress date and time locale object.
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts($scripts)
{
    global $wp_locale;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '	wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );', '} )();')));
    // Calculate the timezone abbr (EDT, PST) if possible.
    $timezone_string = get_option('timezone_string', 'UTC');
    $timezone_abbr = '';
    if (!empty($timezone_string)) {
        $timezone_date = new DateTime('now', new DateTimeZone($timezone_string));
        $timezone_abbr = $timezone_date->format('T');
    }
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => $timezone_string, 'abbr' => $timezone_abbr)))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
    /*
     * wp-editor module is exposed as window.wp.editor.
     * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
     * Solution: fuse the two objects together to maintain backward compatibility.
     * For more context, see https://github.com/WordPress/gutenberg/issues/33203.
     */
    $scripts->add_inline_script('wp-editor', 'Object.assign( window.wp.editor, window.wp.oldEditor );', 'after');
}

WordPress Version: 5.8

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts($scripts)
{
    global $wp_locale;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '	wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );', '} )();')));
    // Calculate the timezone abbr (EDT, PST) if possible.
    $timezone_string = get_option('timezone_string', 'UTC');
    $timezone_abbr = '';
    if (!empty($timezone_string)) {
        $timezone_date = new DateTime(null, new DateTimeZone($timezone_string));
        $timezone_abbr = $timezone_date->format('T');
    }
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => $timezone_string, 'abbr' => $timezone_abbr)))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
    /*
     * wp-editor module is exposed as window.wp.editor.
     * Problem: there is quite some code expecting window.wp.oldEditor object available under window.wp.editor.
     * Solution: fuse the two objects together to maintain backward compatibility.
     * For more context, see https://github.com/WordPress/gutenberg/issues/33203.
     */
    $scripts->add_inline_script('wp-editor', 'Object.assign( window.wp.editor, window.wp.oldEditor );', 'after');
}

WordPress Version: 5.6

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts($scripts)
{
    global $wp_locale;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '	wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );', '} )();')));
    // Calculate the timezone abbr (EDT, PST) if possible.
    $timezone_string = get_option('timezone_string', 'UTC');
    $timezone_abbr = '';
    if (!empty($timezone_string)) {
        $timezone_date = new DateTime(null, new DateTimeZone($timezone_string));
        $timezone_abbr = $timezone_date->format('T');
    }
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => $timezone_string, 'abbr' => $timezone_abbr)))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
}

WordPress Version: 5.4

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts($scripts)
{
    global $wp_locale;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '	wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );', '} )();')));
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://www.php.net/date */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://www.php.net/date */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://www.php.net/date */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://www.php.net/date */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => get_option('timezone_string', 'UTC'))))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
}

WordPress Version: 5.3

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts(&$scripts)
{
    global $wp_locale;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-api-fetch', implode("\n", array(sprintf('wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );', 'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );', sprintf('wp.apiFetch.nonceEndpoint = "%s";', admin_url('admin-ajax.php?action=rest-nonce')))), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } );', '	wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );', '} )();')));
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: Duration. */
        'future' => __('%s from now'),
        /* translators: %s: Duration. */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://secure.php.net/date */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://secure.php.net/date */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://secure.php.net/date */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://secure.php.net/date */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => get_option('timezone_string', 'UTC'))))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
}

WordPress Version: 5.2

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts(&$scripts)
{
    global $wp_locale;
    if (isset($scripts->registered['wp-api-fetch'])) {
        $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
    }
    $scripts->add_inline_script('wp-api-fetch', sprintf(implode("\n", array('( function() {', '	var nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', '	wp.apiFetch.use( nonceMiddleware );', '	wp.hooks.addAction(', '		"heartbeat.tick",', '		"core/api-fetch/create-nonce-middleware",', '		function( response ) {', '			if ( response[ "rest_nonce" ] ) {', '				nonceMiddleware.nonce = response[ "rest_nonce" ];', '			}', '		}', '	);', '} )();')), (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'after');
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } )', '		.use( wp.data.plugins.controls );', '	wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );', '} )();')));
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: duration */
        'future' => __('%s from now'),
        /* translators: %s: duration */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://secure.php.net/date */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://secure.php.net/date */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://secure.php.net/date */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://secure.php.net/date */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => get_option('timezone_string', 'UTC'))))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
}

WordPress Version: 5.1

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts(&$scripts)
{
    global $wp_locale;
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createNonceMiddleware( "%s" ) );', (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'after');
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } )', '		.use( wp.data.plugins.controls );', '} )();')));
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: duration */
        'future' => __('%s from now'),
        /* translators: %s: duration */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://secure.php.net/date */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://secure.php.net/date */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://secure.php.net/date */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://secure.php.net/date */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => get_option('timezone_string', 'UTC'))))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
}

WordPress Version: 5.0

/**
 * Adds inline scripts required for the WordPress JavaScript packages.
 *
 * @since 5.0.0
 *
 * @param WP_Scripts $scripts WP_Scripts object.
 */
function wp_default_packages_inline_scripts(&$scripts)
{
    global $wp_locale;
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createNonceMiddleware( "%s" ) );', (wp_installing() && !is_multisite()) ? '' : wp_create_nonce('wp_rest')), 'after');
    $scripts->add_inline_script('wp-api-fetch', sprintf('wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );', esc_url_raw(get_rest_url())), 'after');
    $scripts->add_inline_script('wp-data', implode("\n", array('( function() {', '	var userId = ' . get_current_user_ID() . ';', '	var storageKey = "WP_DATA_USER_" + userId;', '	wp.data', '		.use( wp.data.plugins.persistence, { storageKey: storageKey } )', '		.use( wp.data.plugins.controls );', '} )()')));
    $scripts->add_inline_script('wp-date', sprintf('wp.date.setSettings( %s );', wp_json_encode(array('l10n' => array('locale' => get_user_locale(), 'months' => array_values($wp_locale->month), 'monthsShort' => array_values($wp_locale->month_abbrev), 'weekdays' => array_values($wp_locale->weekday), 'weekdaysShort' => array_values($wp_locale->weekday_abbrev), 'meridiem' => (object) $wp_locale->meridiem, 'relative' => array(
        /* translators: %s: duration */
        'future' => __('%s from now'),
        /* translators: %s: duration */
        'past' => __('%s ago'),
    )), 'formats' => array(
        /* translators: Time format, see https://secure.php.net/date */
        'time' => get_option('time_format', __('g:i a')),
        /* translators: Date format, see https://secure.php.net/date */
        'date' => get_option('date_format', __('F j, Y')),
        /* translators: Date/Time format, see https://secure.php.net/date */
        'datetime' => __('F j, Y g:i a'),
        /* translators: Abbreviated date/time format, see https://secure.php.net/date */
        'datetimeAbbreviated' => __('M j, Y g:i a'),
    ), 'timezone' => array('offset' => get_option('gmt_offset', 0), 'string' => get_option('timezone_string', 'UTC'))))), 'after');
    // Loading the old editor and its config to ensure the classic block works as expected.
    $scripts->add_inline_script('editor', 'window.wp.oldEditor = window.wp.editor;', 'after');
}