wp_parse_slug_list()WP 4.7.0

Clean up an array, comma- or space-separated list of slugs.

1 time — 0.000199 sec (fast) | 50000 times — 3.64 sec (fast) | PHP 7.0.8, WP 4.7

No Hooks.

Return

String[]. Sanitized array of slugs.

Usage

wp_parse_slug_list( $input_list );
$input_list(array|string) (required)
List of slugs.

Examples

0

#1 Demonstration of work

$str = 'Hello, World Hello, World';
$array = wp_parse_slug_list( $str );

/*
$array will be equal to:
Array
(
	[0] => hello
	[1] => world
)
*/

// the following lines will return the same result:
$atr = 'Hello world';
$atr = 'Hello, world';
$atr = 'Hello, world, world,world;'
$atr = 'Hello, world';

Transliteration will be made only if the corresponding plugin is installed, for example, Cyr to Lat.

Changelog

Since 4.7.0 Introduced.
Since 5.1.0 Refactored to use wp_parse_list().

wp_parse_slug_list() code WP 6.5.2

function wp_parse_slug_list( $input_list ) {
	$input_list = wp_parse_list( $input_list );

	return array_unique( array_map( 'sanitize_title', $input_list ) );
}