Alternative_Heap::maybe_create_alt_heap PHP Method

maybe_create_alt_heap() public method

if $_GET[alt_heap] is defined and (@TODO: user has permissions), create that heap and return to it
    public function maybe_create_alt_heap()
    {
        if (!isset($_GET['alt_heap'])) {
            return;
            // nothing to do;
        }
        $query_vars = $_GET;
        $alt_heap = $query_vars['alt_heap'];
        if ($alt_heap === 'clear') {
            // this means we want to clear the heap cookie
            // equivalent to empty ?alt_heap=
            $alt_heap = '';
        }
        // not in a heap yet and GET alt_heap is defined and current user has plugin install privileges
        if (!empty($alt_heap) && current_user_can('install_plugins') && !currheap()) {
            // create plugins dir for alt_heap
            $this->create_alt_plugins_dir($alt_heap);
            // clone tables for alt_heap
            $this->clone_wp_tables($alt_heap);
            // set the _alt_heap cookie
            setcookie('_alt_heap', $alt_heap, 0, '/');
        } else {
            // clear the alt heap cookie
            setcookie('_alt_heap', '', 0, '/');
        }
        // no need for alt_heap in query string anymore
        unset($query_vars['alt_heap']);
        // rebuild query string
        $query_string = http_build_query($query_vars);
        $request_uri = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));
        $request_uri .= empty($query_string) ? '' : '?' . $query_string;
        // redirect to requested page, but with alt heap this time
        wp_redirect($request_uri);
        exit;
    }