wpcf7_rest_get_contact_forms

The Contact Form 7 wpcf7 rest get contact forms function.

Description

wpcf7_rest_get_contact_forms( WP_REST_Request $request ); 

Parameters (1)

0. $request
The request.

Usage

  1. if ( !function_exists( 'wpcf7_rest_get_contact_forms' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/includes/rest-api.php'; 
  3.  
  4. // The request. 
  5. $request = WP_REST_Request $request; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpcf7_rest_get_contact_forms($request); 
  9.  

Defined (1)

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

/includes/rest-api.php  
  1. function wpcf7_rest_get_contact_forms( WP_REST_Request $request ) { 
  2. if ( ! current_user_can( 'wpcf7_read_contact_forms' ) ) { 
  3. return new WP_Error( 'wpcf7_forbidden',  
  4. __( "You are not allowed to access contact forms.", 'contact-form-7' ),  
  5. array( 'status' => 403 ) ); 
  6.  
  7. $args = array(); 
  8.  
  9. $per_page = $request->get_param( 'per_page' ); 
  10.  
  11. if ( null !== $per_page ) { 
  12. $args['posts_per_page'] = (int) $per_page; 
  13.  
  14. $offset = $request->get_param( 'offset' ); 
  15.  
  16. if ( null !== $offset ) { 
  17. $args['offset'] = (int) $offset; 
  18.  
  19. $order = $request->get_param( 'order' ); 
  20.  
  21. if ( null !== $order ) { 
  22. $args['order'] = (string) $order; 
  23.  
  24. $orderby = $request->get_param( 'orderby' ); 
  25.  
  26. if ( null !== $orderby ) { 
  27. $args['orderby'] = (string) $orderby; 
  28.  
  29. $search = $request->get_param( 'search' ); 
  30.  
  31. if ( null !== $search ) { 
  32. $args['s'] = (string) $search; 
  33.  
  34. $items = WPCF7_ContactForm::find( $args ); 
  35.  
  36. $response = array(); 
  37.  
  38. foreach ( $items as $item ) { 
  39. $response[] = array( 
  40. 'id' => $item->id(),  
  41. 'slug' => $item->name(),  
  42. 'title' => $item->title(),  
  43. 'locale' => $item->locale(),  
  44. ); 
  45.  
  46. return rest_ensure_response( $response );