: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @param string $relation_type The relation type the URLs are printed for. One of
* 'dns-prefetch', 'preconnect', 'prefetch', or 'prerender'.
$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type );
foreach ( $urls as $key => $url ) {
if ( is_array( $url ) ) {
if ( isset( $url['href'] ) ) {
$url = esc_url( $url, array( 'http', 'https' ) );
if ( isset( $unique_urls[ $url ] ) ) {
if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ), true ) ) {
$parsed = wp_parse_url( $url );
if ( empty( $parsed['host'] ) ) {
if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) {
$url = $parsed['scheme'] . '://' . $parsed['host'];
// Use protocol-relative URLs for dns-prefetch or if scheme is missing.
$url = '//' . $parsed['host'];
$atts['rel'] = $relation_type;
$unique_urls[ $url ] = $atts;
foreach ( $unique_urls as $atts ) {
foreach ( $atts as $attr => $value ) {
if ( ! is_scalar( $value )
|| ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) )
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
if ( ! is_string( $attr ) ) {
$html .= " $attr='$value'";
* Prints resource preloads directives to browsers.
* Gives directive to browsers to preload specific resources that website will
* need very soon, this ensures that they are available earlier and are less
* likely to block the page's render. Preload directives should not be used for
* non-render-blocking elements, as then they would compete with the
* render-blocking ones, slowing down the render.
* These performance improving indicators work by using `<link rel="preload">`.
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload
* @link https://web.dev/preload-responsive-images/
function wp_preload_resources() {
* Filters domains and URLs for resource preloads.
* @since 6.6.0 Added the `$fetchpriority` attribute.
* @param array $preload_resources {
* Array of resources and their attributes, or URLs to print for resource preloads.
* Array of resource attributes.
* @type string $href URL to include in resource preloads. Required.
* @type string $as How the browser should treat the resource
* (`script`, `style`, `image`, `document`, etc).
* @type string $crossorigin Indicates the CORS policy of the specified resource.
* @type string $type Type of the resource (`text/html`, `text/css`, etc).
* @type string $media Accepts media types or media queries. Allows responsive preloading.
* @type string $imagesizes Responsive source size to the source Set.
* @type string $imagesrcset Responsive image sources to the source set.
* @type string $fetchpriority Fetchpriority value for the resource.
$preload_resources = apply_filters( 'wp_preload_resources', array() );
if ( ! is_array( $preload_resources ) ) {
$unique_resources = array();
// Parse the complete resource list and extract unique resources.
foreach ( $preload_resources as $resource ) {
if ( ! is_array( $resource ) ) {
if ( isset( $resource['href'] ) ) {
$href = $resource['href'];
if ( isset( $unique_resources[ $href ] ) ) {
$unique_resources[ $href ] = $attributes;
// Media can use imagesrcset and not href.
} elseif ( ( 'image' === $resource['as'] ) &&
( isset( $resource['imagesrcset'] ) || isset( $resource['imagesizes'] ) )
if ( isset( $unique_resources[ $resource['imagesrcset'] ] ) ) {
$unique_resources[ $resource['imagesrcset'] ] = $attributes;
// Build and output the HTML for each unique resource.
foreach ( $unique_resources as $unique_resource ) {
foreach ( $unique_resource as $resource_key => $resource_value ) {
if ( ! is_scalar( $resource_value ) ) {
// Ignore non-supported attributes.
$non_supported_attributes = array( 'as', 'crossorigin', 'href', 'imagesrcset', 'imagesizes', 'type', 'media', 'fetchpriority' );
if ( ! in_array( $resource_key, $non_supported_attributes, true ) && ! is_numeric( $resource_key ) ) {
// imagesrcset only usable when preloading image, ignore otherwise.
if ( ( 'imagesrcset' === $resource_key ) && ( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) ) ) {
// imagesizes only usable when preloading image and imagesrcset present, ignore otherwise.
if ( ( 'imagesizes' === $resource_key ) &&
( ! isset( $unique_resource['as'] ) || ( 'image' !== $unique_resource['as'] ) || ! isset( $unique_resource['imagesrcset'] ) )
$resource_value = ( 'href' === $resource_key ) ? esc_url( $resource_value, array( 'http', 'https' ) ) : esc_attr( $resource_value );
if ( ! is_string( $resource_key ) ) {
$html .= " $resource_value";
$html .= " $resource_key='$resource_value'";
printf( "<link rel='preload' %s />\n", $html );
* Retrieves a list of unique hosts of all enqueued scripts and styles.
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
* @return string[] A list of unique hosts of enqueued scripts and styles.
function wp_dependencies_unique_hosts() {
global $wp_scripts, $wp_styles;
foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) {
if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) {
foreach ( $dependencies->queue as $handle ) {
if ( ! isset( $dependencies->registered[ $handle ] ) ) {
/* @var _WP_Dependency $dependency */
$dependency = $dependencies->registered[ $handle ];
$parsed = wp_parse_url( $dependency->src );
if ( ! empty( $parsed['host'] )
&& ! in_array( $parsed['host'], $unique_hosts, true ) && $parsed['host'] !== $_SERVER['SERVER_NAME']
$unique_hosts[] = $parsed['host'];
* Determines whether the user can access the visual editor.
* Checks if the user can access the visual editor and that it's supported by the user's browser.
* @global bool $wp_rich_edit Whether the user can access the visual editor.
* @global bool $is_gecko Whether the browser is Gecko-based.
* @global bool $is_opera Whether the browser is Opera.
* @global bool $is_safari Whether the browser is Safari.
* @global bool $is_chrome Whether the browser is Chrome.
* @global bool $is_IE Whether the browser is Internet Explorer.
* @global bool $is_edge Whether the browser is Microsoft Edge.
* @return bool True if the user can access the visual editor, false otherwise.
function user_can_richedit() {
global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge;
if ( ! isset( $wp_rich_edit ) ) {
if ( 'true' === get_user_option( 'rich_editing' ) || ! is_user_logged_in() ) { // Default to 'true' for logged out users.
$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && (int) $match[1] >= 534 );
$wp_rich_edit = str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' );
} elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) {
* Filters whether the user can access the visual editor.
* @param bool $wp_rich_edit Whether the user can access the visual editor.
return apply_filters( 'user_can_richedit', $wp_rich_edit );
* Finds out which editor should be displayed by default.
* Works out which of the editors to display as the current editor for a
* user. The 'html' setting is for the "Text" editor tab.
* @return string Either 'tinymce', 'html', or 'test'
function wp_default_editor() {
$r = user_can_richedit() ? 'tinymce' : 'html'; // Defaults.
if ( wp_get_current_user() ) { // Look for cookie.
$ed = get_user_setting( 'editor', 'tinymce' );
$r = ( in_array( $ed, array( 'tinymce', 'html', 'test' ), true ) ) ? $ed : $r;
* Filters which editor should be displayed by default.
* @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'.
return apply_filters( 'wp_default_editor', $r );
* Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
* _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
* NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
* running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used.
* On the post edit screen several actions can be used to include additional editors
* containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
* See https://core.trac.wordpress.org/ticket/19173 for more information.
* @see _WP_Editors::editor()
* @see _WP_Editors::parse_settings()
* @param string $content Initial content for the editor.
* @param string $editor_id HTML ID attribute value for the textarea and TinyMCE.
* Should not contain square brackets.
* @param array $settings See _WP_Editors::parse_settings() for description.
function wp_editor( $content, $editor_id, $settings = array() ) {
if ( ! class_exists( '_WP_Editors', false ) ) {
require ABSPATH . WPINC . '/class-wp-editor.php';
_WP_Editors::editor( $content, $editor_id, $settings );
* Outputs the editor scripts, stylesheets, and default settings.
* The editor can be initialized when needed after page load.
* See wp.editor.initialize() in wp-admin/js/editor.js for initialization options.
function wp_enqueue_editor() {
if ( ! class_exists( '_WP_Editors', false ) ) {
require ABSPATH . WPINC . '/class-wp-editor.php';
_WP_Editors::enqueue_default_editor();
* Enqueues assets needed by the code editor for the given settings.
* @see wp_enqueue_editor()
* @see wp_get_code_editor_settings();
* @see _WP_Editors::parse_settings()
* @type string $type The MIME type of the file to be edited.
* @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
* @type WP_Theme $theme Theme being edited when on the theme file editor.
* @type string $plugin Plugin being edited when on the plugin file editor.
* @type array $codemirror Additional CodeMirror setting overrides.
* @type array $csslint CSSLint rule overrides.
* @type array $jshint JSHint rule overrides.
* @type array $htmlhint HTMLHint rule overrides.
* @return array|false Settings for the enqueued code editor, or false if the editor was not enqueued.
function wp_enqueue_code_editor( $args ) {
if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) {
$settings = wp_get_code_editor_settings( $args );
if ( empty( $settings ) || empty( $settings['codemirror'] ) ) {
wp_enqueue_script( 'code-editor' );
wp_enqueue_style( 'code-editor' );
if ( isset( $settings['codemirror']['mode'] ) ) {
$mode = $settings['codemirror']['mode'];
if ( is_string( $mode ) ) {
if ( ! empty( $settings['codemirror']['lint'] ) ) {
switch ( $mode['name'] ) {
wp_enqueue_script( 'csslint' );
case 'application/x-httpd-php':
wp_enqueue_script( 'htmlhint' );
wp_enqueue_script( 'csslint' );
wp_enqueue_script( 'jshint' );
if ( ! current_user_can( 'unfiltered_html' ) ) {
wp_enqueue_script( 'htmlhint-kses' );
case 'application/ecmascript':
case 'application/javascript':
case 'application/ld+json':
case 'application/typescript':
wp_enqueue_script( 'jshint' );
wp_enqueue_script( 'jsonlint' );
wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) );
* Fires when scripts and styles are enqueued for the code editor.
* @param array $settings Settings for the enqueued code editor.
do_action( 'wp_enqueue_code_editor', $settings );
* Generates and returns code editor settings.
* @see wp_enqueue_code_editor()
* @type string $type The MIME type of the file to be edited.
* @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param.
* @type WP_Theme $theme Theme being edited when on the theme file editor.
* @type string $plugin Plugin being edited when on the plugin file editor.
* @type array $codemirror Additional CodeMirror setting overrides.
* @type array $csslint CSSLint rule overrides.
* @type array $jshint JSHint rule overrides.
* @type array $htmlhint HTMLHint rule overrides.
* @return array|false Settings for the code editor.
function wp_get_code_editor_settings( $args ) {
'indentWithTabs' => true,
'inputStyle' => 'contenteditable',
'styleActiveLine' => true,
'continueComments' => true,
'Ctrl-Space' => 'autocomplete',
'Ctrl-/' => 'toggleComment',
'Cmd-/' => 'toggleComment',
'Alt-F' => 'findPersistent',
'Ctrl-F' => 'findPersistent',
'Cmd-F' => 'findPersistent',
'direction' => 'ltr', // Code is shown in LTR even in RTL languages.
'errors' => true, // Parsing errors.
'display-property-grouping' => true,
'duplicate-properties' => true,
'known-properties' => true,
// The following are copied from <https://github.com/WordPress/wordpress-develop/blob/4.8.1/.jshintrc>.