wp_reset_vars

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

WordPress Version: 6.1

/**
 * Resets global variables based on $_GET and $_POST.
 *
 * This function resets global variables based on the names passed
 * in the $vars array to the value of $_POST[$var] or $_GET[$var] or ''
 * if neither is defined.
 *
 * @since 2.0.0
 *
 * @param array $vars An array of globals to reset.
 */
function wp_reset_vars($vars)
{
    foreach ($vars as $var) {
        if (empty($_POST[$var])) {
            if (empty($_GET[$var])) {
                $GLOBALS[$var] = '';
            } else {
                $GLOBALS[$var] = $_GET[$var];
            }
        } else {
            $GLOBALS[$var] = $_POST[$var];
        }
    }
}

WordPress Version: 4.0

/**
 * Resets global variables based on $_GET and $_POST
 *
 * This function resets global variables based on the names passed
 * in the $vars array to the value of $_POST[$var] or $_GET[$var] or ''
 * if neither is defined.
 *
 * @since 2.0.0
 *
 * @param array $vars An array of globals to reset.
 */
function wp_reset_vars($vars)
{
    foreach ($vars as $var) {
        if (empty($_POST[$var])) {
            if (empty($_GET[$var])) {
                $GLOBALS[$var] = '';
            } else {
                $GLOBALS[$var] = $_GET[$var];
            }
        } else {
            $GLOBALS[$var] = $_POST[$var];
        }
    }
}

WordPress Version: 3.7

/**
 * Resets global variables based on $_GET and $_POST
 *
 * This function resets global variables based on the names passed
 * in the $vars array to the value of $_POST[$var] or $_GET[$var] or ''
 * if neither is defined.
 *
 * @since 2.0.0
 *
 * @param array $vars An array of globals to reset.
 */
function wp_reset_vars($vars)
{
    for ($i = 0; $i < count($vars); $i += 1) {
        $var = $vars[$i];
        global ${$var};
        if (empty($_POST[$var])) {
            if (empty($_GET[$var])) {
                ${$var} = '';
            } else {
                ${$var} = $_GET[$var];
            }
        } else {
            ${$var} = $_POST[$var];
        }
    }
}