PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.6
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.6
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 / labels-edit / inc / class-pble-import.php

class-pble-import.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.9.6, at add-ons-free/labels-edit/inc/class-pble-import.php

73 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WPPB_LE_Import {
4
5 protected $args_to_import;
6 public $import_messages = array();
7 private $j = '0';
8
9 /**
10 * this will take labels that will be imported to database.
11 *
12 * @param array $args_to_import labels to import.
13 */
14 function __construct( $args_to_import ) {
15 $this->args_to_import = $args_to_import;
16 }
17
18 /**
19 * this will save imported json.
20 *
21 * @param string $json_content imported json.
22 */
23 private function json_to_db( $json_content, $nonce ) {
24
25 if( !wp_verify_nonce( $nonce, 'wppb_import_labels' ) ){
26 $this->import_messages[$this->j]['message'] = __( 'You are not allowed to do this!', 'profile-builder' );
27 $this->import_messages[$this->j]['type'] = 'error';
28 $this->j++;
29 return;
30 }
31
32 /* decode and put json to array */
33 $imported_array_from_json = json_decode( $json_content, true );
34 if ( $imported_array_from_json !== NULL ) {
35 /* import labels to database */
36 foreach( $imported_array_from_json as $key => $value ) {
37 if( $key == 'pble' && ! empty( $value ) ) {
38 update_option( $key, $value );
39 }
40 }
41 } else {
42 $this->import_messages[$this->j]['message'] = __( 'Uploaded file is not valid json!', 'profile-builder' );
43 $this->import_messages[$this->j]['type'] = 'error';
44 $this->j++;
45 }
46 }
47
48 /* upload json file function */
49 public function upload_json_file() {
50 if( isset( $_POST['pble-import'] ) && isset( $_POST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['wppb_nonce'] ), 'wppb_import_labels' ) ) {
51 if( ! empty( $_FILES['pble-upload']['tmp_name'] ) ) {
52 $json_content = file_get_contents( $_FILES['pble-upload']['tmp_name'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
53 $this->json_to_db( $json_content, sanitize_text_field( $_POST['wppb_nonce'] ) );
54
55 if( empty( $this->import_messages ) ) {
56 $this->import_messages[$this->j]['message'] = __( 'Import successfully!', 'profile-builder' ) . "</p><p>" . __( 'Page will refresh in 3 seconds...', 'profile-builder' ) . '<META HTTP-EQUIV="refresh" CONTENT="3">';
57 $this->import_messages[$this->j]['type'] = 'updated';
58 $this->j++;
59 flush_rewrite_rules( false );
60 }
61 } else {
62 $this->import_messages[$this->j]['message'] = __( 'Please select a .json file to import!', 'profile-builder' );
63 $this->import_messages[$this->j]['type'] = 'error';
64 $this->j++;
65 }
66 }
67 }
68
69 /* messages return function */
70 public function get_messages() {
71 return $this->import_messages;
72 }
73 }