WordPress.org

Make WordPress Core

Ticket #50551: 50551.2.diff

File 50551.2.diff, 6.4 KB (added by pbiron, 5 months ago)
  • src/wp-includes/l10n.php

    From e5f3dc0fde5ea75b26d8763f1199f7daed6acf08 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Wed, 8 Jul 2020 09:39:40 -0600
    Subject: [PATCH] Add l10n helpers for esc_xml() and replace all occurrences of
     esc_xml( __() ) in core with esc_xml__().
    
    ---
     src/wp-includes/l10n.php                      | 53 +++++++++++++++++++
     .../sitemaps/class-wp-sitemaps-renderer.php   |  4 +-
     .../sitemaps/class-wp-sitemaps-stylesheet.php | 28 +++++-----
     3 files changed, 69 insertions(+), 16 deletions(-)
    
    diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php
    index 226cc2d8fd..61fd92dcea 100644
    a b function esc_html_e( $text, $domain = 'default' ) { 
    371371        echo esc_html( translate( $text, $domain ) );
    372372}
    373373
     374/**
     375 * Retrieve the translation of $text and escapes it for safe use in XML output.
     376 *
     377 * If there is no translation, or the text domain isn't loaded, the original text
     378 * is escaped and returned.
     379 *
     380 * @since 5.5.0
     381 *
     382 * @param string $text   Text to translate.
     383 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
     384 *                       Default 'default'.
     385 * @return string Translated text.
     386 */
     387function esc_xml__( $text, $domain = 'default' ) {
     388        return esc_xml( translate( $text, $domain ) );
     389}
     390
     391/**
     392 * Display translated text that has been escaped for safe use in XML output.
     393 *
     394 * If there is no translation, or the text domain isn't loaded, the original text
     395 * is escaped and displayed.
     396 *
     397 * If you need the value for use in PHP, use esc_xml__().
     398 *
     399 * @since 5.5.0
     400 *
     401 * @param string $text   Text to translate.
     402 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
     403 *                       Default 'default'.
     404 */
     405function esc_xml_e( $text, $domain = 'default' ) {
     406        echo esc_xml( translate( $text, $domain ) );
     407}
     408
     409/**
     410 * Translate string with gettext context, and escapes it for safe use in XML output.
     411 *
     412 * If there is no translation, or the text domain isn't loaded, the original text
     413 * is escaped and returned.
     414 *
     415 * @since 5.5.0
     416 *
     417 * @param string $text    Text to translate.
     418 * @param string $context Context information for the translators.
     419 * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
     420 *                        Default 'default'.
     421 * @return string Translated text.
     422 */
     423function esc_xml_x( $text, $context, $domain = 'default' ) {
     424        return esc_xml( translate_with_gettext_context( $text, $context, $domain ) );
     425}
     426
    374427/**
    375428 * Retrieve translated string with gettext context.
    376429 *
  • src/wp-includes/sitemaps/class-wp-sitemaps-renderer.php

    diff --git a/src/wp-includes/sitemaps/class-wp-sitemaps-renderer.php b/src/wp-includes/sitemaps/class-wp-sitemaps-renderer.php
    index c313585d22..c49f5a5962 100644
    a b class WP_Sitemaps_Renderer { 
    261261                        wp_die(
    262262                                sprintf(
    263263                                        /* translators: %s: SimpleXML */
    264                                         esc_xml( __( 'Could not generate XML sitemap due to missing %s extension' ) ),
     264                                        esc_xml__( 'Could not generate XML sitemap due to missing %s extension' ),
    265265                                        'SimpleXML'
    266266                                ),
    267                                 esc_xml( __( 'WordPress &rsaquo; Error' ) ),
     267                                esc_xml__( 'WordPress &rsaquo; Error' ),
    268268                                array(
    269269                                        'response' => 501, // "Not implemented".
    270270                                )
  • src/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php

    diff --git a/src/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php b/src/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php
    index 490541ab28..57f53c8fdf 100644
    a b class WP_Sitemaps_Stylesheet { 
    4343         */
    4444        public function get_sitemap_stylesheet() {
    4545                $css         = $this->get_stylesheet_css();
    46                 $title       = esc_xml( __( 'XML Sitemap' ) );
    47                 $description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) );
     46                $title       = esc_xml__( 'XML Sitemap' );
     47                $description = esc_xml__( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' );
    4848                $learn_more  = sprintf(
    4949                        '<a href="%s">%s</a>',
    5050                        esc_url( __( 'https://www.sitemaps.org/' ) ),
    51                         esc_xml( __( 'Learn more about XML sitemaps.' ) )
     51                        esc_xml__( 'Learn more about XML sitemaps.' )
    5252                );
    5353
    5454                $text = sprintf(
    5555                        /* translators: %s: Number of URLs. */
    56                         esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ),
     56                        esc_xml__( 'Number of URLs in this XML Sitemap: %s.' ),
    5757                        '<xsl:value-of select="count( sitemap:urlset/sitemap:url )" />'
    5858                );
    5959
    6060                $lang       = get_language_attributes( 'html' );
    61                 $url        = esc_xml( __( 'URL' ) );
    62                 $lastmod    = esc_xml( __( 'Last Modified' ) );
    63                 $changefreq = esc_xml( __( 'Change Frequency' ) );
    64                 $priority   = esc_xml( __( 'Priority' ) );
     61                $url        = esc_xml__( 'URL' );
     62                $lastmod    = esc_xml__( 'Last Modified' );
     63                $changefreq = esc_xml__( 'Change Frequency' );
     64                $priority   = esc_xml__( 'Priority' );
    6565
    6666                $xsl_content = <<<XSL
    6767<?xml version="1.0" encoding="UTF-8"?>
    XSL; 
    153153         */
    154154        public function get_sitemap_index_stylesheet() {
    155155                $css         = $this->get_stylesheet_css();
    156                 $title       = esc_xml( __( 'XML Sitemap' ) );
    157                 $description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) );
     156                $title       = esc_xml__( 'XML Sitemap' );
     157                $description = esc_xml__( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' );
    158158                $learn_more  = sprintf(
    159159                        '<a href="%s">%s</a>',
    160160                        esc_url( __( 'https://www.sitemaps.org/' ) ),
    161                         esc_xml( __( 'Learn more about XML sitemaps.' ) )
     161                        esc_xml__( 'Learn more about XML sitemaps.' )
    162162                );
    163163
    164164                $text = sprintf(
    165165                        /* translators: %s: Number of URLs. */
    166                         esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ),
     166                        esc_xml__( 'Number of URLs in this XML Sitemap: %s.' ),
    167167                        '<xsl:value-of select="count( sitemap:sitemapindex/sitemap:sitemap )" />'
    168168                );
    169169
    170170                $lang    = get_language_attributes( 'html' );
    171                 $url     = esc_xml( __( 'URL' ) );
    172                 $lastmod = esc_xml( __( 'Last Modified' ) );
     171                $url     = esc_xml__( 'URL' );
     172                $lastmod = esc_xml__( 'Last Modified' );
    173173
    174174                $xsl_content = <<<XSL
    175175<?xml version="1.0" encoding="UTF-8"?>