record = $record;
}
/**
* Registers hooks.
*
* @return void
*/
public function register(): void {
add_action( 'wp_dashboard_setup', array( $this, 'add_widget' ) );
}
/**
* Adds the widget.
*
* @return void
*/
public function add_widget(): void {
if ( ! current_user_can( self::CAPABILITY ) ) {
return;
}
wp_add_dashboard_widget(
self::ID,
__( 'AI Blackout', 'ai-blackout' ),
array( $this, 'render' )
);
}
/**
* Renders the widget.
*
* @return void
*/
public function render(): void {
$status = $this->record->get_live_status();
echo '
';
printf(
'
%2$s
',
esc_attr( $status ),
esc_html( Result::label_for( $status ) )
);
echo '
';
$streak = $this->record->get_streak();
if ( $streak > 0 ) {
printf(
'- %s
',
esc_html(
sprintf(
/* translators: %s: Number of consecutive days. */
_n( 'Verified protected for %s day in a row.', 'Verified protected for %s days in a row.', $streak, 'ai-blackout' ),
number_format_i18n( $streak )
)
)
);
}
$companies = $this->record->get_blocked_companies();
$total = $this->record->get_total_company_count();
if ( ! empty( $companies ) ) {
printf(
'- %s
',
esc_html(
sprintf(
/* translators: 1: Number of companies blocked. 2: Total known companies. */
__( 'Blocking %1$d of %2$d known AI companies.', 'ai-blackout' ),
count( $companies ),
$total
)
)
);
}
$lifetime_total = $this->record->get_lifetime_total();
$blocking_since = $this->record->get_blocking_since();
if ( $lifetime_total > 0 && null !== $blocking_since ) {
printf(
'- %s
',
esc_html(
sprintf(
/* translators: 1: Number of requests. 2: Date. */
__( '%1$s requests refused by WordPress since %2$s -- a floor, not a total, since most crawlers never reach WordPress at all. A small or flat number usually means it is working, not failing.', 'ai-blackout' ),
number_format_i18n( $lifetime_total ),
date_i18n( get_option( 'date_format' ), $blocking_since )
)
)
);
}
echo '
';
printf(
'',
esc_html__( 'This blocks crawlers that identify themselves honestly. It cannot stop one that disguises itself as an ordinary browser.', 'ai-blackout' )
);
printf(
'
%s
',
esc_url( $this->get_status_url() ),
esc_html__( 'See full protection status', 'ai-blackout' )
);
echo '
';
}
/**
* Returns the URL of the Status screen.
*
* @return string Admin URL.
*/
private function get_status_url(): string {
return admin_url( 'admin.php?page=' . MainScreen::SLUG );
}
}