wp_sprintf_l

The timeline below displays how wordpress function wp_sprintf_l has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Localizes list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match.
    if (!str_starts_with($pattern, '%l')) {
        return $pattern;
    }
    // Nothing to work with.
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: Used to join items in a list with more than 2 items. */
        'between' => sprintf(__('%1$s, %2$s'), '', ''),
        /* translators: Used to join last two items in a list with more than 2 times. */
        'between_last_two' => sprintf(__('%1$s, and %2$s'), '', ''),
        /* translators: Used to join items in a list with only 2 items. */
        'between_only_two' => sprintf(__('%1$s and %2$s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) === 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args.
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        --$i;
        if (0 === $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 6.3

/**
 * Localizes list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match.
    if (!str_starts_with($pattern, '%l')) {
        return $pattern;
    }
    // Nothing to work with.
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: Used to join items in a list with more than 2 items. */
        'between' => sprintf(__('%1$s, %2$s'), '', ''),
        /* translators: Used to join last two items in a list with more than 2 times. */
        'between_last_two' => sprintf(__('%1$s, and %2$s'), '', ''),
        /* translators: Used to join items in a list with only 2 items. */
        'between_only_two' => sprintf(__('%1$s and %2$s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) === 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args.
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 === $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 6.1

/**
 * Localizes list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match.
    if ('%l' !== substr($pattern, 0, 2)) {
        return $pattern;
    }
    // Nothing to work with.
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: Used to join items in a list with more than 2 items. */
        'between' => sprintf(__('%1$s, %2$s'), '', ''),
        /* translators: Used to join last two items in a list with more than 2 times. */
        'between_last_two' => sprintf(__('%1$s, and %2$s'), '', ''),
        /* translators: Used to join items in a list with only 2 items. */
        'between_only_two' => sprintf(__('%1$s and %2$s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args.
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 5.5

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match.
    if ('%l' !== substr($pattern, 0, 2)) {
        return $pattern;
    }
    // Nothing to work with.
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: Used to join items in a list with more than 2 items. */
        'between' => sprintf(__('%1$s, %2$s'), '', ''),
        /* translators: Used to join last two items in a list with more than 2 times. */
        'between_last_two' => sprintf(__('%1$s, and %2$s'), '', ''),
        /* translators: Used to join items in a list with only 2 items. */
        'between_only_two' => sprintf(__('%1$s and %2$s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args.
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 5.4

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match.
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with.
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: Used to join items in a list with more than 2 items. */
        'between' => sprintf(__('%1$s, %2$s'), '', ''),
        /* translators: Used to join last two items in a list with more than 2 times. */
        'between_last_two' => sprintf(__('%1$s, and %2$s'), '', ''),
        /* translators: Used to join items in a list with only 2 items. */
        'between_only_two' => sprintf(__('%1$s and %2$s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args.
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 5.3

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: Used to join items in a list with more than 2 items. */
        'between' => sprintf(__('%1$s, %2$s'), '', ''),
        /* translators: Used to join last two items in a list with more than 2 times. */
        'between_last_two' => sprintf(__('%1$s, and %2$s'), '', ''),
        /* translators: Used to join items in a list with only 2 items. */
        'between_only_two' => sprintf(__('%1$s and %2$s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 5.1

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: used to join items in a list with more than 2 items */
        'between' => sprintf(__('%1$s, %2$s'), '', ''),
        /* translators: used to join last two items in a list with more than 2 times */
        'between_last_two' => sprintf(__('%1$s, and %2$s'), '', ''),
        /* translators: used to join items in a list with only 2 items */
        'between_only_two' => sprintf(__('%1$s and %2$s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 4.6

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with
    if (empty($args)) {
        return '';
    }
    /**
     * Filters the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: used to join items in a list with more than 2 items */
        'between' => sprintf(__('%s, %s'), '', ''),
        /* translators: used to join last two items in a list with more than 2 times */
        'between_last_two' => sprintf(__('%s, and %s'), '', ''),
        /* translators: used to join items in a list with only 2 items */
        'between_only_two' => sprintf(__('%s and %s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 4.3

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array  $args    List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with
    if (empty($args)) {
        return '';
    }
    /**
     * Filter the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: used to join items in a list with more than 2 items */
        'between' => sprintf(__('%s, %s'), '', ''),
        /* translators: used to join last two items in a list with more than 2 times */
        'between_last_two' => sprintf(__('%s, and %s'), '', ''),
        /* translators: used to join items in a list with only 2 items */
        'between_only_two' => sprintf(__('%s and %s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 3.9

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array $args List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with
    if (empty($args)) {
        return '';
    }
    /**
     * Filter the translated delimiters used by wp_sprintf_l().
     * Placeholders (%s) are included to assist translators and then
     * removed before the array of strings reaches the filter.
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: used to join items in a list with more than 2 items */
        'between' => sprintf(__('%s, %s'), '', ''),
        /* translators: used to join last two items in a list with more than 2 times */
        'between_last_two' => sprintf(__('%s, and %s'), '', ''),
        /* translators: used to join items in a list with only 2 items */
        'between_only_two' => sprintf(__('%s and %s'), '', ''),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 3.8

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array $args List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with
    if (empty($args)) {
        return '';
    }
    /**
     * Filter the translated delimiters used by wp_sprintf_l().
     *
     * Please note: Ampersands and entities should be avoided here.
     *
     * @since 2.5.0
     *
     * @param array $delimiters An array of translated delimiters.
     */
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: used between list items, there is a space after the comma */
        'between' => __(', '),
        /* translators: used between list items, there is a space after the and */
        'between_last_two' => __(', and '),
        /* translators: used between only two list items, there is a space after the and */
        'between_only_two' => __(' and '),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}

WordPress Version: 3.7

/**
 * Localize list items before the rest of the content.
 *
 * The '%l' must be at the first characters can then contain the rest of the
 * content. The list items will have ', ', ', and', and ' and ' added depending
 * on the amount of list items in the $args parameter.
 *
 * @since 2.5.0
 *
 * @param string $pattern Content containing '%l' at the beginning.
 * @param array $args List items to prepend to the content and replace '%l'.
 * @return string Localized list items and rest of the content.
 */
function wp_sprintf_l($pattern, $args)
{
    // Not a match
    if (substr($pattern, 0, 2) != '%l') {
        return $pattern;
    }
    // Nothing to work with
    if (empty($args)) {
        return '';
    }
    // Translate and filter the delimiter set (avoid ampersands and entities here)
    $l = apply_filters('wp_sprintf_l', array(
        /* translators: used between list items, there is a space after the comma */
        'between' => __(', '),
        /* translators: used between list items, there is a space after the and */
        'between_last_two' => __(', and '),
        /* translators: used between only two list items, there is a space after the and */
        'between_only_two' => __(' and '),
    ));
    $args = (array) $args;
    $result = array_shift($args);
    if (count($args) == 1) {
        $result .= $l['between_only_two'] . array_shift($args);
    }
    // Loop when more than two args
    $i = count($args);
    while ($i) {
        $arg = array_shift($args);
        $i--;
        if (0 == $i) {
            $result .= $l['between_last_two'] . $arg;
        } else {
            $result .= $l['between'] . $arg;
        }
    }
    return $result . substr($pattern, 2);
}