0, 'duplicates' => array(), 'broken' => array(), 'noindex_leaks' => array(), 'ok' => true, ); if ( ! is_string( $content ) || '' === $content ) { return $report; } // Extract markdown links: - [title](url) $matches = array(); if ( ! preg_match_all( '/\[[^\]]*\]\((https?:\/\/[^)\s]+)\)/', $content, $matches ) ) { return $report; } $urls = $matches[1]; $report['urls'] = count( $urls ); // Duplicates. $counted = array_count_values( $urls ); foreach ( $counted as $url => $n ) { if ( $n > 1 ) { $report['duplicates'][] = $url; } } // Broken internal links + noindex leaks. $home = home_url(); foreach ( array_unique( $urls ) as $url ) { if ( 0 !== strpos( $url, $home ) ) { continue; // External link — not validated here. } $post_id = url_to_postid( $url ); if ( 0 === $post_id ) { // Front page or non-post URL — acceptable, skip. if ( untrailingslashit( $url ) === untrailingslashit( $home ) ) { continue; } $report['broken'][] = $url; continue; } $post = get_post( $post_id ); if ( ! $post ) { $report['broken'][] = $url; continue; } // noindex leak: a noindex post present in the file. if ( self::is_noindex_post( $post ) ) { $report['noindex_leaks'][] = $url; } } $report['ok'] = empty( $report['duplicates'] ) && empty( $report['broken'] ) && empty( $report['noindex_leaks'] ); return $report; } /** * Simplified noindex check for scanner purposes (no wp_robots emulation). * * @param WP_Post $post Post. * @return bool */ private static function is_noindex_post( $post ) { if ( (int) get_option( 'blog_public', 1 ) === 0 ) { return true; } if ( ! empty( $post->post_password ) ) { return true; } return false; } }