This commit is contained in:
Javier Casares 2026-06-03 06:30:49 +00:00
commit 4402f3570d
20 changed files with 1683 additions and 382 deletions

View file

@ -7,6 +7,7 @@
namespace MediaRightsAudit\Admin;
use MediaRightsAudit\Admin\AlertsPage;
use MediaRightsAudit\Admin\AttachmentDetailPage;
use MediaRightsAudit\External\HostnameFilter;
@ -290,7 +291,23 @@ class MediaListTable extends \WP_List_Table {
$top_domains_data[ $td_key ] = $td_val;
}
}
$has_alert = ! empty( $top_domains_data ) && HostnameFilter::has_alert_domains( $top_domains_data );
$has_alert = ! empty( $top_domains_data ) && HostnameFilter::has_alert_domains( $top_domains_data );
$is_dismissed = ! empty( $item['is_dismissed'] );
if ( $has_alert && $is_dismissed ) {
$aid_val = $item['attachment_id'];
$aid = is_numeric( $aid_val ) ? (int) $aid_val : 0;
$out = sprintf(
'<span class="mra-badge mra-badge-dismissed">%s</span>',
esc_html__( 'Dismissed', 'robotstxt-mediaaudit' )
);
$out .= sprintf(
' <a href="#" class="mra-view-details" data-id="%d">%s</a>',
$aid,
esc_html__( 'View Results', 'robotstxt-mediaaudit' )
);
return $out;
}
if ( $has_alert ) {
$out = sprintf(
@ -486,6 +503,8 @@ class MediaListTable extends \WP_List_Table {
public function prepare_items() {
global $wpdb;
$dismissed_ids = AlertsPage::get_dismissed_ids();
$per_page = 20;
$paged = $this->get_pagenum();
$offset = ( $paged - 1 ) * $per_page;
@ -508,8 +527,10 @@ class MediaListTable extends \WP_List_Table {
// Detect alert filter before normalising external_status.
$filter_alert = ( 'alert' === $external_status );
if ( $filter_alert ) {
// Reuse existing matches WHERE logic to narrow the candidate set.
$external_status = 'matches';
// Do not restrict by external_status: attachments can have alert domains
// even when external_status is not 'matches'. The PHP pass below handles
// the real filter, consistent with get_alert_attachment_count().
$external_status = '';
}
if ( ! in_array( $external_status, self::EXTERNAL_STATUSES, true ) ) {
@ -578,7 +599,7 @@ class MediaListTable extends \WP_List_Table {
$all_ids = array_map( 'intval', array_column( $all_rows, 'attachment_id' ) );
$top_domains_by_id = self::fetch_top_domains( $all_ids );
// PHP-filter: keep only rows that have at least one alert domain.
// PHP-filter: keep only rows that have at least one alert domain and are not dismissed.
$filtered = array();
foreach ( $all_rows as $r ) {
if ( ! is_array( $r ) ) {
@ -586,7 +607,7 @@ class MediaListTable extends \WP_List_Table {
}
$aid_val = $r['attachment_id'] ?? null;
$aid = is_numeric( $aid_val ) ? (int) $aid_val : 0;
if ( HostnameFilter::has_alert_domains( $top_domains_by_id[ $aid ] ?? array() ) ) {
if ( HostnameFilter::has_alert_domains( $top_domains_by_id[ $aid ] ?? array() ) && ! isset( $dismissed_ids[ $aid ] ) ) {
$filtered[] = $r;
}
}
@ -594,11 +615,12 @@ class MediaListTable extends \WP_List_Table {
$total = count( $filtered );
$rows = array_slice( $filtered, $offset, $per_page );
// Attach top_domains_data for the page slice.
// Attach top_domains_data and is_dismissed for the page slice.
foreach ( $rows as &$row ) {
$rid_val = $row['attachment_id'] ?? null;
$rid = is_numeric( $rid_val ) ? (int) $rid_val : 0;
$row['top_domains_data'] = $top_domains_by_id[ $rid ] ?? array();
$row['is_dismissed'] = isset( $dismissed_ids[ $rid ] );
}
unset( $row );
} else {
@ -649,6 +671,7 @@ class MediaListTable extends \WP_List_Table {
$rid_val = $row['attachment_id'] ?? null;
$rid = is_numeric( $rid_val ) ? (int) $rid_val : 0;
$row['top_domains_data'] = $top_domains_by_id[ $rid ] ?? array();
$row['is_dismissed'] = isset( $dismissed_ids[ $rid ] );
}
unset( $row );
}