| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
class WPPB_LE_Export { |
| 6 |
|
| 7 |
protected $args_to_export; |
| 8 |
|
| 9 |
/** |
| 10 |
* this will take labels that will be exported from database. |
| 11 |
* |
| 12 |
* @param array $args_to_export labels to export. |
| 13 |
*/ |
| 14 |
function __construct( $args_to_export ) { |
| 15 |
$this->args_to_export = $args_to_export; |
| 16 |
} |
| 17 |
|
| 18 |
/* function to export from database */ |
| 19 |
private function export_array( $nonce ) { |
| 20 |
|
| 21 |
if( !wp_verify_nonce( $nonce, 'wppb_export_labels' ) ) |
| 22 |
return; |
| 23 |
|
| 24 |
/* export labels from database */ |
| 25 |
$all_for_export = array(); |
| 26 |
foreach( $this->args_to_export as $labels ) { |
| 27 |
$all_for_export['pble'] = get_option( $labels ); |
| 28 |
} |
| 29 |
|
| 30 |
return $all_for_export; |
| 31 |
} |
| 32 |
|
| 33 |
/* export to json file */ |
| 34 |
public function download_to_json_format( $prefix ) { |
| 35 |
|
| 36 |
if( isset( $_POST['pble-export'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_export_labels' ) ) { |
| 37 |
$all_for_export = $this->export_array( sanitize_text_field( $_POST['wppb_nonce'] ) ); |
| 38 |
$json = json_encode( $all_for_export ); |
| 39 |
$filename = $prefix . date( 'Y-m-d_h.i.s', time() ); |
| 40 |
$filename .= '.json'; |
| 41 |
header( "Content-Disposition: attachment; filename=$filename" ); |
| 42 |
header( 'Content-type: application/json' ); |
| 43 |
header( 'Content-Length: ' . mb_strlen( $json ) ); |
| 44 |
header( 'Connection: close' ); |
| 45 |
echo $json; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 46 |
exit; |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
} |
| 51 |
|