/** * Returns the home URL. * * @since 4.7.3 * * @param bool $unfiltered Whether to get the unfiltered value. * @return string The home URL. */ private function getHomeUrl( $unfiltered = false ) { $homeUrl = home_url(); if ( $unfiltered ) { // We want to get this value straight from the DB to prevent plugins like WPML from filtering it. // This will otherwise mess with things like license activation requests and redirects. $homeUrl = get_option( 'home' ); } return $homeUrl; } /** * Checks if the given URL is an internal URL for the current site. * * @since 4.2.6 * * @param string $urlToCheck The URL to check. * @return bool Whether the given URL is an internal one. */ public function isInternalUrl( $urlToCheck ) { $parsedHomeUrl = wp_parse_url( home_url() ); $parsedUrlToCheck = wp_parse_url( $urlToCheck ); return ! empty( $parsedHomeUrl['host'] ) && ! empty( $parsedUrlToCheck['host'] ) ? $parsedHomeUrl['host'] === $parsedUrlToCheck['host'] : false; } /** * Helper for the rest url. * * @since 4.4.9 * * @return string */ public function getRestUrl() { $restUrl = get_rest_url(); if ( aioseo()->helpers->isWpmlActive() ) { global $sitepress; // Replace the rest url 'all' language prefix so our rest calls don't fail. if ( is_object( $sitepress ) && method_exists( $sitepress, 'get_current_language' ) && method_exists( $sitepress, 'get_default_language' ) && 'all' === $sitepress->get_current_language() ) { $restUrl = str_replace( get_home_url( null, '/all/' ), get_home_url( null, '/' . $sitepress->get_default_language() . '/' ), $restUrl ); } } return $restUrl; } /** * Exclude the home path from a full path. * * @since 1.2.3 Moved from aioseo-redirects. * @version 4.5.8 * * @param string $path The original path. * @return string The path without WP's home path. */ public function excludeHomePath( $path ) { return preg_replace( '@^' . $this->getHomePath() . '@', '/', $path ); } /** * Get the canonical URL for a post. * This is a duplicate of wp_get_canonical_url() with a fix for issue #6372 where * posts with paginated comment pages return the wrong canonical URL due to how WordPress sets the cpage var. * We can remove this once trac ticket 60806 is resolved. * * @since 4.6.9 * * @param \WP_Post|int|null $post The post object or ID. * @return string|false The post's canonical URL, or false if the post is not published. */ public function wpGetCanonicalUrl( $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } if ( 'publish' !== $post->post_status ) { return false; } $canonical_url = get_permalink( $post ); // If a canonical is being generated for the current page, make sure it has pagination if needed. if ( get_queried_object_id() === $post->ID ) { $page = get_query_var( 'page', 0 ); if ( $page >= 2 ) { if ( ! get_option( 'permalink_structure' ) ) { $canonical_url = add_query_arg( 'page', $page, $canonical_url ); } else { $canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' ); } } $cpage = aioseo()->helpers->getCommentPageNumber(); // We're calling our own function here to get the correct cpage number. if ( $cpage ) { $canonical_url = get_comments_pagenum_link( $cpage ); } } return apply_filters( 'get_canonical_url', $canonical_url, $post ); } }