render();
?>
render_notice(); ?>
handle_bulk_delete();
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Routing only; nonce verified in handle_empty_trash().
if ( isset( $_POST['activelayer_empty_trash'] ) ) {
$this->handle_empty_trash();
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Routing only; nonce verified in handle_delete_all_spam().
if ( isset( $_POST['activelayer_delete_all_spam'] ) ) {
$this->handle_delete_all_spam();
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Routing only; nonce verified in handle_delete_all_submissions().
if ( isset( $_POST['activelayer_delete_all_submissions'] ) ) {
$this->handle_delete_all_submissions();
return;
}
}
/**
* Handle bulk delete by age action.
*
* @since 1.0.0
*/
private function handle_bulk_delete(): void {
if ( ! check_admin_referer( 'activelayer_tools_bulk_delete' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'Security check failed. Please try again.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
if ( ! current_user_can( 'manage_activelayer' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'You do not have permission to perform this action.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
$days = isset( $_POST['retention_days'] ) ? absint( wp_unslash( $_POST['retention_days'] ) ) : 0;
if ( ! in_array( $days, self::RETENTION_DAYS, true ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'Invalid retention period selected.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
$deleted_count = Storage::get_instance()->delete_older_than( $days );
$this->notice = [
'type' => 'success',
'message' => sprintf(
/* translators: %d: number of deleted submissions. */
_n(
'%d submission deleted successfully.',
'%d submissions deleted successfully.',
$deleted_count,
'activelayer-anti-spam-spam-protection-for-forms-comments'
),
$deleted_count
),
];
}
/**
* Handle empty trash action.
*
* @since 1.1.0
*/
private function handle_empty_trash(): void {
if ( ! check_admin_referer( 'activelayer_tools_empty_trash' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'Security check failed. Please try again.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
if ( ! current_user_can( 'manage_activelayer' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'You do not have permission to perform this action.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
$deleted_count = Storage::get_instance()->delete_by_status( 'trash' );
$this->notice = [
'type' => 'success',
'message' => sprintf(
/* translators: %d: number of deleted submissions. */
_n(
'%d trashed submission deleted.',
'%d trashed submissions deleted.',
$deleted_count,
'activelayer-anti-spam-spam-protection-for-forms-comments'
),
$deleted_count
),
];
}
/**
* Handle delete all spam action.
*
* @since 1.1.0
*/
private function handle_delete_all_spam(): void {
if ( ! check_admin_referer( 'activelayer_tools_delete_spam' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'Security check failed. Please try again.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
if ( ! current_user_can( 'manage_activelayer' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'You do not have permission to perform this action.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
$deleted_count = Storage::get_instance()->delete_by_status( 'spam' );
$this->notice = [
'type' => 'success',
'message' => sprintf(
/* translators: %d: number of deleted submissions. */
_n(
'%d spam submission deleted.',
'%d spam submissions deleted.',
$deleted_count,
'activelayer-anti-spam-spam-protection-for-forms-comments'
),
$deleted_count
),
];
}
/**
* Handle delete all submissions action.
*
* Deletes every submission regardless of status, trashed ones included.
*
* @since 1.7.0
*/
private function handle_delete_all_submissions(): void {
if ( ! check_admin_referer( 'activelayer_tools_delete_all_submissions' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'Security check failed. Please try again.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
if ( ! current_user_can( 'manage_activelayer' ) ) {
$this->notice = [
'type' => 'error',
'message' => __( 'You do not have permission to perform this action.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ),
];
return;
}
$deleted_count = Storage::get_instance()->delete_all();
$this->notice = [
'type' => 'success',
'message' => sprintf(
/* translators: %d: number of deleted submissions. */
_n(
'%d submission deleted.',
'%d submissions deleted.',
$deleted_count,
'activelayer-anti-spam-spam-protection-for-forms-comments'
),
$deleted_count
),
];
}
/**
* Render admin notice if set.
*
* @since 1.0.0
*/
private function render_notice(): void {
if ( empty( $this->notice ) ) {
return;
}
NoticeHelper::render(
$this->notice['message'],
$this->notice['type'],
false
);
}
}