PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / add-ons-free / import-export / inc / class-pbie-export.php

class-pbie-export.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at add-ons-free/import-export/inc/class-pbie-export.php

70 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 class WPPB_ImpEx_Export {
6
7 protected $args_to_export;
8
9 /**
10 * this will take custom options and posttypes that will be exported from database.
11 *
12 * @param array $args_to_export custom options and posttypes 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 if( !wp_verify_nonce( $nonce, 'wppb_export_settings' ) )
21 return array();
22
23 /* export options from database */
24 $option_values = array();
25 foreach( $this->args_to_export['options'] as $option ) {
26 $get_option = get_option( $option );
27 if( $get_option !== false ) {
28 $option_values[$option] = $get_option;
29 }
30 }
31
32 /* export custom posts from database */
33 $all_custom_posts = array();
34 foreach( $this->args_to_export['cpts'] as $post_type ) {
35 $all_custom_posts[$post_type] = get_posts( "post_type=$post_type&posts_per_page=-1" );
36 foreach( $all_custom_posts[$post_type] as $key => $value ) {
37 $all_custom_posts[$post_type][$key]->postmeta = get_post_custom( $value->ID );
38 }
39 }
40
41 /* create and return array for export */
42 $all_for_export = array(
43 "options" => $option_values,
44 "posts" => $all_custom_posts
45 );
46
47 return $all_for_export;
48 }
49
50 /* export to json file */
51 public function download_to_json_format( $prefix ) {
52
53 if( isset( $_POST['cozmos-export'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_export_settings' ) ) {
54
55 $all_for_export = $this->export_array( sanitize_text_field( $_POST['wppb_nonce'] ) );
56 $json = json_encode( $all_for_export );
57 $filename = $prefix . date( 'Y-m-d_h.i.s', time() );
58 $filename .= '.json';
59 header( "Content-Disposition: attachment; filename=$filename" );
60 header( 'Content-type: application/json' );
61 header( 'Content-Length: ' . mb_strlen( $json ) );
62 header( 'Connection: close' );
63 echo $json; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
64 exit;
65
66 }
67
68 }
69 }
70