/** * Filters links to the root page, so that they are displayed properly in the front-end. * * @param $url * * @return string */ public function filter_root_permalink($url) { $root_page_utils = $this->sitepress->get_root_page_utils(); if ($root_page_utils->get_root_page_id() > 0 && $root_page_utils->is_url_root_page($url)) { $url_parts = wpml_parse_url($url); $query = isset($url_parts['query']) ? $url_parts['query'] : ''; $path = isset($url_parts['path']) ? $url_parts['path'] : ''; $slugs = array_filter(explode('/', $path)); $last_slug = array_pop($slugs); $new_url = $this->url_converter->get_abs_home(); $new_url = is_numeric($last_slug) ? trailingslashit(trailingslashit($new_url) . $last_slug) : $new_url; $query = $this->unset_page_query_vars($query); $new_url = trailingslashit($new_url); $url = (bool) $query === true ? trailingslashit($new_url) . '?' . $query : $new_url; } return $url; }
/** * @param string $req_uri * @param WPML_URL_Converter $wpml_url_converter * @param bool $directory * * @return string */ function wpml_validate_host($req_uri, $wpml_url_converter, $directory = true) { if ($directory === true) { $req_uri_parts = array_filter(explode('/', $req_uri)); $lang_slug = array_pop($req_uri_parts); if (strpos($lang_slug, '?') === 0) { $lang_slug = array_pop($req_uri_parts); } elseif (strpos($lang_slug, '?') !== false) { $parts = explode('?', $lang_slug); $lang_slug = array_shift($parts); } } else { $lang_slug = ''; } return '<!--' . untrailingslashit(trailingslashit($wpml_url_converter->get_abs_home()) . $lang_slug) . '-->'; }
private function get_sample_url($sample_lang_code) { $abs_home = $this->url_converter->get_abs_home(); return untrailingslashit(trailingslashit($abs_home) . $sample_lang_code); }