self::MAX_PER_BATCH ) { $post_ids = array_slice( $post_ids, 0, self::MAX_PER_BATCH ); $truncated = true; } $audit = new AEOMATIC_Audit(); $gaps = new AEOMATIC_Citation_Gaps(); $rows = array(); foreach ( $post_ids as $post_id ) { $post = get_post( $post_id ); if ( ! $post instanceof WP_Post || ! current_user_can( 'edit_post', $post_id ) ) { continue; } $audit_result = $audit->score_post( $post ); $gaps_result = $gaps->rebuild( $post_id ); $rows[] = array( 'id' => (int) $post_id, 'title' => (string) get_the_title( $post ), 'edit_url' => (string) get_edit_post_link( $post_id, 'raw' ), 'audit' => (int) ( $audit_result['score'] ?? 0 ), 'gap_score' => (int) ( $gaps_result['score'] ?? 0 ), 'gap_count' => is_array( $gaps_result['gaps'] ?? null ) ? count( $gaps_result['gaps'] ) : 0, ); } // Bust the site-wide audit summary transient so the widget sees fresh numbers. delete_transient( 'aeomatic_site_audit_cache' ); // Stash results in a short-lived transient keyed to the user; the // notice on the next request reads and clears it. $transient_key = self::transient_key(); set_transient( $transient_key, array( 'rows' => $rows, 'truncated' => $truncated, 'ts' => time(), ), self::TRANSIENT_TTL ); AEOMATIC_Activity::log( 'bulk_refresh', sprintf( /* translators: %d: post count */ _n( 'Bulk refresh: %d post rescored.', 'Bulk refresh: %d posts rescored.', count( $rows ), 'aeomatic' ), count( $rows ) ) ); return add_query_arg( self::QUERY_ARG, '1', $redirect_to ); } /** * Render the results notice after a bulk run. */ public function maybe_show_notice(): void { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( empty( $_GET[ self::QUERY_ARG ] ) ) { return; } if ( ! current_user_can( 'edit_posts' ) ) { return; } $key = self::transient_key(); $result = get_transient( $key ); if ( ! is_array( $result ) || empty( $result['rows'] ) ) { return; } delete_transient( $key ); $rows = $result['rows']; $truncated = ! empty( $result['truncated'] ); $count = count( $rows ); $avg_audit = $count ? (int) round( array_sum( array_column( $rows, 'audit' ) ) / $count ) : 0; $avg_gaps = $count ? (int) round( array_sum( array_column( $rows, 'gap_score' ) ) / $count ) : 0; $total_gap = array_sum( array_column( $rows, 'gap_count' ) ); $dashboard_url = admin_url( 'admin.php?page=' . AEOMATIC_Admin::MENU_SLUG ); $gaps_url = admin_url( 'admin.php?page=' . AEOMATIC_Admin::SLUG_GAPS ); ?>

/100 /100 ·

= 70 ? 'aeom-chip--good' : ( $row['audit'] >= 40 ? 'aeom-chip--okay' : 'aeom-chip--poor' ); $gap_class = $row['gap_score'] >= 70 ? 'aeom-chip--good' : ( $row['gap_score'] >= 40 ? 'aeom-chip--okay' : 'aeom-chip--poor' ); ?>