lash at the end. $path = untrailingslashit( $path ); // Normalize case. $path = String_Utils::lowercase( $path ); // Encode characters. $path = $this->encode_path( $path ); // Always start with a slash. return $this->enforce_starting_slash( $path ); } /** * Encode path. * * @param string $path Path. * * @return string */ private function encode_path( $path ) { $decode = array( '/', ':', '[', ']', '@', '~', ',', '(', ')', ';', '?', ); // Below is just a trick to fix double encoding issue in URL handling. $path = rawurldecode( $path ); // URL encode everything - this converts any i10n to the proper encoding. $path = rawurlencode( $path ); // We also converted things we don't want encoding, such as a /. Change these back. foreach ( $decode as $char ) { $path = str_replace( rawurlencode( $char ), $char, $path ); } return $path; } /** * Prepare destination from destination url. * * @param string $destination Destination url. * * @return string */ private function prepare_destination( $destination ) { return $destination ? $this->prepare_url( $destination ) : ''; } /** * Add starting slash to string. * * @param string $str_val String. * * @return string */ private function enforce_starting_slash( $str_val ) { return '/' . ltrim( $str_val, '/' ); } /** * Make sure url to be absolute url or starting with slash. * * @param string $url Url. * * @return string */ private function prepare_url( $url ) { // Trim. $url = trim( $url ); // Remove new lines. $url = preg_replace( "/[\r\n\t].*?$/s", '', $url ); // Remove control codes. $url = preg_replace( '/[^\PC\s]/u', '', $url ); // Escape. $url = esc_url_raw( $url ); return $this->is_url_absolute( $url ) ? $url : $this->enforce_starting_slash( $url ); } /** * Check if it's absolute url. * * @param string $url Url. * * @return bool */ private function is_url_absolute( $url ) { return strpos( $url, 'http://' ) === 0 || strpos( $url, 'https://' ) === 0; } /** * Retrieves full url including host. * * @param string $url Url. * * @return string */ public function get_full_url( $url ) { if ( ! empty( $url['id'] ) ) { $url = get_permalink( $url['id'] ); } if ( '/' === $url[0] ) { $url = get_site_url() . $url; } return rtrim( $url, '/' ); } /** * Retrieves the URL for the current site where the front end is accessible. * * This is an alternative method for WP core home_url() function to skip all * filters from home_url. * * @since 3.8.2 * * @param string $path Optional. Path relative to the home URL. Default empty. * * @return string Home URL link with optional path appended. */ public function get_unfiltered_home_url( $path = '' ) { $url = get_option( 'home' ); $scheme = is_ssl() ? 'https' : wp_parse_url( $url, PHP_URL_SCHEME ); $url = set_url_scheme( $url, $scheme ); if ( $path && is_string( $path ) ) { $url .= '/' . ltrim( $path, '/' ); } /** * Filters the unfiltered home URL. * * @since 3.8.2 * * @param string $url The complete home URL including scheme and path. * @param string $path Path relative to the home URL. Blank string if no path is specified. * @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https', * 'relative', 'rest', or null. */ return apply_filters( 'smartcrawl_unfiltered_home_url', $url, $path ); } }