: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
__( 'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/' )
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
__( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
$version = sprintf( '(This message was added in version %s.)', $version );
' Please see <a href="%s">Debugging in WordPress</a> for more information.',
'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/'
'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s',
wp_trigger_error( '', $message );
* Generates a user-level error/warning/notice/deprecation message.
* Generates the message when `WP_DEBUG` is true.
* @param string $function_name The function that triggered the error.
* @param string $message The message explaining the error.
* The message can contain allowed HTML 'a' (with href), 'code',
* 'br', 'em', and 'strong' tags and http or https protocols.
* If it contains other HTML tags or protocols, the message should be escaped
* before passing to this function to avoid being stripped {@see wp_kses()}.
* @param int $error_level Optional. The designated error type for this error.
* Only works with E_USER family of constants. Default E_USER_NOTICE.
function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
// Bail out if WP_DEBUG is not turned on.
* Fires when the given function triggers a user-level error/warning/notice/deprecation message.
* Can be used for debug backtracking.
* @param string $function_name The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param int $error_level The designated error type for this error.
do_action( 'wp_trigger_error_run', $function_name, $message, $error_level );
if ( ! empty( $function_name ) ) {
$message = sprintf( '%s(): %s', $function_name, $message );
'a' => array( 'href' => true ),
trigger_error( $message, $error_level );
* Determines whether the server is running an earlier than 1.5.0 version of lighttpd.
* @return bool Whether the server is running lighttpd < 1.5.0.
function is_lighttpd_before_150() {
$server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
$server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : '';
return ( 'lighttpd' === $server_parts[0] && -1 === version_compare( $server_parts[1], '1.5.0' ) );
* Determines whether the specified module exist in the Apache config.
* @global bool $is_apache
* @param string $mod The module, e.g. mod_rewrite.
* @param bool $default_value Optional. The default return value if the module is not found. Default false.
* @return bool Whether the specified module is loaded.
function apache_mod_loaded( $mod, $default_value = false ) {
if ( function_exists( 'apache_get_modules' ) ) {
$loaded_mods = apache_get_modules();
if ( in_array( $mod, $loaded_mods, true ) ) {
if ( empty( $loaded_mods )
&& function_exists( 'phpinfo' )
&& ! str_contains( ini_get( 'disable_functions' ), 'phpinfo' )
$phpinfo = ob_get_clean();
if ( str_contains( $phpinfo, $mod ) ) {
* Checks if IIS 7+ supports pretty permalinks.
* @return bool Whether IIS7 supports permalinks.
function iis7_supports_permalinks() {
$supports_permalinks = false;
/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
* easily update the xml configuration file, hence we just bail out and tell user that
* pretty permalinks cannot be used.
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the website. When
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
* via ISAPI then pretty permalinks will not work.
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( 'cgi-fcgi' === PHP_SAPI );
* Filters whether IIS 7+ supports pretty permalinks.
* @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
* Validates a file name and path against an allowed set of rules.
* A return value of `1` means the file path contains directory traversal.
* A return value of `2` means the file path contains a Windows drive path.
* A return value of `3` means the file is not in the allowed files list.
* @param string $file File path.
* @param string[] $allowed_files Optional. Array of allowed files. Default empty array.
* @return int 0 means nothing is wrong, greater than 0 means something was wrong.
function validate_file( $file, $allowed_files = array() ) {
if ( ! is_scalar( $file ) || '' === $file ) {
// Normalize path for Windows servers.
$file = wp_normalize_path( $file );
// Normalize path for $allowed_files as well so it's an apples to apples comparison.
$allowed_files = array_map( 'wp_normalize_path', $allowed_files );
// `../` on its own is not allowed:
// More than one occurrence of `../` is not allowed:
if ( preg_match_all( '#\.\./#', $file, $matches, PREG_SET_ORDER ) && ( count( $matches ) > 1 ) ) {
// `../` which does not occur at the end of the path is not allowed:
if ( str_contains( $file, '../' ) && '../' !== mb_substr( $file, -3, 3 ) ) {
// Files not in the allowed file list are not allowed:
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files, true ) ) {
// Absolute Windows drive paths are not allowed:
if ( ':' === substr( $file, 1, 1 ) ) {
* Determines whether to force SSL used for the Administration Screens.
* @param string|bool $force Optional. Whether to force SSL in admin screens. Default null.
* @return bool True if forced, false if not forced.
function force_ssl_admin( $force = null ) {
if ( ! is_null( $force ) ) {
* Guesses the URL for the site.
* Will remove wp-admin links to retrieve only return URLs not in the wp-admin
* @return string The guessed URL.
function wp_guess_url() {
if ( defined( 'WP_SITEURL' ) && '' !== WP_SITEURL ) {
$abspath_fix = str_replace( '\\', '/', ABSPATH );
$script_filename_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
// The request is for the admin.
if ( str_contains( $_SERVER['REQUEST_URI'], 'wp-admin' ) || str_contains( $_SERVER['REQUEST_URI'], 'wp-login.php' ) ) {
$path = preg_replace( '#/(wp-admin/?.*|wp-login\.php.*)#i', '', $_SERVER['REQUEST_URI'] );
// The request is for a file in ABSPATH.
} elseif ( $script_filename_dir . '/' === $abspath_fix ) {
// Strip off any file/query params in the path.
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
if ( str_contains( $_SERVER['SCRIPT_FILENAME'], $abspath_fix ) ) {
// Request is hitting a file inside ABSPATH.
$directory = str_replace( ABSPATH, '', $script_filename_dir );
// Strip off the subdirectory, and any file/query params.
$path = preg_replace( '#/' . preg_quote( $directory, '#' ) . '/[^/]*$#i', '', $_SERVER['REQUEST_URI'] );
} elseif ( str_contains( $abspath_fix, $script_filename_dir ) ) {
// Request is hitting a file above ABSPATH.
$subdirectory = substr( $abspath_fix, strpos( $abspath_fix, $script_filename_dir ) + strlen( $script_filename_dir ) );
// Strip off any file/query params from the path, appending the subdirectory to the installation.
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['REQUEST_URI'] ) . $subdirectory;
$path = $_SERVER['REQUEST_URI'];
$schema = is_ssl() ? 'https://' : 'http://'; // set_url_scheme() is not defined yet.
$url = $schema . $_SERVER['HTTP_HOST'] . $path;
return rtrim( $url, '/' );
* Temporarily suspends cache additions.
* Stops more data being added to the cache, but still allows cache retrieval.
* This is useful for actions, such as imports, when a lot of data would otherwise
* be almost uselessly added to the cache.
* Suspension lasts for a single page load at most. Remember to call this
* function again if you wish to re-enable cache adds earlier.
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false.
* Defaults to not changing the current setting.
* @return bool The current suspend setting.
function wp_suspend_cache_addition( $suspend = null ) {
static $_suspend = false;
if ( is_bool( $suspend ) ) {
* Suspends cache invalidation.
* Turns cache invalidation on and off. Useful during imports where you don't want to do
* invalidations every time a post is inserted. Callers must be sure that what they are
* doing won't lead to an inconsistent cache when invalidation is suspended.
* @global bool $_wp_suspend_cache_invalidation
* @param bool $suspend Optional. Whether to suspend or enable cache invalidation. Default true.
* @return bool The current suspend setting.
function wp_suspend_cache_invalidation( $suspend = true ) {
global $_wp_suspend_cache_invalidation;
$current_suspend = $_wp_suspend_cache_invalidation;
$_wp_suspend_cache_invalidation = $suspend;
* Determines whether a site is the main site of the current network.
* @since 4.9.0 The `$network_id` parameter was added.
* @param int $site_id Optional. Site ID to test. Defaults to current site.
* @param int $network_id Optional. Network ID of the network to check for.
* Defaults to current network.
* @return bool True if $site_id is the main site of the network, or if not
function is_main_site( $site_id = null, $network_id = null ) {
if ( ! is_multisite() ) {
$site_id = get_current_blog_id();
$site_id = (int) $site_id;
return get_main_site_id( $network_id ) === $site_id;
* @param int $network_id Optional. The ID of the network for which to get the main site.
* Defaults to the current network.
* @return int The ID of the main site.
function get_main_site_id( $network_id = null ) {
if ( ! is_multisite() ) {
return get_current_blog_id();
$network = get_network( $network_id );
return $network->site_id;
* Determines whether a network is the main network of the Multisite installation.
* @param int $network_id Optional. Network ID to test. Defaults to current network.
* @return bool True if $network_id is the main network, or if not running Multisite.
function is_main_network( $network_id = null ) {
if ( ! is_multisite() ) {
if ( null === $network_id ) {
$network_id = get_current_network_id();
$network_id = (int) $network_id;
return ( get_main_network_id() === $network_id );
* Gets the main network ID.
* @return int The ID of the main network.
function get_main_network_id() {
if ( ! is_multisite() ) {
$current_network = get_network();
if ( defined( 'PRIMARY_NETWORK_ID' ) ) {
$main_network_id = PRIMARY_NETWORK_ID;
} elseif ( isset( $current_network->id ) && 1 === (int) $current_network->id ) {
// If the current network has an ID of 1, assume it is the main network.
$_networks = get_networks(
$main_network_id = array_shift( $_networks );
* Filters the main network ID.
* @param int $main_network_id The ID of the main network.
return (int) apply_filters( 'get_main_network_id', $main_network_id );
* Determines whether site meta is enabled.
* This function checks whether the 'blogmeta' database table exists. The result is saved as
* a setting for the main network, making it essentially a global setting. Subsequent requests
* will refer to this setting instead of running the query.
* @global wpdb $wpdb WordPress database abstraction object.
* @return bool True if site meta is supported, false otherwise.
function is_site_meta_supported() {
if ( ! is_multisite() ) {
$network_id = get_main_network_id();
$supported = get_network_option( $network_id, 'site_meta_supported', false );
if ( false === $supported ) {
$supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0;
update_network_option( $network_id, 'site_meta_supported', $supported );
return (bool) $supported;
* Modifies gmt_offset for smart timezone handling.
* Overrides the gmt_offset option if we have a timezone_string available.
* @return float|false Timezone GMT offset, false otherwise.