admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aqct_nonce' ), 'strings' => array( 'running' => __( 'Running...', 'aims-quick-cleanup-tools' ), 'success' => __( 'Success!', 'aims-quick-cleanup-tools' ), 'error' => __( 'Error!', 'aims-quick-cleanup-tools' ), 'confirm' => __( 'Are you sure? This action cannot be undone.', 'aims-quick-cleanup-tools' ), ), ) ); } /** * Handle AJAX fix execution */ public function aqct_run_fix() { check_ajax_referer( 'aqct_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'Permission denied', 'aims-quick-cleanup-tools' ) ) ); } // FIXED: Ensure $_POST['fix'] exists. $fix = isset( $_POST['fix'] ) ? sanitize_text_field( wp_unslash( $_POST['fix'] ) ) : ''; if ( empty( $fix ) ) { wp_send_json_error( array( 'message' => __( 'Invalid fix type', 'aims-quick-cleanup-tools' ) ) ); } // Map fix names to methods. $fixes = array( 'broken_images' => 'fix_broken_images', 'orphaned_postmeta' => 'clean_orphaned_postmeta', 'duplicate_slugs' => 'fix_duplicate_slugs', 'orphaned_comments' => 'clean_orphaned_comments', 'transients' => 'clean_transients', 'revisions' => 'clean_revisions', 'unused_tags' => 'clean_unused_tags', 'auto_drafts' => 'clean_auto_drafts', 'optimize_db' => 'optimize_database', 'regenerate_htaccess' => 'regenerate_htaccess', 'file_permissions' => 'fix_file_permissions', 'spam_comments' => 'clean_spam_comments', ); if ( ! isset( $fixes[ $fix ] ) ) { wp_send_json_error( array( 'message' => __( 'Unknown fix type', 'aims-quick-cleanup-tools' ) ) ); } $method = $fixes[ $fix ]; $result = call_user_func( array( 'AQCT_Fixer', $method ) ); if ( ! empty( $result['success'] ) ) { wp_send_json_success( $result ); } wp_send_json_error( $result ); } /** * Render admin page */ public function render_admin_page() { ?>