PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.8
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.8
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / admin / class-admin-tools.php

class-admin-tools.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.4.8, at includes/admin/class-admin-tools.php

122 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Manage Import Export
5 *
6 * @since 1.1.0
7 */
8 class WeForms_Admin_Tools {
9
10 /**
11 * Import json file into database
12 *
13 * @param array $file
14 *
15 * @return bool
16 */
17 public static function import_json_file( $file ) {
18 $encode_data = file_get_contents( $file );
19 $options = json_decode( $encode_data, true );
20
21 foreach ( $options as $key => $value ) {
22 $generate_post = [
23 'post_title' => $value['post_data']['post_title'],
24 'post_status' => $value['post_data']['post_status'],
25 'post_type' => $value['post_data']['post_type'],
26 'ping_status' => $value['post_data']['ping_status'],
27 'comment_status' => $value['post_data']['comment_status'],
28 ];
29
30 $post_id = wp_insert_post( $generate_post, true );
31
32 if ( $post_id && !is_wp_error( $post_id ) ) {
33 foreach ( $value['meta_data']['fields'] as $order => $field ) {
34 weforms_insert_form_field( $post_id, $field, false, $order );
35 }
36
37 update_post_meta( $post_id, 'wpuf_form_settings', $value['meta_data']['settings'] );
38 update_post_meta( $post_id, 'notifications', $value['meta_data']['notifications'] );
39 }
40 }
41
42 return true;
43 }
44
45 /**
46 * Export into json file
47 *
48 * @param string $post_type
49 * @param array $post_ids
50 */
51 public static function export_to_json( $post_ids = [ ] ) {
52 $formatted_data = [];
53 $ids = [];
54 $blogname = strtolower( str_replace( ' ', '-', get_option( 'blogname' ) ) );
55 $json_name = $blogname . '-weforms-' . time(); // Namming the filename will be generated.
56
57 if ( !empty( $post_ids ) ) {
58 foreach ( $post_ids as $key => $value ) {
59 array_push( $ids, $value );
60 }
61 }
62
63 $args = [
64 'post_status' => 'publish',
65 'post_type' => 'wpuf_contact_form',
66 'post__in' => ( !empty( $ids ) ) ? $ids : '',
67 ];
68
69 $query = new WP_Query( $args );
70
71 foreach ( $query->posts as $post ) {
72 $postdata = get_object_vars( $post );
73 unset( $postdata['ID'] );
74
75 $form = weforms()->form->get( $post );
76
77 $data = [
78 'post_data' => $postdata,
79 'meta_data' => [
80 'fields' => $form->get_fields(),
81 'settings' => $form->get_settings(),
82 'notifications' => $form->get_notifications(),
83 ],
84 ];
85
86 array_push( $formatted_data, $data );
87 }
88
89 $json_file = json_encode( $formatted_data ); // Encode data into json data
90
91 error_reporting( 0 );
92
93 if ( ob_get_contents() ) {
94 ob_clean();
95 }
96
97 header( 'Content-Type: text/json; charset=' . get_option( 'blog_charset' ) );
98 header( "Content-Disposition: attachment; filename=$json_name.json" );
99
100 echo esc_attr( $json_file );
101
102 exit();
103 }
104
105 /**
106 * Formetted meta key value
107 *
108 * @param array $array
109 *
110 * @return array
111 */
112 public function formetted_meta_key_value( $array ) {
113 $result = [ ];
114
115 foreach ( $array as $key => $val ) {
116 $result[$key] = $val[0];
117 }
118
119 return $result;
120 }
121 }
122