public function isInternal($url)
    {
        // Check if post exist by url (only works with 'public' posts)
        $postId = url_to_postid($url);
        if ($postId > 0) {
            return true;
        }

        // Check if the URL is internal or external
        $siteUrlComponents = parse_url(get_site_url());
        $urlComponents = parse_url($url);
        if (!empty($siteUrlComponents['host']) && !empty($urlComponents['host']) && strcasecmp($urlComponents['host'], $siteUrlComponents['host']) === 0) {
            // Test with get_page_by_path() to get other post statuses
            $postTypes = get_post_types(array('public' => true));
            if (!empty($urlComponents['path']) && !empty(get_page_by_path(basename(untrailingslashit($urlComponents['path'])), ARRAY_A, $postTypes))) {
                return true;
            }
        }

        return false;
    }
public function isInternal($url)
    {
        // Check if post exist by url (only works with 'public' posts)
        $postId = url_to_postid($url);
        if ($postId > 0) {
            return true;
        }

        // Check if the URL is internal or external
        $siteUrlComponents = parse_url(get_site_url());
        $urlComponents = parse_url($url);
        if (!empty($siteUrlComponents['host']) && !empty($urlComponents['host']) && strcasecmp($urlComponents['host'], $siteUrlComponents['host']) === 0) {
            // Test with get_page_by_path() to get other post statuses
            $postTypes = get_post_types(array('public' => true));
            if (!empty($urlComponents['path']) && !empty(get_page_by_path(basename(untrailingslashit($urlComponents['path'])), ARRAY_A, $postTypes))) {
                return true;
            }
        }

        return false;
    }
public function isInternal ( $ url ) { // Check if post exist by url (only works with 'public' posts) $ postId = url_to_postid ( $ url ) ; if ( $ postId > 0 ) { return true ; } // Check if the URL is internal or external $ siteUrlComponents = parse_url ( get_site_url ( ) ) ; $ urlComponents = parse_url ( $ url ) ; if ( ! empty ( $ siteUrlComponents [ 'host' ] ) && ! empty ( $ urlComponents [ 'host' ] ) && strcasecmp ( $ urlComponents [ 'host' ] , $ siteUrlComponents [ 'host' ] ) === 0 ) { // Test with get_page_by_path() to get other post statuses $ postTypes = get_post_types ( array ( 'public' => true ) ) ; if ( ! empty ( $ urlComponents [ 'path' ] ) && ! empty ( get_page_by_path ( basename ( untrailingslashit ( $ urlComponents [ 'path' ] ) ) , ARRAY_A , $ postTypes ) ) ) { return true ; } } return false ; }
Test if URL is internal and page exist
@param string $url Url to check
@return bool
Test if URL is internal and page exist