: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* 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( $input_array, array( 'a', 'b', 'c' ) );
* @param array $input_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_value Optional. The return value if the path does not exist within the array,
* or if `$input_array` or `$path` are not arrays. Default null.
* @return mixed The value from the path specified.
function _wp_array_get( $input_array, $path, $default_value = null ) {
// Confirm $path is valid.
if ( ! is_array( $path ) || 0 === count( $path ) ) {
foreach ( $path as $path_element ) {
if ( ! is_array( $input_array ) ) {
if ( is_string( $path_element )
|| is_integer( $path_element )
|| null === $path_element
* Check if the path element exists in the input array.
* We check with `isset()` first, as it is a lot faster
* than `array_key_exists()`.
if ( isset( $input_array[ $path_element ] ) ) {
$input_array = $input_array[ $path_element ];
* If `isset()` returns false, we check with `array_key_exists()`,
* which also checks for `null` values.
if ( array_key_exists( $path_element, $input_array ) ) {
$input_array = $input_array[ $path_element ];
* Sets an array in depth based on a path of keys.
* It is the PHP equivalent of JavaScript's `lodash.set()` and mirroring it may help other components
* retain some symmetry between client and server implementations.
* $input_array = array();
* _wp_array_set( $input_array, array( 'a', 'b', 'c', 1 ) );
* @param array $input_array An array that we want to mutate to include a specific value in a path.
* @param array $path An array of keys describing the path that we want to mutate.
* @param mixed $value The value that will be set.
function _wp_array_set( &$input_array, $path, $value = null ) {
// Confirm $input_array is valid.
if ( ! is_array( $input_array ) ) {
// Confirm $path is valid.
if ( ! is_array( $path ) ) {
$path_length = count( $path );
if ( 0 === $path_length ) {
foreach ( $path as $path_element ) {
! is_string( $path_element ) && ! is_integer( $path_element ) &&
! is_null( $path_element )
for ( $i = 0; $i < $path_length - 1; ++$i ) {
$path_element = $path[ $i ];
! array_key_exists( $path_element, $input_array ) ||
! is_array( $input_array[ $path_element ] )
$input_array[ $path_element ] = array();
$input_array = &$input_array[ $path_element ];
$input_array[ $path[ $i ] ] = $value;
* This function is trying to replicate what
* lodash's kebabCase (JS library) does in the client.
* The reason we need this function is that we do some processing
* in both the client and the server (e.g.: we generate
* preset classes from preset slugs) that needs to
* create the same output.
* We can't remove or update the client's library due to backward compatibility
* (some of the output of lodash's kebabCase is saved in the post content).
* We have to make the server behave like the client.
* Changes to this function should follow updates in the client
* @link https://github.com/lodash/lodash/blob/4.17/dist/lodash.js#L14369
* @link https://github.com/lodash/lodash/blob/4.17/dist/lodash.js#L278
* @link https://github.com/lodash-php/lodash-php/blob/master/src/String/kebabCase.php
* @link https://github.com/lodash-php/lodash-php/blob/master/src/internal/unicodeWords.php
* @param string $input_string The string to kebab-case.
* @return string kebab-cased-string.
function _wp_to_kebab_case( $input_string ) {
// Ignore the camelCase names for variables so the names are the same as lodash so comparing and porting new changes is easier.
// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
* Some notable things we've removed compared to the lodash version are:
* - non-alphanumeric characters: rsAstralRange, rsEmoji, etc
* - the groups that processed the apostrophe, as it's removed before passing the string to preg_match: rsApos, rsOptContrLower, and rsOptContrUpper
/** Used to compose unicode character classes. */
$rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff';
$rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf';
$rsPunctuationRange = '\\x{2000}-\\x{206f}';
$rsSpaceRange = ' \\t\\x0b\\f\\xa0\\x{feff}\\n\\r\\x{2028}\\x{2029}\\x{1680}\\x{180e}\\x{2000}\\x{2001}\\x{2002}\\x{2003}\\x{2004}\\x{2005}\\x{2006}\\x{2007}\\x{2008}\\x{2009}\\x{200a}\\x{202f}\\x{205f}\\x{3000}';
$rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde';
$rsBreakRange = $rsNonCharRange . $rsPunctuationRange . $rsSpaceRange;
/** Used to compose unicode capture groups. */
$rsBreak = '[' . $rsBreakRange . ']';
$rsDigits = '\\d+'; // The last lodash version in GitHub uses a single digit here and expands it when in use.
$rsLower = '[' . $rsLowerRange . ']';
$rsMisc = '[^' . $rsBreakRange . $rsDigits . $rsLowerRange . $rsUpperRange . ']';
$rsUpper = '[' . $rsUpperRange . ']';
/** Used to compose unicode regexes. */
$rsMiscLower = '(?:' . $rsLower . '|' . $rsMisc . ')';
$rsMiscUpper = '(?:' . $rsUpper . '|' . $rsMisc . ')';
$rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])';
$rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])';
$rsUpper . '?' . $rsLower . '+' . '(?=' . implode( '|', array( $rsBreak, $rsUpper, '$' ) ) . ')',
$rsMiscUpper . '+' . '(?=' . implode( '|', array( $rsBreak, $rsUpper . $rsMiscLower, '$' ) ) . ')',
$rsUpper . '?' . $rsMiscLower . '+',
preg_match_all( $regexp, str_replace( "'", '', $input_string ), $matches );
return strtolower( implode( '-', $matches[0] ) );
// phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
* 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.
* Retrieves the objects from the list that match the given arguments.
* Key represents property name, and value represents property value.
* If an object has more properties than those specified in arguments,
* that will not disqualify it. When using the 'AND' operator,
* any missing properties will disqualify it.
* When using the `$field` argument, this function can also retrieve
* a particular field from all matching objects, whereas wp_list_filter()
* only does the filtering.
* @since 4.7.0 Uses `WP_List_Util` class.
* @param array $input_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
* @param bool|string $field Optional. A field from the object to place instead
* of the entire object. Default false.
* @return array A list of objects or object fields.
function wp_filter_object_list( $input_list, $args = array(), $operator = 'and', $field = false ) {
if ( ! is_array( $input_list ) ) {
$util = new WP_List_Util( $input_list );
$util->filter( $args, $operator );
return $util->get_output();
* Filters a list of objects, based on a set of key => value arguments.
* Retrieves the objects from the list that match the given arguments.
* Key represents property name, and value represents property value.
* If an object has more properties than those specified in arguments,
* that will not disqualify it. When using the 'AND' operator,
* any missing properties will disqualify it.
* If you want to retrieve a particular field from all matching objects,
* use wp_filter_object_list() instead.
* @since 4.7.0 Uses `WP_List_Util` class.
* @since 5.9.0 Converted into a wrapper for `wp_filter_object_list()`.
* @param array $input_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( $input_list, $args = array(), $operator = 'AND' ) {
return wp_filter_object_list( $input_list, $args, $operator );
* Plucks a certain field out of each object or array in an array.
* 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 $input_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
* `$input_list` will be preserved in the results.
function wp_list_pluck( $input_list, $field, $index_key = null ) {
if ( ! is_array( $input_list ) ) {
$util = new WP_List_Util( $input_list );
return $util->pluck( $field, $index_key );
* Sorts an array of objects or arrays based on one or more orderby arguments.
* @param array $input_list An array of objects or arrays 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`
* is a string. Default 'ASC'.
* @param bool $preserve_keys Optional. Whether to preserve keys. Default false.
* @return array The sorted array.
function wp_list_sort( $input_list, $orderby = array(), $order = 'ASC', $preserve_keys = false ) {
if ( ! is_array( $input_list ) ) {
$util = new WP_List_Util( $input_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' );
* Appends the Widgets menu to the themes main menu.
* @since 5.9.3 Don't specify menu order when the active theme is a block theme.
function wp_widgets_add_menu() {
if ( ! current_theme_supports( 'widgets' ) ) {
$menu_name = __( 'Widgets' );
if ( wp_is_block_theme() ) {
$submenu['themes.php'][] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
$submenu['themes.php'][8] = array( $menu_name, 'edit_theme_options', 'widgets.php' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
* Flushes 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++ ) {
* Loads 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' ) );
* Converts 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 );
* Marks a function as deprecated and inform when it has been used.
* There is a {@see 'deprecated_function_run'} hook that will be called that can be used
* to get the backtrace up to what file and function called the deprecated function.
* 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_name 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 string.
function _deprecated_function( $function_name, $version, $replacement = '' ) {