4309 * @deprecated 6.0.0 |
4327 * @deprecated 6.0.0 |
4310 */ |
4328 */ |
4311 function wp_add_iframed_editor_assets_html() { |
4329 function wp_add_iframed_editor_assets_html() { |
4312 _deprecated_function( __FUNCTION__, '6.0.0' ); |
4330 _deprecated_function( __FUNCTION__, '6.0.0' ); |
4313 } |
4331 } |
|
4332 |
|
4333 /** |
|
4334 * Retrieves thumbnail for an attachment. |
|
4335 * Note that this works only for the (very) old image metadata style where 'thumb' was set, |
|
4336 * and the 'sizes' array did not exist. This function returns false for the newer image metadata style |
|
4337 * despite that 'thumbnail' is present in the 'sizes' array. |
|
4338 * |
|
4339 * @since 2.1.0 |
|
4340 * @deprecated 6.1.0 |
|
4341 * |
|
4342 * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`. |
|
4343 * @return string|false Thumbnail file path on success, false on failure. |
|
4344 */ |
|
4345 function wp_get_attachment_thumb_file( $post_id = 0 ) { |
|
4346 _deprecated_function( __FUNCTION__, '6.1.0' ); |
|
4347 |
|
4348 $post_id = (int) $post_id; |
|
4349 $post = get_post( $post_id ); |
|
4350 |
|
4351 if ( ! $post ) { |
|
4352 return false; |
|
4353 } |
|
4354 |
|
4355 // Use $post->ID rather than $post_id as get_post() may have used the global $post object. |
|
4356 $imagedata = wp_get_attachment_metadata( $post->ID ); |
|
4357 |
|
4358 if ( ! is_array( $imagedata ) ) { |
|
4359 return false; |
|
4360 } |
|
4361 |
|
4362 $file = get_attached_file( $post->ID ); |
|
4363 |
|
4364 if ( ! empty( $imagedata['thumb'] ) ) { |
|
4365 $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ); |
|
4366 if ( file_exists( $thumbfile ) ) { |
|
4367 /** |
|
4368 * Filters the attachment thumbnail file path. |
|
4369 * |
|
4370 * @since 2.1.0 |
|
4371 * |
|
4372 * @param string $thumbfile File path to the attachment thumbnail. |
|
4373 * @param int $post_id Attachment ID. |
|
4374 */ |
|
4375 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID ); |
|
4376 } |
|
4377 } |
|
4378 |
|
4379 return false; |
|
4380 } |
|
4381 |
|
4382 /** |
|
4383 * Gets the path to a translation file for loading a textdomain just in time. |
|
4384 * |
|
4385 * Caches the retrieved results internally. |
|
4386 * |
|
4387 * @since 4.7.0 |
|
4388 * @deprecated 6.1.0 |
|
4389 * @access private |
|
4390 * |
|
4391 * @see _load_textdomain_just_in_time() |
|
4392 * |
|
4393 * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
4394 * @param bool $reset Whether to reset the internal cache. Used by the switch to locale functionality. |
|
4395 * @return string|false The path to the translation file or false if no translation file was found. |
|
4396 */ |
|
4397 function _get_path_to_translation( $domain, $reset = false ) { |
|
4398 _deprecated_function( __FUNCTION__, '6.1.0', 'WP_Textdomain_Registry' ); |
|
4399 |
|
4400 static $available_translations = array(); |
|
4401 |
|
4402 if ( true === $reset ) { |
|
4403 $available_translations = array(); |
|
4404 } |
|
4405 |
|
4406 if ( ! isset( $available_translations[ $domain ] ) ) { |
|
4407 $available_translations[ $domain ] = _get_path_to_translation_from_lang_dir( $domain ); |
|
4408 } |
|
4409 |
|
4410 return $available_translations[ $domain ]; |
|
4411 } |
|
4412 |
|
4413 /** |
|
4414 * Gets the path to a translation file in the languages directory for the current locale. |
|
4415 * |
|
4416 * Holds a cached list of available .mo files to improve performance. |
|
4417 * |
|
4418 * @since 4.7.0 |
|
4419 * @deprecated 6.1.0 |
|
4420 * @access private |
|
4421 * |
|
4422 * @see _get_path_to_translation() |
|
4423 * |
|
4424 * @param string $domain Text domain. Unique identifier for retrieving translated strings. |
|
4425 * @return string|false The path to the translation file or false if no translation file was found. |
|
4426 */ |
|
4427 function _get_path_to_translation_from_lang_dir( $domain ) { |
|
4428 _deprecated_function( __FUNCTION__, '6.1.0', 'WP_Textdomain_Registry' ); |
|
4429 |
|
4430 static $cached_mofiles = null; |
|
4431 |
|
4432 if ( null === $cached_mofiles ) { |
|
4433 $cached_mofiles = array(); |
|
4434 |
|
4435 $locations = array( |
|
4436 WP_LANG_DIR . '/plugins', |
|
4437 WP_LANG_DIR . '/themes', |
|
4438 ); |
|
4439 |
|
4440 foreach ( $locations as $location ) { |
|
4441 $mofiles = glob( $location . '/*.mo' ); |
|
4442 if ( $mofiles ) { |
|
4443 $cached_mofiles = array_merge( $cached_mofiles, $mofiles ); |
|
4444 } |
|
4445 } |
|
4446 } |
|
4447 |
|
4448 $locale = determine_locale(); |
|
4449 $mofile = "{$domain}-{$locale}.mo"; |
|
4450 |
|
4451 $path = WP_LANG_DIR . '/plugins/' . $mofile; |
|
4452 if ( in_array( $path, $cached_mofiles, true ) ) { |
|
4453 return $path; |
|
4454 } |
|
4455 |
|
4456 $path = WP_LANG_DIR . '/themes/' . $mofile; |
|
4457 if ( in_array( $path, $cached_mofiles, true ) ) { |
|
4458 return $path; |
|
4459 } |
|
4460 |
|
4461 return false; |
|
4462 } |
|
4463 |
|
4464 /** |
|
4465 * Allows multiple block styles. |
|
4466 * |
|
4467 * @since 5.9.0 |
|
4468 * @deprecated 6.1.0 |
|
4469 * |
|
4470 * @param array $metadata Metadata for registering a block type. |
|
4471 * @return array Metadata for registering a block type. |
|
4472 */ |
|
4473 function _wp_multiple_block_styles( $metadata ) { |
|
4474 _deprecated_function( __FUNCTION__, '6.1.0' ); |
|
4475 return $metadata; |
|
4476 } |
|
4477 |
|
4478 /** |
|
4479 * Generates an inline style for a typography feature e.g. text decoration, |
|
4480 * text transform, and font style. |
|
4481 * |
|
4482 * @since 5.8.0 |
|
4483 * @access private |
|
4484 * @deprecated 6.1.0 Use wp_style_engine_get_styles() introduced in 6.1.0. |
|
4485 * |
|
4486 * @see wp_style_engine_get_styles() |
|
4487 * |
|
4488 * @param array $attributes Block's attributes. |
|
4489 * @param string $feature Key for the feature within the typography styles. |
|
4490 * @param string $css_property Slug for the CSS property the inline style sets. |
|
4491 * @return string CSS inline style. |
|
4492 */ |
|
4493 function wp_typography_get_css_variable_inline_style( $attributes, $feature, $css_property ) { |
|
4494 _deprecated_function( __FUNCTION__, '6.1.0', 'wp_style_engine_get_styles()' ); |
|
4495 |
|
4496 // Retrieve current attribute value or skip if not found. |
|
4497 $style_value = _wp_array_get( $attributes, array( 'style', 'typography', $feature ), false ); |
|
4498 if ( ! $style_value ) { |
|
4499 return; |
|
4500 } |
|
4501 |
|
4502 // If we don't have a preset CSS variable, we'll assume it's a regular CSS value. |
|
4503 if ( ! str_contains( $style_value, "var:preset|{$css_property}|" ) ) { |
|
4504 return sprintf( '%s:%s;', $css_property, $style_value ); |
|
4505 } |
|
4506 |
|
4507 /* |
|
4508 * We have a preset CSS variable as the style. |
|
4509 * Get the style value from the string and return CSS style. |
|
4510 */ |
|
4511 $index_to_splice = strrpos( $style_value, '|' ) + 1; |
|
4512 $slug = substr( $style_value, $index_to_splice ); |
|
4513 |
|
4514 // Return the actual CSS inline style e.g. `text-decoration:var(--wp--preset--text-decoration--underline);`. |
|
4515 return sprintf( '%s:var(--wp--preset--%s--%s);', $css_property, $css_property, $slug ); |
|
4516 } |
|
4517 |
|
4518 /** |
|
4519 * Determines whether global terms are enabled. |
|
4520 * |
|
4521 * @since 3.0.0 |
|
4522 * @since 6.1.0 This function now always returns false. |
|
4523 * @deprecated 6.1.0 |
|
4524 * |
|
4525 * @return bool Always returns false. |
|
4526 */ |
|
4527 function global_terms_enabled() { |
|
4528 _deprecated_function( __FUNCTION__, '6.1.0' ); |
|
4529 |
|
4530 return false; |
|
4531 } |
|
4532 |
|
4533 /** |
|
4534 * Filter the SQL clauses of an attachment query to include filenames. |
|
4535 * |
|
4536 * @since 4.7.0 |
|
4537 * @deprecated 6.0.3 |
|
4538 * @access private |
|
4539 * |
|
4540 * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY, |
|
4541 * DISTINCT, fields (SELECT), and LIMITS clauses. |
|
4542 * @return array The unmodified clauses. |
|
4543 */ |
|
4544 function _filter_query_attachment_filenames( $clauses ) { |
|
4545 _deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )' ); |
|
4546 remove_filter( 'posts_clauses', __FUNCTION__ ); |
|
4547 return $clauses; |
|
4548 } |
|
4549 |
|
4550 /** |
|
4551 * Retrieves a page given its title. |
|
4552 * |
|
4553 * If more than one post uses the same title, the post with the smallest ID will be returned. |
|
4554 * Be careful: in case of more than one post having the same title, it will check the oldest |
|
4555 * publication date, not the smallest ID. |
|
4556 * |
|
4557 * Because this function uses the MySQL '=' comparison, $page_title will usually be matched |
|
4558 * as case-insensitive with default collation. |
|
4559 * |
|
4560 * @since 2.1.0 |
|
4561 * @since 3.0.0 The `$post_type` parameter was added. |
|
4562 * @deprecated 6.2.0 Use WP_Query. |
|
4563 * |
|
4564 * @global wpdb $wpdb WordPress database abstraction object. |
|
4565 * |
|
4566 * @param string $page_title Page title. |
|
4567 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which |
|
4568 * correspond to a WP_Post object, an associative array, or a numeric array, |
|
4569 * respectively. Default OBJECT. |
|
4570 * @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
|
4571 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. |
|
4572 */ |
|
4573 function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) { |
|
4574 _deprecated_function( __FUNCTION__, '6.2.0', 'WP_Query' ); |
|
4575 global $wpdb; |
|
4576 |
|
4577 if ( is_array( $post_type ) ) { |
|
4578 $post_type = esc_sql( $post_type ); |
|
4579 $post_type_in_string = "'" . implode( "','", $post_type ) . "'"; |
|
4580 $sql = $wpdb->prepare( |
|
4581 "SELECT ID |
|
4582 FROM $wpdb->posts |
|
4583 WHERE post_title = %s |
|
4584 AND post_type IN ($post_type_in_string)", |
|
4585 $page_title |
|
4586 ); |
|
4587 } else { |
|
4588 $sql = $wpdb->prepare( |
|
4589 "SELECT ID |
|
4590 FROM $wpdb->posts |
|
4591 WHERE post_title = %s |
|
4592 AND post_type = %s", |
|
4593 $page_title, |
|
4594 $post_type |
|
4595 ); |
|
4596 } |
|
4597 |
|
4598 $page = $wpdb->get_var( $sql ); |
|
4599 |
|
4600 if ( $page ) { |
|
4601 return get_post( $page, $output ); |
|
4602 } |
|
4603 |
|
4604 return null; |
|
4605 } |
|
4606 |
|
4607 /** |
|
4608 * Returns the correct template for the site's home page. |
|
4609 * |
|
4610 * @access private |
|
4611 * @since 6.0.0 |
|
4612 * @deprecated 6.2.0 Site Editor's server-side redirect for missing postType and postId |
|
4613 * query args is removed. Thus, this function is no longer used. |
|
4614 * |
|
4615 * @return array|null A template object, or null if none could be found. |
|
4616 */ |
|
4617 function _resolve_home_block_template() { |
|
4618 _deprecated_function( __FUNCTION__, '6.2.0' ); |
|
4619 |
|
4620 $show_on_front = get_option( 'show_on_front' ); |
|
4621 $front_page_id = get_option( 'page_on_front' ); |
|
4622 |
|
4623 if ( 'page' === $show_on_front && $front_page_id ) { |
|
4624 return array( |
|
4625 'postType' => 'page', |
|
4626 'postId' => $front_page_id, |
|
4627 ); |
|
4628 } |
|
4629 |
|
4630 $hierarchy = array( 'front-page', 'home', 'index' ); |
|
4631 $template = resolve_block_template( 'home', $hierarchy, '' ); |
|
4632 |
|
4633 if ( ! $template ) { |
|
4634 return null; |
|
4635 } |
|
4636 |
|
4637 return array( |
|
4638 'postType' => 'wp_template', |
|
4639 'postId' => $template->id, |
|
4640 ); |
|
4641 } |
|
4642 |
|
4643 /** |
|
4644 * Displays the link to the Windows Live Writer manifest file. |
|
4645 * |
|
4646 * @link https://msdn.microsoft.com/en-us/library/bb463265.aspx |
|
4647 * @since 2.3.1 |
|
4648 * @deprecated 6.3.0 WLW manifest is no longer in use and no longer included in core, |
|
4649 * so the output from this function is removed. |
|
4650 */ |
|
4651 function wlwmanifest_link() { |
|
4652 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
4653 } |
|
4654 |
|
4655 /** |
|
4656 * Queues comments for metadata lazy-loading. |
|
4657 * |
|
4658 * @since 4.5.0 |
|
4659 * @deprecated 6.3.0 Use wp_lazyload_comment_meta() instead. |
|
4660 * |
|
4661 * @param WP_Comment[] $comments Array of comment objects. |
|
4662 */ |
|
4663 function wp_queue_comments_for_comment_meta_lazyload( $comments ) { |
|
4664 _deprecated_function( __FUNCTION__, '6.3.0', 'wp_lazyload_comment_meta()' ); |
|
4665 // Don't use `wp_list_pluck()` to avoid by-reference manipulation. |
|
4666 $comment_ids = array(); |
|
4667 if ( is_array( $comments ) ) { |
|
4668 foreach ( $comments as $comment ) { |
|
4669 if ( $comment instanceof WP_Comment ) { |
|
4670 $comment_ids[] = $comment->comment_ID; |
|
4671 } |
|
4672 } |
|
4673 } |
|
4674 |
|
4675 wp_lazyload_comment_meta( $comment_ids ); |
|
4676 } |
|
4677 |
|
4678 /** |
|
4679 * Gets the default value to use for a `loading` attribute on an element. |
|
4680 * |
|
4681 * This function should only be called for a tag and context if lazy-loading is generally enabled. |
|
4682 * |
|
4683 * The function usually returns 'lazy', but uses certain heuristics to guess whether the current element is likely to |
|
4684 * appear above the fold, in which case it returns a boolean `false`, which will lead to the `loading` attribute being |
|
4685 * omitted on the element. The purpose of this refinement is to avoid lazy-loading elements that are within the initial |
|
4686 * viewport, which can have a negative performance impact. |
|
4687 * |
|
4688 * Under the hood, the function uses {@see wp_increase_content_media_count()} every time it is called for an element |
|
4689 * within the main content. If the element is the very first content element, the `loading` attribute will be omitted. |
|
4690 * This default threshold of 3 content elements to omit the `loading` attribute for can be customized using the |
|
4691 * {@see 'wp_omit_loading_attr_threshold'} filter. |
|
4692 * |
|
4693 * @since 5.9.0 |
|
4694 * @deprecated 6.3.0 Use wp_get_loading_optimization_attributes() instead. |
|
4695 * @see wp_get_loading_optimization_attributes() |
|
4696 * |
|
4697 * @global WP_Query $wp_query WordPress Query object. |
|
4698 * |
|
4699 * @param string $context Context for the element for which the `loading` attribute value is requested. |
|
4700 * @return string|bool The default `loading` attribute value. Either 'lazy', 'eager', or a boolean `false`, to indicate |
|
4701 * that the `loading` attribute should be skipped. |
|
4702 */ |
|
4703 function wp_get_loading_attr_default( $context ) { |
|
4704 _deprecated_function( __FUNCTION__, '6.3.0', 'wp_get_loading_optimization_attributes()' ); |
|
4705 global $wp_query; |
|
4706 |
|
4707 // Skip lazy-loading for the overall block template, as it is handled more granularly. |
|
4708 if ( 'template' === $context ) { |
|
4709 return false; |
|
4710 } |
|
4711 |
|
4712 /* |
|
4713 * Do not lazy-load images in the header block template part, as they are likely above the fold. |
|
4714 * For classic themes, this is handled in the condition below using the 'get_header' action. |
|
4715 */ |
|
4716 $header_area = WP_TEMPLATE_PART_AREA_HEADER; |
|
4717 if ( "template_part_{$header_area}" === $context ) { |
|
4718 return false; |
|
4719 } |
|
4720 |
|
4721 // Special handling for programmatically created image tags. |
|
4722 if ( 'the_post_thumbnail' === $context || 'wp_get_attachment_image' === $context ) { |
|
4723 /* |
|
4724 * Skip programmatically created images within post content as they need to be handled together with the other |
|
4725 * images within the post content. |
|
4726 * Without this clause, they would already be counted below which skews the number and can result in the first |
|
4727 * post content image being lazy-loaded only because there are images elsewhere in the post content. |
|
4728 */ |
|
4729 if ( doing_filter( 'the_content' ) ) { |
|
4730 return false; |
|
4731 } |
|
4732 |
|
4733 // Conditionally skip lazy-loading on images before the loop. |
|
4734 if ( |
|
4735 // Only apply for main query but before the loop. |
|
4736 $wp_query->before_loop && $wp_query->is_main_query() |
|
4737 /* |
|
4738 * Any image before the loop, but after the header has started should not be lazy-loaded, |
|
4739 * except when the footer has already started which can happen when the current template |
|
4740 * does not include any loop. |
|
4741 */ |
|
4742 && did_action( 'get_header' ) && ! did_action( 'get_footer' ) |
|
4743 ) { |
|
4744 return false; |
|
4745 } |
|
4746 } |
|
4747 |
|
4748 /* |
|
4749 * The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded, |
|
4750 * as they are likely above the fold. |
|
4751 */ |
|
4752 if ( 'the_content' === $context || 'the_post_thumbnail' === $context ) { |
|
4753 // Only elements within the main query loop have special handling. |
|
4754 if ( is_admin() || ! in_the_loop() || ! is_main_query() ) { |
|
4755 return 'lazy'; |
|
4756 } |
|
4757 |
|
4758 // Increase the counter since this is a main query content element. |
|
4759 $content_media_count = wp_increase_content_media_count(); |
|
4760 |
|
4761 // If the count so far is below the threshold, return `false` so that the `loading` attribute is omitted. |
|
4762 if ( $content_media_count <= wp_omit_loading_attr_threshold() ) { |
|
4763 return false; |
|
4764 } |
|
4765 |
|
4766 // For elements after the threshold, lazy-load them as usual. |
|
4767 return 'lazy'; |
|
4768 } |
|
4769 |
|
4770 // Lazy-load by default for any unknown context. |
|
4771 return 'lazy'; |
|
4772 } |
|
4773 |
|
4774 /** |
|
4775 * Adds `loading` attribute to an `img` HTML tag. |
|
4776 * |
|
4777 * @since 5.5.0 |
|
4778 * @deprecated 6.3.0 Use wp_img_tag_add_loading_optimization_attrs() instead. |
|
4779 * @see wp_img_tag_add_loading_optimization_attrs() |
|
4780 * |
|
4781 * @param string $image The HTML `img` tag where the attribute should be added. |
|
4782 * @param string $context Additional context to pass to the filters. |
|
4783 * @return string Converted `img` tag with `loading` attribute added. |
|
4784 */ |
|
4785 function wp_img_tag_add_loading_attr( $image, $context ) { |
|
4786 _deprecated_function( __FUNCTION__, '6.3.0', 'wp_img_tag_add_loading_optimization_attrs()' ); |
|
4787 /* |
|
4788 * Get loading attribute value to use. This must occur before the conditional check below so that even images that |
|
4789 * are ineligible for being lazy-loaded are considered. |
|
4790 */ |
|
4791 $value = wp_get_loading_attr_default( $context ); |
|
4792 |
|
4793 // Images should have source and dimension attributes for the `loading` attribute to be added. |
|
4794 if ( ! str_contains( $image, ' src="' ) || ! str_contains( $image, ' width="' ) || ! str_contains( $image, ' height="' ) ) { |
|
4795 return $image; |
|
4796 } |
|
4797 |
|
4798 /** This filter is documented in wp-admin/includes/media.php */ |
|
4799 $value = apply_filters( 'wp_img_tag_add_loading_attr', $value, $image, $context ); |
|
4800 |
|
4801 if ( $value ) { |
|
4802 if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) { |
|
4803 $value = 'lazy'; |
|
4804 } |
|
4805 |
|
4806 return str_replace( '<img', '<img loading="' . esc_attr( $value ) . '"', $image ); |
|
4807 } |
|
4808 |
|
4809 return $image; |
|
4810 } |
|
4811 |
|
4812 /** |
|
4813 * Takes input from [0, n] and returns it as [0, 1]. |
|
4814 * |
|
4815 * Direct port of TinyColor's function, lightly simplified to maintain |
|
4816 * consistency with TinyColor. |
|
4817 * |
|
4818 * @link https://github.com/bgrins/TinyColor |
|
4819 * |
|
4820 * @since 5.8.0 |
|
4821 * @deprecated 6.3.0 |
|
4822 * |
|
4823 * @access private |
|
4824 * |
|
4825 * @param mixed $n Number of unknown type. |
|
4826 * @param int $max Upper value of the range to bound to. |
|
4827 * @return float Value in the range [0, 1]. |
|
4828 */ |
|
4829 function wp_tinycolor_bound01( $n, $max ) { |
|
4830 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
4831 if ( 'string' === gettype( $n ) && str_contains( $n, '.' ) && 1 === (float) $n ) { |
|
4832 $n = '100%'; |
|
4833 } |
|
4834 |
|
4835 $n = min( $max, max( 0, (float) $n ) ); |
|
4836 |
|
4837 // Automatically convert percentage into number. |
|
4838 if ( 'string' === gettype( $n ) && str_contains( $n, '%' ) ) { |
|
4839 $n = (int) ( $n * $max ) / 100; |
|
4840 } |
|
4841 |
|
4842 // Handle floating point rounding errors. |
|
4843 if ( ( abs( $n - $max ) < 0.000001 ) ) { |
|
4844 return 1.0; |
|
4845 } |
|
4846 |
|
4847 // Convert into [0, 1] range if it isn't already. |
|
4848 return ( $n % $max ) / (float) $max; |
|
4849 } |
|
4850 |
|
4851 /** |
|
4852 * Direct port of tinycolor's boundAlpha function to maintain consistency with |
|
4853 * how tinycolor works. |
|
4854 * |
|
4855 * @link https://github.com/bgrins/TinyColor |
|
4856 * |
|
4857 * @since 5.9.0 |
|
4858 * @deprecated 6.3.0 |
|
4859 * |
|
4860 * @access private |
|
4861 * |
|
4862 * @param mixed $n Number of unknown type. |
|
4863 * @return float Value in the range [0,1]. |
|
4864 */ |
|
4865 function _wp_tinycolor_bound_alpha( $n ) { |
|
4866 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
4867 |
|
4868 if ( is_numeric( $n ) ) { |
|
4869 $n = (float) $n; |
|
4870 if ( $n >= 0 && $n <= 1 ) { |
|
4871 return $n; |
|
4872 } |
|
4873 } |
|
4874 return 1; |
|
4875 } |
|
4876 |
|
4877 /** |
|
4878 * Rounds and converts values of an RGB object. |
|
4879 * |
|
4880 * Direct port of TinyColor's function, lightly simplified to maintain |
|
4881 * consistency with TinyColor. |
|
4882 * |
|
4883 * @link https://github.com/bgrins/TinyColor |
|
4884 * |
|
4885 * @since 5.8.0 |
|
4886 * @deprecated 6.3.0 |
|
4887 * |
|
4888 * @access private |
|
4889 * |
|
4890 * @param array $rgb_color RGB object. |
|
4891 * @return array Rounded and converted RGB object. |
|
4892 */ |
|
4893 function wp_tinycolor_rgb_to_rgb( $rgb_color ) { |
|
4894 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
4895 |
|
4896 return array( |
|
4897 'r' => wp_tinycolor_bound01( $rgb_color['r'], 255 ) * 255, |
|
4898 'g' => wp_tinycolor_bound01( $rgb_color['g'], 255 ) * 255, |
|
4899 'b' => wp_tinycolor_bound01( $rgb_color['b'], 255 ) * 255, |
|
4900 ); |
|
4901 } |
|
4902 |
|
4903 /** |
|
4904 * Helper function for hsl to rgb conversion. |
|
4905 * |
|
4906 * Direct port of TinyColor's function, lightly simplified to maintain |
|
4907 * consistency with TinyColor. |
|
4908 * |
|
4909 * @link https://github.com/bgrins/TinyColor |
|
4910 * |
|
4911 * @since 5.8.0 |
|
4912 * @deprecated 6.3.0 |
|
4913 * |
|
4914 * @access private |
|
4915 * |
|
4916 * @param float $p first component. |
|
4917 * @param float $q second component. |
|
4918 * @param float $t third component. |
|
4919 * @return float R, G, or B component. |
|
4920 */ |
|
4921 function wp_tinycolor_hue_to_rgb( $p, $q, $t ) { |
|
4922 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
4923 |
|
4924 if ( $t < 0 ) { |
|
4925 ++$t; |
|
4926 } |
|
4927 if ( $t > 1 ) { |
|
4928 --$t; |
|
4929 } |
|
4930 if ( $t < 1 / 6 ) { |
|
4931 return $p + ( $q - $p ) * 6 * $t; |
|
4932 } |
|
4933 if ( $t < 1 / 2 ) { |
|
4934 return $q; |
|
4935 } |
|
4936 if ( $t < 2 / 3 ) { |
|
4937 return $p + ( $q - $p ) * ( 2 / 3 - $t ) * 6; |
|
4938 } |
|
4939 return $p; |
|
4940 } |
|
4941 |
|
4942 /** |
|
4943 * Converts an HSL object to an RGB object with converted and rounded values. |
|
4944 * |
|
4945 * Direct port of TinyColor's function, lightly simplified to maintain |
|
4946 * consistency with TinyColor. |
|
4947 * |
|
4948 * @link https://github.com/bgrins/TinyColor |
|
4949 * |
|
4950 * @since 5.8.0 |
|
4951 * @deprecated 6.3.0 |
|
4952 * |
|
4953 * @access private |
|
4954 * |
|
4955 * @param array $hsl_color HSL object. |
|
4956 * @return array Rounded and converted RGB object. |
|
4957 */ |
|
4958 function wp_tinycolor_hsl_to_rgb( $hsl_color ) { |
|
4959 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
4960 |
|
4961 $h = wp_tinycolor_bound01( $hsl_color['h'], 360 ); |
|
4962 $s = wp_tinycolor_bound01( $hsl_color['s'], 100 ); |
|
4963 $l = wp_tinycolor_bound01( $hsl_color['l'], 100 ); |
|
4964 |
|
4965 if ( 0 === $s ) { |
|
4966 // Achromatic. |
|
4967 $r = $l; |
|
4968 $g = $l; |
|
4969 $b = $l; |
|
4970 } else { |
|
4971 $q = $l < 0.5 ? $l * ( 1 + $s ) : $l + $s - $l * $s; |
|
4972 $p = 2 * $l - $q; |
|
4973 $r = wp_tinycolor_hue_to_rgb( $p, $q, $h + 1 / 3 ); |
|
4974 $g = wp_tinycolor_hue_to_rgb( $p, $q, $h ); |
|
4975 $b = wp_tinycolor_hue_to_rgb( $p, $q, $h - 1 / 3 ); |
|
4976 } |
|
4977 |
|
4978 return array( |
|
4979 'r' => $r * 255, |
|
4980 'g' => $g * 255, |
|
4981 'b' => $b * 255, |
|
4982 ); |
|
4983 } |
|
4984 |
|
4985 /** |
|
4986 * Parses hex, hsl, and rgb CSS strings using the same regex as TinyColor v1.4.2 |
|
4987 * used in the JavaScript. Only colors output from react-color are implemented. |
|
4988 * |
|
4989 * Direct port of TinyColor's function, lightly simplified to maintain |
|
4990 * consistency with TinyColor. |
|
4991 * |
|
4992 * @link https://github.com/bgrins/TinyColor |
|
4993 * @link https://github.com/casesandberg/react-color/ |
|
4994 * |
|
4995 * @since 5.8.0 |
|
4996 * @since 5.9.0 Added alpha processing. |
|
4997 * @deprecated 6.3.0 |
|
4998 * |
|
4999 * @access private |
|
5000 * |
|
5001 * @param string $color_str CSS color string. |
|
5002 * @return array RGB object. |
|
5003 */ |
|
5004 function wp_tinycolor_string_to_rgb( $color_str ) { |
|
5005 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
5006 |
|
5007 $color_str = strtolower( trim( $color_str ) ); |
|
5008 |
|
5009 $css_integer = '[-\\+]?\\d+%?'; |
|
5010 $css_number = '[-\\+]?\\d*\\.\\d+%?'; |
|
5011 |
|
5012 $css_unit = '(?:' . $css_number . ')|(?:' . $css_integer . ')'; |
|
5013 |
|
5014 $permissive_match3 = '[\\s|\\(]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')\\s*\\)?'; |
|
5015 $permissive_match4 = '[\\s|\\(]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')[,|\\s]+(' . $css_unit . ')\\s*\\)?'; |
|
5016 |
|
5017 $rgb_regexp = '/^rgb' . $permissive_match3 . '$/'; |
|
5018 if ( preg_match( $rgb_regexp, $color_str, $match ) ) { |
|
5019 $rgb = wp_tinycolor_rgb_to_rgb( |
|
5020 array( |
|
5021 'r' => $match[1], |
|
5022 'g' => $match[2], |
|
5023 'b' => $match[3], |
|
5024 ) |
|
5025 ); |
|
5026 |
|
5027 $rgb['a'] = 1; |
|
5028 |
|
5029 return $rgb; |
|
5030 } |
|
5031 |
|
5032 $rgba_regexp = '/^rgba' . $permissive_match4 . '$/'; |
|
5033 if ( preg_match( $rgba_regexp, $color_str, $match ) ) { |
|
5034 $rgb = wp_tinycolor_rgb_to_rgb( |
|
5035 array( |
|
5036 'r' => $match[1], |
|
5037 'g' => $match[2], |
|
5038 'b' => $match[3], |
|
5039 ) |
|
5040 ); |
|
5041 |
|
5042 $rgb['a'] = _wp_tinycolor_bound_alpha( $match[4] ); |
|
5043 |
|
5044 return $rgb; |
|
5045 } |
|
5046 |
|
5047 $hsl_regexp = '/^hsl' . $permissive_match3 . '$/'; |
|
5048 if ( preg_match( $hsl_regexp, $color_str, $match ) ) { |
|
5049 $rgb = wp_tinycolor_hsl_to_rgb( |
|
5050 array( |
|
5051 'h' => $match[1], |
|
5052 's' => $match[2], |
|
5053 'l' => $match[3], |
|
5054 ) |
|
5055 ); |
|
5056 |
|
5057 $rgb['a'] = 1; |
|
5058 |
|
5059 return $rgb; |
|
5060 } |
|
5061 |
|
5062 $hsla_regexp = '/^hsla' . $permissive_match4 . '$/'; |
|
5063 if ( preg_match( $hsla_regexp, $color_str, $match ) ) { |
|
5064 $rgb = wp_tinycolor_hsl_to_rgb( |
|
5065 array( |
|
5066 'h' => $match[1], |
|
5067 's' => $match[2], |
|
5068 'l' => $match[3], |
|
5069 ) |
|
5070 ); |
|
5071 |
|
5072 $rgb['a'] = _wp_tinycolor_bound_alpha( $match[4] ); |
|
5073 |
|
5074 return $rgb; |
|
5075 } |
|
5076 |
|
5077 $hex8_regexp = '/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/'; |
|
5078 if ( preg_match( $hex8_regexp, $color_str, $match ) ) { |
|
5079 $rgb = wp_tinycolor_rgb_to_rgb( |
|
5080 array( |
|
5081 'r' => base_convert( $match[1], 16, 10 ), |
|
5082 'g' => base_convert( $match[2], 16, 10 ), |
|
5083 'b' => base_convert( $match[3], 16, 10 ), |
|
5084 ) |
|
5085 ); |
|
5086 |
|
5087 $rgb['a'] = _wp_tinycolor_bound_alpha( |
|
5088 base_convert( $match[4], 16, 10 ) / 255 |
|
5089 ); |
|
5090 |
|
5091 return $rgb; |
|
5092 } |
|
5093 |
|
5094 $hex6_regexp = '/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/'; |
|
5095 if ( preg_match( $hex6_regexp, $color_str, $match ) ) { |
|
5096 $rgb = wp_tinycolor_rgb_to_rgb( |
|
5097 array( |
|
5098 'r' => base_convert( $match[1], 16, 10 ), |
|
5099 'g' => base_convert( $match[2], 16, 10 ), |
|
5100 'b' => base_convert( $match[3], 16, 10 ), |
|
5101 ) |
|
5102 ); |
|
5103 |
|
5104 $rgb['a'] = 1; |
|
5105 |
|
5106 return $rgb; |
|
5107 } |
|
5108 |
|
5109 $hex4_regexp = '/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/'; |
|
5110 if ( preg_match( $hex4_regexp, $color_str, $match ) ) { |
|
5111 $rgb = wp_tinycolor_rgb_to_rgb( |
|
5112 array( |
|
5113 'r' => base_convert( $match[1] . $match[1], 16, 10 ), |
|
5114 'g' => base_convert( $match[2] . $match[2], 16, 10 ), |
|
5115 'b' => base_convert( $match[3] . $match[3], 16, 10 ), |
|
5116 ) |
|
5117 ); |
|
5118 |
|
5119 $rgb['a'] = _wp_tinycolor_bound_alpha( |
|
5120 base_convert( $match[4] . $match[4], 16, 10 ) / 255 |
|
5121 ); |
|
5122 |
|
5123 return $rgb; |
|
5124 } |
|
5125 |
|
5126 $hex3_regexp = '/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/'; |
|
5127 if ( preg_match( $hex3_regexp, $color_str, $match ) ) { |
|
5128 $rgb = wp_tinycolor_rgb_to_rgb( |
|
5129 array( |
|
5130 'r' => base_convert( $match[1] . $match[1], 16, 10 ), |
|
5131 'g' => base_convert( $match[2] . $match[2], 16, 10 ), |
|
5132 'b' => base_convert( $match[3] . $match[3], 16, 10 ), |
|
5133 ) |
|
5134 ); |
|
5135 |
|
5136 $rgb['a'] = 1; |
|
5137 |
|
5138 return $rgb; |
|
5139 } |
|
5140 |
|
5141 /* |
|
5142 * The JS color picker considers the string "transparent" to be a hex value, |
|
5143 * so we need to handle it here as a special case. |
|
5144 */ |
|
5145 if ( 'transparent' === $color_str ) { |
|
5146 return array( |
|
5147 'r' => 0, |
|
5148 'g' => 0, |
|
5149 'b' => 0, |
|
5150 'a' => 0, |
|
5151 ); |
|
5152 } |
|
5153 } |
|
5154 |
|
5155 /** |
|
5156 * Returns the prefixed id for the duotone filter for use as a CSS id. |
|
5157 * |
|
5158 * @since 5.9.1 |
|
5159 * @deprecated 6.3.0 |
|
5160 * |
|
5161 * @access private |
|
5162 * |
|
5163 * @param array $preset Duotone preset value as seen in theme.json. |
|
5164 * @return string Duotone filter CSS id. |
|
5165 */ |
|
5166 function wp_get_duotone_filter_id( $preset ) { |
|
5167 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
5168 return WP_Duotone::get_filter_id_from_preset( $preset ); |
|
5169 } |
|
5170 |
|
5171 /** |
|
5172 * Returns the CSS filter property url to reference the rendered SVG. |
|
5173 * |
|
5174 * @since 5.9.0 |
|
5175 * @since 6.1.0 Allow unset for preset colors. |
|
5176 * @deprecated 6.3.0 |
|
5177 * |
|
5178 * @access private |
|
5179 * |
|
5180 * @param array $preset Duotone preset value as seen in theme.json. |
|
5181 * @return string Duotone CSS filter property url value. |
|
5182 */ |
|
5183 function wp_get_duotone_filter_property( $preset ) { |
|
5184 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
5185 return WP_Duotone::get_filter_css_property_value_from_preset( $preset ); |
|
5186 } |
|
5187 |
|
5188 /** |
|
5189 * Returns the duotone filter SVG string for the preset. |
|
5190 * |
|
5191 * @since 5.9.1 |
|
5192 * @deprecated 6.3.0 |
|
5193 * |
|
5194 * @access private |
|
5195 * |
|
5196 * @param array $preset Duotone preset value as seen in theme.json. |
|
5197 * @return string Duotone SVG filter. |
|
5198 */ |
|
5199 function wp_get_duotone_filter_svg( $preset ) { |
|
5200 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
5201 return WP_Duotone::get_filter_svg_from_preset( $preset ); |
|
5202 } |
|
5203 |
|
5204 /** |
|
5205 * Registers the style and colors block attributes for block types that support it. |
|
5206 * |
|
5207 * @since 5.8.0 |
|
5208 * @deprecated 6.3.0 Use WP_Duotone::register_duotone_support() instead. |
|
5209 * |
|
5210 * @access private |
|
5211 * |
|
5212 * @param WP_Block_Type $block_type Block Type. |
|
5213 */ |
|
5214 function wp_register_duotone_support( $block_type ) { |
|
5215 _deprecated_function( __FUNCTION__, '6.3.0', 'WP_Duotone::register_duotone_support()' ); |
|
5216 return WP_Duotone::register_duotone_support( $block_type ); |
|
5217 } |
|
5218 |
|
5219 /** |
|
5220 * Renders out the duotone stylesheet and SVG. |
|
5221 * |
|
5222 * @since 5.8.0 |
|
5223 * @since 6.1.0 Allow unset for preset colors. |
|
5224 * @deprecated 6.3.0 Use WP_Duotone::render_duotone_support() instead. |
|
5225 * |
|
5226 * @access private |
|
5227 * |
|
5228 * @param string $block_content Rendered block content. |
|
5229 * @param array $block Block object. |
|
5230 * @return string Filtered block content. |
|
5231 */ |
|
5232 function wp_render_duotone_support( $block_content, $block ) { |
|
5233 _deprecated_function( __FUNCTION__, '6.3.0', 'WP_Duotone::render_duotone_support()' ); |
|
5234 $wp_block = new WP_Block( $block ); |
|
5235 return WP_Duotone::render_duotone_support( $block_content, $block, $wp_block ); |
|
5236 } |
|
5237 |
|
5238 /** |
|
5239 * Returns a string containing the SVGs to be referenced as filters (duotone). |
|
5240 * |
|
5241 * @since 5.9.1 |
|
5242 * @deprecated 6.3.0 SVG generation is handled on a per-block basis in block supports. |
|
5243 * |
|
5244 * @return string |
|
5245 */ |
|
5246 function wp_get_global_styles_svg_filters() { |
|
5247 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
5248 |
|
5249 /* |
|
5250 * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme |
|
5251 * developer's workflow. |
|
5252 */ |
|
5253 $can_use_cached = ! wp_is_development_mode( 'theme' ); |
|
5254 $cache_group = 'theme_json'; |
|
5255 $cache_key = 'wp_get_global_styles_svg_filters'; |
|
5256 if ( $can_use_cached ) { |
|
5257 $cached = wp_cache_get( $cache_key, $cache_group ); |
|
5258 if ( $cached ) { |
|
5259 return $cached; |
|
5260 } |
|
5261 } |
|
5262 |
|
5263 $supports_theme_json = wp_theme_has_theme_json(); |
|
5264 |
|
5265 $origins = array( 'default', 'theme', 'custom' ); |
|
5266 if ( ! $supports_theme_json ) { |
|
5267 $origins = array( 'default' ); |
|
5268 } |
|
5269 |
|
5270 $tree = WP_Theme_JSON_Resolver::get_merged_data(); |
|
5271 $svgs = $tree->get_svg_filters( $origins ); |
|
5272 |
|
5273 if ( $can_use_cached ) { |
|
5274 wp_cache_set( $cache_key, $svgs, $cache_group ); |
|
5275 } |
|
5276 |
|
5277 return $svgs; |
|
5278 } |
|
5279 |
|
5280 /** |
|
5281 * Renders the SVG filters supplied by theme.json. |
|
5282 * |
|
5283 * Note that this doesn't render the per-block user-defined |
|
5284 * filters which are handled by wp_render_duotone_support, |
|
5285 * but it should be rendered before the filtered content |
|
5286 * in the body to satisfy Safari's rendering quirks. |
|
5287 * |
|
5288 * @since 5.9.1 |
|
5289 * @deprecated 6.3.0 SVG generation is handled on a per-block basis in block supports. |
|
5290 */ |
|
5291 function wp_global_styles_render_svg_filters() { |
|
5292 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
5293 |
|
5294 /* |
|
5295 * When calling via the in_admin_header action, we only want to render the |
|
5296 * SVGs on block editor pages. |
|
5297 */ |
|
5298 if ( |
|
5299 is_admin() && |
|
5300 ! get_current_screen()->is_block_editor() |
|
5301 ) { |
|
5302 return; |
|
5303 } |
|
5304 |
|
5305 $filters = wp_get_global_styles_svg_filters(); |
|
5306 if ( ! empty( $filters ) ) { |
|
5307 echo $filters; |
|
5308 } |
|
5309 } |
|
5310 |
|
5311 /** |
|
5312 * Build an array with CSS classes and inline styles defining the colors |
|
5313 * which will be applied to the navigation markup in the front-end. |
|
5314 * |
|
5315 * @since 5.9.0 |
|
5316 * @deprecated 6.3.0 This was removed from the Navigation Submenu block in favour of `wp_apply_colors_support()`. |
|
5317 * `wp_apply_colors_support()` returns an array with similar class and style values, |
|
5318 * but with different keys: `class` and `style`. |
|
5319 * |
|
5320 * @param array $context Navigation block context. |
|
5321 * @param array $attributes Block attributes. |
|
5322 * @param bool $is_sub_menu Whether the block is a sub-menu. |
|
5323 * @return array Colors CSS classes and inline styles. |
|
5324 */ |
|
5325 function block_core_navigation_submenu_build_css_colors( $context, $attributes, $is_sub_menu = false ) { |
|
5326 _deprecated_function( __FUNCTION__, '6.3.0' ); |
|
5327 $colors = array( |
|
5328 'css_classes' => array(), |
|
5329 'inline_styles' => '', |
|
5330 ); |
|
5331 |
|
5332 // Text color. |
|
5333 $named_text_color = null; |
|
5334 $custom_text_color = null; |
|
5335 |
|
5336 if ( $is_sub_menu && array_key_exists( 'customOverlayTextColor', $context ) ) { |
|
5337 $custom_text_color = $context['customOverlayTextColor']; |
|
5338 } elseif ( $is_sub_menu && array_key_exists( 'overlayTextColor', $context ) ) { |
|
5339 $named_text_color = $context['overlayTextColor']; |
|
5340 } elseif ( array_key_exists( 'customTextColor', $context ) ) { |
|
5341 $custom_text_color = $context['customTextColor']; |
|
5342 } elseif ( array_key_exists( 'textColor', $context ) ) { |
|
5343 $named_text_color = $context['textColor']; |
|
5344 } elseif ( isset( $context['style']['color']['text'] ) ) { |
|
5345 $custom_text_color = $context['style']['color']['text']; |
|
5346 } |
|
5347 |
|
5348 // If has text color. |
|
5349 if ( ! is_null( $named_text_color ) ) { |
|
5350 // Add the color class. |
|
5351 array_push( $colors['css_classes'], 'has-text-color', sprintf( 'has-%s-color', $named_text_color ) ); |
|
5352 } elseif ( ! is_null( $custom_text_color ) ) { |
|
5353 // Add the custom color inline style. |
|
5354 $colors['css_classes'][] = 'has-text-color'; |
|
5355 $colors['inline_styles'] .= sprintf( 'color: %s;', $custom_text_color ); |
|
5356 } |
|
5357 |
|
5358 // Background color. |
|
5359 $named_background_color = null; |
|
5360 $custom_background_color = null; |
|
5361 |
|
5362 if ( $is_sub_menu && array_key_exists( 'customOverlayBackgroundColor', $context ) ) { |
|
5363 $custom_background_color = $context['customOverlayBackgroundColor']; |
|
5364 } elseif ( $is_sub_menu && array_key_exists( 'overlayBackgroundColor', $context ) ) { |
|
5365 $named_background_color = $context['overlayBackgroundColor']; |
|
5366 } elseif ( array_key_exists( 'customBackgroundColor', $context ) ) { |
|
5367 $custom_background_color = $context['customBackgroundColor']; |
|
5368 } elseif ( array_key_exists( 'backgroundColor', $context ) ) { |
|
5369 $named_background_color = $context['backgroundColor']; |
|
5370 } elseif ( isset( $context['style']['color']['background'] ) ) { |
|
5371 $custom_background_color = $context['style']['color']['background']; |
|
5372 } |
|
5373 |
|
5374 // If has background color. |
|
5375 if ( ! is_null( $named_background_color ) ) { |
|
5376 // Add the background-color class. |
|
5377 array_push( $colors['css_classes'], 'has-background', sprintf( 'has-%s-background-color', $named_background_color ) ); |
|
5378 } elseif ( ! is_null( $custom_background_color ) ) { |
|
5379 // Add the custom background-color inline style. |
|
5380 $colors['css_classes'][] = 'has-background'; |
|
5381 $colors['inline_styles'] .= sprintf( 'background-color: %s;', $custom_background_color ); |
|
5382 } |
|
5383 |
|
5384 return $colors; |
|
5385 } |
|
5386 |
|
5387 /** |
|
5388 * Runs the theme.json webfonts handler. |
|
5389 * |
|
5390 * Using `WP_Theme_JSON_Resolver`, it gets the fonts defined |
|
5391 * in the `theme.json` for the current selection and style |
|
5392 * variations, validates the font-face properties, generates |
|
5393 * the '@font-face' style declarations, and then enqueues the |
|
5394 * styles for both the editor and front-end. |
|
5395 * |
|
5396 * Design Notes: |
|
5397 * This is not a public API, but rather an internal handler. |
|
5398 * A future public Webfonts API will replace this stopgap code. |
|
5399 * |
|
5400 * This code design is intentional. |
|
5401 * a. It hides the inner-workings. |
|
5402 * b. It does not expose API ins or outs for consumption. |
|
5403 * c. It only works with a theme's `theme.json`. |
|
5404 * |
|
5405 * Why? |
|
5406 * a. To avoid backwards-compatibility issues when |
|
5407 * the Webfonts API is introduced in Core. |
|
5408 * b. To make `fontFace` declarations in `theme.json` work. |
|
5409 * |
|
5410 * @link https://github.com/WordPress/gutenberg/issues/40472 |
|
5411 * |
|
5412 * @since 6.0.0 |
|
5413 * @deprecated 6.4.0 Use wp_print_font_faces() instead. |
|
5414 * @access private |
|
5415 */ |
|
5416 function _wp_theme_json_webfonts_handler() { |
|
5417 _deprecated_function( __FUNCTION__, '6.4.0', 'wp_print_font_faces' ); |
|
5418 |
|
5419 // Block themes are unavailable during installation. |
|
5420 if ( wp_installing() ) { |
|
5421 return; |
|
5422 } |
|
5423 |
|
5424 if ( ! wp_theme_has_theme_json() ) { |
|
5425 return; |
|
5426 } |
|
5427 |
|
5428 // Webfonts to be processed. |
|
5429 $registered_webfonts = array(); |
|
5430 |
|
5431 /** |
|
5432 * Gets the webfonts from theme.json. |
|
5433 * |
|
5434 * @since 6.0.0 |
|
5435 * |
|
5436 * @return array Array of defined webfonts. |
|
5437 */ |
|
5438 $fn_get_webfonts_from_theme_json = static function() { |
|
5439 // Get settings from theme.json. |
|
5440 $settings = WP_Theme_JSON_Resolver::get_merged_data()->get_settings(); |
|
5441 |
|
5442 // If in the editor, add webfonts defined in variations. |
|
5443 if ( is_admin() || wp_is_rest_endpoint() ) { |
|
5444 $variations = WP_Theme_JSON_Resolver::get_style_variations(); |
|
5445 foreach ( $variations as $variation ) { |
|
5446 // Skip if fontFamilies are not defined in the variation. |
|
5447 if ( empty( $variation['settings']['typography']['fontFamilies'] ) ) { |
|
5448 continue; |
|
5449 } |
|
5450 |
|
5451 // Initialize the array structure. |
|
5452 if ( empty( $settings['typography'] ) ) { |
|
5453 $settings['typography'] = array(); |
|
5454 } |
|
5455 if ( empty( $settings['typography']['fontFamilies'] ) ) { |
|
5456 $settings['typography']['fontFamilies'] = array(); |
|
5457 } |
|
5458 if ( empty( $settings['typography']['fontFamilies']['theme'] ) ) { |
|
5459 $settings['typography']['fontFamilies']['theme'] = array(); |
|
5460 } |
|
5461 |
|
5462 // Combine variations with settings. Remove duplicates. |
|
5463 $settings['typography']['fontFamilies']['theme'] = array_merge( $settings['typography']['fontFamilies']['theme'], $variation['settings']['typography']['fontFamilies']['theme'] ); |
|
5464 $settings['typography']['fontFamilies'] = array_unique( $settings['typography']['fontFamilies'] ); |
|
5465 } |
|
5466 } |
|
5467 |
|
5468 // Bail out early if there are no settings for webfonts. |
|
5469 if ( empty( $settings['typography']['fontFamilies'] ) ) { |
|
5470 return array(); |
|
5471 } |
|
5472 |
|
5473 $webfonts = array(); |
|
5474 |
|
5475 // Look for fontFamilies. |
|
5476 foreach ( $settings['typography']['fontFamilies'] as $font_families ) { |
|
5477 foreach ( $font_families as $font_family ) { |
|
5478 |
|
5479 // Skip if fontFace is not defined. |
|
5480 if ( empty( $font_family['fontFace'] ) ) { |
|
5481 continue; |
|
5482 } |
|
5483 |
|
5484 // Skip if fontFace is not an array of webfonts. |
|
5485 if ( ! is_array( $font_family['fontFace'] ) ) { |
|
5486 continue; |
|
5487 } |
|
5488 |
|
5489 $webfonts = array_merge( $webfonts, $font_family['fontFace'] ); |
|
5490 } |
|
5491 } |
|
5492 |
|
5493 return $webfonts; |
|
5494 }; |
|
5495 |
|
5496 /** |
|
5497 * Transforms each 'src' into an URI by replacing 'file:./' |
|
5498 * placeholder from theme.json. |
|
5499 * |
|
5500 * The absolute path to the webfont file(s) cannot be defined in |
|
5501 * theme.json. `file:./` is the placeholder which is replaced by |
|
5502 * the theme's URL path to the theme's root. |
|
5503 * |
|
5504 * @since 6.0.0 |
|
5505 * |
|
5506 * @param array $src Webfont file(s) `src`. |
|
5507 * @return array Webfont's `src` in URI. |
|
5508 */ |
|
5509 $fn_transform_src_into_uri = static function( array $src ) { |
|
5510 foreach ( $src as $key => $url ) { |
|
5511 // Tweak the URL to be relative to the theme root. |
|
5512 if ( ! str_starts_with( $url, 'file:./' ) ) { |
|
5513 continue; |
|
5514 } |
|
5515 |
|
5516 $src[ $key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) ); |
|
5517 } |
|
5518 |
|
5519 return $src; |
|
5520 }; |
|
5521 |
|
5522 /** |
|
5523 * Converts the font-face properties (i.e. keys) into kebab-case. |
|
5524 * |
|
5525 * @since 6.0.0 |
|
5526 * |
|
5527 * @param array $font_face Font face to convert. |
|
5528 * @return array Font faces with each property in kebab-case format. |
|
5529 */ |
|
5530 $fn_convert_keys_to_kebab_case = static function( array $font_face ) { |
|
5531 foreach ( $font_face as $property => $value ) { |
|
5532 $kebab_case = _wp_to_kebab_case( $property ); |
|
5533 $font_face[ $kebab_case ] = $value; |
|
5534 if ( $kebab_case !== $property ) { |
|
5535 unset( $font_face[ $property ] ); |
|
5536 } |
|
5537 } |
|
5538 |
|
5539 return $font_face; |
|
5540 }; |
|
5541 |
|
5542 /** |
|
5543 * Validates a webfont. |
|
5544 * |
|
5545 * @since 6.0.0 |
|
5546 * |
|
5547 * @param array $webfont The webfont arguments. |
|
5548 * @return array|false The validated webfont arguments, or false if the webfont is invalid. |
|
5549 */ |
|
5550 $fn_validate_webfont = static function( $webfont ) { |
|
5551 $webfont = wp_parse_args( |
|
5552 $webfont, |
|
5553 array( |
|
5554 'font-family' => '', |
|
5555 'font-style' => 'normal', |
|
5556 'font-weight' => '400', |
|
5557 'font-display' => 'fallback', |
|
5558 'src' => array(), |
|
5559 ) |
|
5560 ); |
|
5561 |
|
5562 // Check the font-family. |
|
5563 if ( empty( $webfont['font-family'] ) || ! is_string( $webfont['font-family'] ) ) { |
|
5564 trigger_error( __( 'Webfont font family must be a non-empty string.' ) ); |
|
5565 |
|
5566 return false; |
|
5567 } |
|
5568 |
|
5569 // Check that the `src` property is defined and a valid type. |
|
5570 if ( empty( $webfont['src'] ) || ( ! is_string( $webfont['src'] ) && ! is_array( $webfont['src'] ) ) ) { |
|
5571 trigger_error( __( 'Webfont src must be a non-empty string or an array of strings.' ) ); |
|
5572 |
|
5573 return false; |
|
5574 } |
|
5575 |
|
5576 // Validate the `src` property. |
|
5577 foreach ( (array) $webfont['src'] as $src ) { |
|
5578 if ( ! is_string( $src ) || '' === trim( $src ) ) { |
|
5579 trigger_error( __( 'Each webfont src must be a non-empty string.' ) ); |
|
5580 |
|
5581 return false; |
|
5582 } |
|
5583 } |
|
5584 |
|
5585 // Check the font-weight. |
|
5586 if ( ! is_string( $webfont['font-weight'] ) && ! is_int( $webfont['font-weight'] ) ) { |
|
5587 trigger_error( __( 'Webfont font weight must be a properly formatted string or integer.' ) ); |
|
5588 |
|
5589 return false; |
|
5590 } |
|
5591 |
|
5592 // Check the font-display. |
|
5593 if ( ! in_array( $webfont['font-display'], array( 'auto', 'block', 'fallback', 'optional', 'swap' ), true ) ) { |
|
5594 $webfont['font-display'] = 'fallback'; |
|
5595 } |
|
5596 |
|
5597 $valid_props = array( |
|
5598 'ascend-override', |
|
5599 'descend-override', |
|
5600 'font-display', |
|
5601 'font-family', |
|
5602 'font-stretch', |
|
5603 'font-style', |
|
5604 'font-weight', |
|
5605 'font-variant', |
|
5606 'font-feature-settings', |
|
5607 'font-variation-settings', |
|
5608 'line-gap-override', |
|
5609 'size-adjust', |
|
5610 'src', |
|
5611 'unicode-range', |
|
5612 ); |
|
5613 |
|
5614 foreach ( $webfont as $prop => $value ) { |
|
5615 if ( ! in_array( $prop, $valid_props, true ) ) { |
|
5616 unset( $webfont[ $prop ] ); |
|
5617 } |
|
5618 } |
|
5619 |
|
5620 return $webfont; |
|
5621 }; |
|
5622 |
|
5623 /** |
|
5624 * Registers webfonts declared in theme.json. |
|
5625 * |
|
5626 * @since 6.0.0 |
|
5627 * |
|
5628 * @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference). |
|
5629 * @uses $fn_get_webfonts_from_theme_json To run the function that gets the webfonts from theme.json. |
|
5630 * @uses $fn_convert_keys_to_kebab_case To run the function that converts keys into kebab-case. |
|
5631 * @uses $fn_validate_webfont To run the function that validates each font-face (webfont) from theme.json. |
|
5632 */ |
|
5633 $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 ) { |
|
5634 $registered_webfonts = array(); |
|
5635 |
|
5636 foreach ( $fn_get_webfonts_from_theme_json() as $webfont ) { |
|
5637 if ( ! is_array( $webfont ) ) { |
|
5638 continue; |
|
5639 } |
|
5640 |
|
5641 $webfont = $fn_convert_keys_to_kebab_case( $webfont ); |
|
5642 |
|
5643 $webfont = $fn_validate_webfont( $webfont ); |
|
5644 |
|
5645 $webfont['src'] = $fn_transform_src_into_uri( (array) $webfont['src'] ); |
|
5646 |
|
5647 // Skip if not valid. |
|
5648 if ( empty( $webfont ) ) { |
|
5649 continue; |
|
5650 } |
|
5651 |
|
5652 $registered_webfonts[] = $webfont; |
|
5653 } |
|
5654 }; |
|
5655 |
|
5656 /** |
|
5657 * Orders 'src' items to optimize for browser support. |
|
5658 * |
|
5659 * @since 6.0.0 |
|
5660 * |
|
5661 * @param array $webfont Webfont to process. |
|
5662 * @return array Ordered `src` items. |
|
5663 */ |
|
5664 $fn_order_src = static function( array $webfont ) { |
|
5665 $src = array(); |
|
5666 $src_ordered = array(); |
|
5667 |
|
5668 foreach ( $webfont['src'] as $url ) { |
|
5669 // Add data URIs first. |
|
5670 if ( str_starts_with( trim( $url ), 'data:' ) ) { |
|
5671 $src_ordered[] = array( |
|
5672 'url' => $url, |
|
5673 'format' => 'data', |
|
5674 ); |
|
5675 continue; |
|
5676 } |
|
5677 $format = pathinfo( $url, PATHINFO_EXTENSION ); |
|
5678 $src[ $format ] = $url; |
|
5679 } |
|
5680 |
|
5681 // Add woff2. |
|
5682 if ( ! empty( $src['woff2'] ) ) { |
|
5683 $src_ordered[] = array( |
|
5684 'url' => sanitize_url( $src['woff2'] ), |
|
5685 'format' => 'woff2', |
|
5686 ); |
|
5687 } |
|
5688 |
|
5689 // Add woff. |
|
5690 if ( ! empty( $src['woff'] ) ) { |
|
5691 $src_ordered[] = array( |
|
5692 'url' => sanitize_url( $src['woff'] ), |
|
5693 'format' => 'woff', |
|
5694 ); |
|
5695 } |
|
5696 |
|
5697 // Add ttf. |
|
5698 if ( ! empty( $src['ttf'] ) ) { |
|
5699 $src_ordered[] = array( |
|
5700 'url' => sanitize_url( $src['ttf'] ), |
|
5701 'format' => 'truetype', |
|
5702 ); |
|
5703 } |
|
5704 |
|
5705 // Add eot. |
|
5706 if ( ! empty( $src['eot'] ) ) { |
|
5707 $src_ordered[] = array( |
|
5708 'url' => sanitize_url( $src['eot'] ), |
|
5709 'format' => 'embedded-opentype', |
|
5710 ); |
|
5711 } |
|
5712 |
|
5713 // Add otf. |
|
5714 if ( ! empty( $src['otf'] ) ) { |
|
5715 $src_ordered[] = array( |
|
5716 'url' => sanitize_url( $src['otf'] ), |
|
5717 'format' => 'opentype', |
|
5718 ); |
|
5719 } |
|
5720 $webfont['src'] = $src_ordered; |
|
5721 |
|
5722 return $webfont; |
|
5723 }; |
|
5724 |
|
5725 /** |
|
5726 * Compiles the 'src' into valid CSS. |
|
5727 * |
|
5728 * @since 6.0.0 |
|
5729 * @since 6.2.0 Removed local() CSS. |
|
5730 * |
|
5731 * @param string $font_family Font family. |
|
5732 * @param array $value Value to process. |
|
5733 * @return string The CSS. |
|
5734 */ |
|
5735 $fn_compile_src = static function( $font_family, array $value ) { |
|
5736 $src = ''; |
|
5737 |
|
5738 foreach ( $value as $item ) { |
|
5739 $src .= ( 'data' === $item['format'] ) |
|
5740 ? ", url({$item['url']})" |
|
5741 : ", url('{$item['url']}') format('{$item['format']}')"; |
|
5742 } |
|
5743 |
|
5744 $src = ltrim( $src, ', ' ); |
|
5745 |
|
5746 return $src; |
|
5747 }; |
|
5748 |
|
5749 /** |
|
5750 * Compiles the font variation settings. |
|
5751 * |
|
5752 * @since 6.0.0 |
|
5753 * |
|
5754 * @param array $font_variation_settings Array of font variation settings. |
|
5755 * @return string The CSS. |
|
5756 */ |
|
5757 $fn_compile_variations = static function( array $font_variation_settings ) { |
|
5758 $variations = ''; |
|
5759 |
|
5760 foreach ( $font_variation_settings as $key => $value ) { |
|
5761 $variations .= "$key $value"; |
|
5762 } |
|
5763 |
|
5764 return $variations; |
|
5765 }; |
|
5766 |
|
5767 /** |
|
5768 * Builds the font-family's CSS. |
|
5769 * |
|
5770 * @since 6.0.0 |
|
5771 * |
|
5772 * @uses $fn_compile_src To run the function that compiles the src. |
|
5773 * @uses $fn_compile_variations To run the function that compiles the variations. |
|
5774 * |
|
5775 * @param array $webfont Webfont to process. |
|
5776 * @return string This font-family's CSS. |
|
5777 */ |
|
5778 $fn_build_font_face_css = static function( array $webfont ) use ( $fn_compile_src, $fn_compile_variations ) { |
|
5779 $css = ''; |
|
5780 |
|
5781 // Wrap font-family in quotes if it contains spaces. |
|
5782 if ( |
|
5783 str_contains( $webfont['font-family'], ' ' ) && |
|
5784 ! str_contains( $webfont['font-family'], '"' ) && |
|
5785 ! str_contains( $webfont['font-family'], "'" ) |
|
5786 ) { |
|
5787 $webfont['font-family'] = '"' . $webfont['font-family'] . '"'; |
|
5788 } |
|
5789 |
|
5790 foreach ( $webfont as $key => $value ) { |
|
5791 /* |
|
5792 * Skip "provider", since it's for internal API use, |
|
5793 * and not a valid CSS property. |
|
5794 */ |
|
5795 if ( 'provider' === $key ) { |
|
5796 continue; |
|
5797 } |
|
5798 |
|
5799 // Compile the "src" parameter. |
|
5800 if ( 'src' === $key ) { |
|
5801 $value = $fn_compile_src( $webfont['font-family'], $value ); |
|
5802 } |
|
5803 |
|
5804 // If font-variation-settings is an array, convert it to a string. |
|
5805 if ( 'font-variation-settings' === $key && is_array( $value ) ) { |
|
5806 $value = $fn_compile_variations( $value ); |
|
5807 } |
|
5808 |
|
5809 if ( ! empty( $value ) ) { |
|
5810 $css .= "$key:$value;"; |
|
5811 } |
|
5812 } |
|
5813 |
|
5814 return $css; |
|
5815 }; |
|
5816 |
|
5817 /** |
|
5818 * Gets the '@font-face' CSS styles for locally-hosted font files. |
|
5819 * |
|
5820 * @since 6.0.0 |
|
5821 * |
|
5822 * @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference). |
|
5823 * @uses $fn_order_src To run the function that orders the src. |
|
5824 * @uses $fn_build_font_face_css To run the function that builds the font-face CSS. |
|
5825 * |
|
5826 * @return string The `@font-face` CSS. |
|
5827 */ |
|
5828 $fn_get_css = static function() use ( &$registered_webfonts, $fn_order_src, $fn_build_font_face_css ) { |
|
5829 $css = ''; |
|
5830 |
|
5831 foreach ( $registered_webfonts as $webfont ) { |
|
5832 // Order the webfont's `src` items to optimize for browser support. |
|
5833 $webfont = $fn_order_src( $webfont ); |
|
5834 |
|
5835 // Build the @font-face CSS for this webfont. |
|
5836 $css .= '@font-face{' . $fn_build_font_face_css( $webfont ) . '}'; |
|
5837 } |
|
5838 |
|
5839 return $css; |
|
5840 }; |
|
5841 |
|
5842 /** |
|
5843 * Generates and enqueues webfonts styles. |
|
5844 * |
|
5845 * @since 6.0.0 |
|
5846 * |
|
5847 * @uses $fn_get_css To run the function that gets the CSS. |
|
5848 */ |
|
5849 $fn_generate_and_enqueue_styles = static function() use ( $fn_get_css ) { |
|
5850 // Generate the styles. |
|
5851 $styles = $fn_get_css(); |
|
5852 |
|
5853 // Bail out if there are no styles to enqueue. |
|
5854 if ( '' === $styles ) { |
|
5855 return; |
|
5856 } |
|
5857 |
|
5858 // Enqueue the stylesheet. |
|
5859 wp_register_style( 'wp-webfonts', '' ); |
|
5860 wp_enqueue_style( 'wp-webfonts' ); |
|
5861 |
|
5862 // Add the styles to the stylesheet. |
|
5863 wp_add_inline_style( 'wp-webfonts', $styles ); |
|
5864 }; |
|
5865 |
|
5866 /** |
|
5867 * Generates and enqueues editor styles. |
|
5868 * |
|
5869 * @since 6.0.0 |
|
5870 * |
|
5871 * @uses $fn_get_css To run the function that gets the CSS. |
|
5872 */ |
|
5873 $fn_generate_and_enqueue_editor_styles = static function() use ( $fn_get_css ) { |
|
5874 // Generate the styles. |
|
5875 $styles = $fn_get_css(); |
|
5876 |
|
5877 // Bail out if there are no styles to enqueue. |
|
5878 if ( '' === $styles ) { |
|
5879 return; |
|
5880 } |
|
5881 |
|
5882 wp_add_inline_style( 'wp-block-library', $styles ); |
|
5883 }; |
|
5884 |
|
5885 add_action( 'wp_loaded', $fn_register_webfonts ); |
|
5886 add_action( 'wp_enqueue_scripts', $fn_generate_and_enqueue_styles ); |
|
5887 add_action( 'admin_init', $fn_generate_and_enqueue_editor_styles ); |
|
5888 } |
|
5889 |
|
5890 /** |
|
5891 * Prints the CSS in the embed iframe header. |
|
5892 * |
|
5893 * @since 4.4.0 |
|
5894 * @deprecated 6.4.0 Use wp_enqueue_embed_styles() instead. |
|
5895 */ |
|
5896 function print_embed_styles() { |
|
5897 _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_embed_styles' ); |
|
5898 |
|
5899 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
|
5900 $suffix = SCRIPT_DEBUG ? '' : '.min'; |
|
5901 ?> |
|
5902 <style<?php echo $type_attr; ?>> |
|
5903 <?php echo file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ); ?> |
|
5904 </style> |
|
5905 <?php |
|
5906 } |
|
5907 |
|
5908 /** |
|
5909 * Prints the important emoji-related styles. |
|
5910 * |
|
5911 * @since 4.2.0 |
|
5912 * @deprecated 6.4.0 Use wp_enqueue_emoji_styles() instead. |
|
5913 */ |
|
5914 function print_emoji_styles() { |
|
5915 _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_emoji_styles' ); |
|
5916 static $printed = false; |
|
5917 |
|
5918 if ( $printed ) { |
|
5919 return; |
|
5920 } |
|
5921 |
|
5922 $printed = true; |
|
5923 |
|
5924 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
|
5925 ?> |
|
5926 <style<?php echo $type_attr; ?>> |
|
5927 img.wp-smiley, |
|
5928 img.emoji { |
|
5929 display: inline !important; |
|
5930 border: none !important; |
|
5931 box-shadow: none !important; |
|
5932 height: 1em !important; |
|
5933 width: 1em !important; |
|
5934 margin: 0 0.07em !important; |
|
5935 vertical-align: -0.1em !important; |
|
5936 background: none !important; |
|
5937 padding: 0 !important; |
|
5938 } |
|
5939 </style> |
|
5940 <?php |
|
5941 } |
|
5942 |
|
5943 /** |
|
5944 * Prints style and scripts for the admin bar. |
|
5945 * |
|
5946 * @since 3.1.0 |
|
5947 * @deprecated 6.4.0 Use wp_enqueue_admin_bar_header_styles() instead. |
|
5948 */ |
|
5949 function wp_admin_bar_header() { |
|
5950 _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_header_styles' ); |
|
5951 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
|
5952 ?> |
|
5953 <style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style> |
|
5954 <?php |
|
5955 } |
|
5956 |
|
5957 /** |
|
5958 * Prints default admin bar callback. |
|
5959 * |
|
5960 * @since 3.1.0 |
|
5961 * @deprecated 6.4.0 Use wp_enqueue_admin_bar_bump_styles() instead. |
|
5962 */ |
|
5963 function _admin_bar_bump_cb() { |
|
5964 _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_bump_styles' ); |
|
5965 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
|
5966 ?> |
|
5967 <style<?php echo $type_attr; ?> media="screen"> |
|
5968 html { margin-top: 32px !important; } |
|
5969 @media screen and ( max-width: 782px ) { |
|
5970 html { margin-top: 46px !important; } |
|
5971 } |
|
5972 </style> |
|
5973 <?php |
|
5974 } |
|
5975 |
|
5976 /** |
|
5977 * Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors. |
|
5978 * |
|
5979 * This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained. |
|
5980 * |
|
5981 * @since 5.7.0 |
|
5982 * @deprecated 6.4.0 The `wp_update_https_detection_errors()` function is no longer used and has been replaced by |
|
5983 * `wp_get_https_detection_errors()`. Previously the function was called by a regular Cron hook to |
|
5984 * update the `https_detection_errors` option, but this is no longer necessary as the errors are |
|
5985 * retrieved directly in Site Health and no longer used outside of Site Health. |
|
5986 * @access private |
|
5987 */ |
|
5988 function wp_update_https_detection_errors() { |
|
5989 _deprecated_function( __FUNCTION__, '6.4.0' ); |
|
5990 |
|
5991 /** |
|
5992 * Short-circuits the process of detecting errors related to HTTPS support. |
|
5993 * |
|
5994 * Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote |
|
5995 * request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead. |
|
5996 * |
|
5997 * @since 5.7.0 |
|
5998 * @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`. |
|
5999 * |
|
6000 * @param null|WP_Error $pre Error object to short-circuit detection, |
|
6001 * or null to continue with the default behavior. |
|
6002 */ |
|
6003 $support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null ); |
|
6004 if ( is_wp_error( $support_errors ) ) { |
|
6005 update_option( 'https_detection_errors', $support_errors->errors ); |
|
6006 return; |
|
6007 } |
|
6008 |
|
6009 $support_errors = wp_get_https_detection_errors(); |
|
6010 |
|
6011 update_option( 'https_detection_errors', $support_errors ); |
|
6012 } |
|
6013 |
|
6014 /** |
|
6015 * Adds `decoding` attribute to an `img` HTML tag. |
|
6016 * |
|
6017 * The `decoding` attribute allows developers to indicate whether the |
|
6018 * browser can decode the image off the main thread (`async`), on the |
|
6019 * main thread (`sync`) or as determined by the browser (`auto`). |
|
6020 * |
|
6021 * By default WordPress adds `decoding="async"` to images but developers |
|
6022 * can use the {@see 'wp_img_tag_add_decoding_attr'} filter to modify this |
|
6023 * to remove the attribute or set it to another accepted value. |
|
6024 * |
|
6025 * @since 6.1.0 |
|
6026 * @deprecated 6.4.0 Use wp_img_tag_add_loading_optimization_attrs() instead. |
|
6027 * @see wp_img_tag_add_loading_optimization_attrs() |
|
6028 * |
|
6029 * @param string $image The HTML `img` tag where the attribute should be added. |
|
6030 * @param string $context Additional context to pass to the filters. |
|
6031 * @return string Converted `img` tag with `decoding` attribute added. |
|
6032 */ |
|
6033 function wp_img_tag_add_decoding_attr( $image, $context ) { |
|
6034 _deprecated_function( __FUNCTION__, '6.4.0', 'wp_img_tag_add_loading_optimization_attrs()' ); |
|
6035 |
|
6036 /* |
|
6037 * Only apply the decoding attribute to images that have a src attribute that |
|
6038 * starts with a double quote, ensuring escaped JSON is also excluded. |
|
6039 */ |
|
6040 if ( ! str_contains( $image, ' src="' ) ) { |
|
6041 return $image; |
|
6042 } |
|
6043 |
|
6044 /** This action is documented in wp-includes/media.php */ |
|
6045 $value = apply_filters( 'wp_img_tag_add_decoding_attr', 'async', $image, $context ); |
|
6046 |
|
6047 if ( in_array( $value, array( 'async', 'sync', 'auto' ), true ) ) { |
|
6048 $image = str_replace( '<img ', '<img decoding="' . esc_attr( $value ) . '" ', $image ); |
|
6049 } |
|
6050 |
|
6051 return $image; |
|
6052 } |
|
6053 |
|
6054 /** |
|
6055 * Parses wp_template content and injects the active theme's |
|
6056 * stylesheet as a theme attribute into each wp_template_part |
|
6057 * |
|
6058 * @since 5.9.0 |
|
6059 * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) instead. |
|
6060 * @access private |
|
6061 * |
|
6062 * @param string $template_content serialized wp_template content. |
|
6063 * @return string Updated 'wp_template' content. |
|
6064 */ |
|
6065 function _inject_theme_attribute_in_block_template_content( $template_content ) { |
|
6066 _deprecated_function( |
|
6067 __FUNCTION__, |
|
6068 '6.4.0', |
|
6069 'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_inject_theme_attribute_in_template_part_block" )' |
|
6070 ); |
|
6071 |
|
6072 $has_updated_content = false; |
|
6073 $new_content = ''; |
|
6074 $template_blocks = parse_blocks( $template_content ); |
|
6075 |
|
6076 $blocks = _flatten_blocks( $template_blocks ); |
|
6077 foreach ( $blocks as &$block ) { |
|
6078 if ( |
|
6079 'core/template-part' === $block['blockName'] && |
|
6080 ! isset( $block['attrs']['theme'] ) |
|
6081 ) { |
|
6082 $block['attrs']['theme'] = get_stylesheet(); |
|
6083 $has_updated_content = true; |
|
6084 } |
|
6085 } |
|
6086 |
|
6087 if ( $has_updated_content ) { |
|
6088 foreach ( $template_blocks as &$block ) { |
|
6089 $new_content .= serialize_block( $block ); |
|
6090 } |
|
6091 |
|
6092 return $new_content; |
|
6093 } |
|
6094 |
|
6095 return $template_content; |
|
6096 } |
|
6097 |
|
6098 /** |
|
6099 * Parses a block template and removes the theme attribute from each template part. |
|
6100 * |
|
6101 * @since 5.9.0 |
|
6102 * @deprecated 6.4.0 Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_remove_theme_attribute_from_template_part_block' ) instead. |
|
6103 * @access private |
|
6104 * |
|
6105 * @param string $template_content Serialized block template content. |
|
6106 * @return string Updated block template content. |
|
6107 */ |
|
6108 function _remove_theme_attribute_in_block_template_content( $template_content ) { |
|
6109 _deprecated_function( |
|
6110 __FUNCTION__, |
|
6111 '6.4.0', |
|
6112 'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_remove_theme_attribute_from_template_part_block" )' |
|
6113 ); |
|
6114 |
|
6115 $has_updated_content = false; |
|
6116 $new_content = ''; |
|
6117 $template_blocks = parse_blocks( $template_content ); |
|
6118 |
|
6119 $blocks = _flatten_blocks( $template_blocks ); |
|
6120 foreach ( $blocks as $key => $block ) { |
|
6121 if ( 'core/template-part' === $block['blockName'] && isset( $block['attrs']['theme'] ) ) { |
|
6122 unset( $blocks[ $key ]['attrs']['theme'] ); |
|
6123 $has_updated_content = true; |
|
6124 } |
|
6125 } |
|
6126 |
|
6127 if ( ! $has_updated_content ) { |
|
6128 return $template_content; |
|
6129 } |
|
6130 |
|
6131 foreach ( $template_blocks as $block ) { |
|
6132 $new_content .= serialize_block( $block ); |
|
6133 } |
|
6134 |
|
6135 return $new_content; |
|
6136 } |
|
6137 |
|
6138 /** |
|
6139 * Prints the skip-link script & styles. |
|
6140 * |
|
6141 * @since 5.8.0 |
|
6142 * @access private |
|
6143 * @deprecated 6.4.0 Use wp_enqueue_block_template_skip_link() instead. |
|
6144 * |
|
6145 * @global string $_wp_current_template_content |
|
6146 */ |
|
6147 function the_block_template_skip_link() { |
|
6148 _deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_block_template_skip_link()' ); |
|
6149 |
|
6150 global $_wp_current_template_content; |
|
6151 |
|
6152 // Early exit if not a block theme. |
|
6153 if ( ! current_theme_supports( 'block-templates' ) ) { |
|
6154 return; |
|
6155 } |
|
6156 |
|
6157 // Early exit if not a block template. |
|
6158 if ( ! $_wp_current_template_content ) { |
|
6159 return; |
|
6160 } |
|
6161 ?> |
|
6162 |
|
6163 <?php |
|
6164 /** |
|
6165 * Print the skip-link styles. |
|
6166 */ |
|
6167 ?> |
|
6168 <style id="skip-link-styles"> |
|
6169 .skip-link.screen-reader-text { |
|
6170 border: 0; |
|
6171 clip: rect(1px,1px,1px,1px); |
|
6172 clip-path: inset(50%); |
|
6173 height: 1px; |
|
6174 margin: -1px; |
|
6175 overflow: hidden; |
|
6176 padding: 0; |
|
6177 position: absolute !important; |
|
6178 width: 1px; |
|
6179 word-wrap: normal !important; |
|
6180 } |
|
6181 |
|
6182 .skip-link.screen-reader-text:focus { |
|
6183 background-color: #eee; |
|
6184 clip: auto !important; |
|
6185 clip-path: none; |
|
6186 color: #444; |
|
6187 display: block; |
|
6188 font-size: 1em; |
|
6189 height: auto; |
|
6190 left: 5px; |
|
6191 line-height: normal; |
|
6192 padding: 15px 23px 14px; |
|
6193 text-decoration: none; |
|
6194 top: 5px; |
|
6195 width: auto; |
|
6196 z-index: 100000; |
|
6197 } |
|
6198 </style> |
|
6199 <?php |
|
6200 /** |
|
6201 * Print the skip-link script. |
|
6202 */ |
|
6203 ?> |
|
6204 <script> |
|
6205 ( function() { |
|
6206 var skipLinkTarget = document.querySelector( 'main' ), |
|
6207 sibling, |
|
6208 skipLinkTargetID, |
|
6209 skipLink; |
|
6210 |
|
6211 // Early exit if a skip-link target can't be located. |
|
6212 if ( ! skipLinkTarget ) { |
|
6213 return; |
|
6214 } |
|
6215 |
|
6216 /* |
|
6217 * Get the site wrapper. |
|
6218 * The skip-link will be injected in the beginning of it. |
|
6219 */ |
|
6220 sibling = document.querySelector( '.wp-site-blocks' ); |
|
6221 |
|
6222 // Early exit if the root element was not found. |
|
6223 if ( ! sibling ) { |
|
6224 return; |
|
6225 } |
|
6226 |
|
6227 // Get the skip-link target's ID, and generate one if it doesn't exist. |
|
6228 skipLinkTargetID = skipLinkTarget.id; |
|
6229 if ( ! skipLinkTargetID ) { |
|
6230 skipLinkTargetID = 'wp--skip-link--target'; |
|
6231 skipLinkTarget.id = skipLinkTargetID; |
|
6232 } |
|
6233 |
|
6234 // Create the skip link. |
|
6235 skipLink = document.createElement( 'a' ); |
|
6236 skipLink.classList.add( 'skip-link', 'screen-reader-text' ); |
|
6237 skipLink.href = '#' + skipLinkTargetID; |
|
6238 skipLink.innerHTML = '<?php /* translators: Hidden accessibility text. */ esc_html_e( 'Skip to content' ); ?>'; |
|
6239 |
|
6240 // Inject the skip link. |
|
6241 sibling.parentElement.insertBefore( skipLink, sibling ); |
|
6242 }() ); |
|
6243 </script> |
|
6244 <?php |
|
6245 } |
|
6246 |
|
6247 /** |
|
6248 * Ensure that the view script has the `wp-interactivity` dependency. |
|
6249 * |
|
6250 * @since 6.4.0 |
|
6251 * @deprecated 6.5.0 |
|
6252 */ |
|
6253 function block_core_query_ensure_interactivity_dependency() { |
|
6254 _deprecated_function( __FUNCTION__, '6.5.0', 'wp_register_script_module' ); |
|
6255 } |
|
6256 |
|
6257 /** |
|
6258 * Ensure that the view script has the `wp-interactivity` dependency. |
|
6259 * |
|
6260 * @since 6.4.0 |
|
6261 * @deprecated 6.5.0 |
|
6262 */ |
|
6263 function block_core_file_ensure_interactivity_dependency() { |
|
6264 _deprecated_function( __FUNCTION__, '6.5.0', 'wp_register_script_module' ); |
|
6265 } |
|
6266 |
|
6267 /** |
|
6268 * Ensures that the view script has the `wp-interactivity` dependency. |
|
6269 * |
|
6270 * @since 6.4.0 |
|
6271 * @deprecated 6.5.0 |
|
6272 */ |
|
6273 function block_core_image_ensure_interactivity_dependency() { |
|
6274 _deprecated_function( __FUNCTION__, '6.5.0', 'wp_register_script_module' ); |
|
6275 } |
|
6276 |
|
6277 /** |
|
6278 * Updates the block content with elements class names. |
|
6279 * |
|
6280 * @deprecated 6.6.0 Generation of element class name is handled via `render_block_data` filter. |
|
6281 * |
|
6282 * @since 5.8.0 |
|
6283 * @since 6.4.0 Added support for button and heading element styling. |
|
6284 * @access private |
|
6285 * |
|
6286 * @param string $block_content Rendered block content. |
|
6287 * @param array $block Block object. |
|
6288 * @return string Filtered block content. |
|
6289 */ |
|
6290 function wp_render_elements_support( $block_content, $block ) { |
|
6291 _deprecated_function( __FUNCTION__, '6.6.0', 'wp_render_elements_class_name' ); |
|
6292 return $block_content; |
|
6293 } |
|
6294 |
|
6295 /** |
|
6296 * Processes the directives on the rendered HTML of the interactive blocks. |
|
6297 * |
|
6298 * This processes only one root interactive block at a time because the |
|
6299 * rendered HTML of that block contains the rendered HTML of all its inner |
|
6300 * blocks, including any interactive block. It does so by ignoring all the |
|
6301 * interactive inner blocks until the root interactive block is processed. |
|
6302 * |
|
6303 * @since 6.5.0 |
|
6304 * @deprecated 6.6.0 |
|
6305 * |
|
6306 * @param array $parsed_block The parsed block. |
|
6307 * @return array The same parsed block. |
|
6308 */ |
|
6309 function wp_interactivity_process_directives_of_interactive_blocks( array $parsed_block ): array { |
|
6310 _deprecated_function( __FUNCTION__, '6.6.0' ); |
|
6311 return $parsed_block; |
|
6312 } |