admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( self::NONCE ),
'i18n' => array(
'starting' => __( 'Starting the pass…', 'aftersweep' ),
/* translators: %s: percentage. */
'progress' => __( 'Pass in progress: %s %%', 'aftersweep' ),
'done' => __( 'Pass finished.', 'aftersweep' ),
'failed' => __( 'The request failed. The pass is kept: you can resume it.', 'aftersweep' ),
'inProgress' => __( 'A pass is already in progress or was interrupted: resume it or start over.', 'aftersweep' ),
'locked' => __( 'Another batch of this pass is still running or was cut off. Wait a minute, then resume.', 'aftersweep' ),
),
)
);
}
/** The Tools page. */
public static function page() {
if ( ! self::allowed() ) {
wp_die( esc_html__( 'Sorry, you are not allowed to access this page.', 'aftersweep' ) );
}
$consent = (bool) get_option( 'ahcl_checksums_consent', false );
$state = Pass::state();
$last = get_option( Pass::REPORT );
?>
Aftersweep – After-Hack Checklist
__( 'Sorry, you are not allowed to do that.', 'aftersweep' ) ), 403 );
}
wp_raise_memory_limit( 'admin' );
}
/** AJAX ahcl_start: saves the consent, starts (or starts over) a pass. */
public static function ajax_start() {
self::guard();
$consent = ! empty( $_POST['consent'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce checked in guard().
$date = isset( $_POST['reference_date'] ) ? Pass::valid_date( sanitize_text_field( wp_unslash( $_POST['reference_date'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce checked in guard().
if ( '' === $date ) {
wp_send_json_error( array( 'message' => __( 'Enter a valid reference date.', 'aftersweep' ) ), 400 );
}
update_option( 'ahcl_checksums_consent', $consent );
if ( ! empty( $_POST['restart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce checked in guard().
Pass::abandon();
}
if ( ! ahcl_start_pass(
array(
'reference_date' => $date,
'trigger' => 'manual',
)
) ) {
wp_send_json_error(
array(
'code' => 'in_progress',
'message' => __( 'A pass is already in progress or was interrupted: resume it or start over.', 'aftersweep' ),
),
409
);
}
wp_send_json_success( array( 'progress' => 0 ) );
}
/** AJAX ahcl_step: one batch; the report HTML when the pass is over. */
public static function ajax_step() {
self::guard();
$result = ahcl_continue_pass();
if ( isset( $result['error'] ) ) {
// The pass stops with a message (D-13); the stored state is kept for "Resume" or "Start over".
$message = 'report_write_failed' === $result['error']
? __( 'The report could not be saved in the database. The pass is stopped; resume it to try again.', 'aftersweep' )
: __( 'The state of the pass could not be saved in the database. The pass is stopped; resume it to try again, or ask your host about the database size limits.', 'aftersweep' );
wp_send_json_error( array( 'message' => $message ), 500 );
}
if ( $result['done'] ) {
$last = get_option( Pass::REPORT );
if ( is_array( $last ) && isset( $last['report'], $last['context'] ) ) {
$result['html'] = Renderer::report( $last );
$result['summary'] = Renderer::summary_text( $last['report'] );
}
}
wp_send_json_success( $result );
}
}