'medium', ABDS_SEO_Content_Analyzer::ACTION_REMOVE => 'medium', ABDS_SEO_Content_Analyzer::ACTION_ADAPT => 'low', ); /** * Content_Analyzer instance, injected so tests can substitute a stub. * * @var ABDS_SEO_Content_Analyzer */ protected ABDS_SEO_Content_Analyzer $analyzer; /** * Constructor. * * @param ?ABDS_SEO_Content_Analyzer $analyzer Analyzer to wrap; defaults to a real instance. */ public function __construct( ?ABDS_SEO_Content_Analyzer $analyzer = null ) { $this->analyzer = $analyzer ?? new ABDS_SEO_Content_Analyzer(); } /** * Content_Analyzer requires a non-empty focus keyword — a real majority * of posts on any given site won't have one set (confirmed live during * this session's own testing). Silently contributing zero issues for * those pages would look identical to "content analysis passed", which * is dishonest (§104): a page with no focus keyword hasn't been judged * at all. This check surfaces that explicitly as its own low-severity * finding instead. * * @param WP_Post $post Post being audited. * @param string $html Unused by this check — Content_Analyzer reads the saved post row directly, not rendered HTML. * @return array */ public function run( WP_Post $post, string $html ): array { $focus_keyword = trim( (string) get_post_meta( $post->ID, '_abds_seo_focus_keyword', true ) ); if ( '' === $focus_keyword ) { return array( array( 'issue_key' => 'no_focus_keyword', 'category' => self::CATEGORY, 'severity' => 'low', 'message' => __( 'No focus keyword is set — content analysis was skipped for this page.', 'abds-seo' ), 'details' => array(), ), ); } $result = $this->analyzer->analyze( $post->ID, $focus_keyword ); return array_map( function ( array $recommendation ): array { return array( 'issue_key' => 'content_' . $recommendation['target'], 'category' => self::CATEGORY, 'severity' => self::SEVERITY_MAP[ $recommendation['action'] ] ?? 'notice', 'message' => $recommendation['message'], // M2 2.3: block_position was already computed by the // analyzer (for h1/subheading/first_paragraph/image_alt // targets — null for the rest) and previously discarded // here before reaching details_json; now kept, it's the // content-analyzer side's own element locator (an index // into the page's ContentUnit stream, not a DOM // selector, but enough for M3 to scroll to/highlight the // right block). 'details' => array( 'action' => $recommendation['action'], 'target' => $recommendation['target'], 'block_position' => $recommendation['block_position'] ?? null, ), ); }, $result['recommendations'] ); } }