Passed
Push — master ( 568391...260ce8 )
by Brian
05:13
created
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -13,616 +13,616 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-
29
-		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
32
-
33
-		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
40
-
41
-		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
-
46
-		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
48
-
49
-		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
-	}
53
-
54
-	/**
55
-	 * Post updated messages.
56
-	 */
57
-	public static function post_updated_messages( $messages ) {
58
-		global $post;
59
-
60
-		$messages['wpi_discount'] = array(
61
-			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
72
-		);
73
-
74
-		$messages['wpi_payment_form'] = array(
75
-			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
-		);
87
-
88
-		return $messages;
89
-
90
-	}
91
-
92
-	/**
93
-	 * Post row actions.
94
-	 */
95
-	public static function post_row_actions( $actions, $post ) {
96
-
97
-		$post = get_post( $post );
98
-
99
-		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
103
-		}
104
-
105
-		return $actions;
106
-	}
107
-
108
-	/**
109
-	 * Returns an array of invoice table columns.
110
-	 */
111
-	public static function invoice_columns( $columns ) {
112
-
113
-		$columns = array(
114
-			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
-		);
123
-
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
125
-	}
126
-
127
-	/**
128
-	 * Displays invoice table columns.
129
-	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
131
-
132
-		$invoice = new WPInv_Invoice( $post_id );
133
-
134
-		switch ( $column_name ) {
135
-
136
-			case 'invoice_date' :
137
-				$date_time = esc_attr( $invoice->get_created_date() );
138
-				$date      = getpaid_format_date_value( $date_time );
139
-				echo "<span title='$date_time'>$date</span>";
140
-				break;
141
-
142
-			case 'amount' :
143
-
144
-				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
-
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
-					echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
-				} else {
151
-
152
-					$discount = $invoice->get_total_discount();
153
-
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
-						echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
-					} else {
158
-						echo $formated_amount;
159
-					}
160
-
161
-				}
162
-
163
-				break;
164
-
165
-			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
-
169
-				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
173 19
 
174
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
-				} else {
176
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
-				}
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
178 22
 
179
-				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
181 25
 
182
-					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
-					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
-					}
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
188 28
 
189
-					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
191
-						$due_date = $invoice->get_due_date();
192
-						$fomatted = getpaid_format_date( $due_date );
29
+        // Invoice table columns.
30
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
193 32
 
194
-						if ( ! empty( $fomatted ) ) {
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
196
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197
-						}
198
-					}
33
+        // Items table columns.
34
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
199 40
 
200
-				}
41
+        // Payment forms columns.
42
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
201 45
 
202
-				break;
46
+        // Discount table columns.
47
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
203 48
 
204
-			case 'recurring':
49
+        // Deleting posts.
50
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
+    }
205 53
 
206
-				if ( $invoice->is_recurring() ) {
207
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
-				} else {
209
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
-				}
211
-				break;
54
+    /**
55
+     * Post updated messages.
56
+     */
57
+    public static function post_updated_messages( $messages ) {
58
+        global $post;
59
+
60
+        $messages['wpi_discount'] = array(
61
+            0   => '',
62
+            1   => __( 'Discount updated.', 'invoicing' ),
63
+            2   => __( 'Custom field updated.', 'invoicing' ),
64
+            3   => __( 'Custom field deleted.', 'invoicing' ),
65
+            4   => __( 'Discount updated.', 'invoicing' ),
66
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
+            6   => __( 'Discount updated.', 'invoicing' ),
68
+            7   => __( 'Discount saved.', 'invoicing' ),
69
+            8   => __( 'Discount submitted.', 'invoicing' ),
70
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
+            10  => __( 'Discount draft updated.', 'invoicing' ),
72
+        );
73
+
74
+        $messages['wpi_payment_form'] = array(
75
+            0   => '',
76
+            1   => __( 'Payment Form updated.', 'invoicing' ),
77
+            2   => __( 'Custom field updated.', 'invoicing' ),
78
+            3   => __( 'Custom field deleted.', 'invoicing' ),
79
+            4   => __( 'Payment Form updated.', 'invoicing' ),
80
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
+            6   => __( 'Payment Form updated.', 'invoicing' ),
82
+            7   => __( 'Payment Form saved.', 'invoicing' ),
83
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
84
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
+        );
87
+
88
+        return $messages;
89
+
90
+    }
91
+
92
+    /**
93
+     * Post row actions.
94
+     */
95
+    public static function post_row_actions( $actions, $post ) {
96
+
97
+        $post = get_post( $post );
98
+
99
+        // We do not want to edit the default payment form.
100
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
+            unset( $actions['trash'] );
102
+            unset( $actions['inline hide-if-no-js'] );
103
+        }
104
+
105
+        return $actions;
106
+    }
107
+
108
+    /**
109
+     * Returns an array of invoice table columns.
110
+     */
111
+    public static function invoice_columns( $columns ) {
112
+
113
+        $columns = array(
114
+            'cb'                => $columns['cb'],
115
+            'number'            => __( 'Invoice', 'invoicing' ),
116
+            'customer'          => __( 'Customer', 'invoicing' ),
117
+            'invoice_date'      => __( 'Date', 'invoicing' ),
118
+            'amount'            => __( 'Amount', 'invoicing' ),
119
+            'recurring'         => __( 'Recurring', 'invoicing' ),
120
+            'status'            => __( 'Status', 'invoicing' ),
121
+            'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
+        );
123
+
124
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
125
+    }
126
+
127
+    /**
128
+     * Displays invoice table columns.
129
+     */
130
+    public static function display_invoice_columns( $column_name, $post_id ) {
131
+
132
+        $invoice = new WPInv_Invoice( $post_id );
133
+
134
+        switch ( $column_name ) {
135
+
136
+            case 'invoice_date' :
137
+                $date_time = esc_attr( $invoice->get_created_date() );
138
+                $date      = getpaid_format_date_value( $date_time );
139
+                echo "<span title='$date_time'>$date</span>";
140
+                break;
141
+
142
+            case 'amount' :
143
+
144
+                $amount = $invoice->get_total();
145
+                $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
+
147
+                if ( $invoice->is_refunded() ) {
148
+                    $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
+                    echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
+                } else {
151
+
152
+                    $discount = $invoice->get_total_discount();
153
+
154
+                    if ( ! empty( $discount ) ) {
155
+                        $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
+                        echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
+                    } else {
158
+                        echo $formated_amount;
159
+                    }
160
+
161
+                }
162
+
163
+                break;
164
+
165
+            case 'status' :
166
+                $status       = sanitize_text_field( $invoice->get_status() );
167
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
+
169
+                // If it is paid, show the gateway title.
170
+                if ( $invoice->is_paid() ) {
171
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
212 173
 
213
-			case 'number' :
174
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
+                } else {
176
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
+                }
214 178
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
179
+                // If it is not paid, display the overdue and view status.
180
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
218 181
 
219
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
182
+                    // Invoice view status.
183
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
+                    } else {
186
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
+                    }
220 188
 
221
-				break;
189
+                    // Display the overview status.
190
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
191
+                        $due_date = $invoice->get_due_date();
192
+                        $fomatted = getpaid_format_date( $due_date );
222 193
 
223
-			case 'customer' :
194
+                        if ( ! empty( $fomatted ) ) {
195
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
196
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197
+                        }
198
+                    }
199
+
200
+                }
201
+
202
+                break;
203
+
204
+            case 'recurring':
205
+
206
+                if ( $invoice->is_recurring() ) {
207
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
+                } else {
209
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
+                }
211
+                break;
212
+
213
+            case 'number' :
214
+
215
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
217
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
218
+
219
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220
+
221
+                break;
222
+
223
+            case 'customer' :
224 224
 	
225
-				$customer_name = $invoice->get_user_full_name();
225
+                $customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
228
-					$customer_name = $invoice->get_email();
229
-				}
227
+                if ( empty( $customer_name ) ) {
228
+                    $customer_name = $invoice->get_email();
229
+                }
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
-				} else {
236
-					echo '<div>&mdash;</div>';
237
-				}
231
+                if ( ! empty( $customer_name ) ) {
232
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
+                } else {
236
+                    echo '<div>&mdash;</div>';
237
+                }
238
+
239
+                break;
240
+
241
+            case 'wpi_actions' :
242
+
243
+                if ( $invoice->is_draft() ) {
244
+                    return;
245
+                }
246
+
247
+                $url    = esc_url( $invoice->get_view_url() );
248
+                $print  = esc_attr__( 'Print invoice', 'invoicing' );
249
+                echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250
+
251
+                $url    = esc_url(
252
+                    wp_nonce_url(
253
+                        add_query_arg(
254
+                            array(
255
+                                'getpaid-admin-action' => 'send_invoice',
256
+                                'invoice_id'           => $invoice->get_id()
257
+                            )
258
+                        ),
259
+                        'getpaid-nonce',
260
+                        'getpaid-nonce'
261
+                    )
262
+                );
263
+
264
+                $send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
+                echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266
+
267
+                break;
268
+        }
238 269
 
239
-				break;
270
+    }
240 271
 
241
-			case 'wpi_actions' :
242
-
243
-				if ( $invoice->is_draft() ) {
244
-					return;
245
-				}
246
-
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
249
-				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
272
+    /**
273
+     * Returns an array of payment forms table columns.
274
+     */
275
+    public static function payment_form_columns( $columns ) {
250 276
 
251
-				$url    = esc_url(
252
-					wp_nonce_url(
253
-						add_query_arg(
254
-							array(
255
-								'getpaid-admin-action' => 'send_invoice',
256
-								'invoice_id'           => $invoice->get_id()
257
-							)
258
-						),
259
-						'getpaid-nonce',
260
-						'getpaid-nonce'
261
-					)
262
-				);
277
+        $columns = array(
278
+            'cb'                => $columns['cb'],
279
+            'title'             => __( 'Name', 'invoicing' ),
280
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
+            'earnings'          => __( 'Revenue', 'invoicing' ),
282
+            'refunds'           => __( 'Refunded', 'invoicing' ),
283
+            'items'             => __( 'Items', 'invoicing' ),
284
+            'date'              => __( 'Date', 'invoicing' ),
285
+        );
263 286
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
-				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
287
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
266 288
 
267
-				break;
268
-		}
289
+    }
269 290
 
270
-	}
291
+    /**
292
+     * Displays payment form table columns.
293
+     */
294
+    public static function display_payment_form_columns( $column_name, $post_id ) {
271 295
 
272
-	/**
273
-	 * Returns an array of payment forms table columns.
274
-	 */
275
-	public static function payment_form_columns( $columns ) {
296
+        // Retrieve the payment form.
297
+        $form = new GetPaid_Payment_Form( $post_id );
276 298
 
277
-		$columns = array(
278
-			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
285
-		);
299
+        switch ( $column_name ) {
286 300
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
301
+            case 'earnings' :
302
+                echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
+                break;
288 304
 
289
-	}
305
+            case 'refunds' :
306
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
+                break;
290 308
 
291
-	/**
292
-	 * Displays payment form table columns.
293
-	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
309
+            case 'refunds' :
310
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
+                break;
295 312
 
296
-		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
313
+            case 'shortcode' :
298 314
 
299
-		switch ( $column_name ) {
315
+                if ( $form->is_default() ) {
316
+                    echo '&mdash;';
317
+                } else {
318
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
+                }
300 320
 
301
-			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
-				break;
321
+                break;
304 322
 
305
-			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
-				break;
323
+            case 'items' :
308 324
 
309
-			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
-				break;
325
+                $items = $form->get_items();
312 326
 
313
-			case 'shortcode' :
327
+                if ( $form->is_default() || empty( $items ) ) {
328
+                    echo '&mdash;';
329
+                    return;
330
+                }
314 331
 
315
-				if ( $form->is_default() ) {
316
-					echo '&mdash;';
317
-				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
-				}
332
+                $_items = array();
320 333
 
321
-				break;
334
+                foreach ( $items as $item ) {
335
+                    $url = $item->get_edit_url();
322 336
 
323
-			case 'items' :
337
+                    if ( empty( $url ) ) {
338
+                        $_items[] = sanitize_text_field( $item->get_name() );
339
+                    } else {
340
+                        $_items[] = sprintf(
341
+                            '<a href="%s">%s</a>',
342
+                            esc_url( $url ),
343
+                            sanitize_text_field( $item->get_name() )
344
+                        );
345
+                    }
324 346
 
325
-				$items = $form->get_items();
347
+                }
326 348
 
327
-				if ( $form->is_default() || empty( $items ) ) {
328
-					echo '&mdash;';
329
-					return;
330
-				}
349
+                echo implode( '<br>', $_items );
331 350
 
332
-				$_items = array();
351
+                break;
333 352
 
334
-				foreach ( $items as $item ) {
335
-					$url = $item->get_edit_url();
353
+        }
336 354
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
339
-					} else {
340
-						$_items[] = sprintf(
341
-							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
344
-						);
345
-					}
355
+    }
346 356
 
347
-				}
357
+    /**
358
+     * Filters post states.
359
+     */
360
+    public static function filter_payment_form_state( $post_states, $post ) {
348 361
 
349
-				echo implode( '<br>', $_items );
362
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
+        }
365
+	
366
+        return $post_states;
350 367
 
351
-				break;
368
+    }
352 369
 
353
-		}
370
+    /**
371
+     * Returns an array of coupon table columns.
372
+     */
373
+    public static function discount_columns( $columns ) {
374
+
375
+        $columns = array(
376
+            'cb'                => $columns['cb'],
377
+            'title'             => __( 'Name', 'invoicing' ),
378
+            'code'              => __( 'Code', 'invoicing' ),
379
+            'amount'            => __( 'Amount', 'invoicing' ),
380
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
+            'start_date'        => __( 'Start Date', 'invoicing' ),
382
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
+        );
384
+
385
+        return apply_filters( 'wpi_discount_table_columns', $columns );
386
+    }
354 387
 
355
-	}
388
+    /**
389
+     * Filters post states.
390
+     */
391
+    public static function filter_discount_state( $post_states, $post ) {
356 392
 
357
-	/**
358
-	 * Filters post states.
359
-	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
393
+        if ( 'wpi_discount' == $post->post_type ) {
361 394
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
-		}
365
-	
366
-		return $post_states;
395
+            $discount = new WPInv_Discount( $post );
367 396
 
368
-	}
397
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
369 398
 
370
-	/**
371
-	 * Returns an array of coupon table columns.
372
-	 */
373
-	public static function discount_columns( $columns ) {
399
+            if ( $status != 'publish' ) {
400
+                return array(
401
+                    'discount_status' => wpinv_discount_status( $status ),
402
+                );
403
+            }
374 404
 
375
-		$columns = array(
376
-			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
-		);
405
+            return array();
384 406
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
386
-	}
407
+        }
387 408
 
388
-	/**
389
-	 * Filters post states.
390
-	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
409
+        return $post_states;
392 410
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
411
+    }
394 412
 
395
-			$discount = new WPInv_Discount( $post );
413
+    /**
414
+     * Returns an array of items table columns.
415
+     */
416
+    public static function item_columns( $columns ) {
417
+        global $wpinv_euvat;
418
+
419
+        $columns = array(
420
+            'cb'                => $columns['cb'],
421
+            'title'             => __( 'Name', 'invoicing' ),
422
+            'price'             => __( 'Price', 'invoicing' ),
423
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
425
+            'type'              => __( 'Type', 'invoicing' ),
426
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
+        );
428
+
429
+        if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
+            unset( $columns['vat_rule'] );
431
+        }
396 432
 
397
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
433
+        if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
+            unset( $columns['vat_class'] );
435
+        }
398 436
 
399
-			if ( $status != 'publish' ) {
400
-				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
402
-				);
403
-			}
437
+        return apply_filters( 'wpi_item_table_columns', $columns );
438
+    }
404 439
 
405
-			return array();
440
+    /**
441
+     * Returns an array of sortable items table columns.
442
+     */
443
+    public static function sortable_item_columns( $columns ) {
444
+
445
+        return array_merge(
446
+            $columns,
447
+            array(
448
+                'price'     => 'price',
449
+                'vat_rule'  => 'vat_rule',
450
+                'vat_class' => 'vat_class',
451
+                'type'      => 'type',
452
+            )
453
+        );
454
+
455
+    }
406 456
 
407
-		}
457
+    /**
458
+     * Displays items table columns.
459
+     */
460
+    public static function display_item_columns( $column_name, $post_id ) {
461
+        global $wpinv_euvat;
408 462
 
409
-		return $post_states;
463
+        $item = new WPInv_Item( $post_id );
410 464
 
411
-	}
465
+        switch ( $column_name ) {
412 466
 
413
-	/**
414
-	 * Returns an array of items table columns.
415
-	 */
416
-	public static function item_columns( $columns ) {
417
-		global $wpinv_euvat;
467
+            case 'price' :
418 468
 
419
-		$columns = array(
420
-			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
-		);
469
+                if ( ! $item->is_recurring() ) {
470
+                    echo $item->get_the_price();
471
+                    break;
472
+                }
428 473
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
431
-		}
474
+                $price = wp_sprintf(
475
+                    __( '%s / %s', 'invoicing' ),
476
+                    $item->get_the_price(),
477
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
478
+                );
432 479
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
435
-		}
480
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
+                    echo $price;
482
+                    break;
483
+                }
436 484
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
438
-	}
485
+                echo $item->get_the_initial_price();
439 486
 
440
-	/**
441
-	 * Returns an array of sortable items table columns.
442
-	 */
443
-	public static function sortable_item_columns( $columns ) {
487
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
+                break;
444 489
 
445
-		return array_merge(
446
-			$columns,
447
-			array(
448
-				'price'     => 'price',
449
-				'vat_rule'  => 'vat_rule',
450
-				'vat_class' => 'vat_class',
451
-				'type'      => 'type',
452
-			)
453
-		);
490
+            case 'vat_rule' :
491
+                echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
+                break;
454 493
 
455
-	}
494
+            case 'vat_class' :
495
+                echo $wpinv_euvat->item_class_label( $item->get_id() );
496
+                break;
456 497
 
457
-	/**
458
-	 * Displays items table columns.
459
-	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
461
-		global $wpinv_euvat;
498
+            case 'shortcode' :
499
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
+                break;
462 501
 
463
-		$item = new WPInv_Item( $post_id );
502
+            case 'type' :
503
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
+                break;
464 505
 
465
-		switch ( $column_name ) {
506
+        }
466 507
 
467
-			case 'price' :
508
+    }
468 509
 
469
-				if ( ! $item->is_recurring() ) {
470
-					echo $item->get_the_price();
471
-					break;
472
-				}
510
+    /**
511
+     * Lets users filter items using taxes.
512
+     */
513
+    public static function add_item_filters( $post_type ) {
514
+        $wpinv_euvat = getpaid_tax();
515
+
516
+        // Abort if we're not dealing with items.
517
+        if ( $post_type != 'wpi_item' ) {
518
+            return;
519
+        }
520
+
521
+        // Filter by vat rules.
522
+        if ( $wpinv_euvat->allow_vat_rules() ) {
523
+	
524
+            // Sanitize selected vat rule.
525
+            $vat_rule   = '';
526
+            $vat_rules  = $wpinv_euvat->get_rules();
527
+            if ( isset( $_GET['vat_rule'] ) ) {
528
+                $vat_rule   =  $_GET['vat_rule'];
529
+            }
530
+
531
+            // Filter by VAT rule.
532
+            echo wpinv_html_select(
533
+                array(
534
+                    'options'          => array_merge(
535
+                        array(
536
+                            '' => __( 'All VAT rules', 'invoicing' )
537
+                        ),
538
+                        $vat_rules
539
+                    ),
540
+                    'name'             => 'vat_rule',
541
+                    'id'               => 'vat_rule',
542
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
543
+                    'show_option_all'  => false,
544
+                    'show_option_none' => false,
545
+                    'class'            => 'gdmbx2-text-medium',
546
+                )
547
+            );
548
+
549
+            // Filter by VAT class.
550
+        }
473 551
 
474
-				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
476
-					$item->get_the_price(),
477
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
478
-				);
552
+        // Filter by vat class.
553
+        if ( $wpinv_euvat->allow_vat_classes() ) {
554
+	
555
+            // Sanitize selected vat rule.
556
+            $vat_class   = '';
557
+            $vat_classes = $wpinv_euvat->get_all_classes();
558
+            if ( isset( $_GET['vat_class'] ) ) {
559
+                $vat_class   =  $_GET['vat_class'];
560
+            }
561
+
562
+            echo wpinv_html_select(
563
+                array(
564
+                    'options'          => array_merge(
565
+                        array(
566
+                            '' => __( 'All VAT classes', 'invoicing' )
567
+                        ),
568
+                        $vat_classes
569
+                    ),
570
+                    'name'             => 'vat_class',
571
+                    'id'               => 'vat_class',
572
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
573
+                    'show_option_all'  => false,
574
+                    'show_option_none' => false,
575
+                    'class'            => 'gdmbx2-text-medium',
576
+                )
577
+            );
479 578
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
-					echo $price;
482
-					break;
483
-				}
579
+        }
484 580
 
485
-				echo $item->get_the_initial_price();
581
+        // Filter by item type.
582
+        $type   = '';
583
+        if ( isset( $_GET['type'] ) ) {
584
+            $type   =  $_GET['type'];
585
+        }
486 586
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
-				break;
587
+        echo wpinv_html_select(
588
+            array(
589
+                'options'          => array_merge(
590
+                    array(
591
+                        '' => __( 'All item types', 'invoicing' )
592
+                    ),
593
+                    wpinv_get_item_types()
594
+                ),
595
+                'name'             => 'type',
596
+                'id'               => 'type',
597
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
598
+                'show_option_all'  => false,
599
+                'show_option_none' => false,
600
+                'class'            => 'gdmbx2-text-medium',
601
+            )
602
+        );
603
+
604
+    }
489 605
 
490
-			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
-				break;
606
+    /**
607
+     * Filters the item query.
608
+     */
609
+    public static function filter_item_query( $query ) {
493 610
 
494
-			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
496
-				break;
611
+        // modify the query only if it admin and main query.
612
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
613
+            return $query;
614
+        }
497 615
 
498
-			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
-				break;
616
+        // we want to modify the query for our items.
617
+        if ( 'wpi_item' != $query->query['post_type'] ){
618
+            return $query;
619
+        }
501 620
 
502
-			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
-				break;
621
+        if ( empty( $query->query_vars['meta_query'] ) ) {
622
+            $query->query_vars['meta_query'] = array();
623
+        }
505 624
 
506
-		}
507
-
508
-	}
509
-
510
-	/**
511
-	 * Lets users filter items using taxes.
512
-	 */
513
-	public static function add_item_filters( $post_type ) {
514
-		$wpinv_euvat = getpaid_tax();
515
-
516
-		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
518
-			return;
519
-		}
520
-
521
-		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
523
-	
524
-			// Sanitize selected vat rule.
525
-			$vat_rule   = '';
526
-			$vat_rules  = $wpinv_euvat->get_rules();
527
-			if ( isset( $_GET['vat_rule'] ) ) {
528
-				$vat_rule   =  $_GET['vat_rule'];
529
-			}
530
-
531
-			// Filter by VAT rule.
532
-			echo wpinv_html_select(
533
-				array(
534
-					'options'          => array_merge(
535
-						array(
536
-							'' => __( 'All VAT rules', 'invoicing' )
537
-						),
538
-						$vat_rules
539
-					),
540
-					'name'             => 'vat_rule',
541
-					'id'               => 'vat_rule',
542
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
543
-					'show_option_all'  => false,
544
-					'show_option_none' => false,
545
-					'class'            => 'gdmbx2-text-medium',
546
-				)
547
-			);
548
-
549
-			// Filter by VAT class.
550
-		}
551
-
552
-		// Filter by vat class.
553
-		if ( $wpinv_euvat->allow_vat_classes() ) {
554
-	
555
-			// Sanitize selected vat rule.
556
-			$vat_class   = '';
557
-			$vat_classes = $wpinv_euvat->get_all_classes();
558
-			if ( isset( $_GET['vat_class'] ) ) {
559
-				$vat_class   =  $_GET['vat_class'];
560
-			}
561
-
562
-			echo wpinv_html_select(
563
-				array(
564
-					'options'          => array_merge(
565
-						array(
566
-							'' => __( 'All VAT classes', 'invoicing' )
567
-						),
568
-						$vat_classes
569
-					),
570
-					'name'             => 'vat_class',
571
-					'id'               => 'vat_class',
572
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
573
-					'show_option_all'  => false,
574
-					'show_option_none' => false,
575
-					'class'            => 'gdmbx2-text-medium',
576
-				)
577
-			);
578
-
579
-		}
580
-
581
-		// Filter by item type.
582
-		$type   = '';
583
-		if ( isset( $_GET['type'] ) ) {
584
-			$type   =  $_GET['type'];
585
-		}
586
-
587
-		echo wpinv_html_select(
588
-			array(
589
-				'options'          => array_merge(
590
-					array(
591
-						'' => __( 'All item types', 'invoicing' )
592
-					),
593
-					wpinv_get_item_types()
594
-				),
595
-				'name'             => 'type',
596
-				'id'               => 'type',
597
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
598
-				'show_option_all'  => false,
599
-				'show_option_none' => false,
600
-				'class'            => 'gdmbx2-text-medium',
601
-			)
602
-		);
603
-
604
-	}
605
-
606
-	/**
607
-	 * Filters the item query.
608
-	 */
609
-	public static function filter_item_query( $query ) {
610
-
611
-		// modify the query only if it admin and main query.
612
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
613
-			return $query;
614
-		}
615
-
616
-		// we want to modify the query for our items.
617
-		if ( 'wpi_item' != $query->query['post_type'] ){
618
-			return $query;
619
-		}
620
-
621
-		if ( empty( $query->query_vars['meta_query'] ) ) {
622
-			$query->query_vars['meta_query'] = array();
623
-		}
624
-
625
-		// Filter vat rule type
625
+        // Filter vat rule type
626 626
         if ( ! empty( $_GET['vat_rule'] ) ) {
627 627
             $query->query_vars['meta_query'][] = array(
628 628
                 'key'     => '_wpinv_vat_rule',
@@ -647,94 +647,94 @@  discard block
 block discarded – undo
647 647
                 'value'   => sanitize_text_field( $_GET['type'] ),
648 648
                 'compare' => '='
649 649
             );
650
-		}
651
-
652
-	}
653
-
654
-	/**
655
-	 * Reorders items.
656
-	 */
657
-	public static function reorder_items( $vars ) {
658
-		global $typenow;
659
-
660
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
661
-			return $vars;
662
-		}
663
-
664
-		// By item type.
665
-		if ( 'type' == $vars['orderby'] ) {
666
-			return array_merge(
667
-				$vars,
668
-				array(
669
-					'meta_key' => '_wpinv_type',
670
-					'orderby'  => 'meta_value'
671
-				)
672
-			);
673
-		}
674
-
675
-		// By vat class.
676
-		if ( 'vat_class' == $vars['orderby'] ) {
677
-			return array_merge(
678
-				$vars,
679
-				array(
680
-					'meta_key' => '_wpinv_vat_class',
681
-					'orderby'  => 'meta_value'
682
-				)
683
-			);
684
-		}
685
-
686
-		// By vat rule.
687
-		if ( 'vat_rule' == $vars['orderby'] ) {
688
-			return array_merge(
689
-				$vars,
690
-				array(
691
-					'meta_key' => '_wpinv_vat_rule',
692
-					'orderby'  => 'meta_value'
693
-				)
694
-			);
695
-		}
696
-
697
-		// By price.
698
-		if ( 'price' == $vars['orderby'] ) {
699
-			return array_merge(
700
-				$vars,
701
-				array(
702
-					'meta_key' => '_wpinv_price',
703
-					'orderby'  => 'meta_value_num'
704
-				)
705
-			);
706
-		}
707
-
708
-		return $vars;
709
-
710
-	}
711
-
712
-	/**
713
-	 * Fired when deleting a post.
714
-	 */
715
-	public static function delete_post( $post_id ) {
716
-
717
-		switch ( get_post_type( $post_id ) ) {
718
-
719
-			case 'wpi_item' :
720
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
721
-				break;
722
-
723
-			case 'wpi_payment_form' :
724
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
725
-				break;
726
-
727
-			case 'wpi_discount' :
728
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
729
-				break;
730
-
731
-			case 'wpi_invoice' :
732
-				$invoice = new WPInv_Invoice( $post_id );
733
-				do_action( "getpaid_before_delete_invoice", $invoice );
734
-				$invoice->get_data_store()->delete_items( $invoice );
735
-				$invoice->get_data_store()->delete_special_fields( $invoice );
736
-				break;
737
-		}
738
-	}
650
+        }
651
+
652
+    }
653
+
654
+    /**
655
+     * Reorders items.
656
+     */
657
+    public static function reorder_items( $vars ) {
658
+        global $typenow;
659
+
660
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
661
+            return $vars;
662
+        }
663
+
664
+        // By item type.
665
+        if ( 'type' == $vars['orderby'] ) {
666
+            return array_merge(
667
+                $vars,
668
+                array(
669
+                    'meta_key' => '_wpinv_type',
670
+                    'orderby'  => 'meta_value'
671
+                )
672
+            );
673
+        }
674
+
675
+        // By vat class.
676
+        if ( 'vat_class' == $vars['orderby'] ) {
677
+            return array_merge(
678
+                $vars,
679
+                array(
680
+                    'meta_key' => '_wpinv_vat_class',
681
+                    'orderby'  => 'meta_value'
682
+                )
683
+            );
684
+        }
685
+
686
+        // By vat rule.
687
+        if ( 'vat_rule' == $vars['orderby'] ) {
688
+            return array_merge(
689
+                $vars,
690
+                array(
691
+                    'meta_key' => '_wpinv_vat_rule',
692
+                    'orderby'  => 'meta_value'
693
+                )
694
+            );
695
+        }
696
+
697
+        // By price.
698
+        if ( 'price' == $vars['orderby'] ) {
699
+            return array_merge(
700
+                $vars,
701
+                array(
702
+                    'meta_key' => '_wpinv_price',
703
+                    'orderby'  => 'meta_value_num'
704
+                )
705
+            );
706
+        }
707
+
708
+        return $vars;
709
+
710
+    }
711
+
712
+    /**
713
+     * Fired when deleting a post.
714
+     */
715
+    public static function delete_post( $post_id ) {
716
+
717
+        switch ( get_post_type( $post_id ) ) {
718
+
719
+            case 'wpi_item' :
720
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
721
+                break;
722
+
723
+            case 'wpi_payment_form' :
724
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
725
+                break;
726
+
727
+            case 'wpi_discount' :
728
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
729
+                break;
730
+
731
+            case 'wpi_invoice' :
732
+                $invoice = new WPInv_Invoice( $post_id );
733
+                do_action( "getpaid_before_delete_invoice", $invoice );
734
+                $invoice->get_data_store()->delete_items( $invoice );
735
+                $invoice->get_data_store()->delete_special_fields( $invoice );
736
+                break;
737
+        }
738
+    }
739 739
 
740 740
 }
Please login to merge, or discard this patch.
includes/class-getpaid-payment-form.php 1 patch
Indentation   +519 added lines, -519 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'               => 'draft',
34
-		'version'              => '',
35
-		'date_created'         => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'               => 'draft',
34
+        'version'              => '',
35
+        'date_created'         => null,
36 36
         'date_modified'        => null,
37 37
         'name'                 => '',
38 38
         'author'               => 1,
39 39
         'elements'             => null,
40
-		'items'                => null,
41
-		'earned'               => 0,
42
-		'refunded'             => 0,
43
-		'cancelled'            => 0,
44
-		'failed'               => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,349 +114,349 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'          => 'gtscicd',
237
-					'name'        => 'gtscicd',
238
-					'type'        => 'gateway_select',
239
-					'premade'     => true
234
+                $_elements[] = array(
235
+                    'text'        => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'          => 'gtscicd',
237
+                    'name'        => 'gtscicd',
238
+                    'type'        => 'gateway_select',
239
+                    'premade'     => true
240 240
 			
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266
+
267
+        // Convert the items.
268
+        $prepared = array();
266 269
 
267
-		// Convert the items.
268
-		$prepared = array();
270
+        foreach ( $items as $key => $value ) {
269 271
 
270
-		foreach ( $items as $key => $value ) {
272
+            //Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
271 274
 
272
-			//Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
274 278
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
279
+                continue;
278 280
 
279
-				continue;
281
+            }
280 282
 
281
-			}
283
+            // $item_id => $quantity
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
282 286
 
283
-			// $item_id => $quantity
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
287
+                if ( $item->can_purchase() ) {
288
+                    $item->set_quantity( $value );
289
+                    $prepared[] = $item;
290
+                }
286 291
 
287
-				if ( $item->can_purchase() ) {
288
-					$item->set_quantity( $value );
289
-					$prepared[] = $item;
290
-				}
292
+                continue;
293
+            }
291 294
 
292
-				continue;
293
-			}
295
+            // $item_id => array( 'price' => 10 )
296
+            if ( is_numeric( $key ) && is_array( $value ) ) {
297
+                $item = new GetPaid_Form_Item( $key );
294 298
 
295
-			// $item_id => array( 'price' => 10 )
296
-			if ( is_numeric( $key ) && is_array( $value ) ) {
297
-				$item = new GetPaid_Form_Item( $key );
299
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
300
+                    $item->set_price( $value['price'] );
301
+                }
298 302
 
299
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
300
-					$item->set_price( $value['price'] );
301
-				}
303
+                if ( $item->can_purchase() ) {
304
+                    $prepared[] = $item;
305
+                }
302 306
 
303
-				if ( $item->can_purchase() ) {
304
-					$prepared[] = $item;
305
-				}
307
+                continue;
308
+            }
306 309
 
307
-				continue;
308
-			}
310
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
309 311
 
310
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
312
+                $item = new GetPaid_Form_Item( $value['id'] );
311 313
 
312
-				$item = new GetPaid_Form_Item( $value['id'] );
314
+                if ( ! $item->can_purchase() ) {
315
+                    continue;
316
+                }
313 317
 
314
-				if ( ! $item->can_purchase() ) {
315
-					continue;
316
-				}
318
+                // Sub-total (Cart items).
319
+                if ( isset( $value['subtotal'] ) ) {
320
+                    $item->set_price( $value['subtotal'] );
321
+                }
317 322
 
318
-				// Sub-total (Cart items).
319
-				if ( isset( $value['subtotal'] ) ) {
320
-					$item->set_price( $value['subtotal'] );
321
-				}
323
+                if ( isset( $value['quantity'] ) ) {
324
+                    $item->set_quantity( $value['quantity'] );
325
+                }
326
+
327
+                if ( isset( $value['allow_quantities'] ) ) {
328
+                    $item->set_allow_quantities( $value['allow_quantities'] );
329
+                }
330
+
331
+                if ( isset( $value['required'] ) ) {
332
+                    $item->set_is_required( $value['required'] );
333
+                }
334
+
335
+                if ( isset( $value['description'] ) ) {
336
+                    $item->set_custom_description( $value['description'] );
337
+                }
338
+
339
+                $prepared[] = $item;
340
+                continue;
341
+
342
+            }
343
+        }
344
+
345
+        if ( 'objects' == $return && 'view' == $context ) {
346
+            return $prepared;
347
+        }
348
+
349
+        $items = array();
350
+        foreach ( $prepared as $item ) {
351
+            $items[] = $item->prepare_data_for_use();
352
+        }
353
+
354
+        return $items;
355
+    }
356
+
357
+    /**
358
+     * Get a single item belonging to the form.
359
+     *
360
+     * @since 1.0.19
361
+     * @param  int $item_id The item id to return.
362
+     * @return GetPaid_Form_Item|bool
363
+     */
364
+    public function get_item( $item_id ) {
365
+
366
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
367
+            return false;
368
+        }
369
+
370
+        foreach( $this->get_items() as $item ) {
371
+            if ( $item->get_id() == (int) $item_id ) {
372
+                return $item;
373
+            }
374
+        }
375
+
376
+        return false;
377
+
378
+    }
379
+
380
+    /**
381
+     * Gets a single element.
382
+     *
383
+     * @since 1.0.19
384
+     * @param  string $element_type The element type to return.
385
+     * @return array|bool
386
+     */
387
+    public function get_element_type( $element_type ) {
388
+
389
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
390
+            return false;
391
+        }
392
+
393
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
394
+
395
+            if ( $element['type'] == $element_type ) {
396
+                return $element;
397
+            }
398
+
399
+        }
400
+
401
+        return false;
402
+
403
+    }
404
+
405
+    /**
406
+     * Get the total amount earned via this form.
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return array
411
+     */
412
+    public function get_earned( $context = 'view' ) {
413
+        return $this->get_prop( 'earned', $context );
414
+    }
415
+
416
+    /**
417
+     * Get the total amount refunded via this form.
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return array
422
+     */
423
+    public function get_refunded( $context = 'view' ) {
424
+        return $this->get_prop( 'refunded', $context );
425
+    }
322 426
 
323
-				if ( isset( $value['quantity'] ) ) {
324
-					$item->set_quantity( $value['quantity'] );
325
-				}
427
+    /**
428
+     * Get the total amount cancelled via this form.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return array
433
+     */
434
+    public function get_cancelled( $context = 'view' ) {
435
+        return $this->get_prop( 'cancelled', $context );
436
+    }
326 437
 
327
-				if ( isset( $value['allow_quantities'] ) ) {
328
-					$item->set_allow_quantities( $value['allow_quantities'] );
329
-				}
438
+    /**
439
+     * Get the total amount failed via this form.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return array
444
+     */
445
+    public function get_failed( $context = 'view' ) {
446
+        return $this->get_prop( 'failed', $context );
447
+    }
330 448
 
331
-				if ( isset( $value['required'] ) ) {
332
-					$item->set_is_required( $value['required'] );
333
-				}
334
-
335
-				if ( isset( $value['description'] ) ) {
336
-					$item->set_custom_description( $value['description'] );
337
-				}
338
-
339
-				$prepared[] = $item;
340
-				continue;
341
-
342
-			}
343
-		}
344
-
345
-		if ( 'objects' == $return && 'view' == $context ) {
346
-			return $prepared;
347
-		}
348
-
349
-		$items = array();
350
-		foreach ( $prepared as $item ) {
351
-			$items[] = $item->prepare_data_for_use();
352
-		}
353
-
354
-		return $items;
355
-	}
356
-
357
-	/**
358
-	 * Get a single item belonging to the form.
359
-	 *
360
-	 * @since 1.0.19
361
-	 * @param  int $item_id The item id to return.
362
-	 * @return GetPaid_Form_Item|bool
363
-	 */
364
-	public function get_item( $item_id ) {
365
-
366
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
367
-			return false;
368
-		}
369
-
370
-		foreach( $this->get_items() as $item ) {
371
-			if ( $item->get_id() == (int) $item_id ) {
372
-				return $item;
373
-			}
374
-		}
375
-
376
-		return false;
377
-
378
-	}
379
-
380
-	/**
381
-	 * Gets a single element.
382
-	 *
383
-	 * @since 1.0.19
384
-	 * @param  string $element_type The element type to return.
385
-	 * @return array|bool
386
-	 */
387
-	public function get_element_type( $element_type ) {
388
-
389
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
390
-			return false;
391
-		}
392
-
393
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
394
-
395
-			if ( $element['type'] == $element_type ) {
396
-				return $element;
397
-			}
398
-
399
-		}
400
-
401
-		return false;
402
-
403
-	}
404
-
405
-	/**
406
-	 * Get the total amount earned via this form.
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return array
411
-	 */
412
-	public function get_earned( $context = 'view' ) {
413
-		return $this->get_prop( 'earned', $context );
414
-	}
415
-
416
-	/**
417
-	 * Get the total amount refunded via this form.
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return array
422
-	 */
423
-	public function get_refunded( $context = 'view' ) {
424
-		return $this->get_prop( 'refunded', $context );
425
-	}
426
-
427
-	/**
428
-	 * Get the total amount cancelled via this form.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return array
433
-	 */
434
-	public function get_cancelled( $context = 'view' ) {
435
-		return $this->get_prop( 'cancelled', $context );
436
-	}
437
-
438
-	/**
439
-	 * Get the total amount failed via this form.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return array
444
-	 */
445
-	public function get_failed( $context = 'view' ) {
446
-		return $this->get_prop( 'failed', $context );
447
-	}
448
-
449
-	/**
450
-	 * Get the currency.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return string
455
-	 */
456
-	public function get_currency() {
457
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
458
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
459
-	}
449
+    /**
450
+     * Get the currency.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return string
455
+     */
456
+    public function get_currency() {
457
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
458
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
459
+    }
460 460
 
461 461
     /*
462 462
 	|--------------------------------------------------------------------------
@@ -469,22 +469,22 @@  discard block
 block discarded – undo
469 469
     */
470 470
 
471 471
     /**
472
-	 * Set plugin version when the item was created.
473
-	 *
474
-	 * @since 1.0.19
475
-	 */
476
-	public function set_version( $value ) {
477
-		$this->set_prop( 'version', $value );
472
+     * Set plugin version when the item was created.
473
+     *
474
+     * @since 1.0.19
475
+     */
476
+    public function set_version( $value ) {
477
+        $this->set_prop( 'version', $value );
478 478
     }
479 479
 
480 480
     /**
481
-	 * Set date when the item was created.
482
-	 *
483
-	 * @since 1.0.19
484
-	 * @param string $value Value to set.
481
+     * Set date when the item was created.
482
+     *
483
+     * @since 1.0.19
484
+     * @param string $value Value to set.
485 485
      * @return bool Whether or not the date was set.
486
-	 */
487
-	public function set_date_created( $value ) {
486
+     */
487
+    public function set_date_created( $value ) {
488 488
         $date = strtotime( $value );
489 489
 
490 490
         if ( $date ) {
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
     }
498 498
 
499 499
     /**
500
-	 * Set date when the item was last modified.
501
-	 *
502
-	 * @since 1.0.19
503
-	 * @param string $value Value to set.
500
+     * Set date when the item was last modified.
501
+     *
502
+     * @since 1.0.19
503
+     * @param string $value Value to set.
504 504
      * @return bool Whether or not the date was set.
505
-	 */
506
-	public function set_date_modified( $value ) {
505
+     */
506
+    public function set_date_modified( $value ) {
507 507
         $date = strtotime( $value );
508 508
 
509 509
         if ( $date ) {
@@ -516,118 +516,118 @@  discard block
 block discarded – undo
516 516
     }
517 517
 
518 518
     /**
519
-	 * Set the item name.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  string $value New name.
523
-	 */
524
-	public function set_name( $value ) {
525
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
526
-    }
527
-
528
-    /**
529
-	 * Alias of self::set_name().
530
-	 *
531
-	 * @since 1.0.19
532
-	 * @param  string $value New name.
533
-	 */
534
-	public function set_title( $value ) {
535
-		$this->set_name( $value );
536
-    }
537
-
538
-    /**
539
-	 * Set the owner of the item.
540
-	 *
541
-	 * @since 1.0.19
542
-	 * @param  int $value New author.
543
-	 */
544
-	public function set_author( $value ) {
545
-		$this->set_prop( 'author', (int) $value );
546
-	}
547
-
548
-	/**
549
-	 * Set the form elements.
550
-	 *
551
-	 * @since 1.0.19
552
-	 * @param  array $value Form elements.
553
-	 */
554
-	public function set_elements( $value ) {
555
-		if ( is_array( $value ) ) {
556
-			$this->set_prop( 'elements', $value );
557
-		}
558
-	}
559
-
560
-	/**
561
-	 * Set the form items.
562
-	 *
563
-	 * @since 1.0.19
564
-	 * @param  array $value Form elements.
565
-	 */
566
-	public function set_items( $value ) {
567
-		if ( is_array( $value ) ) {
568
-			$this->set_prop( 'items', $value );
569
-		}
570
-	}
571
-
572
-	/**
573
-	 * Set the total amount earned via this form.
574
-	 *
575
-	 * @since 1.0.19
576
-	 * @param  float $value Amount earned.
577
-	 */
578
-	public function set_earned( $value ) {
579
-		$value = max( (float) $value, 0 );
580
-		$this->set_prop( 'earned', $value );
581
-	}
582
-
583
-	/**
584
-	 * Set the total amount refunded via this form.
585
-	 *
586
-	 * @since 1.0.19
587
-	 * @param  float $value Amount refunded.
588
-	 */
589
-	public function set_refunded( $value ) {
590
-		$value = max( (float) $value, 0 );
591
-		$this->set_prop( 'refunded', $value );
592
-	}
593
-
594
-	/**
595
-	 * Set the total amount cancelled via this form.
596
-	 *
597
-	 * @since 1.0.19
598
-	 * @param  float $value Amount cancelled.
599
-	 */
600
-	public function set_cancelled( $value ) {
601
-		$value = max( (float) $value, 0 );
602
-		$this->set_prop( 'cancelled', $value );
603
-	}
604
-
605
-	/**
606
-	 * Set the total amount failed via this form.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  float $value Amount cancelled.
610
-	 */
611
-	public function set_failed( $value ) {
612
-		$value = max( (float) $value, 0 );
613
-		$this->set_prop( 'failed', $value );
614
-	}
519
+     * Set the item name.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  string $value New name.
523
+     */
524
+    public function set_name( $value ) {
525
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
526
+    }
527
+
528
+    /**
529
+     * Alias of self::set_name().
530
+     *
531
+     * @since 1.0.19
532
+     * @param  string $value New name.
533
+     */
534
+    public function set_title( $value ) {
535
+        $this->set_name( $value );
536
+    }
537
+
538
+    /**
539
+     * Set the owner of the item.
540
+     *
541
+     * @since 1.0.19
542
+     * @param  int $value New author.
543
+     */
544
+    public function set_author( $value ) {
545
+        $this->set_prop( 'author', (int) $value );
546
+    }
547
+
548
+    /**
549
+     * Set the form elements.
550
+     *
551
+     * @since 1.0.19
552
+     * @param  array $value Form elements.
553
+     */
554
+    public function set_elements( $value ) {
555
+        if ( is_array( $value ) ) {
556
+            $this->set_prop( 'elements', $value );
557
+        }
558
+    }
559
+
560
+    /**
561
+     * Set the form items.
562
+     *
563
+     * @since 1.0.19
564
+     * @param  array $value Form elements.
565
+     */
566
+    public function set_items( $value ) {
567
+        if ( is_array( $value ) ) {
568
+            $this->set_prop( 'items', $value );
569
+        }
570
+    }
571
+
572
+    /**
573
+     * Set the total amount earned via this form.
574
+     *
575
+     * @since 1.0.19
576
+     * @param  float $value Amount earned.
577
+     */
578
+    public function set_earned( $value ) {
579
+        $value = max( (float) $value, 0 );
580
+        $this->set_prop( 'earned', $value );
581
+    }
582
+
583
+    /**
584
+     * Set the total amount refunded via this form.
585
+     *
586
+     * @since 1.0.19
587
+     * @param  float $value Amount refunded.
588
+     */
589
+    public function set_refunded( $value ) {
590
+        $value = max( (float) $value, 0 );
591
+        $this->set_prop( 'refunded', $value );
592
+    }
593
+
594
+    /**
595
+     * Set the total amount cancelled via this form.
596
+     *
597
+     * @since 1.0.19
598
+     * @param  float $value Amount cancelled.
599
+     */
600
+    public function set_cancelled( $value ) {
601
+        $value = max( (float) $value, 0 );
602
+        $this->set_prop( 'cancelled', $value );
603
+    }
604
+
605
+    /**
606
+     * Set the total amount failed via this form.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  float $value Amount cancelled.
610
+     */
611
+    public function set_failed( $value ) {
612
+        $value = max( (float) $value, 0 );
613
+        $this->set_prop( 'failed', $value );
614
+    }
615 615
 
616 616
     /**
617 617
      * Create an item. For backwards compatibilty.
618 618
      *
619 619
      * @deprecated
620
-	 * @return int item id
620
+     * @return int item id
621 621
      */
622 622
     public function create( $data = array() ) {
623 623
 
624
-		// Set the properties.
625
-		if ( is_array( $data ) ) {
626
-			$this->set_props( $data );
627
-		}
624
+        // Set the properties.
625
+        if ( is_array( $data ) ) {
626
+            $this->set_props( $data );
627
+        }
628 628
 
629
-		// Save the item.
630
-		return $this->save();
629
+        // Save the item.
630
+        return $this->save();
631 631
 
632 632
     }
633 633
 
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
      * Updates an item. For backwards compatibilty.
636 636
      *
637 637
      * @deprecated
638
-	 * @return int item id
638
+     * @return int item id
639 639
      */
640 640
     public function update( $data = array() ) {
641 641
         return $this->create( $data );
@@ -651,22 +651,22 @@  discard block
 block discarded – undo
651 651
 	*/
652 652
 
653 653
     /**
654
-	 * Checks whether this is the default payment form.
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @return bool
658
-	 */
654
+     * Checks whether this is the default payment form.
655
+     *
656
+     * @since 1.0.19
657
+     * @return bool
658
+     */
659 659
     public function is_default() {
660 660
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
661 661
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
662
-	}
662
+    }
663 663
 
664 664
     /**
665
-	 * Checks whether the form is active.
666
-	 *
667
-	 * @since 1.0.19
668
-	 * @return bool
669
-	 */
665
+     * Checks whether the form is active.
666
+     *
667
+     * @since 1.0.19
668
+     * @return bool
669
+     */
670 670
     public function is_active() {
671 671
         $is_active = 0 !== (int) $this->get_id();
672 672
 
@@ -675,70 +675,70 @@  discard block
 block discarded – undo
675 675
         }
676 676
 
677 677
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
678
-	}
679
-
680
-	/**
681
-	 * Checks whether the form has a given item.
682
-	 *
683
-	 * @since 1.0.19
684
-	 * @return bool
685
-	 */
678
+    }
679
+
680
+    /**
681
+     * Checks whether the form has a given item.
682
+     *
683
+     * @since 1.0.19
684
+     * @return bool
685
+     */
686 686
     public function has_item( $item_id ) {
687 687
         return false !== $this->get_item( $item_id );
688
-	}
689
-
690
-	/**
691
-	 * Checks whether the form has a given element.
692
-	 *
693
-	 * @since 1.0.19
694
-	 * @return bool
695
-	 */
688
+    }
689
+
690
+    /**
691
+     * Checks whether the form has a given element.
692
+     *
693
+     * @since 1.0.19
694
+     * @return bool
695
+     */
696 696
     public function has_element_type( $element_type ) {
697 697
         return false !== $this->get_element_type( $element_type );
698
-	}
699
-
700
-	/**
701
-	 * Checks whether this form is recurring or not.
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @return bool
705
-	 */
698
+    }
699
+
700
+    /**
701
+     * Checks whether this form is recurring or not.
702
+     *
703
+     * @since 1.0.19
704
+     * @return bool
705
+     */
706 706
     public function is_recurring() {
707 707
 
708
-		if ( ! empty( $this->invoice ) ) {
709
-			return $this->invoice->is_recurring();
710
-		}
708
+        if ( ! empty( $this->invoice ) ) {
709
+            return $this->invoice->is_recurring();
710
+        }
711 711
 
712
-		foreach ( $this->get_items() as $item ) {
712
+        foreach ( $this->get_items() as $item ) {
713 713
 
714
-			if ( $item->is_recurring() ) {
715
-				return true;
716
-			}
714
+            if ( $item->is_recurring() ) {
715
+                return true;
716
+            }
717 717
 
718
-		}
718
+        }
719 719
 
720 720
         return false;
721
-	}
721
+    }
722 722
 
723
-	/**
724
-	 * Retrieves the form's html.
725
-	 *
726
-	 * @since 1.0.19
727
-	 */
723
+    /**
724
+     * Retrieves the form's html.
725
+     *
726
+     * @since 1.0.19
727
+     */
728 728
     public function get_html() {
729 729
 
730
-		// Return the HTML.
731
-		return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
730
+        // Return the HTML.
731
+        return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
732 732
 
733
-	}
733
+    }
734 734
 
735
-	/**
736
-	 * Displays the payment form.
737
-	 *
738
-	 * @since 1.0.19
739
-	 */
735
+    /**
736
+     * Displays the payment form.
737
+     *
738
+     * @since 1.0.19
739
+     */
740 740
     public function display() {
741
-		echo $this->get_html();
741
+        echo $this->get_html();
742 742
     }
743 743
 
744 744
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 1 patch
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -13,282 +13,282 @@
 block discarded – undo
13 13
 class GetPaid_Subscription_Notification_Emails {
14 14
 
15 15
     /**
16
-	 * The array of subscription email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $subscription_actions;
16
+     * The array of subscription email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $subscription_actions;
21 21
 
22 22
     /**
23
-	 * Class constructor
23
+     * Class constructor
24 24
      *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->subscription_actions = apply_filters(
29
-			'getpaid_notification_email_subscription_triggers',
30
-			array(
31
-				'getpaid_subscription_trialling' => 'subscription_trial',
32
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
-				'getpaid_subscription_expired'   => 'subscription_expired',
34
-				'getpaid_subscription_completed' => 'subscription_complete',
35
-				'getpaid_daily_maintenance'      => 'renewal_reminder',
36
-			)
37
-		);
38
-
39
-		$this->init_hooks();
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_trialling' => 'subscription_trial',
32
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
+                'getpaid_subscription_expired'   => 'subscription_expired',
34
+                'getpaid_subscription_completed' => 'subscription_complete',
35
+                'getpaid_daily_maintenance'      => 'renewal_reminder',
36
+            )
37
+        );
38
+
39
+        $this->init_hooks();
40 40
 
41 41
     }
42 42
 
43 43
     /**
44
-	 * Registers email hooks.
45
-	 */
46
-	public function init_hooks() {
47
-
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
50
-
51
-			$email = new GetPaid_Notification_Email( $email_type );
52
-
53
-			if ( ! $email->is_active() ) {
54
-				continue;
55
-			}
56
-
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
59
-				continue;
60
-			}
61
-
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email );
63
-
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * Filters subscription merge tags.
70
-	 *
71
-	 * @param array $merge_tags
72
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
-	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
75
-
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
-			$merge_tags = array_merge(
78
-				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
80
-			);
81
-		}
82
-
83
-		return $merge_tags;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Generates subscription merge tags.
89
-	 *
90
-	 * @param WPInv_Subscription $subscription
91
-	 * @return array
92
-	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
94
-
95
-		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
97
-			return array();
98
-		}
99
-
100
-		$invoice    = $subscription->get_parent_invoice();
101
-		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
-			'{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
-			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
-		);
113
-
114
-	}
115
-
116
-	/**
117
-	 * Checks if we should send a notification for a subscription.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return bool
121
-	 */
122
-	public function should_send_notification( $invoice ) {
123
-		return 0 != $invoice->get_id();
124
-	}
125
-
126
-	/**
127
-	 * Returns notification recipients.
128
-	 *
129
-	 * @param WPInv_Invoice $invoice
130
-	 * @return array
131
-	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
134
-
135
-		$cc = $invoice->get_email_cc();
136
-
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
-		}
141
-
142
-		return $recipients;
143
-	}
144
-
145
-	/**
146
-	 * Helper function to send an email.
147
-	 *
148
-	 * @param WPInv_Subscription $subscription
149
-	 * @param GetPaid_Notification_Email $email
150
-	 * @param string $type
151
-	 * @param array $extra_args Extra template args.
152
-	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
-
155
-		// Abort in case the parent invoice does not exist.
156
-		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
158
-			return;
159
-		}
160
-
161
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
-
163
-		$recipients  = $this->get_recipients( $invoice );
164
-		$mailer      = new GetPaid_Notification_Email_Sender();
165
-		$merge_tags  = $email->get_merge_tags();
166
-		$content     = $email->get_content( $merge_tags, $extra_args );
167
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
-		$attachments = $email->get_attachments();
169
-
170
-		$result = $mailer->send(
171
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
-			$subject,
173
-			$content,
174
-			$attachments
175
-		);
176
-
177
-		// Maybe send a copy to the admin.
178
-		if ( $email->include_admin_bcc() ) {
179
-			$mailer->send(
180
-				wpinv_get_admin_email(),
181
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
-				$content,
183
-				$attachments
184
-			);
185
-		}
186
-
187
-		if ( ! $result ) {
188
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
-		}
190
-
191
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
192
-
193
-	}
44
+     * Registers email hooks.
45
+     */
46
+    public function init_hooks() {
47
+
48
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
+        foreach ( $this->subscription_actions as $hook => $email_type ) {
50
+
51
+            $email = new GetPaid_Notification_Email( $email_type );
52
+
53
+            if ( ! $email->is_active() ) {
54
+                continue;
55
+            }
56
+
57
+            if ( method_exists( $this, $email_type ) ) {
58
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
59
+                continue;
60
+            }
61
+
62
+            do_action( 'getpaid_subscription_notification_email_register_hook', $email );
63
+
64
+        }
65
+
66
+    }
194 67
 
195 68
     /**
196
-	 * Sends a new trial notification.
197
-	 *
198
-	 * @param WPInv_Subscription $subscription
199
-	 */
200
-	public function subscription_trial( $subscription ) {
69
+     * Filters subscription merge tags.
70
+     *
71
+     * @param array $merge_tags
72
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
+     */
74
+    public function subscription_merge_tags( $merge_tags, $object ) {
201 75
 
202
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
-		$this->send_email( $subscription, $email, __FUNCTION__ );
76
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
+            $merge_tags = array_merge(
78
+                $merge_tags,
79
+                $this->get_subscription_merge_tags( $object )
80
+            );
81
+        }
204 82
 
205
-	}
83
+        return $merge_tags;
206 84
 
207
-	/**
208
-	 * Sends a cancelled subscription notification.
209
-	 *
210
-	 * @param WPInv_Subscription $subscription
211
-	 */
212
-	public function subscription_cancelled( $subscription ) {
85
+    }
213 86
 
214
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
-		$this->send_email( $subscription, $email, __FUNCTION__ );
87
+    /**
88
+     * Generates subscription merge tags.
89
+     *
90
+     * @param WPInv_Subscription $subscription
91
+     * @return array
92
+     */
93
+    public function get_subscription_merge_tags( $subscription ) {
94
+
95
+        // Abort if it does not exist.
96
+        if ( ! $subscription->get_id() ) {
97
+            return array();
98
+        }
99
+
100
+        $invoice    = $subscription->get_parent_invoice();
101
+        return array(
102
+            '{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
+            '{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
+            '{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
+            '{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
+            '{subscription_id}'               => absint( $subscription->get_id() ),
107
+            '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
+            '{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
+            '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
+            '{subscription_bill_times}'       => $subscription->get_bill_times(),
111
+            '{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
+        );
216 113
 
217
-	}
114
+    }
218 115
 
219
-	/**
220
-	 * Sends a subscription expired notification.
221
-	 *
222
-	 * @param WPInv_Subscription $subscription
223
-	 */
224
-	public function subscription_expired( $subscription ) {
116
+    /**
117
+     * Checks if we should send a notification for a subscription.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return bool
121
+     */
122
+    public function should_send_notification( $invoice ) {
123
+        return 0 != $invoice->get_id();
124
+    }
225 125
 
226
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
-		$this->send_email( $subscription, $email, __FUNCTION__ );
126
+    /**
127
+     * Returns notification recipients.
128
+     *
129
+     * @param WPInv_Invoice $invoice
130
+     * @return array
131
+     */
132
+    public function get_recipients( $invoice ) {
133
+        $recipients = array( $invoice->get_email() );
228 134
 
229
-	}
135
+        $cc = $invoice->get_email_cc();
230 136
 
231
-	/**
232
-	 * Sends a completed subscription notification.
233
-	 *
234
-	 * @param WPInv_Subscription $subscription
235
-	 */
236
-	public function subscription_complete( $subscription ) {
137
+        if ( ! empty( $cc ) ) {
138
+            $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
+            $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
+        }
237 141
 
238
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
240 144
 
241
-	}
145
+    /**
146
+     * Helper function to send an email.
147
+     *
148
+     * @param WPInv_Subscription $subscription
149
+     * @param GetPaid_Notification_Email $email
150
+     * @param string $type
151
+     * @param array $extra_args Extra template args.
152
+     */
153
+    public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
+
155
+        // Abort in case the parent invoice does not exist.
156
+        $invoice = $subscription->get_parent_invoice();
157
+        if ( ! $this->should_send_notification( $invoice ) ) {
158
+            return;
159
+        }
160
+
161
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
+
163
+        $recipients  = $this->get_recipients( $invoice );
164
+        $mailer      = new GetPaid_Notification_Email_Sender();
165
+        $merge_tags  = $email->get_merge_tags();
166
+        $content     = $email->get_content( $merge_tags, $extra_args );
167
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
+        $attachments = $email->get_attachments();
169
+
170
+        $result = $mailer->send(
171
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
+            $subject,
173
+            $content,
174
+            $attachments
175
+        );
176
+
177
+        // Maybe send a copy to the admin.
178
+        if ( $email->include_admin_bcc() ) {
179
+            $mailer->send(
180
+                wpinv_get_admin_email(),
181
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
+                $content,
183
+                $attachments
184
+            );
185
+        }
186
+
187
+        if ( ! $result ) {
188
+            $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
+        }
190
+
191
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
242 192
 
243
-	/**
244
-	 * Sends a subscription renewal reminder notification.
245
-	 *
246
-	 */
247
-	public function renewal_reminder() {
193
+    }
248 194
 
249
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
195
+    /**
196
+     * Sends a new trial notification.
197
+     *
198
+     * @param WPInv_Subscription $subscription
199
+     */
200
+    public function subscription_trial( $subscription ) {
250 201
 
251
-		// Fetch reminder days.
252
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
202
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
+        $this->send_email( $subscription, $email, __FUNCTION__ );
253 204
 
254
-		// Abort if non is set.
255
-		if ( empty( $reminder_days ) ) {
256
-			return;
257
-		}
205
+    }
258 206
 
259
-		// Fetch matching subscriptions.
207
+    /**
208
+     * Sends a cancelled subscription notification.
209
+     *
210
+     * @param WPInv_Subscription $subscription
211
+     */
212
+    public function subscription_cancelled( $subscription ) {
213
+
214
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
+        $this->send_email( $subscription, $email, __FUNCTION__ );
216
+
217
+    }
218
+
219
+    /**
220
+     * Sends a subscription expired notification.
221
+     *
222
+     * @param WPInv_Subscription $subscription
223
+     */
224
+    public function subscription_expired( $subscription ) {
225
+
226
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
+        $this->send_email( $subscription, $email, __FUNCTION__ );
228
+
229
+    }
230
+
231
+    /**
232
+     * Sends a completed subscription notification.
233
+     *
234
+     * @param WPInv_Subscription $subscription
235
+     */
236
+    public function subscription_complete( $subscription ) {
237
+
238
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
+        $this->send_email( $subscription, $email, __FUNCTION__ );
240
+
241
+    }
242
+
243
+    /**
244
+     * Sends a subscription renewal reminder notification.
245
+     *
246
+     */
247
+    public function renewal_reminder() {
248
+
249
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
250
+
251
+        // Fetch reminder days.
252
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
253
+
254
+        // Abort if non is set.
255
+        if ( empty( $reminder_days ) ) {
256
+            return;
257
+        }
258
+
259
+        // Fetch matching subscriptions.
260 260
         $args  = array(
261 261
             'number'             => -1,
262
-			'count_total'        => false,
263
-			'status'             => 'trialling active',
262
+            'count_total'        => false,
263
+            'status'             => 'trialling active',
264 264
             'date_expires_query' => array(
265
-				'relation'  => 'OR'
265
+                'relation'  => 'OR'
266 266
             ),
267
-		);
267
+        );
268 268
 
269
-		foreach ( $reminder_days as $days ) {
270
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
269
+        foreach ( $reminder_days as $days ) {
270
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
271 271
 
272
-			$args['date_expires_query'][] = array(
273
-				'year'  => $date['year'],
274
-				'month' => $date['month'],
275
-				'day'   => $date['day'],
276
-			);
272
+            $args['date_expires_query'][] = array(
273
+                'year'  => $date['year'],
274
+                'month' => $date['month'],
275
+                'day'   => $date['day'],
276
+            );
277 277
 
278
-		}
278
+        }
279 279
 
280
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
280
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
281 281
 
282 282
         foreach ( $subscriptions as $subscription ) {
283 283
 
284
-			// Skip packages.
285
-			if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
-				$email->object = $subscription;
287
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
288
-			}
284
+            // Skip packages.
285
+            if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
+                $email->object = $subscription;
287
+                $this->send_email( $subscription, $email, __FUNCTION__ );
288
+            }
289 289
 
290
-		}
290
+        }
291 291
 
292
-	}
292
+    }
293 293
 
294 294
 }
Please login to merge, or discard this patch.
templates/subscriptions/subscription-details.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -43,64 +43,64 @@  discard block
 block discarded – undo
43 43
 				<td class="w-75">
44 44
 					<?php
45 45
 
46
-						switch ( $key ) {
46
+                        switch ( $key ) {
47 47
 
48
-							case 'status':
49
-								echo sanitize_text_field( $subscription->get_status_label() );
50
-								break;
48
+                            case 'status':
49
+                                echo sanitize_text_field( $subscription->get_status_label() );
50
+                                break;
51 51
 
52
-							case 'start_date':
53
-								echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) );
54
-								break;
52
+                            case 'start_date':
53
+                                echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) );
54
+                                break;
55 55
 
56
-							case 'expiry_date':
57
-								echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
58
-								break;
56
+                            case 'expiry_date':
57
+                                echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) );
58
+                                break;
59 59
 
60
-							case 'initial_amount':
61
-								echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() );
60
+                            case 'initial_amount':
61
+                                echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() );
62 62
 
63
-								if ( $subscription->has_trial_period() ) {
63
+                                if ( $subscription->has_trial_period() ) {
64 64
 
65
-									echo "<small class='text-muted'>&nbsp;";
66
-									printf(
67
-										_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
68
-										sanitize_text_field( $subscription->get_trial_period() )
69
-									);
70
-									echo '</small>';
65
+                                    echo "<small class='text-muted'>&nbsp;";
66
+                                    printf(
67
+                                        _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ),
68
+                                        sanitize_text_field( $subscription->get_trial_period() )
69
+                                    );
70
+                                    echo '</small>';
71 71
 
72
-								}
72
+                                }
73 73
 								
74
-								break;
74
+                                break;
75 75
 
76
-							case 'recurring_amount':
77
-								$frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
78
-								$amount    = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() );
79
-								echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" );
80
-								break;
76
+                            case 'recurring_amount':
77
+                                $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
78
+                                $amount    = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() );
79
+                                echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" );
80
+                                break;
81 81
 
82
-							case 'item':
83
-								$item = get_post( $subscription->get_product_id() );
82
+                            case 'item':
83
+                                $item = get_post( $subscription->get_product_id() );
84 84
 
85
-								if ( ! empty( $item ) ) {
86
-									echo esc_html( get_the_title( $item ) );
87
-								} else {
88
-									echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
89
-								}
85
+                                if ( ! empty( $item ) ) {
86
+                                    echo esc_html( get_the_title( $item ) );
87
+                                } else {
88
+                                    echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
89
+                                }
90 90
 
91
-								break;
91
+                                break;
92 92
 
93
-							case 'payments':
93
+                            case 'payments':
94 94
 
95
-								$max_activations = (int) $subscription->get_bill_times();
96
-								echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "&infin;" : $max_activations );
95
+                                $max_activations = (int) $subscription->get_bill_times();
96
+                                echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "&infin;" : $max_activations );
97 97
 
98
-								break;
98
+                                break;
99 99
 
100
-						}
101
-						do_action( "getpaid_render_single_subscription_column_$key", $subscription );
100
+                        }
101
+                        do_action( "getpaid_render_single_subscription_column_$key", $subscription );
102 102
 
103
-					?>
103
+                    ?>
104 104
 				</td>
105 105
 
106 106
 			</tr>
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
 <span class="form-text">
118 118
 
119 119
 	<?php
120
-		if ( $subscription->can_cancel() ) {
121
-			printf(
122
-				'<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a>&nbsp;&nbsp;',
123
-				esc_url( $subscription->get_cancel_url() ),
124
-				esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ),
125
-				__( 'Cancel Subscription', 'invoicing' )
126
-			);
127
-		}
128
-	?>
120
+        if ( $subscription->can_cancel() ) {
121
+            printf(
122
+                '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a>&nbsp;&nbsp;',
123
+                esc_url( $subscription->get_cancel_url() ),
124
+                esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ),
125
+                __( 'Cancel Subscription', 'invoicing' )
126
+            );
127
+        }
128
+    ?>
129 129
 
130 130
 	<a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a>
131 131
 </span>
132 132
\ No newline at end of file
Please login to merge, or discard this patch.
templates/subscriptions/subscriptions-table-row.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -13,38 +13,38 @@
 block discarded – undo
13 13
 
14 14
 foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) :
15 15
 
16
-	$class = sanitize_html_class( $column );
17
-	echo "<td class='getpaid-subscriptions-table-column-$class'>";
16
+    $class = sanitize_html_class( $column );
17
+    echo "<td class='getpaid-subscriptions-table-column-$class'>";
18 18
 
19
-		do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription );
19
+        do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription );
20 20
 
21
-		switch( $column ) :
21
+        switch( $column ) :
22 22
 
23
-			case 'subscription':
24
-				$subscription_id = (int) $subscription->get_id();
25
-				$url             = esc_url( $subscription->get_view_url() );
26
-				echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription );
27
-				break;
23
+            case 'subscription':
24
+                $subscription_id = (int) $subscription->get_id();
25
+                $url             = esc_url( $subscription->get_view_url() );
26
+                echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription );
27
+                break;
28 28
 
29
-			case 'status':
30
-				echo $subscription->get_status_label();
31
-				break;
29
+            case 'status':
30
+                echo $subscription->get_status_label();
31
+                break;
32 32
 
33
-			case 'renewal-date':
34
-				$renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() );
35
-				echo $subscription->is_active() ? $renewal : "&mdash;";
36
-				break;
33
+            case 'renewal-date':
34
+                $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() );
35
+                echo $subscription->is_active() ? $renewal : "&mdash;";
36
+                break;
37 37
 
38
-			case 'amount':
39
-				$frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
40
-				$amount    = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() );
41
-				echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency";
42
-				break;
38
+            case 'amount':
39
+                $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
40
+                $amount    = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() );
41
+                echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency";
42
+                break;
43 43
 
44
-		endswitch;
44
+        endswitch;
45 45
 
46
-		do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription );
46
+        do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription );
47 47
 
48
-	echo '</td>';
48
+    echo '</td>';
49 49
 
50 50
 endforeach;
Please login to merge, or discard this patch.