56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* AJAX handler registry.
|
|
*
|
|
* All AJAX actions for the migration wizard are registered here.
|
|
* Every handler verifies a nonce and the manage_network capability
|
|
* before performing any work.
|
|
*
|
|
* @package Robotstxt_Mlp2_Mlp5
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Class Robotstxt_Mlp2_Mlp5_Ajax
|
|
*/
|
|
class Robotstxt_Mlp2_Mlp5_Ajax {
|
|
|
|
/**
|
|
* Nonce action used for all batch AJAX requests.
|
|
*
|
|
* @var string
|
|
*/
|
|
const NONCE_ACTION = 'mlp_migrator_batch';
|
|
|
|
/**
|
|
* Register all AJAX hooks. Called once on plugins_loaded.
|
|
*/
|
|
public static function register(): void {
|
|
add_action( 'wp_ajax_mlp_migrator_run_batch', array( static::class, 'action_run_batch' ) );
|
|
}
|
|
|
|
/**
|
|
* AJAX handler: run one content-relations migration batch.
|
|
*
|
|
* Verifies nonce and capability, delegates to Step_Content_Relations,
|
|
* and returns a JSON progress snapshot.
|
|
*/
|
|
public static function action_run_batch(): void {
|
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
|
$raw_nonce = isset( $_POST['nonce'] ) ? wp_unslash( $_POST['nonce'] ) : '';
|
|
if ( ! wp_verify_nonce( (string) $raw_nonce, self::NONCE_ACTION ) ) {
|
|
wp_send_json_error( array( 'message' => 'Invalid nonce.' ), 403 );
|
|
}
|
|
|
|
if ( ! current_user_can( 'manage_network' ) ) {
|
|
wp_send_json_error( array( 'message' => 'Insufficient permissions.' ), 403 );
|
|
}
|
|
|
|
$progress = Robotstxt_Mlp2_Mlp5_Step_Content_Relations::run_batch();
|
|
|
|
wp_send_json_success( $progress );
|
|
}
|
|
}
|