: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
'Cache-Control' => $cache_control,
if ( function_exists( 'apply_filters' ) ) {
* Filters the cache-controlling HTTP headers that are used to prevent caching.
* @see wp_get_nocache_headers()
* @param array $headers Header names and field values.
$headers = (array) apply_filters( 'nocache_headers', $headers );
$headers['Last-Modified'] = false;
* Sets the HTTP headers to prevent caching for the different browsers.
* Different browsers support different nocache headers, so several
* headers must be sent so that all of them get the point that no
* @see wp_get_nocache_headers()
function nocache_headers() {
$headers = wp_get_nocache_headers();
unset( $headers['Last-Modified'] );
header_remove( 'Last-Modified' );
foreach ( $headers as $name => $field_value ) {
header( "{$name}: {$field_value}" );
* Sets the HTTP headers for caching for 10 days with JavaScript content type.
function cache_javascript_headers() {
$expires_offset = 10 * DAY_IN_SECONDS;
header( 'Content-Type: text/javascript; charset=' . get_bloginfo( 'charset' ) );
header( 'Vary: Accept-Encoding' ); // Handle proxies.
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + $expires_offset ) . ' GMT' );
* Retrieves the number of database queries during the WordPress execution.
* @global wpdb $wpdb WordPress database abstraction object.
* @return int Number of database queries.
function get_num_queries() {
return $wpdb->num_queries;
* Determines whether input is yes or no.
* Must be 'y' to be true.
* @param string $yn Character string containing either 'y' (yes) or 'n' (no).
* @return bool True if 'y', false on anything else.
function bool_from_yn( $yn ) {
return ( 'y' === strtolower( $yn ) );
* Loads the feed template from the use of an action hook.
* If the feed action does not have a hook, then the function will die with a
* message telling the visitor that the feed is not valid.
* It is better to only have one hook for each feed.
* @global WP_Query $wp_query WordPress Query object.
$feed = get_query_var( 'feed' );
// Remove the pad, if present.
$feed = preg_replace( '/^_+/', '', $feed );
if ( '' === $feed || 'feed' === $feed ) {
$feed = get_default_feed();
if ( ! has_action( "do_feed_{$feed}" ) ) {
wp_die( __( '<strong>Error:</strong> This is not a valid feed template.' ), '', array( 'response' => 404 ) );
* Fires once the given feed is loaded.
* The dynamic portion of the hook name, `$feed`, refers to the feed template name.
* Possible hook names include:
* @since 4.4.0 The `$feed` parameter was added.
* @param bool $is_comment_feed Whether the feed is a comment feed.
* @param string $feed The feed name.
do_action( "do_feed_{$feed}", $wp_query->is_comment_feed, $feed );
* Loads the RDF RSS 0.91 Feed template.
load_template( ABSPATH . WPINC . '/feed-rdf.php' );
* Loads the RSS 1.0 Feed Template.
load_template( ABSPATH . WPINC . '/feed-rss.php' );
* Loads either the RSS2 comment feed or the RSS2 posts feed.
* @param bool $for_comments True for the comment feed, false for normal feed.
function do_feed_rss2( $for_comments ) {
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' );
load_template( ABSPATH . WPINC . '/feed-rss2.php' );
* Loads either Atom comment feed or Atom posts feed.
* @param bool $for_comments True for the comment feed, false for normal feed.
function do_feed_atom( $for_comments ) {
load_template( ABSPATH . WPINC . '/feed-atom-comments.php' );
load_template( ABSPATH . WPINC . '/feed-atom.php' );
* Displays the default robots.txt file content.
* @since 5.3.0 Remove the "Disallow: /" output if search engine visibility is
* discouraged in favor of robots meta HTML tag via wp_robots_no_robots()
header( 'Content-Type: text/plain; charset=utf-8' );
* Fires when displaying the robots.txt file.
do_action( 'do_robotstxt' );
$output = "User-agent: *\n";
$public = get_option( 'blog_public' );
$site_url = parse_url( site_url() );
$path = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
$output .= "Disallow: $path/wp-admin/\n";
$output .= "Allow: $path/wp-admin/admin-ajax.php\n";
* Filters the robots.txt output.
* @param string $output The robots.txt output.
* @param bool $public Whether the site is considered "public".
echo apply_filters( 'robots_txt', $output, $public );
* Displays the favicon.ico file content.
* Fires when serving the favicon.ico file.
do_action( 'do_faviconico' );
wp_redirect( get_site_icon_url( 32, includes_url( 'images/w-logo-blue-white-bg.png' ) ) );
* Determines whether WordPress is already installed.
* The cache will be checked first. If you have a cache plugin, which saves
* the cache values, then this will work. If you use the default WordPress
* cache, and the database goes away, then you might have problems.
* Checks for the 'siteurl' option for whether WordPress is installed.
* For more information on this and similar theme functions, check out
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global wpdb $wpdb WordPress database abstraction object.
* @return bool Whether the site is already installed.
function is_blog_installed() {
* Check cache first. If options table goes away and we have true
if ( wp_cache_get( 'is_blog_installed' ) ) {
$suppress = $wpdb->suppress_errors();
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions();
// If siteurl is not set to autoload, check it specifically.
if ( ! isset( $alloptions['siteurl'] ) ) {
$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
$installed = $alloptions['siteurl'];
$wpdb->suppress_errors( $suppress );
$installed = ! empty( $installed );
wp_cache_set( 'is_blog_installed', $installed );
// If visiting repair.php, return true and let it take over.
if ( defined( 'WP_REPAIRING' ) ) {
$suppress = $wpdb->suppress_errors();
* Loop over the WP tables. If none exist, then scratch installation is allowed.
* If one or more exist, suggest table repair since we got here because the
* options table could not be accessed.
$wp_tables = $wpdb->tables();
foreach ( $wp_tables as $table ) {
// The existence of custom user tables shouldn't suggest an unwise state or prevent a clean installation.
if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE === $table ) {
if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE === $table ) {
$described_table = $wpdb->get_results( "DESCRIBE $table;" );
( ! $described_table && empty( $wpdb->last_error ) ) ||
( is_array( $described_table ) && 0 === count( $described_table ) )
// One or more tables exist. This is not good.
wp_load_translations_early();
/* translators: %s: Database repair URL. */
__( 'One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.' ),
'maint/repair.php?referrer=is_blog_installed'
$wpdb->suppress_errors( $suppress );
wp_cache_set( 'is_blog_installed', false );
* Retrieves URL with nonce added to URL query.
* @param string $actionurl URL to add nonce action.
* @param int|string $action Optional. Nonce action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @return string Escaped URL with nonce action added.
function wp_nonce_url( $actionurl, $action = -1, $name = '_wpnonce' ) {
$actionurl = str_replace( '&', '&', $actionurl );
return esc_html( add_query_arg( $name, wp_create_nonce( $action ), $actionurl ) );
* Retrieves or display nonce hidden field for forms.
* The nonce field is used to validate that the contents of the form came from
* the location on the current site and not somewhere else. The nonce does not
* offer absolute protection, but should protect against most cases. It is very
* important to use nonce field in forms.
* The $action and $name are optional, but if you want to have better security,
* it is strongly suggested to set those two parameters. It is easier to just
* call the function without any parameters, because validation of the nonce
* doesn't require any parameters, but since crackers know what the default is
* it won't be difficult for them to find a way around your nonce and cause
* The input name will be whatever $name value you gave. The input value will be
* the nonce creation value.
* @param int|string $action Optional. Action name. Default -1.
* @param string $name Optional. Nonce name. Default '_wpnonce'.
* @param bool $referer Optional. Whether to set the referer field for validation. Default true.
* @param bool $display Optional. Whether to display or return hidden form field. Default true.
* @return string Nonce field HTML markup.
function wp_nonce_field( $action = -1, $name = '_wpnonce', $referer = true, $display = true ) {
$name = esc_attr( $name );
$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />';
$nonce_field .= wp_referer_field( false );
* Retrieves or displays referer hidden field for forms.
* The referer link is the current Request URI from the server super global. The
* input name is '_wp_http_referer', in case you wanted to check manually.
* @param bool $display Optional. Whether to echo or return the referer field. Default true.
* @return string Referer field HTML markup.
function wp_referer_field( $display = true ) {
$request_url = remove_query_arg( '_wp_http_referer' );
$referer_field = '<input type="hidden" name="_wp_http_referer" value="' . esc_url( $request_url ) . '" />';
* Retrieves or displays original referer hidden field for forms.
* The input name is '_wp_original_http_referer' and will be either the same
* value of wp_referer_field(), if that was posted already or it will be the
* current page, if it doesn't exist.
* @param bool $display Optional. Whether to echo the original http referer. Default true.
* @param string $jump_back_to Optional. Can be 'previous' or page you want to jump back to.
* @return string Original referer field.
function wp_original_referer_field( $display = true, $jump_back_to = 'current' ) {
$ref = wp_get_original_referer();
$ref = ( 'previous' === $jump_back_to ) ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';
echo $orig_referer_field;
return $orig_referer_field;
* Retrieves referer from '_wp_http_referer' or HTTP referer.
* If it's the same as the current request URL, will return false.
* @return string|false Referer URL on success, false on failure.
function wp_get_referer() {
// Return early if called before wp_validate_redirect() is defined.
if ( ! function_exists( 'wp_validate_redirect' ) ) {
$ref = wp_get_raw_referer();
if ( $ref && wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
&& home_url() . wp_unslash( $_SERVER['REQUEST_URI'] ) !== $ref
return wp_validate_redirect( $ref, false );
* Retrieves unvalidated referer from the '_wp_http_referer' URL query variable or the HTTP referer.
* If the value of the '_wp_http_referer' URL query variable is not a string then it will be ignored.
* Do not use for redirects, use wp_get_referer() instead.
* @return string|false Referer URL on success, false on failure.
function wp_get_raw_referer() {
if ( ! empty( $_REQUEST['_wp_http_referer'] ) && is_string( $_REQUEST['_wp_http_referer'] ) ) {
return wp_unslash( $_REQUEST['_wp_http_referer'] );
} elseif ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
return wp_unslash( $_SERVER['HTTP_REFERER'] );