Passed
Push — master ( 9a5a12...d6bea2 )
by Brian
04:47
created
includes/libraries/wp-all-import/class-getpaid-wp-all-import.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
  * @package GetPaid
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10
-include plugin_dir_path( __FILE__ ) . 'rapid-addon.php';
10
+include plugin_dir_path(__FILE__) . 'rapid-addon.php';
11 11
 
12 12
 /**
13 13
  * WP All Import class.
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
     public function __construct() {
35 35
 
36 36
 		// Init each store separately.
37
-		foreach ( array_keys( $this->datastores ) as $key ) {
38
-			$this->init_store( $key );
37
+		foreach (array_keys($this->datastores) as $key) {
38
+			$this->init_store($key);
39 39
 		}
40 40
 
41 41
 	}
@@ -43,51 +43,51 @@  discard block
 block discarded – undo
43 43
 	/**
44 44
 	 * Inits a store.
45 45
 	 */
46
-    public function init_store( $key ) {
46
+    public function init_store($key) {
47 47
 
48 48
 		// Register the add-on.
49
-		$this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key );
49
+		$this->add_ons[$key] = new RapidAddon('GetPaid', 'getpaid_wp_al_import_' . $key);
50 50
 
51 51
 		// Create import function.
52
-		$import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) {
53
-			$this->import_store( $key, $post_id, $data, $import_options, $_post );
52
+		$import_function = function($post_id, $data, $import_options, $_post) use ($key) {
53
+			$this->import_store($key, $post_id, $data, $import_options, $_post);
54 54
         };
55 55
 
56
-		$this->add_ons[ $key ]->set_import_function( $import_function );
56
+		$this->add_ons[$key]->set_import_function($import_function);
57 57
 
58 58
 		// Register store fields.
59
-		$this->add_store_fields( $key );
59
+		$this->add_store_fields($key);
60 60
 
61 61
 		// Only load on the correct post type.
62
-		$this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) );
62
+		$this->add_ons[$key]->run(array('post_types' => array('wpi_' . $key)));
63 63
 
64 64
 		// Disable images.
65
-		$this->add_ons[ $key ]->disable_default_images();
65
+		$this->add_ons[$key]->disable_default_images();
66 66
 
67 67
 	}
68 68
 
69 69
 	/**
70 70
 	 * Retrieves store fields.
71 71
 	 */
72
-    public function get_store_fields( $key ) {
72
+    public function get_store_fields($key) {
73 73
 
74 74
 		// Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php
75
-		$fields = wpinv_get_data( $key . '-schema' );
75
+		$fields = wpinv_get_data($key . '-schema');
76 76
 
77
-		if ( empty( $fields ) ) {
77
+		if (empty($fields)) {
78 78
 			return array();
79 79
 		}
80 80
 
81 81
 		// Clean the fields.
82 82
 		$prepared = array();
83
-		foreach ( $fields as $id => $field ) {
83
+		foreach ($fields as $id => $field) {
84 84
 
85 85
 			// Skip read only fields.
86
-			if ( ! empty( $field['readonly'] ) ) {
86
+			if (!empty($field['readonly'])) {
87 87
 				continue;
88 88
 			}
89 89
 
90
-			$prepared[ $id ] = $field;
90
+			$prepared[$id] = $field;
91 91
 
92 92
 		}
93 93
 
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
 	/**
99 99
 	 * Registers store fields.
100 100
 	 */
101
-    public function add_store_fields( $key ) {
101
+    public function add_store_fields($key) {
102 102
 
103
-		foreach ( $this->get_store_fields( $key ) as $field_id => $data ) {
104
-			$this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' );
103
+		foreach ($this->get_store_fields($key) as $field_id => $data) {
104
+			$this->add_ons[$key]->add_field($field_id, $data['description'], 'text');
105 105
 		}
106 106
 
107 107
     }
@@ -109,36 +109,36 @@  discard block
 block discarded – undo
109 109
 	/**
110 110
 	 * Handles store imports.
111 111
 	 */
112
-    public function import_store( $key, $post_id, $data, $import_options, $_post ) {
112
+    public function import_store($key, $post_id, $data, $import_options, $_post) {
113 113
 
114 114
 		// Is the store class set?
115
-		if ( ! isset( $this->datastores[ $key ] ) ) {
115
+		if (!isset($this->datastores[$key])) {
116 116
 			return;
117 117
 		}
118 118
 
119 119
 		/**@var GetPaid_Data */
120
-		$data_store = new $this->datastores[ $key ]( $post_id );
120
+		$data_store = new $this->datastores[$key]($post_id);
121 121
 
122 122
 		// Abort if the invoice/item/discount does not exist.
123
-		if ( ! $data_store->exists() ) {
123
+		if (!$data_store->exists()) {
124 124
 			return;
125 125
 		}
126 126
 
127 127
 		// Prepare data props.
128 128
 		$prepared = array();
129 129
 
130
-		foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { 
130
+		foreach (array_keys($this->get_store_fields($key)) as $field) { 
131 131
 			// Make sure the user has allowed this field to be updated.
132
-			if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { 
132
+			if (empty($_post['ID']) || $this->add_ons[$key]->can_update_meta($field, $import_options)) { 
133 133
 	
134 134
 				// Update the custom field with the imported data.
135
-				$prepared[ $field ] = $data[ $field ];
135
+				$prepared[$field] = $data[$field];
136 136
 			} 
137 137
 		}
138 138
 
139 139
 		// Only update if we have something to update.
140
-		if ( ! empty( $prepared ) ) {
141
-			$data_store->set_props( $prepared );
140
+		if (!empty($prepared)) {
141
+			$data_store->set_props($prepared);
142 142
 			$data_store->save();
143 143
 		}
144 144
 
Please login to merge, or discard this patch.