verifyNonce($nonce, $nonce_action); if (is_wp_error($nonce_check)) { return $nonce_check; } // Check capability $cap_check = $this->checkCapability($capability); if (is_wp_error($cap_check)) { return $cap_check; } return true; } /** * Handle AJAX security check and send error response if needed * * @param string $nonce The nonce to verify * @param string $nonce_action The nonce action * @param string $capability The required capability * @return bool True if checks pass, false otherwise (and sends JSON error) */ protected function handleAjaxSecurity($nonce, $nonce_action = 'easy_invoice_nonce', $capability = 'manage_options') { $security_check = $this->securityCheck($nonce, $nonce_action, $capability); if (is_wp_error($security_check)) { wp_send_json_error([ 'message' => $security_check->get_error_message(), 'code' => $security_check->get_error_code() ]); return false; } return true; } }