From f8947ceb0b8bb555064e6ff73d8b0ffc93963309 Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 25 May 2021 23:43:57 +0000 Subject: [PATCH] Formatting: Introduce the `document_title` filter. In `wp_get_document_title(), the returned value is currently passed directly through `wptexturize()`, `convert_chars()`, and `capital_P_dangit()`, and is done so after the `document_title_parts` filter is run. This makes it impossible to fully control the output of `wp_get_document_title()` and is inconsistent with how other similar text is processed with these functions. This commit introduces the `document_title` filter, which is run immediately before returning the results of the `wp_get_document_title()` function and moves the three formatting functions mentioned above to the new filter hook. This allows developers to further modify the title after being prepared by WordPress, or to modify the functions hooked to this filter as they wish. Props dragunoff, jeremyfelt, paaggeli, audrasjb. Fixes #51643. Built from https://develop.svn.wordpress.org/trunk@51019 git-svn-id: http://core.svn.wordpress.org/trunk@50628 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-filters.php | 4 ++-- wp-includes/general-template.php | 13 +++++++++---- wp-includes/version.php | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 535ed7261c..2dee4e2639 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -131,14 +131,14 @@ foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pr add_action( 'init', 'wp_init_targeted_link_rel_filters' ); // Format strings for display. -foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) { +foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'document_title', 'widget_title' ) as $filter ) { add_filter( $filter, 'wptexturize' ); add_filter( $filter, 'convert_chars' ); add_filter( $filter, 'esc_html' ); } // Format WordPress. -foreach ( array( 'the_content', 'the_title', 'wp_title' ) as $filter ) { +foreach ( array( 'the_content', 'the_title', 'wp_title', 'document_title' ) as $filter ) { add_filter( $filter, 'capital_P_dangit', 11 ); } add_filter( 'comment_text', 'capital_P_dangit', 31 ); diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 6b67cd9a71..0b59b935d3 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -1238,10 +1238,15 @@ function wp_get_document_title() { $title = apply_filters( 'document_title_parts', $title ); $title = implode( " $sep ", array_filter( $title ) ); - $title = wptexturize( $title ); - $title = convert_chars( $title ); - $title = esc_html( $title ); - $title = capital_P_dangit( $title ); + + /** + * Filters the document title. + * + * @since 5.8.0 + * + * @param string $title Document title. + */ + $title = apply_filters( 'document_title', $title ); return $title; } diff --git a/wp-includes/version.php b/wp-includes/version.php index a12fd358ff..bf47eea505 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51018'; +$wp_version = '5.8-alpha-51019'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.