3 ) { // Keep the first 4 blocks, mask the rest $ip = implode( ':', array_slice( $ipv6_parts, 0, 4 ) ) . '::'; } } return $ip; } /** * Unified Request Verifier * A handy wrapper that checks both the Nonce AND the User Capability * at the same time, reducing code duplication in our AJAX endpoints. * * @since 1.0.0 * @param string $nonce_action The name of the nonce action to verify. * @param string $nonce_name (Optional) The key in $_REQUEST where the nonce is stored. Default is 'security'. * @param string $capability (Optional) The capability required. Default is 'manage_tt24_forms'. * @return bool|void Returns true if secure, or automatically calls wp_send_json_error() if it fails. */ public static function verify_admin_ajax( $nonce_action, $nonce_name = 'security', $capability = 'manage_tt24_forms' ) { // 1. Verify Nonce // FIX: Added sanitize_text_field( wp_unslash() ) around the nonce value per WP Review Team. if ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ), $nonce_action ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Security token expired. Please refresh the page.', '24tt-unrestricted-forms' ) ) ); exit; // Stop execution immediately } // 2. Verify Role/Capability if ( ! current_user_can( $capability ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Insufficient permissions.', '24tt-unrestricted-forms' ) ) ); exit; // Stop execution immediately } return true; } }