bp_attachments_json_response

Send a JSON response back to an Ajax upload request.

Description

bp_attachments_json_response( (bool) $success, (constant) $is_html4 = false, (null) $data = null ); 

Parameters (3)

0. $success (bool)
True for a success, false otherwise.
1. $is_html4 — Optional. (constant) => false
True if the Plupload runtime used is html4, false otherwise.
2. $data — Optional. (null) => null
Data to encode as JSON, then print and die.

Usage

  1. if ( !function_exists( 'bp_attachments_json_response' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-attachments.php'; 
  3.  
  4. // True for a success, false otherwise. 
  5. $success = true; 
  6.  
  7. // True if the Plupload runtime used is html4, false otherwise. 
  8. $is_html4 = false; 
  9.  
  10. // Data to encode as JSON, then print and die. 
  11. $data = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_attachments_json_response($success, $is_html4, $data); 
  15.  

Defined (1)

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

/bp-core/bp-core-attachments.php  
  1. function bp_attachments_json_response( $success, $is_html4 = false, $data = null ) { 
  2. $response = array( 'success' => $success ); 
  3.  
  4. if ( isset( $data ) ) { 
  5. $response['data'] = $data; 
  6.  
  7. // Send regular json response. 
  8. if ( ! $is_html4 ) { 
  9. wp_send_json( $response ); 
  10.  
  11. /** 
  12. * Send specific json response 
  13. * the html4 Plupload handler requires a text/html content-type for older IE. 
  14. * See https://core.trac.wordpress.org/ticket/31037 
  15. */ 
  16. } else { 
  17. echo wp_json_encode( $response ); 
  18.  
  19. wp_die();