Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #44212, comment 1


Ignore:
Timestamp:
05/24/2018 03:12:41 PM (5 years ago)
Author:
keesiemeijer
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #44212, comment 1

    initial v1  
    11In [attachment:44212.2.patch] the function `wp_parse_list()` is introduced and is used by `wp_parse_id_list()` and `wp_parse_slug_list()`.
    22
    3 With this function it now removes the empty values returned by `preg_split()`. You can also remove all the values that equal to false by setting the `$format` parameter to 'filter_false'. We could use this filter for `wp_parse_id_list()` as IDs are not supposed to have a value of 0. I've left it as is for back compatibility.
     3With this function it now removes the empty values returned by `preg_split()`. You can also remove all the values that equal to false by setting the `$format` parameter to `filter_false`. We could use this filter for `wp_parse_id_list()` as IDs are not supposed to have a value of 0. I've left it as is for back compatibility.
    44
    5 The other instances where `preg_split()` is used with the same regex should get their own ticket for replacing it with `wp_parse_list()`. This is because sometimes it's expected to have an empty value for empty strings.
     5== Empty strings ==
     6There are differences between what is returned for `preg_split()` (without the `PREG_SPLIT_NO_EMPTY`) flag and the `wp_parse_id_list()` function if you use it with an empty string
     7
    68{{{
     9$array = preg_split( '/[\s,]+/', '' );
     10
     11// non empty array
    712array(
    813    0 => ''
    914)
     15
     16$array = wp_parse_list('');
     17
     18// empty array
     19array(
     20
     21)
    1022}}}
     23
     24New tickets should be created for the other instances where `preg_split()` is used (with the same regex) that expect an empty array (and are now iterating over it).