Make WordPress Core

Ticket #49484: 49484.diff

File 49484.diff, 3.9 KB (added by pedromendonca, 5 years ago)

Patch to add options to wp_sprintf_l()

  • wp-includes/formatting.php

    diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
    index 1545cac45b..327bb43821 100644
    a b function wp_sprintf( $pattern, ...$args ) { 
    50125012/**
    50135013 * Localize list items before the rest of the content.
    50145014 *
    5015  * The '%l' must be at the first characters can then contain the rest of the
    5016  * content. The list items will have ', ', ', and', and ' and ' added depending
     5015 * The '%l', '%l$a' or '%l$o' must be at the first characters can then contain
     5016 * the rest of the content.
     5017 *
     5018 * For '%l' and '%l$a' the list items will have ', ', ', and', and ' and 'added
     5019 * depending on the amount of list items in the $args parameter.
     5020 *
     5021 * For '%l$o' the list items will have ', ', ', or', and ' or ' added depending
    50175022 * on the amount of list items in the $args parameter.
    50185023 *
    50195024 * @since 2.5.0
     5025 * @since 5.4.0 Added support to '%l$o' and to '%l$a' for list delemeters.
     5026 *              Default '%l' is and alias of '%l$a' for backward compatibility.
    50205027 *
    5021  * @param string $pattern Content containing '%l' at the beginning.
    5022  * @param array  $args    List items to prepend to the content and replace '%l'.
     5028 * @param string $pattern Content containing '%l', '%l$a' or '%l$o' at the beginning.
     5029 * @param array  $args    List items to prepend to the content and replace '%l', '%l$a' or '%l$o'.
    50235030 * @return string Localized list items and rest of the content.
    50245031 */
    50255032function wp_sprintf_l( $pattern, $args ) {
    function wp_sprintf_l( $pattern, $args ) { 
    50325039        if ( empty( $args ) ) {
    50335040                return '';
    50345041        }
     5042       
     5043        // Localized delimiters for 'or' type.
     5044        $l_or = array(
     5045                /* translators: Used to join items in a list with more than 2 items. */
     5046                'between'          => sprintf( __( '%1$s, %2$s' ), '', '' ),
     5047                /* translators: Used to join last two items in a list with more than 2 times. */
     5048                'between_last_two' => sprintf( __( '%1$s, or %2$s' ), '', '' ),
     5049                /* translators: Used to join items in a list with only 2 items. */
     5050                'between_only_two' => sprintf( __( '%1$s or %2$s' ), '', '' ),
     5051        );
     5052       
     5053        // Localized delimiters for 'and' type.
     5054        $l_and = array(
     5055                /* translators: Used to join items in a list with more than 2 items. */
     5056                'between'          => sprintf( __( '%1$s, %2$s' ), '', '' ),
     5057                /* translators: Used to join last two items in a list with more than 2 times. */
     5058                'between_last_two' => sprintf( __( '%1$s, and %2$s' ), '', '' ),
     5059                /* translators: Used to join items in a list with only 2 items. */
     5060                'between_only_two' => sprintf( __( '%1$s and %2$s' ), '', '' ),
     5061        );
     5062       
     5063        // Set the delimiters type. Defaults to 'and' type for backward compatibility.
     5064        switch ( substr( $pattern, 0, 4 ) ) {
     5065                case '%l$o':
     5066                        $delimiters = $l_or;
     5067                        $lenght     = 4;
     5068                        break;
     5069                case '%l$a':
     5070                        $delimiters = $l_and;
     5071                        $lenght     = 4;
     5072                        break;
     5073                default:
     5074                        $delimiters = $l_and;
     5075                        $lenght     = 2;
     5076                        break;
     5077        }
    50355078
    50365079        /**
    50375080         * Filters the translated delimiters used by wp_sprintf_l().
    function wp_sprintf_l( $pattern, $args ) { 
    50415084         * Please note: Ampersands and entities should be avoided here.
    50425085         *
    50435086         * @since 2.5.0
     5087         * @since 5.4.0 Added optional 'or' delimiter type. Defaults to 'and' type.
    50445088         *
    50455089         * @param array $delimiters An array of translated delimiters.
    50465090         */
    50475091        $l = apply_filters(
    50485092                'wp_sprintf_l',
    5049                 array(
    5050                         /* translators: Used to join items in a list with more than 2 items. */
    5051                         'between'          => sprintf( __( '%1$s, %2$s' ), '', '' ),
    5052                         /* translators: Used to join last two items in a list with more than 2 times. */
    5053                         'between_last_two' => sprintf( __( '%1$s, and %2$s' ), '', '' ),
    5054                         /* translators: Used to join items in a list with only 2 items. */
    5055                         'between_only_two' => sprintf( __( '%1$s and %2$s' ), '', '' ),
    5056                 )
     5093                $delimiters
    50575094        );
    50585095
    50595096        $args   = (array) $args;
    function wp_sprintf_l( $pattern, $args ) { 
    50745111                }
    50755112        }
    50765113
    5077         return $result . substr( $pattern, 2 );
     5114        return $result . substr( $pattern, $lenght );
    50785115}
    50795116
    50805117/**