[wp-trac] [WordPress Trac] #44212: Add a new helper function for comma- or space-separated lists
WordPress Trac
noreply at wordpress.org
Mon May 28 14:40:47 UTC 2018
#44212: Add a new helper function for comma- or space-separated lists
--------------------------------------+------------------------------
Reporter: keesiemeijer | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------------------
Comment (by subrataemfluence):
Curious to know what if we just wrap the `$list` within a `trim()`
function to clean it up frm any leading or trailing spaces before using
`preg_split` on to it in the core functions since we already have
is_array() guard around this.
Like:
{{{#!php
<?php
function wp_parse_id_list( $list ) {
if ( ! is_array( $list ) ) {
$list = preg_split( '/[\s,]+/', trim( $list ) );
}
return array_unique( array_map( 'absint', $list ) );
}
}}}
and
{{{#!php
<?php
function wp_parse_slug_list( $list ) {
if ( ! is_array( $list ) ) {
$list = preg_split( '/[\s,]+/', trim( $list ) );
}
foreach ( $list as $key => $value ) {
$list[ $key ] = sanitize_title( $value );
}
return array_unique( $list );
}
}}}
Do you think if could create any impact in other areas? Please correct me
if I am wrong.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44212#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list