sanitize_url

The timeline below displays how wordpress function sanitize_url has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Sanitizes a URL for database or redirect usage.
 *
 * @since 2.3.1
 * @since 2.8.0 Deprecated in favor of esc_url_raw().
 * @since 5.9.0 Restored (un-deprecated).
 *
 * @see esc_url()
 *
 * @param string   $url       The URL to be cleaned.
 * @param string[] $protocols Optional. An array of acceptable protocols.
 *                            Defaults to return value of wp_allowed_protocols().
 * @return string The cleaned URL after esc_url() is run with the 'db' context.
 */
function sanitize_url($url, $protocols = null)
{
    return esc_url($url, $protocols, 'db');
}

WordPress Version: 5.9

/**
 * Performs esc_url() for database or redirect usage.
 *
 * This function is an alias for esc_url_raw().
 *
 * @since 2.3.1
 * @since 2.8.0 Deprecated in favor of esc_url_raw().
 * @since 5.9.0 Restored (un-deprecated).
 *
 * @see esc_url_raw()
 *
 * @param string   $url       The URL to be cleaned.
 * @param string[] $protocols Optional. An array of acceptable protocols.
 *                            Defaults to return value of wp_allowed_protocols().
 * @return string The cleaned URL after esc_url() is run with the 'db' context.
 */
function sanitize_url($url, $protocols = null)
{
    return esc_url_raw($url, $protocols);
}

WordPress Version: 4.6

/**
 * Performs esc_url() for database or redirect usage.
 *
 * @since 2.3.1
 * @deprecated 2.8.0 Use esc_url_raw()
 * @see esc_url_raw()
 *
 * @param string $url The URL to be cleaned.
 * @param array $protocols An array of acceptable protocols.
 * @return string The cleaned URL.
 */
function sanitize_url($url, $protocols = null)
{
    _deprecated_function(__FUNCTION__, '2.8.0', 'esc_url_raw()');
    return esc_url_raw($url, $protocols);
}

WordPress Version: 4.4

/**
 * Performs esc_url() for database or redirect usage.
 *
 * @since 2.3.1
 * @deprecated 2.8.0 Use esc_url_raw()
 * @see esc_url_raw()
 *
 * @param string $url The URL to be cleaned.
 * @param array $protocols An array of acceptable protocols.
 * @return string The cleaned URL.
 */
function sanitize_url($url, $protocols = null)
{
    _deprecated_function(__FUNCTION__, '2.8', 'esc_url_raw()');
    return esc_url_raw($url, $protocols);
}

WordPress Version: 3.7

/**
 * Performs esc_url() for database or redirect usage.
 *
 * @since 2.3.1
 * @deprecated 2.8.0
 * @deprecated Use esc_url_raw()
 * @see esc_url_raw()
 *
 * @param string $url The URL to be cleaned.
 * @param array $protocols An array of acceptable protocols.
 * @return string The cleaned URL.
 */
function sanitize_url($url, $protocols = null)
{
    _deprecated_function(__FUNCTION__, '2.8', 'esc_url_raw()');
    return esc_url_raw($url, $protocols);
}