* @param array|string $list List of slugs.
* @return string[] Sanitized array of slugs.
function wp_parse_slug_list( $list ) {
$list = wp_parse_list( $list );
return array_unique( array_map( 'sanitize_title', $list ) );
* Extract a slice of an array, given a list of keys.
* @param array $array The original array.
* @param array $keys The list of keys.
* @return array The array slice.
function wp_array_slice_assoc( $array, $keys ) {
foreach ( $keys as $key ) {
if ( isset( $array[ $key ] ) ) {
$slice[ $key ] = $array[ $key ];
* Accesses an array in depth based on a path of keys.
* It is the PHP equivalent of JavaScript's `lodash.get()` and mirroring it may help other components
* retain some symmetry between client and server implementations.
* _wp_array_get( $array, array( 'a', 'b', 'c' );
* @param array $array An array from which we want to retrieve some information.
* @param array $path An array of keys describing the path with which to retrieve information.
* @param mixed $default The return value if the path does not exist within the array,
* or if `$array` or `$path` are not arrays.
* @return mixed The value from the path specified.
function _wp_array_get( $array, $path, $default = null ) {
// Confirm $path is valid.
if ( ! is_array( $path ) || 0 === count( $path ) ) {
foreach ( $path as $path_element ) {
( ! is_string( $path_element ) && ! is_integer( $path_element ) && ! is_null( $path_element ) ) ||
! array_key_exists( $path_element, $array )
$array = $array[ $path_element ];
* Determines if the variable is a numeric-indexed array.
* @param mixed $data Variable to check.
* @return bool Whether the variable is a list.
function wp_is_numeric_array( $data ) {
if ( ! is_array( $data ) ) {
$keys = array_keys( $data );
$string_keys = array_filter( $keys, 'is_string' );
return count( $string_keys ) === 0;
* Filters a list of objects, based on a set of key => value arguments.
* @since 4.7.0 Uses `WP_List_Util` class.
* @param array $list An array of objects to filter
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'or' means
* only one element from the array needs to match; 'and'
* means all elements must match; 'not' means no elements may
* @param bool|string $field A field from the object to place instead of the entire object.
* @return array A list of objects or object fields.
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) {
if ( ! is_array( $list ) ) {
$util = new WP_List_Util( $list );
$util->filter( $args, $operator );
return $util->get_output();
* Filters a list of objects, based on a set of key => value arguments.
* @since 4.7.0 Uses `WP_List_Util` class.
* @param array $list An array of objects to filter.
* @param array $args Optional. An array of key => value arguments to match
* against each object. Default empty array.
* @param string $operator Optional. The logical operation to perform. 'AND' means
* all elements from the array must match. 'OR' means only
* one element needs to match. 'NOT' means no elements may
* @return array Array of found values.
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) {
if ( ! is_array( $list ) ) {
$util = new WP_List_Util( $list );
return $util->filter( $args, $operator );
* Pluck a certain field out of each object in a list.
* This has the same functionality and prototype of
* array_column() (PHP 5.5) but also supports objects.
* @since 4.0.0 $index_key parameter added.
* @since 4.7.0 Uses `WP_List_Util` class.
* @param array $list List of objects or arrays
* @param int|string $field Field from the object to place instead of the entire object
* @param int|string $index_key Optional. Field from the object to use as keys for the new array.
* @return array Array of found values. If `$index_key` is set, an array of found values with keys
* corresponding to `$index_key`. If `$index_key` is null, array keys from the original
* `$list` will be preserved in the results.
function wp_list_pluck( $list, $field, $index_key = null ) {
$util = new WP_List_Util( $list );
return $util->pluck( $field, $index_key );
* Sorts a list of objects, based on one or more orderby arguments.
* @param array $list An array of objects to sort.
* @param string|array $orderby Optional. Either the field name to order by or an array
* of multiple orderby fields as $orderby => $order.
* @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby
* @param bool $preserve_keys Optional. Whether to preserve keys. Default false.
* @return array The sorted array.
function wp_list_sort( $list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
if ( ! is_array( $list ) ) {
$util = new WP_List_Util( $list );
return $util->sort( $orderby, $order, $preserve_keys );
* Determines if Widgets library should be loaded.
* Checks to make sure that the widgets library hasn't already been loaded.
* If it hasn't, then it will load the widgets library and run an action hook.
function wp_maybe_load_widgets() {
* Filters whether to load the Widgets library.
* Returning a falsey value from the filter will effectively short-circuit
* the Widgets library from loading.
* @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
if ( ! apply_filters( 'load_default_widgets', true ) ) {
require_once ABSPATH . WPINC . '/default-widgets.php';
add_action( '_admin_menu', 'wp_widgets_add_menu' );
* Append the Widgets menu to the themes main menu.
function wp_widgets_add_menu() {
if ( ! current_theme_supports( 'widgets' ) ) {
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
* Flush all output buffers for PHP 5.2.
* Make sure all output buffers are flushed before our singletons are destroyed.
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ( $i = 0; $i < $levels; $i++ ) {
* Load custom DB error or display WordPress DB error.
* If a file exists in the wp-content directory named db-error.php, then it will
* be loaded instead of displaying the WordPress DB error. If it is not found,
* then the WordPress DB error will be displayed instead.
* The WordPress DB error sets the HTTP status header to 500 to try to prevent
* search engines from caching the message. Custom DB messages should do the
* This function was backported to WordPress 2.3.2, but originally was added
* @global wpdb $wpdb WordPress database abstraction object.
wp_load_translations_early();
// Load custom DB error template, if present.
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
require_once WP_CONTENT_DIR . '/db-error.php';
// If installing or in the admin, provide the verbose message.
if ( wp_installing() || defined( 'WP_ADMIN' ) ) {
wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
* Convert a value to non-negative integer.
* @param mixed $maybeint Data you wish to have converted to a non-negative integer.
* @return int A non-negative integer.
function absint( $maybeint ) {
return abs( (int) $maybeint );
* Mark a function as deprecated and inform when it has been used.
* There is a {@see 'hook deprecated_function_run'} that will be called that can be used
* to get the backtrace up to what file and function called the deprecated
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
* This function is to be used in every function that is deprecated.
* @since 5.4.0 This function is no longer marked as "private".
* @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
* @param string $function The function that was called.
* @param string $version The version of WordPress that deprecated the function.
* @param string $replacement Optional. The function that should have been called. Default empty.
function _deprecated_function( $function, $version, $replacement = '' ) {
* Fires when a deprecated function is called.
* @param string $function The function that was called.
* @param string $replacement The function that should have been called.
* @param string $version The version of WordPress that deprecated the function.
do_action( 'deprecated_function_run', $function, $replacement, $version );
* Filters whether to trigger an error for deprecated functions.
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
/* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
__( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
/* translators: 1: PHP function name, 2: Version number. */
__( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
'%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
'%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
* Marks a constructor as deprecated and informs when it has been used.
* Similar to _deprecated_function(), but with different strings. Used to
* remove PHP4 style constructors.
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
* This function is to be used in every PHP4 style constructor method that is deprecated.
* @since 4.5.0 Added the `$parent_class` parameter.
* @since 5.4.0 This function is no longer marked as "private".
* @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class Optional. The parent class calling the deprecated constructor.
function _deprecated_constructor( $class, $version, $parent_class = '' ) {
* Fires when a deprecated constructor is called.
* @since 4.5.0 Added the `$parent_class` parameter.
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
* @param string $parent_class The parent class calling the deprecated constructor.
do_action( 'deprecated_constructor_run', $class, $version, $parent_class );
* Filters whether to trigger an error for deprecated functions.
* `WP_DEBUG` must be true in addition to the filter evaluating to true.
* @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) {
/* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */
__( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
'<code>__construct()</code>'
/* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */
__( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
'<code>__construct()</code>'
'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
'<code>__construct()</code>'
'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
'<code>__construct()</code>'
* Mark a file as deprecated and inform when it has been used.