73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Network admin aggregated Alerts page.
|
|
*
|
|
* @package MediaRightsAudit\Network
|
|
*/
|
|
|
|
namespace MediaRightsAudit\Network;
|
|
|
|
use MediaRightsAudit\Core\NetworkDatabase;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Renders the aggregated alerts view for the network admin.
|
|
*
|
|
* Shows all active (non-dismissed) alert attachments across all sites,
|
|
* ordered by site. Alert dismissal is performed at the per-site level via
|
|
* a link to the site's own Alerts page.
|
|
*/
|
|
class AlertsPage {
|
|
|
|
/**
|
|
* Renders the network Alerts page.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function render(): void {
|
|
if ( ! current_user_can( 'manage_network_options' ) ) {
|
|
wp_die( esc_html__( 'You do not have permission to access this page.', 'robotstxt-mediaaudit' ) );
|
|
}
|
|
|
|
$table = new NetworkListTable( true );
|
|
$table->prepare_items();
|
|
|
|
$total_alert = $this->get_active_alert_count();
|
|
?>
|
|
<div class="wrap">
|
|
<h1>
|
|
<?php esc_html_e( 'Network Alerts', 'robotstxt-mediaaudit' ); ?>
|
|
<?php if ( $total_alert > 0 ) : ?>
|
|
<span class="title-count"><?php echo esc_html( number_format_i18n( $total_alert ) ); ?></span>
|
|
<?php endif; ?>
|
|
</h1>
|
|
|
|
<p class="description">
|
|
<?php esc_html_e( 'Active copyright-risk alerts across all sites. To dismiss an alert, visit the Alerts page on the corresponding site.', 'robotstxt-mediaaudit' ); ?>
|
|
</p>
|
|
|
|
<form method="get">
|
|
<input type="hidden" name="page" value="robotstxt-mediaaudit-network-alerts" />
|
|
<?php $table->display(); ?>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* Returns the total count of active (non-dismissed) alerts across the network.
|
|
*
|
|
* @return int
|
|
*/
|
|
private function get_active_alert_count(): int {
|
|
global $wpdb;
|
|
|
|
$table = NetworkDatabase::table_name();
|
|
|
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
|
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}` WHERE has_alert = 1 AND is_dismissed = 0" );
|
|
}
|
|
}
|