public function get_redirect_target()
 {
     global $wpml_url_filters;
     $target = parent::get_redirect_target();
     $target = $target ? $target : (($filtered_root_url = $wpml_url_filters->filter_root_permalink(wpml_strip_subdir_from_url(site_url()) . $this->request_uri)) !== wpml_strip_subdir_from_url(site_url()) . $this->request_uri ? $filtered_root_url : false);
     if ($target === false) {
         $this->maybe_setup_rootpage();
     }
     return $target;
 }
Пример #2
0
 /**
  *
  * @param string $url
  * @param bool   $only_admin If set to true only language parameters on Admin Screen URLs will be recognized. The
  *                           function will return null for non-Admin Screens.
  *
  * @return null|String Language code
  */
 protected function lang_by_param($url, $only_admin = true)
 {
     if (isset($this->cache[$url])) {
         return $this->cache[$url];
     }
     $url = wpml_strip_subdir_from_url($url);
     $url_query_parts = parse_url($url);
     $url_query = ($only_admin === false || isset($url_query_parts['path']) && strpos($url_query_parts['path'], '/wp-admin') === 0) && isset($url_query_parts['query']) ? untrailingslashit($url_query_parts['query']) : null;
     if (isset($url_query)) {
         parse_str($url_query, $vars);
         if (isset($vars['lang']) && ($only_admin === true && $vars['lang'] === 'all' || in_array($vars['lang'], $this->active_languages, true))) {
             $lang = $vars['lang'];
         }
     }
     $lang = isset($lang) ? $lang : null;
     $this->cache[$url] = $lang;
     return $lang;
 }
 protected function get_lang_from_url_string($url)
 {
     $url = wpml_strip_subdir_from_url($url);
     if (strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0) {
         $url_path = parse_url($url, PHP_URL_PATH);
     } else {
         $pathparts = array_filter(explode('/', $url));
         if (count($pathparts) > 1) {
             unset($pathparts[0]);
             $url_path = implode('/', $pathparts);
         } else {
             $url_path = $url;
         }
     }
     $fragments = array_filter((array) explode("/", $url_path));
     $lang = array_shift($fragments);
     $lang_get_parts = explode('?', $lang);
     $lang = $lang_get_parts[0];
     return $lang && in_array($lang, $this->active_languages) ? $lang : ($this->dir_default ? null : $this->default_language);
 }
Пример #4
0
 function init()
 {
     do_action('wpml_before_init');
     global $wpdb;
     $this->get_user_preferences();
     $this->set_admin_language();
     $default_language = $this->get_default_language();
     // default value for theme_localization_type OR
     // reset theme_localization_type if string translation was on (theme_localization_type was set to 2) and then it was deactivated
     if (!isset($this->settings['theme_localization_type']) || $this->settings['theme_localization_type'] == 1 && !defined('WPML_ST_VERSION') && !defined('WPML_DOING_UPGRADE')) {
         global $sitepress_settings;
         $this->settings['theme_localization_type'] = $sitepress_settings['theme_localization_type'] = 2;
     }
     //configure callbacks for plugin menu pages
     if (defined('WP_ADMIN') && isset($_GET['page']) && 0 === strpos($_GET['page'], basename(ICL_PLUGIN_PATH) . '/')) {
         add_action('icl_menu_footer', array($this, 'menu_footer'));
     }
     //Run only if existing content language has been verified, and is front-end or settings are not corrupted
     if (!empty($this->settings['existing_content_language_verified']) && (!is_admin() || SitePress::check_settings_integrity())) {
         if ($this->settings['language_negotiation_type'] == 1 && $this->settings['urls']['directory_for_default_language'] && $this->settings['urls']['show_on_root'] == 'page') {
             include ICL_PLUGIN_PATH . '/inc/home-url-functions.php';
         }
         if ($this->settings['language_negotiation_type'] == 2) {
             add_filter('allowed_redirect_hosts', array($this, 'allowed_redirect_hosts'));
         }
         if (defined('WP_ADMIN')) {
             if ($this->settings['language_negotiation_type'] == 2) {
                 //Login and Logout
                 add_filter('login_url', array($this, 'convert_url'));
                 add_filter('logout_url', array($this, 'convert_url'));
                 add_filter('site_url', array($this, 'convert_url'));
             }
             if (isset($_GET['post']) && is_numeric($_GET['post'])) {
                 $post_type = get_post_type($_GET['post']);
             }
             $current_user = wp_get_current_user();
             if (isset($_GET['lang'])) {
                 $this->this_lang = rtrim(strip_tags($_GET['lang']), '/');
                 $al = $this->get_active_languages();
                 $al['all'] = true;
                 if (empty($al[$this->this_lang])) {
                     $this->this_lang = $default_language;
                 }
                 // force default language for string translation
                 // we also make sure it's not saved in the cookie
             } elseif (isset($_GET['page']) && (defined('WPML_ST_FOLDER') && $_GET['page'] == WPML_ST_FOLDER . '/menu/string-translation.php' || defined('WPML_TM_FOLDER') && $_GET['page'] == WPML_TM_FOLDER . '/menu/translations-queue.php')) {
                 $this->this_lang = $default_language;
             } elseif (wpml_is_ajax()) {
                 $al = $this->get_active_languages();
                 if (isset($_POST['lang']) && isset($al[$_POST['lang']])) {
                     $this->this_lang = $_POST['lang'];
                 } else {
                     if ($this->check_if_admin_action_from_referer()) {
                         $this->this_lang = $this->get_admin_language_cookie();
                     } elseif (isset($_SERVER['HTTP_REFERER'])) {
                         $this->this_lang = $this->get_language_from_url($_SERVER['HTTP_REFERER']);
                     } elseif ($this->get_language_cookie()) {
                         $this->this_lang = $this->get_language_cookie();
                     } else {
                         $this->this_lang = $this->get_default_language();
                     }
                 }
             } elseif ($lang = $this->get_admin_language_cookie()) {
                 $this->this_lang = $lang;
             } elseif (isset($_POST['action']) && $_POST['action'] == 'editpost' && isset($_POST['icl_post_language'])) {
                 $this->this_lang = $_POST['icl_post_language'];
             } elseif (isset($_GET['post']) && is_numeric($_GET['post']) && isset($post_type) && $this->is_translated_post_type($post_type)) {
                 $this->this_lang = $this->get_language_for_element($_GET['post'], 'post_' . $post_type);
             } elseif (isset($current_user->data)) {
                 $lang = $this->get_user_admin_language($current_user->data->ID);
                 $this->this_lang = $lang ? $lang : $default_language;
             }
             $update_admin_language_cookie = false;
             $update_admin_language_cookie |= (is_admin() && !wpml_is_ajax() || wpml_is_ajax() && $this->check_if_admin_action_from_referer()) && isset($_GET['lang']) && $this->get_current_language() != $this->get_admin_language_cookie();
             $update_admin_language_cookie |= isset($_GET['admin_bar']) && $_GET['admin_bar'] == 1 && !isset($_GET['page']);
             $update_admin_language_cookie |= !defined('WPML_ST_FOLDER') || isset($_GET['page']) && $_GET['page'] != WPML_ST_FOLDER . '/menu/string-translation.php';
             $update_admin_language_cookie |= !$this->get_admin_language_cookie();
             if ($update_admin_language_cookie) {
                 $this->set_admin_language_cookie();
             }
         } else {
             $al = $this->get_active_languages();
             foreach ($al as $l) {
                 $active_languages[] = $l['code'];
             }
             $active_languages[] = 'all';
             $s = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '';
             $home = get_home_url();
             if ($s) {
                 $home = preg_replace('#^http://#', 'https://', $home);
             }
             $url_parts = parse_url($home);
             $non_default_port = isset($url_parts['port']) && $url_parts['port'] != 80 ? ':' . $url_parts['port'] : '';
             $request = 'http' . $s . '://' . $this->get_server_host_name() . $_SERVER['REQUEST_URI'];
             $blog_path = !empty($url_parts['path']) ? $url_parts['path'] : '';
             switch ($this->settings['language_negotiation_type']) {
                 case 1:
                     $path = str_replace($home, '', $request);
                     $parts = explode('?', $path);
                     $path = $parts[0];
                     $exp = explode('/', trim($path, '/'));
                     $language_part = $exp[0];
                     if (in_array($language_part, $active_languages)) {
                         $this->this_lang = $exp[0];
                         // before hijacking the SERVER[REQUEST_URI]
                         // override the canonical_redirect action
                         // keep a copy of the original request uri
                         remove_action('template_redirect', 'redirect_canonical');
                         global $_icl_server_request_uri;
                         $_icl_server_request_uri = $_SERVER['REQUEST_URI'];
                         add_action('template_redirect', array($this, 'icl_redirect_canonical_wrapper'), 0);
                         //deal with situations when template files need to be called directly
                         add_action('template_redirect', array($this, '_allow_calling_template_file_directly'));
                         //$_SERVER['REQUEST_URI'] = preg_replace('@^'. $blog_path . '/' . $this->this_lang.'@i', $blog_path ,$_SERVER['REQUEST_URI']);
                         // Check for special case of www.example.com/fr where the / is missing on the end
                         $parts = parse_url($_SERVER['REQUEST_URI']);
                         if (strlen($parts['path']) == 0) {
                             $_SERVER['REQUEST_URI'] = '/' . $_SERVER['REQUEST_URI'];
                         }
                     } else {
                         $this->this_lang = $default_language;
                     }
                     /* If we access the root url via a non root slug/parameter combination,
                      * we redirect accordingly.
                      */
                     if ($this->settings['language_negotiation_type'] == 1 && $this->settings['urls']['directory_for_default_language'] && $this->settings['urls']['show_on_root'] == 'page') {
                         $filtered_root_url = WPML_Root_Page::filter_root_permalink(wpml_strip_subdir_from_url(site_url()) . $_SERVER['REQUEST_URI']);
                         if ($filtered_root_url != wpml_strip_subdir_from_url(site_url()) . $_SERVER['REQUEST_URI']) {
                             wp_redirect($filtered_root_url, 302);
                             exit;
                         }
                     }
                     if (WPML_Root_Page::is_current_request_root()) {
                         if ($this->settings['urls']['show_on_root'] == 'html_file') {
                             // html file
                             if (false === strpos($this->settings['urls']['root_html_file_path'], '/')) {
                                 $html_file = ABSPATH . $this->settings['urls']['root_html_file_path'];
                             } else {
                                 $html_file = $this->settings['urls']['root_html_file_path'];
                             }
                             /** @noinspection PhpIncludeInspection */
                             include $html_file;
                             exit;
                         } else {
                             wpml_home_url_setup_root_page();
                         }
                     }
                     break;
                 case 2:
                     $this->this_lang = $default_language;
                     foreach ($this->settings['language_domains'] as $language_code => $domain) {
                         if (rtrim($this->get_server_host_name() . $blog_path, '/') == rtrim(preg_replace('@^https?://@', '', $domain), '/')) {
                             $this->this_lang = $language_code;
                             break;
                         }
                     }
                     if (defined('ICL_USE_MULTIPLE_DOMAIN_LOGIN') && ICL_USE_MULTIPLE_DOMAIN_LOGIN) {
                         include ICL_PLUGIN_PATH . '/modules/multiple-domains-login.php';
                     }
                     add_filter('site_url', array($this, 'convert_url'));
                     break;
                 case 3:
                 default:
                     if (isset($_GET['lang'])) {
                         $this->this_lang = preg_replace("/[^0-9a-zA-Z-]/i", '', strip_tags($_GET['lang']));
                         // set the language based on the content id - for short links
                     } elseif (isset($_GET['page_id'])) {
                         $language_code_prepared = $wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type='post_page' AND element_id=%d", $_GET['page_id']);
                         $this->this_lang = $wpdb->get_var($language_code_prepared);
                     } elseif (isset($_GET['p'])) {
                         $post_type_prepared = $wpdb->prepare("SELECT post_type FROM {$wpdb->posts} WHERE ID=%d", $_GET['p']);
                         $post_type = $wpdb->get_var($post_type_prepared);
                         $language_code_prepared = $wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d", 'post_' . $post_type, $_GET['p']);
                         $this->this_lang = $wpdb->get_var($language_code_prepared);
                     } elseif (isset($_GET['cat_ID'])) {
                         $cat_tax_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", $_GET['cat_ID'], 'category');
                         $cat_tax_id = $wpdb->get_var($cat_tax_id_prepared);
                         $language_code_prepared = $wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type='tax_category' AND element_id=%d", $cat_tax_id);
                         $this->this_lang = $wpdb->get_var($language_code_prepared);
                     } elseif (isset($_GET['tag'])) {
                         $tag_tax_id_prepared = $wpdb->prepare("\r\n\t\t\t\t\t\t\t\t\t SELECT x.term_taxonomy_id FROM {$wpdb->term_taxonomy} x JOIN {$wpdb->terms} t ON t.term_id = x.term_id\r\n\t\t\t\t\t\t\t\t\t WHERE t.slug=%s AND x.taxonomy='post_tag'", $_GET['tag']);
                         $tag_tax_id = $wpdb->get_var($tag_tax_id_prepared);
                         $language_code_prepared = $wpdb->prepare("SELECT language_code FROM {$wpdb->prefix}icl_translations\r\n\t\t\t\t\t\t\t\t\t WHERE element_type='tax_post_tag' AND element_id=%d", $tag_tax_id);
                         $this->this_lang = $wpdb->get_var($language_code_prepared);
                     }
                     //
                     if (!isset($_GET['lang']) && ($this->this_lang && $this->this_lang != $default_language)) {
                         if (!isset($GLOBALS['wp_rewrite'])) {
                             require_once ABSPATH . WPINC . '/rewrite.php';
                             $GLOBALS['wp_rewrite'] = new WP_Rewrite();
                         }
                         define('ICL_DOING_REDIRECT', true);
                         if (isset($_GET['page_id'])) {
                             wp_redirect(get_page_link($_GET['page_id']), '301');
                             exit;
                         } elseif (isset($_GET['p'])) {
                             wp_redirect(get_permalink($_GET['p']), '301');
                             exit;
                         } elseif (isset($_GET['cat_ID'])) {
                             wp_redirect(get_term_link(intval($_GET['cat_ID']), 'category'));
                             exit;
                         } elseif (isset($_GET['tag'])) {
                             wp_redirect(get_term_link($_GET['tag'], 'post_tag'));
                             exit;
                         } else {
                             if (isset($this->settings['taxonomies_sync_option'])) {
                                 $taxs = array_keys((array) $this->settings['taxonomies_sync_option']);
                                 foreach ($taxs as $t) {
                                     if (isset($_GET[$t])) {
                                         $term_obj = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON t.term_id = x.term_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE t.slug=%s AND x.taxonomy=%s", $_GET[$t], $t));
                                         $term_link = get_term_link($term_obj, $t);
                                         $term_link = str_replace('&', '&', $term_link);
                                         // fix
                                         if ($term_link && !is_wp_error($term_link)) {
                                             wp_redirect($term_link);
                                             exit;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (empty($this->this_lang)) {
                         $this->this_lang = $default_language;
                     }
             }
             // allow forcing the current language when it can't be decoded from the URL
             $this->this_lang = apply_filters('icl_set_current_language', $this->this_lang);
         }
         //reorder active language to put 'this_lang' in front
         foreach ($this->active_languages as $k => $al) {
             if ($al['code'] == $this->this_lang) {
                 unset($this->active_languages[$k]);
                 $this->active_languages = array_merge(array($k => $al), $this->active_languages);
             }
         }
         WPML_Troubleshooting_Terms_Menu::display_terms_with_suffix_admin_notice();
         // filter some queries
         add_filter('query', array($this, 'filter_queries'));
         add_filter('option_rewrite_rules', array($this, 'rewrite_rules_filter'));
         $this->set_language_cookie();
         if (is_admin() && (!isset($_GET['page']) || !defined('WPML_ST_FOLDER') || $_GET['page'] != WPML_ST_FOLDER . '/menu/string-translation.php') && (!isset($_GET['page']) || !defined('WPML_TM_FOLDER') || $_GET['page'] != WPML_TM_FOLDER . '/menu/translations-queue.php')) {
             if (version_compare($GLOBALS['wp_version'], '3.3', '<')) {
                 // Legacy code for admin language switcher
                 if (!$this->is_rtl() && version_compare($GLOBALS['wp_version'], '3.3', '>')) {
                     add_action('admin_notices', 'wpml_set_admin_language_switcher_place', 100);
                     add_action('network_admin_notices', 'wpml_set_admin_language_switcher_place', 100);
                     add_action('user_admin_notices', 'wpml_set_admin_language_switcher_place', 100);
                     function wpml_set_admin_language_switcher_place()
                     {
                         echo '<br clear="all" />';
                     }
                 }
                 add_action('in_admin_header', array($this, 'admin_language_switcher_legacy'));
             } else {
                 // Admin language switcher goes to the WP admin bar
                 add_action('wp_before_admin_bar_render', array($this, 'admin_language_switcher'));
             }
         }
         if (!is_admin() && defined('DISQUS_VERSION')) {
             include ICL_PLUGIN_PATH . '/modules/disqus.php';
         }
     }
     /*
      * If user perform bulk taxonomy deletion when displaying non-default
      * language taxonomies, after deletion should stay with same language
      */
     if (is_admin() && isset($_POST['_wp_http_referer']) && false !== strpos($_POST['_wp_http_referer'], 'edit-tags.php') && !empty($_POST['delete_tags']) && is_array($_POST['delete_tags']) && !empty($_GET['lang']) && ($_POST['action'] == 'delete' || $_POST['action2'] == 'delete')) {
         add_filter('wp_redirect', array($this, 'preserve_lang_param_after_bulk_category_delete'));
     }
     if ($this->is_rtl()) {
         $GLOBALS['text_direction'] = 'rtl';
     }
     if (!wpml_is_ajax() && is_admin() && empty($this->settings['dont_show_help_admin_notice'])) {
         if (!$this->get_setting('setup_wizard_step')) {
             if (SitePress::check_settings_integrity()) {
                 add_action('admin_notices', array($this, 'help_admin_notice'));
             }
         }
     }
     $short_v = implode('.', array_slice(explode('.', ICL_SITEPRESS_VERSION), 0, 3));
     if (is_admin() && (!isset($this->settings['hide_upgrade_notice']) || $this->settings['hide_upgrade_notice'] != $short_v)) {
         add_action('admin_notices', array($this, 'upgrade_notice'));
     }
     require ICL_PLUGIN_PATH . '/inc/template-constants.php';
     if (defined('WPML_LOAD_API_SUPPORT')) {
         require ICL_PLUGIN_PATH . '/inc/wpml-api.php';
     }
     add_action('wp_footer', array($this, 'display_wpml_footer'), 20);
     if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) {
         add_action('xmlrpc_call', array($this, 'xmlrpc_call_actions'));
         add_filter('xmlrpc_methods', array($this, 'xmlrpc_methods'));
     }
     if (defined('WPML_TM_VERSION') && is_admin()) {
         require ICL_PLUGIN_PATH . '/inc/quote.php';
     }
     add_action('init', array($this, 'set_up_language_selector'));
     global $pagenow;
     // set language to default and remove language switcher when in Taxonomy Translation page
     // If the page uses AJAX and the language must be forced to default, please use the
     // if ( $pagenow == 'admin-ajax.php' )above
     if (is_admin() && (isset($_GET['page']) && ($_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/taxonomy-translation.php' || $_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/menus-sync.php' || $_GET['page'] == ICL_PLUGIN_FOLDER . '/menu/taxonomy-translation-display.class.php') || $pagenow == 'admin-ajax.php' && isset($_POST['action']) && $_POST['action'] == 'wpml_tt_save_labels_translation')) {
         $default_language = $this->get_admin_language();
         $this->switch_lang($default_language, true);
         add_action("admin_init", array("WPML_Taxonomy_Translation_Table_Display", "enqueue_taxonomy_table_js"));
         add_action('init', array($this, 'remove_admin_language_switcher'));
     }
     /* Posts and new inline created terms, can only be saved in an active language.
      * Also the content of the post-new.php should always be filtered for one specific
      * active language, so to display the correct taxonomy terms for selection.
      */
     if ($pagenow == 'post-new.php') {
         if (!$this->is_active_language($this->get_current_language())) {
             $default_language = $this->get_admin_language();
             $this->switch_lang($default_language, true);
         }
     }
     //Code to run when reactivating the plugin
     $recently_activated = $this->get_setting('just_reactivated');
     if ($recently_activated) {
         add_action('init', array($this, 'rebuild_language_information'), 1000);
     }
     do_action('wpml_after_init');
 }
Пример #5
0
 /**
  * @param $requested_url string
  *
  * Takes a request_url in the format of $_SERVER['REQUEST_URI']
  * and returns an associative array containing its slugs ans query string.
  *
  * @return array
  */
 private static function get_slugs_and_get_query($requested_url)
 {
     $result = array();
     $request_path = parse_url($requested_url, PHP_URL_PATH);
     $request_path = wpml_strip_subdir_from_url($request_path);
     $slugs = self::get_slugs_array($request_path);
     $result['slugs'] = $slugs;
     $query_string = parse_url($requested_url, PHP_URL_QUERY);
     $result['querystring'] = !$query_string ? '' : $query_string;
     return $result;
 }
Пример #6
0
 /**
  * @param bool|String $requested_url String If this is specified the value of $url will be checked for whether it's the root page.
  *                       Checks whether the currently requested page is the root page.
  *
  * @return bool
  */
 function is_root_page($requested_url = false)
 {
     /*
      * A request leads to the root page under the following conditions.
      *
      * 1. The get parameter on it specifically requests the root page via either:
      *  ?preview_id = {root_page_id}
      *  ?page_id = {root_page_id}
      *  ?p = {root_page_id}
      *
      * 2. The root page slug is the first slug after the domain.
      *
      * 3. There is no slug after the domain and the get parameters are not set as to redirect
      *    to another page meaning:
      *  no ?p, ?page_id or similar query parameter redirects to another post/page
      *  no get parameter such as ?cat redirects to an archive page
      *
      */
     $is_root = true;
     // before checking anything see if the site even uses a root page
     $urls = $this->get_setting('urls');
     if (!$urls || !isset($urls['directory_for_default_language']) || !$urls['directory_for_default_language'] || !isset($urls['root_page']) || $urls['root_page'] == 0) {
         $is_root = false;
     } elseif (isset($_SERVER['REQUEST_URI']) || $requested_url !== false) {
         $root_id = $urls['root_page'];
         $root_slug = false;
         if ($root_id) {
             $root_page_object = get_post($root_id);
             if ($root_page_object && isset($root_page_object->post_name)) {
                 $root_slug = $root_page_object->post_name;
             }
         }
         if ($root_slug === false) {
             $is_root = false;
         } else {
             if ($requested_url) {
                 $request_uri = parse_url($requested_url, PHP_URL_PATH);
                 $query_string = parse_url($requested_url, PHP_URL_QUERY);
                 if ($query_string) {
                     $request_uri .= '?' . $query_string;
                 }
             } else {
                 $request_uri = $_SERVER['REQUEST_URI'];
             }
             //If the get parameter ? is not preceeded by a /, add a '/'
             if (strpos($request_uri, '?') !== false && strpos($request_uri, '/?') === false) {
                 $request_uri = str_replace('?', '/?', $request_uri);
             }
             $request_uri = wpml_strip_subdir_from_url($request_uri);
             //First get the slug of the requested url, should there be one.
             $slugs_and_get_params = explode('/', $request_uri);
             foreach ($slugs_and_get_params as $key => $slug) {
                 if (!trim($slug)) {
                     unset($slugs_and_get_params[$key]);
                 }
             }
             // if we have any slugs or get parameters it could be we are not on the root page
             if (!empty($slugs_and_get_params)) {
                 $get_query_string = '';
                 // First of all see if we have get parameters
                 if (isset($_GET) && !empty($_GET)) {
                     $get_query_string = array_pop($slugs_and_get_params);
                     /* In case we have get parameters we can instantly be sure to be on the root page
                      * This can be done by either id parameters or by slug/name parameters.
                      * ID parametes as of WP 4.1 are : p, page_id
                      * Name parameters as of WP 4.1 are: name, pagename
                      */
                     if (isset($_GET['p']) && $_GET['p'] != $root_id || isset($_GET['page_id']) && $_GET['page_id'] != $root_id || isset($_GET['name']) && $_GET['name'] != $root_slug || isset($_GET['pagename']) && $_GET['pagename'] != $root_slug) {
                         $is_root = false;
                     }
                 }
                 /*
                  * Next up there are other get parameters that allow us to recognize not being on the root page for certain.
                  * These only come into play when neither of the above page parameters is set and therefore no specific page is queried for.
                  */
                 if (!(isset($_GET['pagename']) || isset($_GET['name']) || isset($_GET['page_id']) || isset($_GET['p']))) {
                     /* The under these conditions excluded parameters, that ensure the root page to not be queried for, are determined in this way:
                      * First we fetch all rewrite rules. This has to be done from the options cache since the actual rewrite object is not initialized yet.
                      * Initializing it would impose a siginificant performance hit too.
                      */
                     $query = new WP_Query(str_replace('?', '', $get_query_string));
                     if ($query->is_archive()) {
                         $is_root = false;
                     }
                 }
                 // In case we have slugs, we need to check the last slug for whether it is the slug of the root page
                 if ($is_root && !empty($slugs_and_get_params)) {
                     $slugs = $slugs_and_get_params;
                     $last_slug = array_pop($slugs);
                     $second_slug = array_pop($slugs);
                     if (($root_slug != $last_slug && !is_numeric($last_slug) || is_numeric($last_slug) && $second_slug != null && $root_slug != $second_slug && 'page' != $second_slug) && (!(isset($_GET['p']) && $_GET['p'] == $root_id) || !(isset($_GET['page_id']) && $_GET['page_id'] == $root_id) || !(isset($_GET['name']) && $_GET['name'] == $root_slug) || !(isset($_GET['pagename']) && $_GET['pagename'] == $root_slug))) {
                         /* If the last slug is not the root slug or numeric,
                          * then the current page is not the root page. This condition only holds though
                          * in case no page/post parameters are appended to the request, that point towards the root page.
                          */
                         $is_root = false;
                     }
                 }
             }
         }
     }
     return $is_root;
 }