WordPress.org

Make WordPress Core

Ticket #47678: 47678-wp_sprintf.patch

File 47678-wp_sprintf.patch, 1.5 KB (added by jrf, 13 months ago)

Simplify & modernize wp_sprintf()

  • src/wp-includes/formatting.php

    From 2d0a4779095b47ce3a0e2808b3759d084a8f5721 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Fri, 12 Jul 2019 06:10:12 +0200
    Subject: [PATCH] Simplify & modernize wp_sprintf()
    
    ---
     src/wp-includes/formatting.php | 8 ++++----
     1 file changed, 4 insertions(+), 4 deletions(-)
    
    diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
    index ea7b80d6c2..abfbcbf815 100644
    a b function wp_pre_kses_less_than_callback( $matches ) { 
    48314831 * @param mixed  ...$args Arguments to be formatted into the $pattern string.
    48324832 * @return string The formatted string.
    48334833 */
    4834 function wp_sprintf( $pattern ) {
    4835         $args      = func_get_args();
     4834function wp_sprintf( $pattern, ...$args ) {
    48364835        $len       = strlen( $pattern );
    48374836        $start     = 0;
    48384837        $result    = '';
    function wp_sprintf( $pattern ) { 
    48624861                if ( $pattern[ $start ] == '%' ) {
    48634862                        // Find numbered arguments or take the next one in order
    48644863                        if ( preg_match( '/^%(\d+)\$/', $fragment, $matches ) ) {
    4865                                 $arg      = isset( $args[ $matches[1] ] ) ? $args[ $matches[1] ] : '';
     4864                                $index    = $matches[1] - 1; // 0-based array vs 1-based sprintf arguments.
     4865                                $arg      = isset( $args[ $index ] ) ? $args[ $index ] : '';
    48664866                                $fragment = str_replace( "%{$matches[1]}$", '%', $fragment );
    48674867                        } else {
    4868                                 ++$arg_index;
    48694868                                $arg = isset( $args[ $arg_index ] ) ? $args[ $arg_index ] : '';
     4869                                ++$arg_index;
    48704870                        }
    48714871
    48724872                        /**