Esempio n. 1
0
/**
 * Redirects to a URL corrected for the language information in it, in case request URI and $_REQUEST['lang'],
 * requested domain or $_SERVER['REQUEST_URI'] do not match and gives precedence to the explicit language parameter if
 * there.
 *
 * @return string The language code of the currently requested URL in case no redirection was necessary.
 */
function wpml_maybe_frontend_redirect()
{
    /** @var WPML_Redirection $redirect_helper */
    list($redirect_helper, $language_code) = _wpml_get_redirect_helper($_SERVER['REQUEST_URI'], $_SERVER['HTTP_HOST']);
    if (($target = $redirect_helper->get_redirect_target()) !== false) {
        wp_safe_redirect($target);
        exit;
    }
    // allow forcing the current language when it can't be decoded from the URL
    return apply_filters('icl_set_current_language', $language_code);
}
Esempio n. 2
0
 /**
  * Sets the current language in \SitePress::$this_lang, redirects if
  * frontend requests point to incomplete or incorrect urls, un-sets the
  * $_GET['lang'] and $_GET['admin_bar'] values so that upload.php is able to
  * enqueue 'media-grid' correctly without url parameters breaking its
  * functionality.
  */
 public function maybe_set_this_lang()
 {
     global $wpml_request_handler, $pagenow, $wpml_language_resolution;
     if (!defined('WP_ADMIN') && isset($_SERVER['HTTP_HOST']) && did_action('init')) {
         require_once ICL_PLUGIN_PATH . '/inc/request-handling/redirection/wpml-frontend-redirection.php';
         /** @var WPML_Frontend_Request $wpml_request_handler */
         $redirect_helper = _wpml_get_redirect_helper();
         $redirection = new WPML_Frontend_Redirection($this, $wpml_request_handler, $redirect_helper, $wpml_language_resolution);
         $this->this_lang = $redirection->maybe_redirect();
     } else {
         $this->this_lang = $wpml_request_handler->get_requested_lang();
     }
     $wpml_request_handler->set_language_cookie($this->this_lang);
     if ($pagenow === 'upload.php') {
         $_GET['lang'] = null;
         $_GET['admin_bar'] = null;
     }
 }
 public function maybe_set_this_lang()
 {
     global $wpml_request_handler;
     if (!defined('WP_ADMIN') && isset($_SERVER['HTTP_HOST']) && did_action('init')) {
         require ICL_PLUGIN_PATH . '/inc/request-handling/redirection/wpml-frontend-redirection.php';
         $redirect_helper = _wpml_get_redirect_helper();
         $redirection = new WPML_Frontend_Redirection($this, $wpml_request_handler, $redirect_helper);
         $this->this_lang = $redirection->maybe_redirect();
     } else {
         $this->this_lang = $wpml_request_handler->get_requested_lang();
     }
     $wpml_request_handler->set_language_cookie($this->this_lang);
 }