Caldera_Forms_API_Tokens

REST API route for verification tokens.

Defined (1)

The class is defined in the following location(s).

/classes/api/tokens.php  
  1. class Caldera_Forms_API_Tokens implements Caldera_Forms_API_Route { 
  2.  
  3. /** 
  4. * @since 1.5.0 
  5. * @inheritdoc 
  6. */ 
  7. public function add_routes( $namespace ) { 
  8. register_rest_route( $namespace, '/tokens/form',  
  9. array( 
  10. 'methods' => 'post',  
  11. 'callback' => array( $this, 'get_new_nonce' ),  
  12. 'args' => array( 
  13. 'form_id' => array( 
  14. 'required' => 'true',  
  15. 'type' => 'string',  
  16. 'validate_callback' => array( $this, 'form_exists' ) 
  17. ); 
  18.  
  19. /** 
  20. * Check that form exists, by ID 
  21. * @since 1.5.0 
  22. * @param string $form_id 
  23. * @return bool 
  24. */ 
  25. public function form_exists( $form_id ) { 
  26. $form = Caldera_Forms_Forms::get_form( $form_id ); 
  27. return ( is_array( $form ) && ! empty( $form ) ); 
  28.  
  29. /** 
  30. * Get a new form nonce 
  31. * @since 1.5.0 
  32. * @param WP_REST_Request $request REST API request object 
  33. * @return Caldera_Forms_API_Response 
  34. */ 
  35. public function get_new_nonce( WP_REST_Request $request ) { 
  36. $form_id = $request[ 'form_id' ]; 
  37. $nonce = Caldera_Forms_Render_Nonce::create_verify_nonce( $form_id ); 
  38. $response = new Caldera_Forms_API_Response( array( 
  39. 'nonce' => $nonce,  
  40. ) ); 
  41. return $response; 
  42.