Function Reference: geodir_check_redirect

Summary

Change country slug czech-republic to czechia and redirect.

Parameters

$wp
(object) (required) The WordPress object.

Default: None

Change Log

Since: 1.6.18

Source File

geodir_check_redirect() is located in geodirectory_hooks_actions.php [Line: 2961]

Source Code

function geodir_check_redirect($wp) {
    if (is_404() || (!empty($wp->query_vars['error']) && $wp->query_vars['error'] == '404')) {
        $current_url = geodir_curPageURL();
        $search = 'czech-republic';
        $replace = 'czechia';        
        
        $has_slash = substr($current_url, -1);
        if ($has_slash != "/") {
            $current_url .= '/';
        }
        
        $redirect = false;
        if (strpos($current_url, '/' . $search . '/') !== false) {
            $redirect = true;
            $current_url = preg_replace('/\/' . $search . '\//', '/' . $replace . '/', $current_url, 1);
        }
        
        if ($has_slash != "/") {
            $current_url = trim($current_url, '/');
        }
        
        if (strpos($current_url, 'gd_country=' . $search) !== false) {
            $redirect = true;
            $current_url = str_replace('gd_country=' . $search, 'gd_country=' . $replace, $current_url);
        }

        if ($redirect) {
            wp_redirect($current_url);
            exit;
        }
    }
}