public function add_region($region, $custom = true) {
        global $SESSION;
        $this->check_not_yet_loaded();
        if ($custom) {
            if (array_key_exists($region, $this->regions)) {
                // This here is EXACTLY why we should not be adding block regions into a page. It should
                // ALWAYS be done in a theme layout.
                debugging('A custom region conflicts with a block region in the theme.', DEBUG_DEVELOPER);
            }
            // We need to register this custom region against the page type being used.
            // This allows us to check, when performing block actions, that unrecognised regions can be worked with.
            $type = $this->page->pagetype;
            if (!isset($SESSION->custom_block_regions)) {
                $SESSION->custom_block_regions = array($type => array($region));
            } else if (!isset($SESSION->custom_block_regions[$type])) {
                $SESSION->custom_block_regions[$type] = array($region);
            } else if (!in_array($region, $SESSION->custom_block_regions[$type])) {
                $SESSION->custom_block_regions[$type][] = $region;
            }
        }
        $this->regions[$region] = 1;

        // Checking the actual property instead of calling get_default_region as it ends up in a recursive call.
        if (empty($this->defaultregion)) {
            $this->set_default_region($region);
        }
    }