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\ExternalScanner;
use MediaRightsAudit\External\HostnameFilter;
@ -131,7 +132,7 @@ class AuditPage {
* @return void
*/
public function render(): void {
if ( ! current_user_can( 'edit_posts' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'You do not have permission to access this page.', 'robotstxt-mediaaudit' ) );
}
@ -171,7 +172,7 @@ class AuditPage {
public function ajax_usage_details(): void {
check_ajax_referer( 'mra_usage_details', 'nonce' );
if ( ! current_user_can( 'edit_posts' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_send_json_error( array( 'message' => __( 'Insufficient permissions.', 'robotstxt-mediaaudit' ) ) );
}
@ -525,7 +526,7 @@ class AuditPage {
private function handle_export_csv( bool $alerts_only ): void {
check_admin_referer( 'bulk-mra-attachments' );
if ( ! current_user_can( 'edit_posts' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'Insufficient permissions.', 'robotstxt-mediaaudit' ) );
}
@ -565,6 +566,8 @@ class AuditPage {
__( 'Alert Domains', 'robotstxt-mediaaudit' ),
__( 'Other Domains', 'robotstxt-mediaaudit' ),
__( 'Ignored Domains', 'robotstxt-mediaaudit' ),
__( 'Dismissed', 'robotstxt-mediaaudit' ),
__( 'Dismissed Notes', 'robotstxt-mediaaudit' ),
)
);
@ -696,6 +699,29 @@ class AuditPage {
}
}
// Fetch dismissed IDs and notes for CSV columns.
$dismissed_ids = AlertsPage::get_dismissed_ids();
// phpcs:disable WordPress.DB.DirectDatabaseQuery
$dismissed_notes_rows = $wpdb->get_results(
"SELECT attachment_id, notes FROM {$wpdb->prefix}mra_dismissed_alerts",
ARRAY_A
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery
$dismissed_notes = array();
if ( is_array( $dismissed_notes_rows ) ) {
foreach ( $dismissed_notes_rows as $dn ) {
if ( is_array( $dn ) ) {
$dn_aid_raw = $dn['attachment_id'] ?? null;
$dn_aid = is_numeric( $dn_aid_raw ) ? (int) $dn_aid_raw : 0;
if ( $dn_aid > 0 ) {
$dismissed_notes[ $dn_aid ] = is_string( $dn['notes'] ?? null ) ? (string) $dn['notes'] : '';
}
}
}
}
$known_providers = array( 'google_vision', 'tineye', 'picdefense' );
$output = array();
@ -731,9 +757,11 @@ class AuditPage {
}
}
$has_alert = ! empty( $alert_list );
$has_alert = ! empty( $alert_list );
$is_dismissed = isset( $dismissed_ids[ $aid ] );
if ( $alerts_only && ! $has_alert ) {
// Skip row if alerts_only and either no alert or already dismissed.
if ( $alerts_only && ( ! $has_alert || $is_dismissed ) ) {
continue;
}
@ -757,6 +785,8 @@ class AuditPage {
$row_data[] = implode( '; ', $alert_list );
$row_data[] = implode( '; ', $other_list );
$row_data[] = implode( '; ', $ignored_list );
$row_data[] = $is_dismissed ? __( 'Yes', 'robotstxt-mediaaudit' ) : __( 'No', 'robotstxt-mediaaudit' );
$row_data[] = $dismissed_notes[ $aid ] ?? '';
$output[] = $row_data;
}
@ -772,7 +802,7 @@ class AuditPage {
private function handle_run_external_scan(): void {
check_admin_referer( 'bulk-mra-attachments' );
if ( ! current_user_can( 'edit_posts' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'Insufficient permissions.', 'robotstxt-mediaaudit' ) );
}
@ -804,7 +834,7 @@ class AuditPage {
private function handle_purge_external_data(): void {
check_admin_referer( 'bulk-mra-attachments' );
if ( ! current_user_can( 'edit_posts' ) ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
wp_die( esc_html__( 'Insufficient permissions.', 'robotstxt-mediaaudit' ) );
}
@ -942,8 +972,12 @@ class AuditPage {
}
}
$dismissed = AlertsPage::get_dismissed_ids();
$alert_count = 0;
foreach ( $merged as $domains ) {
foreach ( $merged as $aid => $domains ) {
if ( isset( $dismissed[ $aid ] ) ) {
continue;
}
if ( HostnameFilter::has_alert_domains( $domains ) ) {
++$alert_count;
}