layers_create_export_file

Simple output of a JSON'd string of the widget data.

Description

layers_create_export_file(); 

Usage

  1. if ( !function_exists( 'layers_create_export_file' ) ) { 
  2. require_once '/core/helpers/migrator.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = layers_create_export_file(); 
  7.  

Defined (1)

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

/core/helpers/migrator.php  
  1. function layers_create_export_file() { 
  2.  
  3. $layers_migrator = new Layers_Widget_Migrator(); 
  4.  
  5. // Make sur a post ID exists or return 
  6. if( !isset( $_GET[ 'post' ] ) ) return; 
  7.  
  8. // Get the post ID 
  9. $post_id = $_GET[ 'post' ]; 
  10.  
  11. $post = get_post( $post_id ); 
  12.  
  13. $widget_data = json_encode( $layers_migrator->export_data( $post ) ); 
  14.  
  15. $filesize = strlen( $widget_data ); 
  16.  
  17. // Headers to prompt "Save As" 
  18. header( 'Content-Type: application/json' ); 
  19. header( 'Content-Disposition: attachment; filename=' . $post->post_name .'-' . date( 'Y-m-d' ) . '.json' ); 
  20. header( 'Expires: 0' ); 
  21. header( 'Cache-Control: must-revalidate' ); 
  22. header( 'Pragma: public' ); 
  23. header( 'Content-Length: ' . $filesize ); 
  24.  
  25. // Clear buffering just in case 
  26. @ob_end_clean(); 
  27. flush(); 
  28.  
  29. // Output file contents 
  30. die( $widget_data ); 
  31.  
  32. // Stop execution 
  33. wp_redirect( admin_url( 'post.php?post=' . $post->ID . '&action=edit' ) ); 
  34.