Passed
Push — master ( 0af8ea...fbe222 )
by Brian
04:13
created
includes/admin/class-getpaid-metaboxes.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -12,274 +12,274 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
47
-
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
50
-
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
53
-
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
58
-
59
-	}
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
60 21
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
65 26
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
68 29
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
71 32
 
72
-			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
74 35
 
75
-		}
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
76 39
 
77
-	}
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
78 44
 
79
-	/**
80
-	 * Register core metaboxes.
81
-	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
83 47
 
84
-		if ( $post_type == 'wpi_item' ) {
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type );
85 50
 
86
-			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
88 53
 
89
-			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
-			}
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
93 58
 
94
-			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
59
+    }
96 60
 
97
-		}
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type ) {
98 65
 
99
-	}
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
100 68
 
101
-	/**
102
-	 * Register invoice metaboxes.
103
-	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
105 71
 
106
-		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
72
+            // Payment form information.
73
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
109 74
 
110
-			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
75
+        }
112 76
 
113
-				add_meta_box(
114
-					'wpinv-mb-resend-invoice',
115
-					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
118
-					),
119
-					'GetPaid_Meta_Box_Resend_Invoice::output',
120
-					$post_type,
121
-					'side',
122
-					'low'
123
-				);
77
+    }
124 78
 
125
-			}
79
+    /**
80
+     * Register core metaboxes.
81
+     */
82
+    protected static function add_item_meta_boxes( $post_type ) {
126 83
 
127
-			// Subscriptions.
128
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
-			if ( ! empty( $subscriptions ) ) {
84
+        if ( $post_type == 'wpi_item' ) {
130 85
 
131
-				if ( is_array( $subscriptions ) ) {
132
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
133
-				} else {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
135
-				}
86
+            // Item details.
87
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
136 88
 
137
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
139
-				}
89
+            // If taxes are enabled, register the tax metabox.
90
+            if ( wpinv_use_taxes() ) {
91
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
+            }
140 93
 
141
-			}
94
+            // Item info.
95
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
142 96
 
143
-			// Invoice details.
144
-			add_meta_box(
145
-				'wpinv-details',
146
-				sprintf(
147
-					__( '%s Details', 'invoicing' ),
148
-					ucfirst( $invoice->get_invoice_quote_type() )
149
-				),
150
-				'GetPaid_Meta_Box_Invoice_Details::output',
151
-				$post_type,
152
-				'side'
153
-			);
97
+        }
154 98
 
155
-			// Payment details.
156
-			add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
99
+    }
157 100
 
158
-			// Billing details.
159
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
101
+    /**
102
+     * Register invoice metaboxes.
103
+     */
104
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
105
+
106
+        // For invoices...
107
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
+            $invoice = new WPInv_Invoice( $post );
109
+
110
+            // Resend invoice.
111
+            if ( ! $invoice->is_draft() ) {
112
+
113
+                add_meta_box(
114
+                    'wpinv-mb-resend-invoice',
115
+                    sprintf(
116
+                        __( 'Resend %s', 'invoicing' ),
117
+                        ucfirst( $invoice->get_invoice_quote_type() )
118
+                    ),
119
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
120
+                    $post_type,
121
+                    'side',
122
+                    'low'
123
+                );
124
+
125
+            }
126
+
127
+            // Subscriptions.
128
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
+            if ( ! empty( $subscriptions ) ) {
130
+
131
+                if ( is_array( $subscriptions ) ) {
132
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
133
+                } else {
134
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
135
+                }
136
+
137
+                if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
+                    add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
139
+                }
140
+
141
+            }
142
+
143
+            // Invoice details.
144
+            add_meta_box(
145
+                'wpinv-details',
146
+                sprintf(
147
+                    __( '%s Details', 'invoicing' ),
148
+                    ucfirst( $invoice->get_invoice_quote_type() )
149
+                ),
150
+                'GetPaid_Meta_Box_Invoice_Details::output',
151
+                $post_type,
152
+                'side'
153
+            );
154
+
155
+            // Payment details.
156
+            add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
157
+
158
+            // Billing details.
159
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
160 160
 			
161
-			// Invoice items.
162
-			add_meta_box(
163
-				'wpinv-items',
164
-				sprintf(
165
-					__( '%s Items', 'invoicing' ),
166
-					ucfirst( $invoice->get_invoice_quote_type() )
167
-				),
168
-				'GetPaid_Meta_Box_Invoice_Items::output',
169
-				$post_type,
170
-				'normal',
171
-				'high'
172
-			);
161
+            // Invoice items.
162
+            add_meta_box(
163
+                'wpinv-items',
164
+                sprintf(
165
+                    __( '%s Items', 'invoicing' ),
166
+                    ucfirst( $invoice->get_invoice_quote_type() )
167
+                ),
168
+                'GetPaid_Meta_Box_Invoice_Items::output',
169
+                $post_type,
170
+                'normal',
171
+                'high'
172
+            );
173 173
 			
174
-			// Invoice notes.
175
-			add_meta_box(
176
-				'wpinv-notes',
177
-				sprintf(
178
-					__( '%s Notes', 'invoicing' ),
179
-					ucfirst( $invoice->get_invoice_quote_type() )
180
-				),
181
-				'WPInv_Meta_Box_Notes::output',
182
-				$post_type,
183
-				'side',
184
-				'low'
185
-			);
186
-
187
-			// Shipping Address.
188
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
189
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
190
-			}
191
-
192
-			// Payment form information.
193
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
194
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
195
-			}
196
-
197
-		}
198
-
199
-	}
200
-
201
-	/**
202
-	 * Remove some metaboxes.
203
-	 */
204
-	public static function remove_meta_boxes() {
205
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
206
-	}
207
-
208
-	/**
209
-	 * Rename other metaboxes.
210
-	 */
211
-	public static function rename_meta_boxes() {
174
+            // Invoice notes.
175
+            add_meta_box(
176
+                'wpinv-notes',
177
+                sprintf(
178
+                    __( '%s Notes', 'invoicing' ),
179
+                    ucfirst( $invoice->get_invoice_quote_type() )
180
+                ),
181
+                'WPInv_Meta_Box_Notes::output',
182
+                $post_type,
183
+                'side',
184
+                'low'
185
+            );
186
+
187
+            // Shipping Address.
188
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
189
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
190
+            }
191
+
192
+            // Payment form information.
193
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
194
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
195
+            }
196
+
197
+        }
198
+
199
+    }
200
+
201
+    /**
202
+     * Remove some metaboxes.
203
+     */
204
+    public static function remove_meta_boxes() {
205
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
206
+    }
207
+
208
+    /**
209
+     * Rename other metaboxes.
210
+     */
211
+    public static function rename_meta_boxes() {
212 212
 		
213
-	}
214
-
215
-	/**
216
-	 * Check if we're saving, then trigger an action based on the post type.
217
-	 *
218
-	 * @param  int    $post_id Post ID.
219
-	 * @param  object $post Post object.
220
-	 */
221
-	public static function save_meta_boxes( $post_id, $post ) {
222
-		$post_id = absint( $post_id );
223
-		$data    = wp_kses_post_deep( wp_unslash( $_POST ) );
224
-
225
-		// Do not save for ajax requests.
226
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
227
-			return;
228
-		}
229
-
230
-		// $post_id and $post are required
231
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
232
-			return;
233
-		}
234
-
235
-		// Dont' save meta boxes for revisions or autosaves.
236
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
237
-			return;
238
-		}
239
-
240
-		// Check the nonce.
241
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
242
-			return;
243
-		}
244
-
245
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
246
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
247
-			return;
248
-		}
249
-
250
-		// Check user has permission to edit.
251
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
252
-			return;
253
-		}
254
-
255
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
256
-
257
-			// We need this save event to run once to avoid potential endless loops.
258
-			self::$saved_meta_boxes = true;
259
-
260
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
261
-
262
-		}
263
-
264
-		// Ensure this is our post type.
265
-		$post_types_map = array(
266
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
267
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
268
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
269
-		);
270
-
271
-		// Is this our post type?
272
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
273
-			return;
274
-		}
275
-
276
-		// We need this save event to run once to avoid potential endless loops.
277
-		self::$saved_meta_boxes = true;
213
+    }
214
+
215
+    /**
216
+     * Check if we're saving, then trigger an action based on the post type.
217
+     *
218
+     * @param  int    $post_id Post ID.
219
+     * @param  object $post Post object.
220
+     */
221
+    public static function save_meta_boxes( $post_id, $post ) {
222
+        $post_id = absint( $post_id );
223
+        $data    = wp_kses_post_deep( wp_unslash( $_POST ) );
224
+
225
+        // Do not save for ajax requests.
226
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
227
+            return;
228
+        }
229
+
230
+        // $post_id and $post are required
231
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
232
+            return;
233
+        }
234
+
235
+        // Dont' save meta boxes for revisions or autosaves.
236
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
237
+            return;
238
+        }
239
+
240
+        // Check the nonce.
241
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
242
+            return;
243
+        }
244
+
245
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
246
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
247
+            return;
248
+        }
249
+
250
+        // Check user has permission to edit.
251
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
252
+            return;
253
+        }
254
+
255
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
256
+
257
+            // We need this save event to run once to avoid potential endless loops.
258
+            self::$saved_meta_boxes = true;
259
+
260
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
261
+
262
+        }
263
+
264
+        // Ensure this is our post type.
265
+        $post_types_map = array(
266
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
267
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
268
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
269
+        );
270
+
271
+        // Is this our post type?
272
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
273
+            return;
274
+        }
275
+
276
+        // We need this save event to run once to avoid potential endless loops.
277
+        self::$saved_meta_boxes = true;
278 278
 		
279
-		// Save the post.
280
-		$class = $post_types_map[ $post->post_type ];
281
-		$class::save( $post_id, $_POST, $post );
279
+        // Save the post.
280
+        $class = $post_types_map[ $post->post_type ];
281
+        $class::save( $post_id, $_POST, $post );
282 282
 
283
-	}
283
+    }
284 284
 
285 285
 }
Please login to merge, or discard this patch.