Passed
Push — master ( 9a5a12...d6bea2 )
by Brian
04:47
created
includes/libraries/wp-all-import/class-getpaid-wp-all-import.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -14,133 +14,133 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_WP_All_Import {
16 16
 
17
-	/**
18
-	 * @var RapidAddon[]
19
-	 */
20
-	protected $add_ons;
21
-
22
-	/**
23
-	 * @var array
24
-	 */
25
-	protected $datastores = array(
26
-		'item'     =>'WPInv_Item',
27
-		'invoice'  =>'WPInv_Invoice',
28
-		'discount' =>'WPInv_Discount',
29
-	);
17
+    /**
18
+     * @var RapidAddon[]
19
+     */
20
+    protected $add_ons;
21
+
22
+    /**
23
+     * @var array
24
+     */
25
+    protected $datastores = array(
26
+        'item'     =>'WPInv_Item',
27
+        'invoice'  =>'WPInv_Invoice',
28
+        'discount' =>'WPInv_Discount',
29
+    );
30 30
 
31 31
     /**
32
-	 * Class constructor.
33
-	 */
32
+     * Class constructor.
33
+     */
34 34
     public function __construct() {
35 35
 
36
-		// Init each store separately.
37
-		foreach ( array_keys( $this->datastores ) as $key ) {
38
-			$this->init_store( $key );
39
-		}
36
+        // Init each store separately.
37
+        foreach ( array_keys( $this->datastores ) as $key ) {
38
+            $this->init_store( $key );
39
+        }
40 40
 
41
-	}
41
+    }
42 42
 
43
-	/**
44
-	 * Inits a store.
45
-	 */
43
+    /**
44
+     * Inits a store.
45
+     */
46 46
     public function init_store( $key ) {
47 47
 
48
-		// Register the add-on.
49
-		$this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key );
48
+        // Register the add-on.
49
+        $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key );
50 50
 
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 );
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 );
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
-		// Register store fields.
59
-		$this->add_store_fields( $key );
58
+        // Register store fields.
59
+        $this->add_store_fields( $key );
60 60
 
61
-		// Only load on the correct post type.
62
-		$this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) );
61
+        // Only load on the correct post type.
62
+        $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) );
63 63
 
64
-		// Disable images.
65
-		$this->add_ons[ $key ]->disable_default_images();
64
+        // Disable images.
65
+        $this->add_ons[ $key ]->disable_default_images();
66 66
 
67
-	}
67
+    }
68 68
 
69
-	/**
70
-	 * Retrieves store fields.
71
-	 */
69
+    /**
70
+     * Retrieves store fields.
71
+     */
72 72
     public function get_store_fields( $key ) {
73 73
 
74
-		// Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php
75
-		$fields = wpinv_get_data( $key . '-schema' );
74
+        // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php
75
+        $fields = wpinv_get_data( $key . '-schema' );
76 76
 
77
-		if ( empty( $fields ) ) {
78
-			return array();
79
-		}
77
+        if ( empty( $fields ) ) {
78
+            return array();
79
+        }
80 80
 
81
-		// Clean the fields.
82
-		$prepared = array();
83
-		foreach ( $fields as $id => $field ) {
81
+        // Clean the fields.
82
+        $prepared = array();
83
+        foreach ( $fields as $id => $field ) {
84 84
 
85
-			// Skip read only fields.
86
-			if ( ! empty( $field['readonly'] ) ) {
87
-				continue;
88
-			}
85
+            // Skip read only fields.
86
+            if ( ! empty( $field['readonly'] ) ) {
87
+                continue;
88
+            }
89 89
 
90
-			$prepared[ $id ] = $field;
90
+            $prepared[ $id ] = $field;
91 91
 
92
-		}
92
+        }
93 93
 
94
-		return $prepared;
94
+        return $prepared;
95 95
 
96
-	}
96
+    }
97 97
 
98
-	/**
99
-	 * Registers store fields.
100
-	 */
98
+    /**
99
+     * Registers store fields.
100
+     */
101 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' );
105
-		}
103
+        foreach ( $this->get_store_fields( $key ) as $field_id => $data ) {
104
+            $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' );
105
+        }
106 106
 
107 107
     }
108 108
 
109
-	/**
110
-	 * Handles store imports.
111
-	 */
109
+    /**
110
+     * Handles store imports.
111
+     */
112 112
     public function import_store( $key, $post_id, $data, $import_options, $_post ) {
113 113
 
114
-		// Is the store class set?
115
-		if ( ! isset( $this->datastores[ $key ] ) ) {
116
-			return;
117
-		}
114
+        // Is the store class set?
115
+        if ( ! isset( $this->datastores[ $key ] ) ) {
116
+            return;
117
+        }
118 118
 
119
-		/**@var GetPaid_Data */
120
-		$data_store = new $this->datastores[ $key ]( $post_id );
119
+        /**@var GetPaid_Data */
120
+        $data_store = new $this->datastores[ $key ]( $post_id );
121 121
 
122
-		// Abort if the invoice/item/discount does not exist.
123
-		if ( ! $data_store->exists() ) {
124
-			return;
125
-		}
122
+        // Abort if the invoice/item/discount does not exist.
123
+        if ( ! $data_store->exists() ) {
124
+            return;
125
+        }
126 126
 
127
-		// Prepare data props.
128
-		$prepared = array();
127
+        // Prepare data props.
128
+        $prepared = array();
129 129
 
130
-		foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { 
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 ) ) { 
130
+        foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { 
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 ) ) { 
133 133
 	
134
-				// Update the custom field with the imported data.
135
-				$prepared[ $field ] = $data[ $field ];
136
-			} 
137
-		}
138
-
139
-		// Only update if we have something to update.
140
-		if ( ! empty( $prepared ) ) {
141
-			$data_store->set_props( $prepared );
142
-			$data_store->save();
143
-		}
134
+                // Update the custom field with the imported data.
135
+                $prepared[ $field ] = $data[ $field ];
136
+            } 
137
+        }
138
+
139
+        // Only update if we have something to update.
140
+        if ( ! empty( $prepared ) ) {
141
+            $data_store->set_props( $prepared );
142
+            $data_store->save();
143
+        }
144 144
 
145 145
     }
146 146
 
Please login to merge, or discard this patch.