Merged in feature/81-dev-dev01 (pull request #5)
auto-patch 81-dev-dev01-2023-12-05T22_45_26 * auto-patch 81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
@@ -4008,7 +4008,7 @@ function wp_make_content_images_responsive( $content ) {
|
||||
* @access private
|
||||
* @deprecated 5.5.0
|
||||
*/
|
||||
function wp_unregister_GLOBALS() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
|
||||
function wp_unregister_GLOBALS() {
|
||||
// register_globals was deprecated in PHP 5.3 and removed entirely in PHP 5.4.
|
||||
_deprecated_function( __FUNCTION__, '5.5.0' );
|
||||
}
|
||||
@@ -4253,7 +4253,9 @@ function wp_render_duotone_filter_preset( $preset ) {
|
||||
function wp_skip_border_serialization( $block_type ) {
|
||||
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
|
||||
|
||||
$border_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), false );
|
||||
$border_support = isset( $block_type->supports['__experimentalBorder'] )
|
||||
? $block_type->supports['__experimentalBorder']
|
||||
: false;
|
||||
|
||||
return is_array( $border_support ) &&
|
||||
array_key_exists( '__experimentalSkipSerialization', $border_support ) &&
|
||||
@@ -4275,7 +4277,9 @@ function wp_skip_border_serialization( $block_type ) {
|
||||
function wp_skip_dimensions_serialization( $block_type ) {
|
||||
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
|
||||
|
||||
$dimensions_support = _wp_array_get( $block_type->supports, array( '__experimentalDimensions' ), false );
|
||||
$dimensions_support = isset( $block_type->supports['__experimentalDimensions'] )
|
||||
? $block_type->supports['__experimentalDimensions']
|
||||
: false;
|
||||
|
||||
return is_array( $dimensions_support ) &&
|
||||
array_key_exists( '__experimentalSkipSerialization', $dimensions_support ) &&
|
||||
@@ -4297,7 +4301,9 @@ function wp_skip_dimensions_serialization( $block_type ) {
|
||||
function wp_skip_spacing_serialization( $block_type ) {
|
||||
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
|
||||
|
||||
$spacing_support = _wp_array_get( $block_type->supports, array( 'spacing' ), false );
|
||||
$spacing_support = isset( $block_type->supports['spacing'] )
|
||||
? $block_type->supports['spacing']
|
||||
: false;
|
||||
|
||||
return is_array( $spacing_support ) &&
|
||||
array_key_exists( '__experimentalSkipSerialization', $spacing_support ) &&
|
||||
@@ -5367,3 +5373,863 @@ function block_core_navigation_submenu_build_css_colors( $context, $attributes,
|
||||
|
||||
return $colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the theme.json webfonts handler.
|
||||
*
|
||||
* Using `WP_Theme_JSON_Resolver`, it gets the fonts defined
|
||||
* in the `theme.json` for the current selection and style
|
||||
* variations, validates the font-face properties, generates
|
||||
* the '@font-face' style declarations, and then enqueues the
|
||||
* styles for both the editor and front-end.
|
||||
*
|
||||
* Design Notes:
|
||||
* This is not a public API, but rather an internal handler.
|
||||
* A future public Webfonts API will replace this stopgap code.
|
||||
*
|
||||
* This code design is intentional.
|
||||
* a. It hides the inner-workings.
|
||||
* b. It does not expose API ins or outs for consumption.
|
||||
* c. It only works with a theme's `theme.json`.
|
||||
*
|
||||
* Why?
|
||||
* a. To avoid backwards-compatibility issues when
|
||||
* the Webfonts API is introduced in Core.
|
||||
* b. To make `fontFace` declarations in `theme.json` work.
|
||||
*
|
||||
* @link https://github.com/WordPress/gutenberg/issues/40472
|
||||
*
|
||||
* @since 6.0.0
|
||||
* @deprecated 6.4.0 Use wp_print_font_faces() instead.
|
||||
* @access private
|
||||
*/
|
||||
function _wp_theme_json_webfonts_handler() {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_print_font_faces' );
|
||||
|
||||
// Block themes are unavailable during installation.
|
||||
if ( wp_installing() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_theme_has_theme_json() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Webfonts to be processed.
|
||||
$registered_webfonts = array();
|
||||
|
||||
/**
|
||||
* Gets the webfonts from theme.json.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @return array Array of defined webfonts.
|
||||
*/
|
||||
$fn_get_webfonts_from_theme_json = static function() {
|
||||
// Get settings from theme.json.
|
||||
$settings = WP_Theme_JSON_Resolver::get_merged_data()->get_settings();
|
||||
|
||||
// If in the editor, add webfonts defined in variations.
|
||||
if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
|
||||
$variations = WP_Theme_JSON_Resolver::get_style_variations();
|
||||
foreach ( $variations as $variation ) {
|
||||
// Skip if fontFamilies are not defined in the variation.
|
||||
if ( empty( $variation['settings']['typography']['fontFamilies'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Initialize the array structure.
|
||||
if ( empty( $settings['typography'] ) ) {
|
||||
$settings['typography'] = array();
|
||||
}
|
||||
if ( empty( $settings['typography']['fontFamilies'] ) ) {
|
||||
$settings['typography']['fontFamilies'] = array();
|
||||
}
|
||||
if ( empty( $settings['typography']['fontFamilies']['theme'] ) ) {
|
||||
$settings['typography']['fontFamilies']['theme'] = array();
|
||||
}
|
||||
|
||||
// Combine variations with settings. Remove duplicates.
|
||||
$settings['typography']['fontFamilies']['theme'] = array_merge( $settings['typography']['fontFamilies']['theme'], $variation['settings']['typography']['fontFamilies']['theme'] );
|
||||
$settings['typography']['fontFamilies'] = array_unique( $settings['typography']['fontFamilies'] );
|
||||
}
|
||||
}
|
||||
|
||||
// Bail out early if there are no settings for webfonts.
|
||||
if ( empty( $settings['typography']['fontFamilies'] ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$webfonts = array();
|
||||
|
||||
// Look for fontFamilies.
|
||||
foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
|
||||
foreach ( $font_families as $font_family ) {
|
||||
|
||||
// Skip if fontFace is not defined.
|
||||
if ( empty( $font_family['fontFace'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip if fontFace is not an array of webfonts.
|
||||
if ( ! is_array( $font_family['fontFace'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$webfonts = array_merge( $webfonts, $font_family['fontFace'] );
|
||||
}
|
||||
}
|
||||
|
||||
return $webfonts;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transforms each 'src' into an URI by replacing 'file:./'
|
||||
* placeholder from theme.json.
|
||||
*
|
||||
* The absolute path to the webfont file(s) cannot be defined in
|
||||
* theme.json. `file:./` is the placeholder which is replaced by
|
||||
* the theme's URL path to the theme's root.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param array $src Webfont file(s) `src`.
|
||||
* @return array Webfont's `src` in URI.
|
||||
*/
|
||||
$fn_transform_src_into_uri = static function( array $src ) {
|
||||
foreach ( $src as $key => $url ) {
|
||||
// Tweak the URL to be relative to the theme root.
|
||||
if ( ! str_starts_with( $url, 'file:./' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$src[ $key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) );
|
||||
}
|
||||
|
||||
return $src;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the font-face properties (i.e. keys) into kebab-case.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param array $font_face Font face to convert.
|
||||
* @return array Font faces with each property in kebab-case format.
|
||||
*/
|
||||
$fn_convert_keys_to_kebab_case = static function( array $font_face ) {
|
||||
foreach ( $font_face as $property => $value ) {
|
||||
$kebab_case = _wp_to_kebab_case( $property );
|
||||
$font_face[ $kebab_case ] = $value;
|
||||
if ( $kebab_case !== $property ) {
|
||||
unset( $font_face[ $property ] );
|
||||
}
|
||||
}
|
||||
|
||||
return $font_face;
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates a webfont.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param array $webfont The webfont arguments.
|
||||
* @return array|false The validated webfont arguments, or false if the webfont is invalid.
|
||||
*/
|
||||
$fn_validate_webfont = static function( $webfont ) {
|
||||
$webfont = wp_parse_args(
|
||||
$webfont,
|
||||
array(
|
||||
'font-family' => '',
|
||||
'font-style' => 'normal',
|
||||
'font-weight' => '400',
|
||||
'font-display' => 'fallback',
|
||||
'src' => array(),
|
||||
)
|
||||
);
|
||||
|
||||
// Check the font-family.
|
||||
if ( empty( $webfont['font-family'] ) || ! is_string( $webfont['font-family'] ) ) {
|
||||
trigger_error( __( 'Webfont font family must be a non-empty string.' ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the `src` property is defined and a valid type.
|
||||
if ( empty( $webfont['src'] ) || ( ! is_string( $webfont['src'] ) && ! is_array( $webfont['src'] ) ) ) {
|
||||
trigger_error( __( 'Webfont src must be a non-empty string or an array of strings.' ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the `src` property.
|
||||
foreach ( (array) $webfont['src'] as $src ) {
|
||||
if ( ! is_string( $src ) || '' === trim( $src ) ) {
|
||||
trigger_error( __( 'Each webfont src must be a non-empty string.' ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the font-weight.
|
||||
if ( ! is_string( $webfont['font-weight'] ) && ! is_int( $webfont['font-weight'] ) ) {
|
||||
trigger_error( __( 'Webfont font weight must be a properly formatted string or integer.' ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the font-display.
|
||||
if ( ! in_array( $webfont['font-display'], array( 'auto', 'block', 'fallback', 'optional', 'swap' ), true ) ) {
|
||||
$webfont['font-display'] = 'fallback';
|
||||
}
|
||||
|
||||
$valid_props = array(
|
||||
'ascend-override',
|
||||
'descend-override',
|
||||
'font-display',
|
||||
'font-family',
|
||||
'font-stretch',
|
||||
'font-style',
|
||||
'font-weight',
|
||||
'font-variant',
|
||||
'font-feature-settings',
|
||||
'font-variation-settings',
|
||||
'line-gap-override',
|
||||
'size-adjust',
|
||||
'src',
|
||||
'unicode-range',
|
||||
);
|
||||
|
||||
foreach ( $webfont as $prop => $value ) {
|
||||
if ( ! in_array( $prop, $valid_props, true ) ) {
|
||||
unset( $webfont[ $prop ] );
|
||||
}
|
||||
}
|
||||
|
||||
return $webfont;
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers webfonts declared in theme.json.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference).
|
||||
* @uses $fn_get_webfonts_from_theme_json To run the function that gets the webfonts from theme.json.
|
||||
* @uses $fn_convert_keys_to_kebab_case To run the function that converts keys into kebab-case.
|
||||
* @uses $fn_validate_webfont To run the function that validates each font-face (webfont) from theme.json.
|
||||
*/
|
||||
$fn_register_webfonts = static function() use ( &$registered_webfonts, $fn_get_webfonts_from_theme_json, $fn_convert_keys_to_kebab_case, $fn_validate_webfont, $fn_transform_src_into_uri ) {
|
||||
$registered_webfonts = array();
|
||||
|
||||
foreach ( $fn_get_webfonts_from_theme_json() as $webfont ) {
|
||||
if ( ! is_array( $webfont ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$webfont = $fn_convert_keys_to_kebab_case( $webfont );
|
||||
|
||||
$webfont = $fn_validate_webfont( $webfont );
|
||||
|
||||
$webfont['src'] = $fn_transform_src_into_uri( (array) $webfont['src'] );
|
||||
|
||||
// Skip if not valid.
|
||||
if ( empty( $webfont ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$registered_webfonts[] = $webfont;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Orders 'src' items to optimize for browser support.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param array $webfont Webfont to process.
|
||||
* @return array Ordered `src` items.
|
||||
*/
|
||||
$fn_order_src = static function( array $webfont ) {
|
||||
$src = array();
|
||||
$src_ordered = array();
|
||||
|
||||
foreach ( $webfont['src'] as $url ) {
|
||||
// Add data URIs first.
|
||||
if ( str_starts_with( trim( $url ), 'data:' ) ) {
|
||||
$src_ordered[] = array(
|
||||
'url' => $url,
|
||||
'format' => 'data',
|
||||
);
|
||||
continue;
|
||||
}
|
||||
$format = pathinfo( $url, PATHINFO_EXTENSION );
|
||||
$src[ $format ] = $url;
|
||||
}
|
||||
|
||||
// Add woff2.
|
||||
if ( ! empty( $src['woff2'] ) ) {
|
||||
$src_ordered[] = array(
|
||||
'url' => sanitize_url( $src['woff2'] ),
|
||||
'format' => 'woff2',
|
||||
);
|
||||
}
|
||||
|
||||
// Add woff.
|
||||
if ( ! empty( $src['woff'] ) ) {
|
||||
$src_ordered[] = array(
|
||||
'url' => sanitize_url( $src['woff'] ),
|
||||
'format' => 'woff',
|
||||
);
|
||||
}
|
||||
|
||||
// Add ttf.
|
||||
if ( ! empty( $src['ttf'] ) ) {
|
||||
$src_ordered[] = array(
|
||||
'url' => sanitize_url( $src['ttf'] ),
|
||||
'format' => 'truetype',
|
||||
);
|
||||
}
|
||||
|
||||
// Add eot.
|
||||
if ( ! empty( $src['eot'] ) ) {
|
||||
$src_ordered[] = array(
|
||||
'url' => sanitize_url( $src['eot'] ),
|
||||
'format' => 'embedded-opentype',
|
||||
);
|
||||
}
|
||||
|
||||
// Add otf.
|
||||
if ( ! empty( $src['otf'] ) ) {
|
||||
$src_ordered[] = array(
|
||||
'url' => sanitize_url( $src['otf'] ),
|
||||
'format' => 'opentype',
|
||||
);
|
||||
}
|
||||
$webfont['src'] = $src_ordered;
|
||||
|
||||
return $webfont;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compiles the 'src' into valid CSS.
|
||||
*
|
||||
* @since 6.0.0
|
||||
* @since 6.2.0 Removed local() CSS.
|
||||
*
|
||||
* @param string $font_family Font family.
|
||||
* @param array $value Value to process.
|
||||
* @return string The CSS.
|
||||
*/
|
||||
$fn_compile_src = static function( $font_family, array $value ) {
|
||||
$src = '';
|
||||
|
||||
foreach ( $value as $item ) {
|
||||
$src .= ( 'data' === $item['format'] )
|
||||
? ", url({$item['url']})"
|
||||
: ", url('{$item['url']}') format('{$item['format']}')";
|
||||
}
|
||||
|
||||
$src = ltrim( $src, ', ' );
|
||||
|
||||
return $src;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compiles the font variation settings.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param array $font_variation_settings Array of font variation settings.
|
||||
* @return string The CSS.
|
||||
*/
|
||||
$fn_compile_variations = static function( array $font_variation_settings ) {
|
||||
$variations = '';
|
||||
|
||||
foreach ( $font_variation_settings as $key => $value ) {
|
||||
$variations .= "$key $value";
|
||||
}
|
||||
|
||||
return $variations;
|
||||
};
|
||||
|
||||
/**
|
||||
* Builds the font-family's CSS.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @uses $fn_compile_src To run the function that compiles the src.
|
||||
* @uses $fn_compile_variations To run the function that compiles the variations.
|
||||
*
|
||||
* @param array $webfont Webfont to process.
|
||||
* @return string This font-family's CSS.
|
||||
*/
|
||||
$fn_build_font_face_css = static function( array $webfont ) use ( $fn_compile_src, $fn_compile_variations ) {
|
||||
$css = '';
|
||||
|
||||
// Wrap font-family in quotes if it contains spaces.
|
||||
if (
|
||||
str_contains( $webfont['font-family'], ' ' ) &&
|
||||
! str_contains( $webfont['font-family'], '"' ) &&
|
||||
! str_contains( $webfont['font-family'], "'" )
|
||||
) {
|
||||
$webfont['font-family'] = '"' . $webfont['font-family'] . '"';
|
||||
}
|
||||
|
||||
foreach ( $webfont as $key => $value ) {
|
||||
/*
|
||||
* Skip "provider", since it's for internal API use,
|
||||
* and not a valid CSS property.
|
||||
*/
|
||||
if ( 'provider' === $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Compile the "src" parameter.
|
||||
if ( 'src' === $key ) {
|
||||
$value = $fn_compile_src( $webfont['font-family'], $value );
|
||||
}
|
||||
|
||||
// If font-variation-settings is an array, convert it to a string.
|
||||
if ( 'font-variation-settings' === $key && is_array( $value ) ) {
|
||||
$value = $fn_compile_variations( $value );
|
||||
}
|
||||
|
||||
if ( ! empty( $value ) ) {
|
||||
$css .= "$key:$value;";
|
||||
}
|
||||
}
|
||||
|
||||
return $css;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the '@font-face' CSS styles for locally-hosted font files.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference).
|
||||
* @uses $fn_order_src To run the function that orders the src.
|
||||
* @uses $fn_build_font_face_css To run the function that builds the font-face CSS.
|
||||
*
|
||||
* @return string The `@font-face` CSS.
|
||||
*/
|
||||
$fn_get_css = static function() use ( &$registered_webfonts, $fn_order_src, $fn_build_font_face_css ) {
|
||||
$css = '';
|
||||
|
||||
foreach ( $registered_webfonts as $webfont ) {
|
||||
// Order the webfont's `src` items to optimize for browser support.
|
||||
$webfont = $fn_order_src( $webfont );
|
||||
|
||||
// Build the @font-face CSS for this webfont.
|
||||
$css .= '@font-face{' . $fn_build_font_face_css( $webfont ) . '}';
|
||||
}
|
||||
|
||||
return $css;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates and enqueues webfonts styles.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @uses $fn_get_css To run the function that gets the CSS.
|
||||
*/
|
||||
$fn_generate_and_enqueue_styles = static function() use ( $fn_get_css ) {
|
||||
// Generate the styles.
|
||||
$styles = $fn_get_css();
|
||||
|
||||
// Bail out if there are no styles to enqueue.
|
||||
if ( '' === $styles ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Enqueue the stylesheet.
|
||||
wp_register_style( 'wp-webfonts', '' );
|
||||
wp_enqueue_style( 'wp-webfonts' );
|
||||
|
||||
// Add the styles to the stylesheet.
|
||||
wp_add_inline_style( 'wp-webfonts', $styles );
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates and enqueues editor styles.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @uses $fn_get_css To run the function that gets the CSS.
|
||||
*/
|
||||
$fn_generate_and_enqueue_editor_styles = static function() use ( $fn_get_css ) {
|
||||
// Generate the styles.
|
||||
$styles = $fn_get_css();
|
||||
|
||||
// Bail out if there are no styles to enqueue.
|
||||
if ( '' === $styles ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_add_inline_style( 'wp-block-library', $styles );
|
||||
};
|
||||
|
||||
add_action( 'wp_loaded', $fn_register_webfonts );
|
||||
add_action( 'wp_enqueue_scripts', $fn_generate_and_enqueue_styles );
|
||||
add_action( 'admin_init', $fn_generate_and_enqueue_editor_styles );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the CSS in the embed iframe header.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @deprecated 6.4.0 Use wp_enqueue_embed_styles() instead.
|
||||
*/
|
||||
function print_embed_styles() {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_embed_styles' );
|
||||
|
||||
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
|
||||
$suffix = SCRIPT_DEBUG ? '' : '.min';
|
||||
?>
|
||||
<style<?php echo $type_attr; ?>>
|
||||
<?php echo file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ); ?>
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the important emoji-related styles.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @deprecated 6.4.0 Use wp_enqueue_emoji_styles() instead.
|
||||
*/
|
||||
function print_emoji_styles() {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_emoji_styles' );
|
||||
static $printed = false;
|
||||
|
||||
if ( $printed ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$printed = true;
|
||||
|
||||
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
|
||||
?>
|
||||
<style<?php echo $type_attr; ?>>
|
||||
img.wp-smiley,
|
||||
img.emoji {
|
||||
display: inline !important;
|
||||
border: none !important;
|
||||
box-shadow: none !important;
|
||||
height: 1em !important;
|
||||
width: 1em !important;
|
||||
margin: 0 0.07em !important;
|
||||
vertical-align: -0.1em !important;
|
||||
background: none !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints style and scripts for the admin bar.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @deprecated 6.4.0 Use wp_enqueue_admin_bar_header_styles() instead.
|
||||
*/
|
||||
function wp_admin_bar_header() {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_header_styles' );
|
||||
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
|
||||
?>
|
||||
<style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints default admin bar callback.
|
||||
*
|
||||
* @since 3.1.0
|
||||
* @deprecated 6.4.0 Use wp_enqueue_admin_bar_bump_styles() instead.
|
||||
*/
|
||||
function _admin_bar_bump_cb() {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_bump_styles' );
|
||||
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
|
||||
?>
|
||||
<style<?php echo $type_attr; ?> media="screen">
|
||||
html { margin-top: 32px !important; }
|
||||
@media screen and ( max-width: 782px ) {
|
||||
html { margin-top: 46px !important; }
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.
|
||||
*
|
||||
* This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained.
|
||||
*
|
||||
* @since 5.7.0
|
||||
* @deprecated 6.4.0 The `wp_update_https_detection_errors()` function is no longer used and has been replaced by
|
||||
* `wp_get_https_detection_errors()`. Previously the function was called by a regular Cron hook to
|
||||
* update the `https_detection_errors` option, but this is no longer necessary as the errors are
|
||||
* retrieved directly in Site Health and no longer used outside of Site Health.
|
||||
* @access private
|
||||
*/
|
||||
function wp_update_https_detection_errors() {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0' );
|
||||
|
||||
/**
|
||||
* Short-circuits the process of detecting errors related to HTTPS support.
|
||||
*
|
||||
* Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote
|
||||
* request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead.
|
||||
*
|
||||
* @since 5.7.0
|
||||
* @deprecated 6.4.0 The `wp_update_https_detection_errors` filter is no longer used and has been replaced by `pre_wp_get_https_detection_errors`.
|
||||
*
|
||||
* @param null|WP_Error $pre Error object to short-circuit detection,
|
||||
* or null to continue with the default behavior.
|
||||
*/
|
||||
$support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null );
|
||||
if ( is_wp_error( $support_errors ) ) {
|
||||
update_option( 'https_detection_errors', $support_errors->errors );
|
||||
return;
|
||||
}
|
||||
|
||||
$support_errors = wp_get_https_detection_errors();
|
||||
|
||||
update_option( 'https_detection_errors', $support_errors );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds `decoding` attribute to an `img` HTML tag.
|
||||
*
|
||||
* The `decoding` attribute allows developers to indicate whether the
|
||||
* browser can decode the image off the main thread (`async`), on the
|
||||
* main thread (`sync`) or as determined by the browser (`auto`).
|
||||
*
|
||||
* By default WordPress adds `decoding="async"` to images but developers
|
||||
* can use the {@see 'wp_img_tag_add_decoding_attr'} filter to modify this
|
||||
* to remove the attribute or set it to another accepted value.
|
||||
*
|
||||
* @since 6.1.0
|
||||
* @deprecated 6.4.0 Use wp_img_tag_add_loading_optimization_attrs() instead.
|
||||
* @see wp_img_tag_add_loading_optimization_attrs()
|
||||
*
|
||||
* @param string $image The HTML `img` tag where the attribute should be added.
|
||||
* @param string $context Additional context to pass to the filters.
|
||||
* @return string Converted `img` tag with `decoding` attribute added.
|
||||
*/
|
||||
function wp_img_tag_add_decoding_attr( $image, $context ) {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_img_tag_add_loading_optimization_attrs()' );
|
||||
|
||||
/*
|
||||
* Only apply the decoding attribute to images that have a src attribute that
|
||||
* starts with a double quote, ensuring escaped JSON is also excluded.
|
||||
*/
|
||||
if ( ! str_contains( $image, ' src="' ) ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
/** This action is documented in wp-includes/media.php */
|
||||
$value = apply_filters( 'wp_img_tag_add_decoding_attr', 'async', $image, $context );
|
||||
|
||||
if ( in_array( $value, array( 'async', 'sync', 'auto' ), true ) ) {
|
||||
$image = str_replace( '<img ', '<img decoding="' . esc_attr( $value ) . '" ', $image );
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses wp_template content and injects the active theme's
|
||||
* stylesheet as a theme attribute into each wp_template_part
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) instead.
|
||||
* @access private
|
||||
*
|
||||
* @param string $template_content serialized wp_template content.
|
||||
* @return string Updated 'wp_template' content.
|
||||
*/
|
||||
function _inject_theme_attribute_in_block_template_content( $template_content ) {
|
||||
_deprecated_function(
|
||||
__FUNCTION__,
|
||||
'6.4.0',
|
||||
'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_inject_theme_attribute_in_template_part_block" )'
|
||||
);
|
||||
|
||||
$has_updated_content = false;
|
||||
$new_content = '';
|
||||
$template_blocks = parse_blocks( $template_content );
|
||||
|
||||
$blocks = _flatten_blocks( $template_blocks );
|
||||
foreach ( $blocks as &$block ) {
|
||||
if (
|
||||
'core/template-part' === $block['blockName'] &&
|
||||
! isset( $block['attrs']['theme'] )
|
||||
) {
|
||||
$block['attrs']['theme'] = get_stylesheet();
|
||||
$has_updated_content = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $has_updated_content ) {
|
||||
foreach ( $template_blocks as &$block ) {
|
||||
$new_content .= serialize_block( $block );
|
||||
}
|
||||
|
||||
return $new_content;
|
||||
}
|
||||
|
||||
return $template_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a block template and removes the theme attribute from each template part.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead.
|
||||
* @access private
|
||||
*
|
||||
* @param string $template_content Serialized block template content.
|
||||
* @return string Updated block template content.
|
||||
*/
|
||||
function _remove_theme_attribute_in_block_template_content( $template_content ) {
|
||||
_deprecated_function(
|
||||
__FUNCTION__,
|
||||
'6.4.0',
|
||||
'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_remove_theme_attribute_from_template_part_block" )'
|
||||
);
|
||||
|
||||
$has_updated_content = false;
|
||||
$new_content = '';
|
||||
$template_blocks = parse_blocks( $template_content );
|
||||
|
||||
$blocks = _flatten_blocks( $template_blocks );
|
||||
foreach ( $blocks as $key => $block ) {
|
||||
if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) {
|
||||
unset( $blocks[ $key ]['attrs']['theme'] );
|
||||
$has_updated_content = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $has_updated_content ) {
|
||||
return $template_content;
|
||||
}
|
||||
|
||||
foreach ( $template_blocks as $block ) {
|
||||
$new_content .= serialize_block( $block );
|
||||
}
|
||||
|
||||
return $new_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the skip-link script & styles.
|
||||
*
|
||||
* @since 5.8.0
|
||||
* @access private
|
||||
* @deprecated 6.4.0 Use wp_enqueue_block_template_skip_link() instead.
|
||||
*
|
||||
* @global string $_wp_current_template_content
|
||||
*/
|
||||
function the_block_template_skip_link() {
|
||||
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_block_template_skip_link()' );
|
||||
|
||||
global $_wp_current_template_content;
|
||||
|
||||
// Early exit if not a block theme.
|
||||
if ( ! current_theme_supports( 'block-templates' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Early exit if not a block template.
|
||||
if ( ! $_wp_current_template_content ) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Print the skip-link styles.
|
||||
*/
|
||||
?>
|
||||
<style id="skip-link-styles">
|
||||
.skip-link.screen-reader-text {
|
||||
border: 0;
|
||||
clip: rect(1px,1px,1px,1px);
|
||||
clip-path: inset(50%);
|
||||
height: 1px;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
position: absolute !important;
|
||||
width: 1px;
|
||||
word-wrap: normal !important;
|
||||
}
|
||||
|
||||
.skip-link.screen-reader-text:focus {
|
||||
background-color: #eee;
|
||||
clip: auto !important;
|
||||
clip-path: none;
|
||||
color: #444;
|
||||
display: block;
|
||||
font-size: 1em;
|
||||
height: auto;
|
||||
left: 5px;
|
||||
line-height: normal;
|
||||
padding: 15px 23px 14px;
|
||||
text-decoration: none;
|
||||
top: 5px;
|
||||
width: auto;
|
||||
z-index: 100000;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
/**
|
||||
* Print the skip-link script.
|
||||
*/
|
||||
?>
|
||||
<script>
|
||||
( function() {
|
||||
var skipLinkTarget = document.querySelector( 'main' ),
|
||||
sibling,
|
||||
skipLinkTargetID,
|
||||
skipLink;
|
||||
|
||||
// Early exit if a skip-link target can't be located.
|
||||
if ( ! skipLinkTarget ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the site wrapper.
|
||||
* The skip-link will be injected in the beginning of it.
|
||||
*/
|
||||
sibling = document.querySelector( '.wp-site-blocks' );
|
||||
|
||||
// Early exit if the root element was not found.
|
||||
if ( ! sibling ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the skip-link target's ID, and generate one if it doesn't exist.
|
||||
skipLinkTargetID = skipLinkTarget.id;
|
||||
if ( ! skipLinkTargetID ) {
|
||||
skipLinkTargetID = 'wp--skip-link--target';
|
||||
skipLinkTarget.id = skipLinkTargetID;
|
||||
}
|
||||
|
||||
// Create the skip link.
|
||||
skipLink = document.createElement( 'a' );
|
||||
skipLink.classList.add( 'skip-link', 'screen-reader-text' );
|
||||
skipLink.href = '#' + skipLinkTargetID;
|
||||
skipLink.innerHTML = '<?php /* translators: Hidden accessibility text. */ esc_html_e( 'Skip to content' ); ?>';
|
||||
|
||||
// Inject the skip link.
|
||||
sibling.parentElement.insertBefore( skipLink, sibling );
|
||||
}() );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user