Passed
Push — master ( c16653...06c25c )
by Brian
04:36
created
templates/invoice-history.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -40,86 +40,86 @@  discard block
 block discarded – undo
40 40
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
41 41
 					<?php
42 42
 
43
-						foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) :
43
+                        foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) :
44 44
 
45
-							$column_id = sanitize_html_class( $column_id );
46
-							$class     = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] );
45
+                            $column_id = sanitize_html_class( $column_id );
46
+                            $class     = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] );
47 47
 
48
-							echo "<td class='$column_id $class'>";
49
-							switch ( $column_id ) {
48
+                            echo "<td class='$column_id $class'>";
49
+                            switch ( $column_id ) {
50 50
 
51
-								case 'invoice-number':
52
-									echo wpinv_invoice_link( $invoice );
53
-									break;
51
+                                case 'invoice-number':
52
+                                    echo wpinv_invoice_link( $invoice );
53
+                                    break;
54 54
 
55
-								case 'created-date':
56
-									echo getpaid_format_date_value( $invoice->get_date_created() );
57
-									break;
55
+                                case 'created-date':
56
+                                    echo getpaid_format_date_value( $invoice->get_date_created() );
57
+                                    break;
58 58
 
59
-								case 'payment-date':
59
+                                case 'payment-date':
60 60
 
61
-									if ( $invoice->needs_payment() ) {
62
-										echo "&mdash;";
63
-									} else {
64
-										echo getpaid_format_date_value( $invoice->get_date_completed() );
65
-									}
61
+                                    if ( $invoice->needs_payment() ) {
62
+                                        echo "&mdash;";
63
+                                    } else {
64
+                                        echo getpaid_format_date_value( $invoice->get_date_completed() );
65
+                                    }
66 66
 									
67
-									break;
67
+                                    break;
68 68
 
69
-								case 'invoice-status':
70
-									echo $invoice->get_status_label_html();
69
+                                case 'invoice-status':
70
+                                    echo $invoice->get_status_label_html();
71 71
 									
72
-									break;
72
+                                    break;
73 73
 
74
-								case 'invoice-total':
75
-									echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) );
74
+                                case 'invoice-total':
75
+                                    echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) );
76 76
 									
77
-									break;
77
+                                    break;
78 78
 
79
-								case 'invoice-actions':
79
+                                case 'invoice-actions':
80 80
 
81
-									$actions = array(
81
+                                    $actions = array(
82 82
 
83
-										'pay'       => array(
84
-											'url'   => $invoice->get_checkout_payment_url(),
85
-											'name'  => __( 'Pay Now', 'invoicing' ),
83
+                                        'pay'       => array(
84
+                                            'url'   => $invoice->get_checkout_payment_url(),
85
+                                            'name'  => __( 'Pay Now', 'invoicing' ),
86 86
                                             'class' => 'btn-success'
87
-										),
87
+                                        ),
88 88
 
89 89
                                         'print'     => array(
90
-											'url'   => $invoice->get_view_url(),
91
-											'name'  => __( 'View Invoice', 'invoicing' ),
90
+                                            'url'   => $invoice->get_view_url(),
91
+                                            'name'  => __( 'View Invoice', 'invoicing' ),
92 92
                                             'class' => 'btn-secondary',
93 93
                                             'attrs' => 'target="_blank"'
94
-										)
95
-									);
94
+                                        )
95
+                                    );
96 96
 
97
-									if ( ! $invoice->needs_payment() ) {
98
-										unset( $actions['pay'] );
99
-									}
97
+                                    if ( ! $invoice->needs_payment() ) {
98
+                                        unset( $actions['pay'] );
99
+                                    }
100 100
 
101
-									$actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice );
101
+                                    $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice );
102 102
 
103
-									foreach ( $actions as $key => $action ) {
104
-										$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
105
-										echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
106
-									}
103
+                                    foreach ( $actions as $key => $action ) {
104
+                                        $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
105
+                                        echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
106
+                                    }
107 107
 									
108
-									break;
108
+                                    break;
109 109
 
110
-								default:
111
-									do_action( "wpinv_user_invoices_column_$column_id", $invoice );
112
-									break;
110
+                                default:
111
+                                    do_action( "wpinv_user_invoices_column_$column_id", $invoice );
112
+                                    break;
113 113
 
114 114
 								
115
-							}
115
+                            }
116 116
 
117
-							do_action( "wpinv_user_invoices_column_after_$column_id", $invoice );
117
+                            do_action( "wpinv_user_invoices_column_after_$column_id", $invoice );
118 118
 						
119
-							echo '</td>';
119
+                            echo '</td>';
120 120
 
121
-						endforeach;
122
-					?>
121
+                        endforeach;
122
+                    ?>
123 123
 				</tr>
124 124
 
125 125
 			<?php endforeach; ?>
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
 	<?php if ( 1 < $invoices->max_num_pages ) : ?>
133 133
 		<div class="invoicing-Pagination">
134 134
 			<?php
135
-			$big = 999999;
136
-
137
-			echo paginate_links( array(
138
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
139
-				'format'  => '?paged=%#%',
140
-				'total'   => $invoices->max_num_pages,
141
-			) );
142
-			?>
135
+            $big = 999999;
136
+
137
+            echo paginate_links( array(
138
+                'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
139
+                'format'  => '?paged=%#%',
140
+                'total'   => $invoices->max_num_pages,
141
+            ) );
142
+            ?>
143 143
 		</div>
144 144
 	<?php endif; ?>
145 145
 
Please login to merge, or discard this patch.
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
+                    WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $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
-					WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $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/admin/subscriptions.php 1 patch
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<form id="subscribers-filter" class="bsui" method="get">
67 67
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
68 68
 		<?php $subscribers_table->views(); ?>
@@ -80,27 +80,27 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83
-	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->get_id() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->get_id() ) {
86 86
 
87
-		echo aui()->alert(
88
-			array(
89
-				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
91
-			)
92
-		);
87
+        echo aui()->alert(
88
+            array(
89
+                'type'    => 'danger',
90
+                'content' => __( 'Subscription not found.', 'invoicing' ),
91
+            )
92
+        );
93 93
 
94
-		return;
95
-	}
94
+        return;
95
+    }
96 96
 
97
-	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
97
+    // Use metaboxes to display the subscription details.
98
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
102 102
 
103
-	?>
103
+    ?>
104 104
 
105 105
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
106 106
 
@@ -140,41 +140,41 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function getpaid_admin_subscription_details_metabox( $sub ) {
142 142
 
143
-	// Prepare subscription detail columns.
144
-	$fields = apply_filters(
145
-		'getpaid_subscription_admin_page_fields',
146
-		array(
147
-			'subscription'   => __( 'Subscription', 'invoicing' ),
148
-			'customer'       => __( 'Customer', 'invoicing' ),
149
-			'amount'         => __( 'Amount', 'invoicing' ),
150
-			'start_date'     => __( 'Start Date', 'invoicing' ),
151
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
-			'renewals'       => __( 'Renewals', 'invoicing' ),
153
-			'item'           => __( 'Item', 'invoicing' ),
154
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
155
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
-			'status'         => __( 'Status', 'invoicing' ),
157
-		)
158
-	);
159
-
160
-	if ( ! $sub->is_active() ) {
161
-
162
-		if ( isset( $fields['renews_on'] ) ) {
163
-			unset( $fields['renews_on'] );
164
-		}
165
-
166
-		if ( isset( $fields['gateway'] ) ) {
167
-			unset( $fields['gateway'] );
168
-		}
143
+    // Prepare subscription detail columns.
144
+    $fields = apply_filters(
145
+        'getpaid_subscription_admin_page_fields',
146
+        array(
147
+            'subscription'   => __( 'Subscription', 'invoicing' ),
148
+            'customer'       => __( 'Customer', 'invoicing' ),
149
+            'amount'         => __( 'Amount', 'invoicing' ),
150
+            'start_date'     => __( 'Start Date', 'invoicing' ),
151
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
+            'renewals'       => __( 'Renewals', 'invoicing' ),
153
+            'item'           => __( 'Item', 'invoicing' ),
154
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
155
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
+            'status'         => __( 'Status', 'invoicing' ),
157
+        )
158
+    );
159
+
160
+    if ( ! $sub->is_active() ) {
161
+
162
+        if ( isset( $fields['renews_on'] ) ) {
163
+            unset( $fields['renews_on'] );
164
+        }
165
+
166
+        if ( isset( $fields['gateway'] ) ) {
167
+            unset( $fields['gateway'] );
168
+        }
169 169
 		
170
-	}
170
+    }
171 171
 
172
-	$profile_id = $sub->get_profile_id();
173
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
-		unset( $fields['profile_id'] );
175
-	}
172
+    $profile_id = $sub->get_profile_id();
173
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
+        unset( $fields['profile_id'] );
175
+    }
176 176
 
177
-	?>
177
+    ?>
178 178
 
179 179
 		<table class="table table-borderless" style="font-size: 14px;">
180 180
 			<tbody>
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
  */
209 209
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
210 210
 
211
-	$username = __( '(Missing User)', 'invoicing' );
211
+    $username = __( '(Missing User)', 'invoicing' );
212 212
 
213
-	$user = get_userdata( $subscription->get_customer_id() );
214
-	if ( $user ) {
213
+    $user = get_userdata( $subscription->get_customer_id() );
214
+    if ( $user ) {
215 215
 
216
-		$username = sprintf(
217
-			'<a href="user-edit.php?user_id=%s">%s</a>',
218
-			absint( $user->ID ),
219
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
-		);
216
+        $username = sprintf(
217
+            '<a href="user-edit.php?user_id=%s">%s</a>',
218
+            absint( $user->ID ),
219
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
+        );
221 221
 
222
-	}
222
+    }
223 223
 
224
-	echo  $username;
224
+    echo  $username;
225 225
 }
226 226
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
227 227
 
@@ -232,43 +232,43 @@  discard block
 block discarded – undo
232 232
  */
233 233
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
234 234
 
235
-	$initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() );
236
-	$recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() );
237
-	$period    = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() );
235
+    $initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_initial_amount() ) ), $subscription->get_parent_payment()->get_currency() );
236
+    $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() );
237
+    $period    = 1 == $subscription->get_frequency() ? getpaid_get_subscription_period_label( $subscription->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(),$subscription->get_frequency() );
238 238
 
239
-	if ( $subscription->has_trial_period() ) {
239
+    if ( $subscription->has_trial_period() ) {
240 240
 
241
-		// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
242
-		$amount = sprintf(
243
-			_x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
244
-			$initial,
245
-			sanitize_text_field( $subscription->get_trial_period() ),
246
-			$recurring,
247
-			sanitize_text_field( strtolower( $period ) )
248
-		);
241
+        // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
242
+        $amount = sprintf(
243
+            _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
244
+            $initial,
245
+            sanitize_text_field( $subscription->get_trial_period() ),
246
+            $recurring,
247
+            sanitize_text_field( strtolower( $period ) )
248
+        );
249 249
 
250
-	} else if ( $initial != $recurring ) {
250
+    } else if ( $initial != $recurring ) {
251 251
 
252
-		// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
253
-		$amount = sprintf(
254
-			_x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
255
-			$initial,
256
-			$recurring,
257
-			sanitize_text_field( strtolower( $period ) )
258
-		);
252
+        // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
253
+        $amount = sprintf(
254
+            _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
255
+            $initial,
256
+            $recurring,
257
+            sanitize_text_field( strtolower( $period ) )
258
+        );
259 259
 
260
-	} else {
260
+    } else {
261 261
 
262
-		// translators: $1: is the recurring amount, $2: is the recurring period
263
-		$amount = sprintf(
264
-			_x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
265
-			$initial,
266
-			sanitize_text_field( strtolower( $period ) )
267
-		);
262
+        // translators: $1: is the recurring amount, $2: is the recurring period
263
+        $amount = sprintf(
264
+            _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
265
+            $initial,
266
+            sanitize_text_field( strtolower( $period ) )
267
+        );
268 268
 
269
-	}
269
+    }
270 270
 
271
-	echo "<span>$amount</span>";
271
+    echo "<span>$amount</span>";
272 272
 }
273 273
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
274 274
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
  * @param WPInv_Subscription $subscription
279 279
  */
280 280
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
281
-	echo  '#' . absint( $subscription->get_id() );
281
+    echo  '#' . absint( $subscription->get_id() );
282 282
 }
283 283
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
284 284
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
  * @param WPInv_Subscription $subscription
289 289
  */
290 290
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
291
-	echo getpaid_format_date_value( $subscription->get_date_created() );
291
+    echo getpaid_format_date_value( $subscription->get_date_created() );
292 292
 }
293 293
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
294 294
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
  * @param WPInv_Subscription $subscription
299 299
  */
300 300
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
301
-	echo getpaid_format_date_value( $subscription->get_expiration() );
301
+    echo getpaid_format_date_value( $subscription->get_expiration() );
302 302
 }
303 303
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
304 304
 
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
  * @param WPInv_Subscription $subscription
309 309
  */
310 310
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
311
-	$max_bills = $subscription->get_bill_times();
312
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
311
+    $max_bills = $subscription->get_bill_times();
312
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
313 313
 }
314 314
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
315 315
 
@@ -320,16 +320,16 @@  discard block
 block discarded – undo
320 320
  */
321 321
 function getpaid_admin_subscription_metabox_display_item( $subscription ) {
322 322
 
323
-	$item = get_post( $subscription->get_product_id() );
323
+    $item = get_post( $subscription->get_product_id() );
324 324
 
325
-	if ( ! empty( $item ) ) {
326
-		$link = get_edit_post_link( $item );
327
-		$link = esc_url( $link );
328
-		$name = esc_html( get_the_title( $item ) );
329
-		echo "<a href='$link'>$name</a>";
330
-	} else {
331
-		echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
332
-	}
325
+    if ( ! empty( $item ) ) {
326
+        $link = get_edit_post_link( $item );
327
+        $link = esc_url( $link );
328
+        $name = esc_html( get_the_title( $item ) );
329
+        echo "<a href='$link'>$name</a>";
330
+    } else {
331
+        echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
332
+    }
333 333
 
334 334
 }
335 335
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' );
@@ -341,13 +341,13 @@  discard block
 block discarded – undo
341 341
  */
342 342
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
343 343
 
344
-	$gateway = $subscription->get_gateway();
344
+    $gateway = $subscription->get_gateway();
345 345
 
346
-	if ( ! empty( $gateway ) ) {
347
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
348
-	} else {
349
-		echo "&mdash;";
350
-	}
346
+    if ( ! empty( $gateway ) ) {
347
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
348
+    } else {
349
+        echo "&mdash;";
350
+    }
351 351
 
352 352
 }
353 353
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
  * @param WPInv_Subscription $subscription
359 359
  */
360 360
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
361
-	echo $subscription->get_status_label_html();
361
+    echo $subscription->get_status_label_html();
362 362
 }
363 363
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
364 364
 
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
  */
370 370
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
371 371
 
372
-	$profile_id = $subscription->get_profile_id();
372
+    $profile_id = $subscription->get_profile_id();
373 373
 
374
-	if ( ! empty( $profile_id ) ) {
375
-		$profile_id = sanitize_text_field( $profile_id );
376
-		echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
377
-	} else {
378
-		echo "&mdash;";
379
-	}
374
+    if ( ! empty( $profile_id ) ) {
375
+        $profile_id = sanitize_text_field( $profile_id );
376
+        echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
377
+    } else {
378
+        echo "&mdash;";
379
+    }
380 380
 
381 381
 }
382 382
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -388,39 +388,39 @@  discard block
 block discarded – undo
388 388
  */
389 389
 function getpaid_admin_subscription_update_metabox( $subscription ) {
390 390
 
391
-	?>
391
+    ?>
392 392
 	<div class="mt-3">
393 393
 
394 394
 		<?php
395
-			echo aui()->select(
396
-				array(
397
-					'options'          => getpaid_get_subscription_statuses(),
398
-					'name'             => 'subscription_status',
399
-					'id'               => 'subscription_status_update_select',
400
-					'required'         => true,
401
-					'no_wrap'          => false,
402
-					'label'            => __( 'Subscription Status', 'invoicing' ),
403
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
404
-					'select2'          => true,
405
-					'value'            => $subscription->get_status( 'edit' ),
406
-				)
407
-			);
408
-		?>
395
+            echo aui()->select(
396
+                array(
397
+                    'options'          => getpaid_get_subscription_statuses(),
398
+                    'name'             => 'subscription_status',
399
+                    'id'               => 'subscription_status_update_select',
400
+                    'required'         => true,
401
+                    'no_wrap'          => false,
402
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
403
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
404
+                    'select2'          => true,
405
+                    'value'            => $subscription->get_status( 'edit' ),
406
+                )
407
+            );
408
+        ?>
409 409
 
410 410
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
411 411
 	
412 412
 		<?php
413
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
413
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
414 414
 
415
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
416
-			$anchor = __( 'Renew Subscription', 'invoicing' );
417
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
415
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
416
+            $anchor = __( 'Renew Subscription', 'invoicing' );
417
+            $title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
418 418
 
419
-			if ( $subscription->is_active() ) {
420
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
421
-			}
419
+            if ( $subscription->is_active() ) {
420
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
421
+            }
422 422
 
423
-	echo '</div></div>';
423
+    echo '</div></div>';
424 424
 }
425 425
 
426 426
 /**
@@ -430,33 +430,33 @@  discard block
 block discarded – undo
430 430
  */
431 431
 function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
432 432
 
433
-	$columns = apply_filters(
434
-		'getpaid_subscription_related_invoices_columns',
435
-		array(
436
-			'invoice'      => __( 'Invoice', 'invoicing' ),
437
-			'relationship' => __( 'Relationship', 'invoicing' ),
438
-			'date'         => __( 'Date', 'invoicing' ),
439
-			'status'       => __( 'Status', 'invoicing' ),
440
-			'total'        => __( 'Total', 'invoicing' ),
441
-		),
442
-		$subscription
443
-	);
444
-
445
-	// Prepare the invoices.
446
-	$payments = $subscription->get_child_payments();
447
-	$parent   = $subscription->get_parent_invoice();
448
-
449
-	if ( $parent->get_id() ) {
450
-		$payments = array_merge( array( $parent ), $payments );
451
-	}
433
+    $columns = apply_filters(
434
+        'getpaid_subscription_related_invoices_columns',
435
+        array(
436
+            'invoice'      => __( 'Invoice', 'invoicing' ),
437
+            'relationship' => __( 'Relationship', 'invoicing' ),
438
+            'date'         => __( 'Date', 'invoicing' ),
439
+            'status'       => __( 'Status', 'invoicing' ),
440
+            'total'        => __( 'Total', 'invoicing' ),
441
+        ),
442
+        $subscription
443
+    );
444
+
445
+    // Prepare the invoices.
446
+    $payments = $subscription->get_child_payments();
447
+    $parent   = $subscription->get_parent_invoice();
448
+
449
+    if ( $parent->get_id() ) {
450
+        $payments = array_merge( array( $parent ), $payments );
451
+    }
452 452
 	
453
-	$table_class = 'w-100 bg-white';
453
+    $table_class = 'w-100 bg-white';
454 454
 
455
-	if ( ! is_admin() ) {
456
-		$table_class = 'table table-bordered table-striped';
457
-	}
455
+    if ( ! is_admin() ) {
456
+        $table_class = 'table table-bordered table-striped';
457
+    }
458 458
 
459
-	?>
459
+    ?>
460 460
 		<div class="m-0" style="overflow: auto;">
461 461
 
462 462
 			<table class="<?php echo $table_class; ?>">
@@ -464,13 +464,13 @@  discard block
 block discarded – undo
464 464
 				<thead>
465 465
 					<tr>
466 466
 						<?php
467
-							foreach ( $columns as $key => $label ) {
468
-								$key   = esc_attr( $key );
469
-								$label = sanitize_text_field( $label );
467
+                            foreach ( $columns as $key => $label ) {
468
+                                $key   = esc_attr( $key );
469
+                                $label = sanitize_text_field( $label );
470 470
 
471
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>";
472
-							}
473
-						?>
471
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>";
472
+                            }
473
+                        ?>
474 474
 					</tr>
475 475
 				</thead>
476 476
 
@@ -486,66 +486,66 @@  discard block
 block discarded – undo
486 486
 
487 487
 					<?php
488 488
 
489
-						foreach( $payments as $payment ) :
489
+                        foreach( $payments as $payment ) :
490 490
 
491
-							// Ensure that we have an invoice.
492
-							$payment = new WPInv_Invoice( $payment );
491
+                            // Ensure that we have an invoice.
492
+                            $payment = new WPInv_Invoice( $payment );
493 493
 
494
-							// Abort if the invoice is invalid.
495
-							if ( ! $payment->get_id() ) {
496
-								continue;
497
-							}
494
+                            // Abort if the invoice is invalid.
495
+                            if ( ! $payment->get_id() ) {
496
+                                continue;
497
+                            }
498 498
 
499
-							echo '<tr>';
499
+                            echo '<tr>';
500 500
 
501
-								foreach ( array_keys( $columns ) as $key ) {
501
+                                foreach ( array_keys( $columns ) as $key ) {
502 502
 									
503
-									echo '<td class="p-2 text-left">';
503
+                                    echo '<td class="p-2 text-left">';
504 504
 
505
-										switch( $key ) {
505
+                                        switch( $key ) {
506 506
 
507
-											case 'total':
508
-												echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>';
509
-												break;
507
+                                            case 'total':
508
+                                                echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>';
509
+                                                break;
510 510
 
511
-											case 'relationship':
512
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
513
-												break;
511
+                                            case 'relationship':
512
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
513
+                                                break;
514 514
 
515
-											case 'date':
516
-												echo getpaid_format_date_value( $payment->get_date_created() );
517
-												break;
515
+                                            case 'date':
516
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
517
+                                                break;
518 518
 
519
-											case 'status':
519
+                                            case 'status':
520 520
 
521
-												$status = $payment->get_status_nicename();
522
-												if ( is_admin() ) {
523
-													$status = $payment->get_status_label_html();
524
-												}
521
+                                                $status = $payment->get_status_nicename();
522
+                                                if ( is_admin() ) {
523
+                                                    $status = $payment->get_status_label_html();
524
+                                                }
525 525
 
526
-												echo $status;
527
-												break;
526
+                                                echo $status;
527
+                                                break;
528 528
 
529
-											case 'invoice':
530
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
529
+                                            case 'invoice':
530
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
531 531
 
532
-												if ( ! is_admin() ) {
533
-													$link = esc_url( $payment->get_view_url() );
534
-												}
532
+                                                if ( ! is_admin() ) {
533
+                                                    $link = esc_url( $payment->get_view_url() );
534
+                                                }
535 535
 
536
-												$invoice = sanitize_text_field( $payment->get_number() );
537
-												echo "<a href='$link'>$invoice</a>";
538
-												break;
539
-										}
536
+                                                $invoice = sanitize_text_field( $payment->get_number() );
537
+                                                echo "<a href='$link'>$invoice</a>";
538
+                                                break;
539
+                                        }
540 540
 
541
-									echo '</td>';
541
+                                    echo '</td>';
542 542
 
543
-								}
543
+                                }
544 544
 
545
-							echo '</tr>';
545
+                            echo '</tr>';
546 546
 
547
-						endforeach;
548
-					?>
547
+                        endforeach;
548
+                    ?>
549 549
 
550 550
 				</tbody>
551 551
 
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 if ( ! defined( 'ABSPATH' ) ) exit;
7 7
 
8 8
 if ( ! class_exists( 'WP_List_Table' ) ) {
9
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
12 12
 /**
@@ -14,409 +14,409 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
16 16
 
17
-	/**
18
-	 * URL of this page
19
-	 *
20
-	 * @var   string
21
-	 * @since 1.0.19
22
-	 */
23
-	public $base_url;
24
-
25
-	/**
26
-	 * Query
27
-	 *
28
-	 * @var   GetPaid_Subscriptions_Query
29
-	 * @since 1.0.19
30
-	 */
31
-	public $query;
32
-
33
-	/**
34
-	 * Total subscriptions
35
-	 *
36
-	 * @var   string
37
-	 * @since 1.0.0
38
-	 */
39
-	public $total_count;
40
-
41
-	/**
42
-	 * Current status subscriptions
43
-	 *
44
-	 * @var   string
45
-	 * @since 1.0.0
46
-	 */
47
-	public $current_total_count;
48
-
49
-	/**
50
-	 * Status counts
51
-	 *
52
-	 * @var   array
53
-	 * @since 1.0.19
54
-	 */
55
-	public $status_counts;
56
-
57
-	/**
58
-	 * Number of results to show per page
59
-	 *
60
-	 * @var   int
61
-	 * @since 1.0.0
62
-	 */
63
-	public $per_page = 10;
64
-
65
-	/**
66
-	 *  Constructor function.
67
-	 */
68
-	public function __construct() {
69
-
70
-		parent::__construct(
71
-			array(
72
-				'singular' => 'subscription',
73
-				'plural'   => 'subscriptions',
74
-			)
75
-		);
76
-
77
-		$this->process_bulk_action();
78
-
79
-		$this->prepare_query();
80
-
81
-		$this->base_url = remove_query_arg( 'status' );
82
-
83
-	}
84
-
85
-	/**
86
-	 *  Prepares the display query
87
-	 */
88
-	public function prepare_query() {
89
-
90
-		// Prepare query args.
91
-		$query = array(
92
-			'number'  => $this->per_page,
93
-			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
-		);
98
-
99
-		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
101
-		$this->total_count         = $this->query->get_total();
102
-		$this->current_total_count = $this->query->get_total();
103
-		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
-
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
-		}
110
-
111
-	}
112
-
113
-	/**
114
-	 * Gets the list of views available on this table.
115
-	 *
116
-	 * The format is an associative array:
117
-	 * - `'id' => 'link'`
118
-	 *
119
-	 * @since 1.0.0
120
-	 *
121
-	 * @return array
122
-	 */
123
-	protected function get_views() {
124
-
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
-		$views    = array(
127
-
128
-			'all' => sprintf(
129
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
-				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
133
-				$this->total_count
134
-			)
135
-
136
-		);
137
-
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
-
140
-			$views[ $status ] = sprintf(
141
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
-				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
-				$count
146
-			);
147
-
148
-		}
149
-
150
-		return $views;
151
-
152
-	}
153
-
154
-	/**
155
-	 * Render most columns
156
-	 *
157
-	 * @access      private
158
-	 * @since       1.0.0
159
-	 * @return      string
160
-	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
-	}
164
-
165
-	/**
166
-	 * This is how checkbox column renders.
167
-	 *
168
-	 * @param WPInv_Subscription $item
169
-	 * @return string
170
-	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
-	}
174
-
175
-	/**
176
-	 * Status column
177
-	 *
178
-	 * @param WPInv_Subscription $item
179
-	 * @since       1.0.0
180
-	 * @return      string
181
-	 */
182
-	public function column_status( $item ) {
183
-		return $item->get_status_label_html();
184
-	}
185
-
186
-	/**
187
-	 * Subscription column
188
-	 *
189
-	 * @param WPInv_Subscription $item
190
-	 * @since       1.0.0
191
-	 * @return      string
192
-	 */
193
-	public function column_subscription( $item ) {
194
-
195
-		$username = __( '(Missing User)', 'invoicing' );
196
-
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
199
-
200
-			$username = sprintf(
201
-				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
-			);
205
-
206
-		}
207
-
208
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
-		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
-			$username
214
-		);
215
-
216
-		$row_actions = array();
217
-
218
-		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
-
222
-		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
224
-
225
-		if ( ! empty( $invoice ) ) {
226
-			$view_url    = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
-		}
229
-
230
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
-
232
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
-	}
234
-
235
-	/**
236
-	 * Renewal date column
237
-	 *
238
-	 * @param WPInv_Subscription $item
239
-	 * @since       1.0.0
240
-	 * @return      string
241
-	 */
242
-	public function column_renewal_date( $item ) {
243
-		return getpaid_format_date_value( $item->get_expiration() );
244
-	}
245
-
246
-	/**
247
-	 * Start date column
248
-	 *
249
-	 * @param WPInv_Subscription $item
250
-	 * @since       1.0.0
251
-	 * @return      string
252
-	 */
253
-	public function column_start_date( $item ) {
254
-		return getpaid_format_date_value( $item->get_date_created() );
255
-	}
256
-
257
-	/**
258
-	 * Amount column
259
-	 *
260
-	 * @param WPInv_Subscription $item
261
-	 * @since       1.0.19
262
-	 * @return      string
263
-	 */
264
-	public function column_amount( $item ) {
265
-
266
-		$initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() );
267
-		$recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() );
268
-		$period    = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() );
269
-
270
-		if ( $item->has_trial_period() ) {
271
-
272
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
273
-			$amount = sprintf(
274
-				_x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
275
-				$initial,
276
-				sanitize_text_field( $item->get_trial_period() ),
277
-				$recurring,
278
-				sanitize_text_field( strtolower( $period ) )
279
-			);
280
-
281
-		} else if ( $initial != $recurring ) {
282
-
283
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
284
-			$amount = sprintf(
285
-				_x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
286
-				$initial,
287
-				$recurring,
288
-				sanitize_text_field( strtolower( $period ) )
289
-			);
290
-
291
-		} else {
292
-
293
-			// translators: $1: is the recurring amount, $2: is the recurring period
294
-			$amount = sprintf(
295
-				_x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
296
-				$initial,
297
-				sanitize_text_field( strtolower( $period ) )
298
-			);
299
-
300
-		}
301
-
302
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
303
-	}
304
-
305
-	/**
306
-	 * Billing Times column
307
-	 *
308
-	 * @param WPInv_Subscription $item
309
-	 * @since       1.0.0
310
-	 * @return      string
311
-	 */
312
-	public function column_renewals( $item ) {
313
-		$max_bills = $item->get_bill_times();
314
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
315
-	}
316
-
317
-	/**
318
-	 * Product ID column
319
-	 *
320
-	 * @param WPInv_Subscription $item
321
-	 * @since       1.0.0
322
-	 * @return      string
323
-	 */
324
-	public function column_item( $item ) {
325
-		$_item = get_post( $item->get_product_id() );
326
-
327
-		if ( ! empty( $_item ) ) {
328
-			$link = get_edit_post_link( $_item );
329
-			$link = esc_url( $link );
330
-			$name = esc_html( get_the_title( $_item ) );
331
-			return "<a href='$link'>$name</a>";
332
-		} else {
333
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
334
-		}
335
-
336
-	}
337
-
338
-	/**
339
-	 * Retrieve the current page number
340
-	 *
341
-	 * @return      int
342
-	 */
343
-	public function get_paged() {
344
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
345
-	}
346
-
347
-	/**
348
-	 * Setup the final data for the table
349
-	 *
350
-	 */
351
-	public function prepare_items() {
352
-
353
-		$columns  = $this->get_columns();
354
-		$hidden   = array();
355
-		$sortable = $this->get_sortable_columns();
356
-
357
-		$this->_column_headers = array( $columns, $hidden, $sortable );
358
-
359
-		$this->set_pagination_args(
360
-			array(
361
-			'total_items' => $this->current_total_count,
362
-			'per_page'    => $this->per_page,
363
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
364
-			)
365
-		);
366
-	}
367
-
368
-	/**
369
-	 * Table columns
370
-	 *
371
-	 * @return array
372
-	 */
373
-	public function get_columns(){
374
-		$columns = array(
375
-			'cb'                => '<input type="checkbox" />',
376
-			'subscription'      => __( 'Subscription', 'invoicing' ),
377
-			'start_date'        => __( 'Start Date', 'invoicing' ),
378
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
379
-			'renewals'          => __( 'Renewals', 'invoicing' ),
380
-			'item'              => __( 'Item', 'invoicing' ),
381
-			'status'            => __( 'Status', 'invoicing' ),
382
-		);
383
-
384
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
385
-	}
386
-
387
-	/**
388
-	 * Sortable table columns.
389
-	 *
390
-	 * @return array
391
-	 */
392
-	public function get_sortable_columns() {
393
-		$sortable = array(
394
-			'subscription' => array( 'id', true ),
395
-			'start_date'   => array( 'created', true ),
396
-			'renewal_date' => array( 'expiration', true ),
397
-			'renewals'     => array( 'bill_times', true ),
398
-			'item'         => array( 'product_id', true ),
399
-			'status'       => array( 'status', true ),
400
-		);
401
-
402
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
403
-	}
404
-
405
-	/**
406
-	 * Whether the table has items to display or not
407
-	 *
408
-	 * @return bool
409
-	 */
410
-	public function has_items() {
411
-		return ! empty( $this->current_total_count );
412
-	}
413
-
414
-	/**
415
-	 * Processes bulk actions.
416
-	 *
417
-	 */
418
-	public function process_bulk_action() {
419
-
420
-	}
17
+    /**
18
+     * URL of this page
19
+     *
20
+     * @var   string
21
+     * @since 1.0.19
22
+     */
23
+    public $base_url;
24
+
25
+    /**
26
+     * Query
27
+     *
28
+     * @var   GetPaid_Subscriptions_Query
29
+     * @since 1.0.19
30
+     */
31
+    public $query;
32
+
33
+    /**
34
+     * Total subscriptions
35
+     *
36
+     * @var   string
37
+     * @since 1.0.0
38
+     */
39
+    public $total_count;
40
+
41
+    /**
42
+     * Current status subscriptions
43
+     *
44
+     * @var   string
45
+     * @since 1.0.0
46
+     */
47
+    public $current_total_count;
48
+
49
+    /**
50
+     * Status counts
51
+     *
52
+     * @var   array
53
+     * @since 1.0.19
54
+     */
55
+    public $status_counts;
56
+
57
+    /**
58
+     * Number of results to show per page
59
+     *
60
+     * @var   int
61
+     * @since 1.0.0
62
+     */
63
+    public $per_page = 10;
64
+
65
+    /**
66
+     *  Constructor function.
67
+     */
68
+    public function __construct() {
69
+
70
+        parent::__construct(
71
+            array(
72
+                'singular' => 'subscription',
73
+                'plural'   => 'subscriptions',
74
+            )
75
+        );
76
+
77
+        $this->process_bulk_action();
78
+
79
+        $this->prepare_query();
80
+
81
+        $this->base_url = remove_query_arg( 'status' );
82
+
83
+    }
84
+
85
+    /**
86
+     *  Prepares the display query
87
+     */
88
+    public function prepare_query() {
89
+
90
+        // Prepare query args.
91
+        $query = array(
92
+            'number'  => $this->per_page,
93
+            'paged'   => $this->get_paged(),
94
+            'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
+            'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
+            'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
+        );
98
+
99
+        // Prepare class properties.
100
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
101
+        $this->total_count         = $this->query->get_total();
102
+        $this->current_total_count = $this->query->get_total();
103
+        $this->items               = $this->query->get_results();
104
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
+
106
+        if ( 'all' != $query['status'] ) {
107
+            unset( $query['status'] );
108
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
+        }
110
+
111
+    }
112
+
113
+    /**
114
+     * Gets the list of views available on this table.
115
+     *
116
+     * The format is an associative array:
117
+     * - `'id' => 'link'`
118
+     *
119
+     * @since 1.0.0
120
+     *
121
+     * @return array
122
+     */
123
+    protected function get_views() {
124
+
125
+        $current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
+        $views    = array(
127
+
128
+            'all' => sprintf(
129
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
+                $current === 'all' ? ' class="current"' : '',
132
+                __('All','invoicing' ),
133
+                $this->total_count
134
+            )
135
+
136
+        );
137
+
138
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
+
140
+            $views[ $status ] = sprintf(
141
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
+                $current === $status ? ' class="current"' : '',
144
+                sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
+                $count
146
+            );
147
+
148
+        }
149
+
150
+        return $views;
151
+
152
+    }
153
+
154
+    /**
155
+     * Render most columns
156
+     *
157
+     * @access      private
158
+     * @since       1.0.0
159
+     * @return      string
160
+     */
161
+    public function column_default( $item, $column_name ) {
162
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
+    }
164
+
165
+    /**
166
+     * This is how checkbox column renders.
167
+     *
168
+     * @param WPInv_Subscription $item
169
+     * @return string
170
+     */
171
+    public function column_cb( $item ) {
172
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
+    }
174
+
175
+    /**
176
+     * Status column
177
+     *
178
+     * @param WPInv_Subscription $item
179
+     * @since       1.0.0
180
+     * @return      string
181
+     */
182
+    public function column_status( $item ) {
183
+        return $item->get_status_label_html();
184
+    }
185
+
186
+    /**
187
+     * Subscription column
188
+     *
189
+     * @param WPInv_Subscription $item
190
+     * @since       1.0.0
191
+     * @return      string
192
+     */
193
+    public function column_subscription( $item ) {
194
+
195
+        $username = __( '(Missing User)', 'invoicing' );
196
+
197
+        $user = get_userdata( $item->get_customer_id() );
198
+        if ( $user ) {
199
+
200
+            $username = sprintf(
201
+                '<a href="user-edit.php?user_id=%s">%s</a>',
202
+                absint( $user->ID ),
203
+                ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
+            );
205
+
206
+        }
207
+
208
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
+        $column_content = sprintf(
210
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
+            $username
214
+        );
215
+
216
+        $row_actions = array();
217
+
218
+        // View subscription.
219
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
+
222
+        // View invoice.
223
+        $invoice = get_post( $item->get_parent_invoice_id() );
224
+
225
+        if ( ! empty( $invoice ) ) {
226
+            $view_url    = get_edit_post_link( $invoice );
227
+            $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
+        }
229
+
230
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
+
232
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
+    }
234
+
235
+    /**
236
+     * Renewal date column
237
+     *
238
+     * @param WPInv_Subscription $item
239
+     * @since       1.0.0
240
+     * @return      string
241
+     */
242
+    public function column_renewal_date( $item ) {
243
+        return getpaid_format_date_value( $item->get_expiration() );
244
+    }
245
+
246
+    /**
247
+     * Start date column
248
+     *
249
+     * @param WPInv_Subscription $item
250
+     * @since       1.0.0
251
+     * @return      string
252
+     */
253
+    public function column_start_date( $item ) {
254
+        return getpaid_format_date_value( $item->get_date_created() );
255
+    }
256
+
257
+    /**
258
+     * Amount column
259
+     *
260
+     * @param WPInv_Subscription $item
261
+     * @since       1.0.19
262
+     * @return      string
263
+     */
264
+    public function column_amount( $item ) {
265
+
266
+        $initial   = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_initial_amount() ) ), $item->get_parent_payment()->get_currency() );
267
+        $recurring = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $item->get_recurring_amount() ) ), $item->get_parent_payment()->get_currency() );
268
+        $period    = 1 == $item->get_frequency() ? getpaid_get_subscription_period_label( $item->get_period() ) : WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_period(),$item->get_frequency() );
269
+
270
+        if ( $item->has_trial_period() ) {
271
+
272
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
273
+            $amount = sprintf(
274
+                _x( '%1$s trial for %2$s(s) then %3$s / %4$s', 'Subscription amount on admin table. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
275
+                $initial,
276
+                sanitize_text_field( $item->get_trial_period() ),
277
+                $recurring,
278
+                sanitize_text_field( strtolower( $period ) )
279
+            );
280
+
281
+        } else if ( $initial != $recurring ) {
282
+
283
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring perio
284
+            $amount = sprintf(
285
+                _x( 'Initial payment of %1$s then %2$s / %3$s', 'Subscription amount on admin table. (e.g.:Initial payment of $100 then $120 / year)', 'invoicing' ),
286
+                $initial,
287
+                $recurring,
288
+                sanitize_text_field( strtolower( $period ) )
289
+            );
290
+
291
+        } else {
292
+
293
+            // translators: $1: is the recurring amount, $2: is the recurring period
294
+            $amount = sprintf(
295
+                _x( '%1$s / %2$s', 'Subscription amount on admin table. (e.g.: $120 / year)', 'invoicing' ),
296
+                $initial,
297
+                sanitize_text_field( strtolower( $period ) )
298
+            );
299
+
300
+        }
301
+
302
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
303
+    }
304
+
305
+    /**
306
+     * Billing Times column
307
+     *
308
+     * @param WPInv_Subscription $item
309
+     * @since       1.0.0
310
+     * @return      string
311
+     */
312
+    public function column_renewals( $item ) {
313
+        $max_bills = $item->get_bill_times();
314
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
315
+    }
316
+
317
+    /**
318
+     * Product ID column
319
+     *
320
+     * @param WPInv_Subscription $item
321
+     * @since       1.0.0
322
+     * @return      string
323
+     */
324
+    public function column_item( $item ) {
325
+        $_item = get_post( $item->get_product_id() );
326
+
327
+        if ( ! empty( $_item ) ) {
328
+            $link = get_edit_post_link( $_item );
329
+            $link = esc_url( $link );
330
+            $name = esc_html( get_the_title( $_item ) );
331
+            return "<a href='$link'>$name</a>";
332
+        } else {
333
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
334
+        }
335
+
336
+    }
337
+
338
+    /**
339
+     * Retrieve the current page number
340
+     *
341
+     * @return      int
342
+     */
343
+    public function get_paged() {
344
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
345
+    }
346
+
347
+    /**
348
+     * Setup the final data for the table
349
+     *
350
+     */
351
+    public function prepare_items() {
352
+
353
+        $columns  = $this->get_columns();
354
+        $hidden   = array();
355
+        $sortable = $this->get_sortable_columns();
356
+
357
+        $this->_column_headers = array( $columns, $hidden, $sortable );
358
+
359
+        $this->set_pagination_args(
360
+            array(
361
+            'total_items' => $this->current_total_count,
362
+            'per_page'    => $this->per_page,
363
+            'total_pages' => ceil( $this->current_total_count / $this->per_page )
364
+            )
365
+        );
366
+    }
367
+
368
+    /**
369
+     * Table columns
370
+     *
371
+     * @return array
372
+     */
373
+    public function get_columns(){
374
+        $columns = array(
375
+            'cb'                => '<input type="checkbox" />',
376
+            'subscription'      => __( 'Subscription', 'invoicing' ),
377
+            'start_date'        => __( 'Start Date', 'invoicing' ),
378
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
379
+            'renewals'          => __( 'Renewals', 'invoicing' ),
380
+            'item'              => __( 'Item', 'invoicing' ),
381
+            'status'            => __( 'Status', 'invoicing' ),
382
+        );
383
+
384
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
385
+    }
386
+
387
+    /**
388
+     * Sortable table columns.
389
+     *
390
+     * @return array
391
+     */
392
+    public function get_sortable_columns() {
393
+        $sortable = array(
394
+            'subscription' => array( 'id', true ),
395
+            'start_date'   => array( 'created', true ),
396
+            'renewal_date' => array( 'expiration', true ),
397
+            'renewals'     => array( 'bill_times', true ),
398
+            'item'         => array( 'product_id', true ),
399
+            'status'       => array( 'status', true ),
400
+        );
401
+
402
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
403
+    }
404
+
405
+    /**
406
+     * Whether the table has items to display or not
407
+     *
408
+     * @return bool
409
+     */
410
+    public function has_items() {
411
+        return ! empty( $this->current_total_count );
412
+    }
413
+
414
+    /**
415
+     * Processes bulk actions.
416
+     *
417
+     */
418
+    public function process_bulk_action() {
419
+
420
+    }
421 421
 
422 422
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
15
+    /**
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
21 21
 
22 22
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-		global $wpinv_euvat;
45
-
46
-		// For invoices...
47
-		if ( $post_type == 'wpi_invoice' ) {
48
-			$invoice = new WPInv_Invoice( $post );
49
-
50
-			// Resend invoice.
51
-			if ( ! $invoice->is_draft() ) {
52
-				add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' );
53
-			}
54
-
55
-			// Subscriptions.
56
-			$subscription = getpaid_get_invoice_subscription( $invoice );
57
-			if ( ! empty( $subscription ) ) {
58
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' );
59
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' );
60
-			}
61
-
62
-			// Invoice details.
63
-			add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' );
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
26
+
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
+
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
+
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
+
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
39
+
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
44
+        global $wpinv_euvat;
45
+
46
+        // For invoices...
47
+        if ( $post_type == 'wpi_invoice' ) {
48
+            $invoice = new WPInv_Invoice( $post );
49
+
50
+            // Resend invoice.
51
+            if ( ! $invoice->is_draft() ) {
52
+                add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' );
53
+            }
54
+
55
+            // Subscriptions.
56
+            $subscription = getpaid_get_invoice_subscription( $invoice );
57
+            if ( ! empty( $subscription ) ) {
58
+                add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' );
59
+                add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' );
60
+            }
61
+
62
+            // Invoice details.
63
+            add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' );
64 64
 			
65
-			// Payment details.
66
-			add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' );
65
+            // Payment details.
66
+            add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' );
67 67
 
68
-			// Billing details.
69
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' );
68
+            // Billing details.
69
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' );
70 70
 			
71
-			// Invoice items.
72
-			add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' );
71
+            // Invoice items.
72
+            add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' );
73 73
 			
74
-			// Invoice notes.
75
-			add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' );
74
+            // Invoice notes.
75
+            add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' );
76 76
 
77
-			// Payment form information.
78
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
79
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' );
80
-			}
81
-		}
77
+            // Payment form information.
78
+            if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
79
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' );
80
+            }
81
+        }
82 82
 
83
-		// For payment forms.
84
-		if ( $post_type == 'wpi_payment_form' ) {
83
+        // For payment forms.
84
+        if ( $post_type == 'wpi_payment_form' ) {
85 85
 
86
-			// Design payment form.
87
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
86
+            // Design payment form.
87
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
88 88
 
89
-			// Payment form information.
90
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
89
+            // Payment form information.
90
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
91 91
 
92
-		}
92
+        }
93 93
 
94
-		// For invoice items.
95
-		if ( $post_type == 'wpi_item' ) {
94
+        // For invoice items.
95
+        if ( $post_type == 'wpi_item' ) {
96 96
 
97
-			// Item details.
98
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
97
+            // Item details.
98
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
99 99
 
100
-			// If taxes are enabled, register the tax metabox.
101
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
102
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
103
-			}
100
+            // If taxes are enabled, register the tax metabox.
101
+            if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
102
+                add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
103
+            }
104 104
 
105
-			// Item info.
106
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
105
+            // Item info.
106
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
107 107
 
108
-		}
108
+        }
109 109
 
110
-		// For invoice discounts.
111
-		if ( $post_type == 'wpi_discount' ) {
112
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
113
-		}
110
+        // For invoice discounts.
111
+        if ( $post_type == 'wpi_discount' ) {
112
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
113
+        }
114 114
 		
115 115
 
116
-	}
116
+    }
117 117
 
118
-	/**
119
-	 * Remove some metaboxes.
120
-	 */
121
-	public static function remove_meta_boxes() {
122
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
123
-	}
118
+    /**
119
+     * Remove some metaboxes.
120
+     */
121
+    public static function remove_meta_boxes() {
122
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
123
+    }
124 124
 
125
-	/**
126
-	 * Rename other metaboxes.
127
-	 */
128
-	public static function rename_meta_boxes() {
125
+    /**
126
+     * Rename other metaboxes.
127
+     */
128
+    public static function rename_meta_boxes() {
129 129
 		
130
-	}
131
-
132
-	/**
133
-	 * Check if we're saving, then trigger an action based on the post type.
134
-	 *
135
-	 * @param  int    $post_id Post ID.
136
-	 * @param  object $post Post object.
137
-	 */
138
-	public static function save_meta_boxes( $post_id, $post ) {
139
-		$post_id = absint( $post_id );
140
-		$data    = wp_unslash( $_POST );
141
-
142
-		// Do not save for ajax requests.
143
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
144
-			return;
145
-		}
146
-
147
-		// $post_id and $post are required
148
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
149
-			return;
150
-		}
151
-
152
-		// Dont' save meta boxes for revisions or autosaves.
153
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
154
-			return;
155
-		}
156
-
157
-		// Check the nonce.
158
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
159
-			return;
160
-		}
161
-
162
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
163
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
164
-			return;
165
-		}
166
-
167
-		// Check user has permission to edit.
168
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
169
-			return;
170
-		}
171
-
172
-		// Ensure this is our post type.
173
-		$post_types_map = array(
174
-			'wpi_invoice'      => 'GetPaid_Meta_Box_Invoice_Address',
175
-			'wpi_quote'        => 'GetPaid_Meta_Box_Invoice_Address',
176
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
177
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
178
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
179
-		);
180
-
181
-		// Is this our post type?
182
-		if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) {
183
-			return;
184
-		}
185
-
186
-		// We need this save event to run once to avoid potential endless loops.
187
-		self::$saved_meta_boxes = true;
130
+    }
131
+
132
+    /**
133
+     * Check if we're saving, then trigger an action based on the post type.
134
+     *
135
+     * @param  int    $post_id Post ID.
136
+     * @param  object $post Post object.
137
+     */
138
+    public static function save_meta_boxes( $post_id, $post ) {
139
+        $post_id = absint( $post_id );
140
+        $data    = wp_unslash( $_POST );
141
+
142
+        // Do not save for ajax requests.
143
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
144
+            return;
145
+        }
146
+
147
+        // $post_id and $post are required
148
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
149
+            return;
150
+        }
151
+
152
+        // Dont' save meta boxes for revisions or autosaves.
153
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
154
+            return;
155
+        }
156
+
157
+        // Check the nonce.
158
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
159
+            return;
160
+        }
161
+
162
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
163
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
164
+            return;
165
+        }
166
+
167
+        // Check user has permission to edit.
168
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
169
+            return;
170
+        }
171
+
172
+        // Ensure this is our post type.
173
+        $post_types_map = array(
174
+            'wpi_invoice'      => 'GetPaid_Meta_Box_Invoice_Address',
175
+            'wpi_quote'        => 'GetPaid_Meta_Box_Invoice_Address',
176
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
177
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
178
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
179
+        );
180
+
181
+        // Is this our post type?
182
+        if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) {
183
+            return;
184
+        }
185
+
186
+        // We need this save event to run once to avoid potential endless loops.
187
+        self::$saved_meta_boxes = true;
188 188
 		
189
-		// Save the post.
190
-		$class = $post_types_map[ $post->post_type ];
191
-		$class::save( $post_id, $_POST, $post );
189
+        // Save the post.
190
+        $class = $post_types_map[ $post->post_type ];
191
+        $class::save( $post_id, $_POST, $post );
192 192
 
193
-	}
193
+    }
194 194
 
195 195
 }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +2293 added lines, -2293 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 class WPInv_Invoice extends GetPaid_Data {
15 15
 
16 16
     /**
17
-	 * Which data store to load.
18
-	 *
19
-	 * @var string
20
-	 */
17
+     * Which data store to load.
18
+     *
19
+     * @var string
20
+     */
21 21
     protected $data_store_name = 'invoice';
22 22
 
23 23
     /**
24
-	 * This is the name of this object type.
25
-	 *
26
-	 * @var string
27
-	 */
24
+     * This is the name of this object type.
25
+     *
26
+     * @var string
27
+     */
28 28
     protected $object_type = 'invoice';
29 29
 
30 30
     /**
31
-	 * Item Data array. This is the core item data exposed in APIs.
32
-	 *
33
-	 * @since 1.0.19
34
-	 * @var array
35
-	 */
36
-	protected $data = array(
37
-		'parent_id'            => 0,
38
-		'status'               => 'wpi-pending',
39
-		'version'              => '',
40
-		'date_created'         => null,
31
+     * Item Data array. This is the core item data exposed in APIs.
32
+     *
33
+     * @since 1.0.19
34
+     * @var array
35
+     */
36
+    protected $data = array(
37
+        'parent_id'            => 0,
38
+        'status'               => 'wpi-pending',
39
+        'version'              => '',
40
+        'date_created'         => null,
41 41
         'date_modified'        => null,
42 42
         'due_date'             => null,
43 43
         'completed_date'       => null,
@@ -79,21 +79,21 @@  discard block
 block discarded – undo
79 79
         'transaction_id'       => '',
80 80
         'currency'             => '',
81 81
         'disable_taxes'        => false,
82
-		'subscription_id'      => null,
83
-		'remote_subscription_id' => null,
84
-		'is_viewed'            => false,
85
-		'email_cc'             => '',
86
-		'template'             => 'quantity', // hours, amount only
82
+        'subscription_id'      => null,
83
+        'remote_subscription_id' => null,
84
+        'is_viewed'            => false,
85
+        'email_cc'             => '',
86
+        'template'             => 'quantity', // hours, amount only
87 87
     );
88 88
 
89 89
     /**
90
-	 * Stores meta in cache for future reads.
91
-	 *
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @var string
95
-	 */
96
-	protected $cache_group = 'getpaid_invoices';
90
+     * Stores meta in cache for future reads.
91
+     *
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @var string
95
+     */
96
+    protected $cache_group = 'getpaid_invoices';
97 97
 
98 98
     /**
99 99
      * Stores a reference to the original WP_Post object
@@ -107,104 +107,104 @@  discard block
 block discarded – undo
107 107
      *
108 108
      * @var int
109 109
      */
110
-	protected $recurring_item = null;
110
+    protected $recurring_item = null;
111 111
 
112
-	/**
112
+    /**
113 113
      * Stores an array of item totals.
114
-	 *
115
-	 * e.g $totals['discount'] = array(
116
-	 * 		'initial'   => 10,
117
-	 * 		'recurring' => 10,
118
-	 * )
114
+     *
115
+     * e.g $totals['discount'] = array(
116
+     * 		'initial'   => 10,
117
+     * 		'recurring' => 10,
118
+     * )
119 119
      *
120 120
      * @var array
121 121
      */
122
-	protected $totals = array();
122
+    protected $totals = array();
123 123
 
124
-	/**
125
-	 * Stores the status transition information.
126
-	 *
127
-	 * @since 1.0.19
128
-	 * @var bool
129
-	 */
130
-	protected $status_transition = false;
124
+    /**
125
+     * Stores the status transition information.
126
+     *
127
+     * @since 1.0.19
128
+     * @var bool
129
+     */
130
+    protected $status_transition = false;
131 131
 
132 132
     /**
133
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
134
-	 *
135
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
136
-	 */
133
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
134
+     *
135
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
136
+     */
137 137
     public function __construct( $invoice = false ) {
138 138
 
139 139
         parent::__construct( $invoice );
140 140
 
141
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
142
-			$this->set_id( $invoice );
143
-		} elseif ( $invoice instanceof self ) {
144
-			$this->set_id( $invoice->get_id() );
145
-		} elseif ( ! empty( $invoice->ID ) ) {
146
-			$this->set_id( $invoice->ID );
147
-		} elseif ( is_array( $invoice ) ) {
148
-			$this->set_props( $invoice );
149
-
150
-			if ( isset( $invoice['ID'] ) ) {
151
-				$this->set_id( $invoice['ID'] );
152
-			}
153
-
154
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
155
-			$this->set_id( $invoice_id );
156
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
157
-			$this->set_id( $invoice_id );
158
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
159
-			$this->set_id( $invoice_id );
160
-		}else {
161
-			$this->set_object_read( true );
162
-		}
141
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
142
+            $this->set_id( $invoice );
143
+        } elseif ( $invoice instanceof self ) {
144
+            $this->set_id( $invoice->get_id() );
145
+        } elseif ( ! empty( $invoice->ID ) ) {
146
+            $this->set_id( $invoice->ID );
147
+        } elseif ( is_array( $invoice ) ) {
148
+            $this->set_props( $invoice );
149
+
150
+            if ( isset( $invoice['ID'] ) ) {
151
+                $this->set_id( $invoice['ID'] );
152
+            }
153
+
154
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
155
+            $this->set_id( $invoice_id );
156
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
157
+            $this->set_id( $invoice_id );
158
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
159
+            $this->set_id( $invoice_id );
160
+        }else {
161
+            $this->set_object_read( true );
162
+        }
163 163
 
164 164
         // Load the datastore.
165
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
165
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
166 166
 
167
-		if ( $this->get_id() > 0 ) {
167
+        if ( $this->get_id() > 0 ) {
168 168
             $this->post = get_post( $this->get_id() );
169 169
             $this->ID   = $this->get_id();
170
-			$this->data_store->read( $this );
170
+            $this->data_store->read( $this );
171 171
         }
172 172
 
173 173
     }
174 174
 
175 175
     /**
176
-	 * Given an invoice key/number, it returns its id.
177
-	 *
178
-	 *
179
-	 * @static
180
-	 * @param string $value The invoice key or number
181
-	 * @param string $field Either key, transaction_id or number.
182
-	 * @since 1.0.15
183
-	 * @return int
184
-	 */
185
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
176
+     * Given an invoice key/number, it returns its id.
177
+     *
178
+     *
179
+     * @static
180
+     * @param string $value The invoice key or number
181
+     * @param string $field Either key, transaction_id or number.
182
+     * @since 1.0.15
183
+     * @return int
184
+     */
185
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
186 186
         global $wpdb;
187 187
 
188
-		// Trim the value.
189
-		$value = trim( $value );
188
+        // Trim the value.
189
+        $value = trim( $value );
190 190
 
191
-		if ( empty( $value ) ) {
192
-			return 0;
193
-		}
191
+        if ( empty( $value ) ) {
192
+            return 0;
193
+        }
194 194
 
195 195
         // Valid fields.
196 196
         $fields = array( 'key', 'number', 'transaction_id' );
197 197
 
198
-		// Ensure a field has been passed.
199
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
200
-			return 0;
201
-		}
198
+        // Ensure a field has been passed.
199
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
200
+            return 0;
201
+        }
202 202
 
203
-		// Maybe retrieve from the cache.
204
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
205
-		if ( false !== $invoice_id ) {
206
-			return $invoice_id;
207
-		}
203
+        // Maybe retrieve from the cache.
204
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
205
+        if ( false !== $invoice_id ) {
206
+            return $invoice_id;
207
+        }
208 208
 
209 209
         // Fetch from the db.
210 210
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
213 213
         );
214 214
 
215
-		// Update the cache with our data
216
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
215
+        // Update the cache with our data
216
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
217 217
 
218
-		return $invoice_id;
218
+        return $invoice_id;
219 219
     }
220 220
 
221 221
     /**
@@ -241,80 +241,80 @@  discard block
 block discarded – undo
241 241
     */
242 242
 
243 243
     /**
244
-	 * Get parent invoice ID.
245
-	 *
246
-	 * @since 1.0.19
247
-	 * @param  string $context View or edit context.
248
-	 * @return int
249
-	 */
250
-	public function get_parent_id( $context = 'view' ) {
251
-		return (int) $this->get_prop( 'parent_id', $context );
244
+     * Get parent invoice ID.
245
+     *
246
+     * @since 1.0.19
247
+     * @param  string $context View or edit context.
248
+     * @return int
249
+     */
250
+    public function get_parent_id( $context = 'view' ) {
251
+        return (int) $this->get_prop( 'parent_id', $context );
252 252
     }
253 253
 
254 254
     /**
255
-	 * Get parent invoice.
256
-	 *
257
-	 * @since 1.0.19
258
-	 * @return WPInv_Invoice
259
-	 */
255
+     * Get parent invoice.
256
+     *
257
+     * @since 1.0.19
258
+     * @return WPInv_Invoice
259
+     */
260 260
     public function get_parent_payment() {
261 261
         return new WPInv_Invoice( $this->get_parent_id() );
262 262
     }
263 263
 
264 264
     /**
265
-	 * Alias for self::get_parent_payment().
266
-	 *
267
-	 * @since 1.0.19
268
-	 * @return WPInv_Invoice
269
-	 */
265
+     * Alias for self::get_parent_payment().
266
+     *
267
+     * @since 1.0.19
268
+     * @return WPInv_Invoice
269
+     */
270 270
     public function get_parent() {
271 271
         return $this->get_parent_payment();
272 272
     }
273 273
 
274 274
     /**
275
-	 * Get invoice status.
276
-	 *
277
-	 * @since 1.0.19
278
-	 * @param  string $context View or edit context.
279
-	 * @return string
280
-	 */
281
-	public function get_status( $context = 'view' ) {
282
-		return $this->get_prop( 'status', $context );
283
-	}
275
+     * Get invoice status.
276
+     *
277
+     * @since 1.0.19
278
+     * @param  string $context View or edit context.
279
+     * @return string
280
+     */
281
+    public function get_status( $context = 'view' ) {
282
+        return $this->get_prop( 'status', $context );
283
+    }
284 284
 	
285
-	/**
286
-	 * Retrieves an array of possible invoice statuses.
287
-	 *
288
-	 * @since 1.0.19
289
-	 * @return array
290
-	 */
291
-	public function get_all_statuses() {
292
-
293
-		$statuses = wpinv_get_invoice_statuses( true, true, $this );
294
-
295
-		// For backwards compatibility.
296
-		if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
285
+    /**
286
+     * Retrieves an array of possible invoice statuses.
287
+     *
288
+     * @since 1.0.19
289
+     * @return array
290
+     */
291
+    public function get_all_statuses() {
292
+
293
+        $statuses = wpinv_get_invoice_statuses( true, true, $this );
294
+
295
+        // For backwards compatibility.
296
+        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
297 297
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
298
-		}
298
+        }
299 299
 
300
-		return $statuses;
300
+        return $statuses;
301 301
     }
302 302
 
303 303
     /**
304
-	 * Get invoice status nice name.
305
-	 *
306
-	 * @since 1.0.19
307
-	 * @return string
308
-	 */
304
+     * Get invoice status nice name.
305
+     *
306
+     * @since 1.0.19
307
+     * @return string
308
+     */
309 309
     public function get_status_nicename() {
310
-		$statuses = $this->get_all_statuses();
310
+        $statuses = $this->get_all_statuses();
311 311
 
312 312
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
313 313
 
314 314
         return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this );
315 315
     }
316 316
 
317
-	/**
317
+    /**
318 318
      * Retrieves the invoice status label html
319 319
      *
320 320
      * @since  1.0.0
@@ -322,262 +322,262 @@  discard block
 block discarded – undo
322 322
      */
323 323
     public function get_status_label_html() {
324 324
 
325
-		$status_label = sanitize_text_field( $this->get_status_nicename() );
326
-		$status       = sanitize_html_class( $this->get_status() );
325
+        $status_label = sanitize_text_field( $this->get_status_nicename() );
326
+        $status       = sanitize_html_class( $this->get_status() );
327 327
 
328
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
329
-	}
328
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
329
+    }
330 330
 
331 331
     /**
332
-	 * Get plugin version when the invoice was created.
333
-	 *
334
-	 * @since 1.0.19
335
-	 * @param  string $context View or edit context.
336
-	 * @return string
337
-	 */
338
-	public function get_version( $context = 'view' ) {
339
-		return $this->get_prop( 'version', $context );
340
-	}
332
+     * Get plugin version when the invoice was created.
333
+     *
334
+     * @since 1.0.19
335
+     * @param  string $context View or edit context.
336
+     * @return string
337
+     */
338
+    public function get_version( $context = 'view' ) {
339
+        return $this->get_prop( 'version', $context );
340
+    }
341 341
 
342
-	/**
343
-	 * @deprecated
344
-	 */
345
-	public function get_invoice_date( $format = true ) {
346
-		$date      = getpaid_format_date( $this->get_date_completed() );
347
-		$date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
348
-		$formatted = getpaid_format_date( $date );
342
+    /**
343
+     * @deprecated
344
+     */
345
+    public function get_invoice_date( $format = true ) {
346
+        $date      = getpaid_format_date( $this->get_date_completed() );
347
+        $date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
348
+        $formatted = getpaid_format_date( $date );
349 349
 
350
-		if ( $format ) {
351
-			return $formatted;
352
-		}
350
+        if ( $format ) {
351
+            return $formatted;
352
+        }
353 353
 
354
-		return empty( $formatted ) ? '' : $date;
354
+        return empty( $formatted ) ? '' : $date;
355 355
 
356 356
     }
357 357
 
358 358
     /**
359
-	 * Get date when the invoice was created.
360
-	 *
361
-	 * @since 1.0.19
362
-	 * @param  string $context View or edit context.
363
-	 * @return string
364
-	 */
365
-	public function get_date_created( $context = 'view' ) {
366
-		return $this->get_prop( 'date_created', $context );
367
-	}
359
+     * Get date when the invoice was created.
360
+     *
361
+     * @since 1.0.19
362
+     * @param  string $context View or edit context.
363
+     * @return string
364
+     */
365
+    public function get_date_created( $context = 'view' ) {
366
+        return $this->get_prop( 'date_created', $context );
367
+    }
368 368
 	
369
-	/**
370
-	 * Alias for self::get_date_created().
371
-	 *
372
-	 * @since 1.0.19
373
-	 * @param  string $context View or edit context.
374
-	 * @return string
375
-	 */
376
-	public function get_created_date( $context = 'view' ) {
377
-		return $this->get_date_created( $context );
378
-    }
379
-
380
-    /**
381
-	 * Get GMT date when the invoice was created.
382
-	 *
383
-	 * @since 1.0.19
384
-	 * @param  string $context View or edit context.
385
-	 * @return string
386
-	 */
387
-	public function get_date_created_gmt( $context = 'view' ) {
369
+    /**
370
+     * Alias for self::get_date_created().
371
+     *
372
+     * @since 1.0.19
373
+     * @param  string $context View or edit context.
374
+     * @return string
375
+     */
376
+    public function get_created_date( $context = 'view' ) {
377
+        return $this->get_date_created( $context );
378
+    }
379
+
380
+    /**
381
+     * Get GMT date when the invoice was created.
382
+     *
383
+     * @since 1.0.19
384
+     * @param  string $context View or edit context.
385
+     * @return string
386
+     */
387
+    public function get_date_created_gmt( $context = 'view' ) {
388 388
         $date = $this->get_date_created( $context );
389 389
 
390 390
         if ( $date ) {
391 391
             $date = get_gmt_from_date( $date );
392 392
         }
393
-		return $date;
393
+        return $date;
394 394
     }
395 395
 
396 396
     /**
397
-	 * Get date when the invoice was last modified.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  string $context View or edit context.
401
-	 * @return string
402
-	 */
403
-	public function get_date_modified( $context = 'view' ) {
404
-		return $this->get_prop( 'date_modified', $context );
405
-	}
397
+     * Get date when the invoice was last modified.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  string $context View or edit context.
401
+     * @return string
402
+     */
403
+    public function get_date_modified( $context = 'view' ) {
404
+        return $this->get_prop( 'date_modified', $context );
405
+    }
406 406
 
407
-	/**
408
-	 * Alias for self::get_date_modified().
409
-	 *
410
-	 * @since 1.0.19
411
-	 * @param  string $context View or edit context.
412
-	 * @return string
413
-	 */
414
-	public function get_modified_date( $context = 'view' ) {
415
-		return $this->get_date_modified( $context );
407
+    /**
408
+     * Alias for self::get_date_modified().
409
+     *
410
+     * @since 1.0.19
411
+     * @param  string $context View or edit context.
412
+     * @return string
413
+     */
414
+    public function get_modified_date( $context = 'view' ) {
415
+        return $this->get_date_modified( $context );
416 416
     }
417 417
 
418 418
     /**
419
-	 * Get GMT date when the invoice was last modified.
420
-	 *
421
-	 * @since 1.0.19
422
-	 * @param  string $context View or edit context.
423
-	 * @return string
424
-	 */
425
-	public function get_date_modified_gmt( $context = 'view' ) {
419
+     * Get GMT date when the invoice was last modified.
420
+     *
421
+     * @since 1.0.19
422
+     * @param  string $context View or edit context.
423
+     * @return string
424
+     */
425
+    public function get_date_modified_gmt( $context = 'view' ) {
426 426
         $date = $this->get_date_modified( $context );
427 427
 
428 428
         if ( $date ) {
429 429
             $date = get_gmt_from_date( $date );
430 430
         }
431
-		return $date;
431
+        return $date;
432 432
     }
433 433
 
434 434
     /**
435
-	 * Get the invoice due date.
436
-	 *
437
-	 * @since 1.0.19
438
-	 * @param  string $context View or edit context.
439
-	 * @return string
440
-	 */
441
-	public function get_due_date( $context = 'view' ) {
442
-		return $this->get_prop( 'due_date', $context );
435
+     * Get the invoice due date.
436
+     *
437
+     * @since 1.0.19
438
+     * @param  string $context View or edit context.
439
+     * @return string
440
+     */
441
+    public function get_due_date( $context = 'view' ) {
442
+        return $this->get_prop( 'due_date', $context );
443 443
     }
444 444
 
445 445
     /**
446
-	 * Alias for self::get_due_date().
447
-	 *
448
-	 * @since 1.0.19
449
-	 * @param  string $context View or edit context.
450
-	 * @return string
451
-	 */
452
-	public function get_date_due( $context = 'view' ) {
453
-		return $this->get_due_date( $context );
446
+     * Alias for self::get_due_date().
447
+     *
448
+     * @since 1.0.19
449
+     * @param  string $context View or edit context.
450
+     * @return string
451
+     */
452
+    public function get_date_due( $context = 'view' ) {
453
+        return $this->get_due_date( $context );
454 454
     }
455 455
 
456 456
     /**
457
-	 * Get the invoice GMT due date.
458
-	 *
459
-	 * @since 1.0.19
460
-	 * @param  string $context View or edit context.
461
-	 * @return string
462
-	 */
463
-	public function get_due_date_gmt( $context = 'view' ) {
457
+     * Get the invoice GMT due date.
458
+     *
459
+     * @since 1.0.19
460
+     * @param  string $context View or edit context.
461
+     * @return string
462
+     */
463
+    public function get_due_date_gmt( $context = 'view' ) {
464 464
         $date = $this->get_due_date( $context );
465 465
 
466 466
         if ( $date ) {
467 467
             $date = get_gmt_from_date( $date );
468 468
         }
469
-		return $date;
469
+        return $date;
470 470
     }
471 471
 
472 472
     /**
473
-	 * Alias for self::get_due_date_gmt().
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return string
478
-	 */
479
-	public function get_gmt_date_due( $context = 'view' ) {
480
-		return $this->get_due_date_gmt( $context );
473
+     * Alias for self::get_due_date_gmt().
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return string
478
+     */
479
+    public function get_gmt_date_due( $context = 'view' ) {
480
+        return $this->get_due_date_gmt( $context );
481 481
     }
482 482
 
483 483
     /**
484
-	 * Get date when the invoice was completed.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @param  string $context View or edit context.
488
-	 * @return string
489
-	 */
490
-	public function get_completed_date( $context = 'view' ) {
491
-		return $this->get_prop( 'completed_date', $context );
484
+     * Get date when the invoice was completed.
485
+     *
486
+     * @since 1.0.19
487
+     * @param  string $context View or edit context.
488
+     * @return string
489
+     */
490
+    public function get_completed_date( $context = 'view' ) {
491
+        return $this->get_prop( 'completed_date', $context );
492 492
     }
493 493
 
494 494
     /**
495
-	 * Alias for self::get_completed_date().
496
-	 *
497
-	 * @since 1.0.19
498
-	 * @param  string $context View or edit context.
499
-	 * @return string
500
-	 */
501
-	public function get_date_completed( $context = 'view' ) {
502
-		return $this->get_completed_date( $context );
495
+     * Alias for self::get_completed_date().
496
+     *
497
+     * @since 1.0.19
498
+     * @param  string $context View or edit context.
499
+     * @return string
500
+     */
501
+    public function get_date_completed( $context = 'view' ) {
502
+        return $this->get_completed_date( $context );
503 503
     }
504 504
 
505 505
     /**
506
-	 * Get GMT date when the invoice was was completed.
507
-	 *
508
-	 * @since 1.0.19
509
-	 * @param  string $context View or edit context.
510
-	 * @return string
511
-	 */
512
-	public function get_completed_date_gmt( $context = 'view' ) {
506
+     * Get GMT date when the invoice was was completed.
507
+     *
508
+     * @since 1.0.19
509
+     * @param  string $context View or edit context.
510
+     * @return string
511
+     */
512
+    public function get_completed_date_gmt( $context = 'view' ) {
513 513
         $date = $this->get_completed_date( $context );
514 514
 
515 515
         if ( $date ) {
516 516
             $date = get_gmt_from_date( $date );
517 517
         }
518
-		return $date;
518
+        return $date;
519 519
     }
520 520
 
521 521
     /**
522
-	 * Alias for self::get_completed_date_gmt().
523
-	 *
524
-	 * @since 1.0.19
525
-	 * @param  string $context View or edit context.
526
-	 * @return string
527
-	 */
528
-	public function get_gmt_completed_date( $context = 'view' ) {
529
-		return $this->get_completed_date_gmt( $context );
522
+     * Alias for self::get_completed_date_gmt().
523
+     *
524
+     * @since 1.0.19
525
+     * @param  string $context View or edit context.
526
+     * @return string
527
+     */
528
+    public function get_gmt_completed_date( $context = 'view' ) {
529
+        return $this->get_completed_date_gmt( $context );
530 530
     }
531 531
 
532 532
     /**
533
-	 * Get the invoice number.
534
-	 *
535
-	 * @since 1.0.19
536
-	 * @param  string $context View or edit context.
537
-	 * @return string
538
-	 */
539
-	public function get_number( $context = 'view' ) {
540
-		$number = $this->get_prop( 'number', $context );
533
+     * Get the invoice number.
534
+     *
535
+     * @since 1.0.19
536
+     * @param  string $context View or edit context.
537
+     * @return string
538
+     */
539
+    public function get_number( $context = 'view' ) {
540
+        $number = $this->get_prop( 'number', $context );
541 541
 
542
-		if ( empty( $number ) ) {
543
-			$number = $this->generate_number();
544
-			$this->set_number( $this->generate_number() );
545
-		}
542
+        if ( empty( $number ) ) {
543
+            $number = $this->generate_number();
544
+            $this->set_number( $this->generate_number() );
545
+        }
546 546
 
547
-		return $number;
547
+        return $number;
548 548
     }
549 549
 
550
-	/**
551
-	 * Set the invoice number.
552
-	 *
553
-	 * @since 1.0.19
554
-	 */
555
-	public function maybe_set_number() {
550
+    /**
551
+     * Set the invoice number.
552
+     *
553
+     * @since 1.0.19
554
+     */
555
+    public function maybe_set_number() {
556 556
         $number = $this->get_number();
557 557
 
558 558
         if ( empty( $number ) || $this->get_id() == $number ) {
559
-			$this->set_number( $this->generate_number() );
559
+            $this->set_number( $this->generate_number() );
560 560
         }
561 561
 
562
-	}
562
+    }
563 563
 
564 564
     /**
565
-	 * Get the invoice key.
566
-	 *
567
-	 * @since 1.0.19
568
-	 * @param  string $context View or edit context.
569
-	 * @return string
570
-	 */
571
-	public function get_key( $context = 'view' ) {
565
+     * Get the invoice key.
566
+     *
567
+     * @since 1.0.19
568
+     * @param  string $context View or edit context.
569
+     * @return string
570
+     */
571
+    public function get_key( $context = 'view' ) {
572 572
         return $this->get_prop( 'key', $context );
573
-	}
574
-
575
-	/**
576
-	 * Set the invoice key.
577
-	 *
578
-	 * @since 1.0.19
579
-	 */
580
-	public function maybe_set_key() {
573
+    }
574
+
575
+    /**
576
+     * Set the invoice key.
577
+     *
578
+     * @since 1.0.19
579
+     */
580
+    public function maybe_set_key() {
581 581
         $key = $this->get_key();
582 582
 
583 583
         if ( empty( $key ) ) {
@@ -588,126 +588,126 @@  discard block
 block discarded – undo
588 588
     }
589 589
 
590 590
     /**
591
-	 * Get the invoice type.
592
-	 *
593
-	 * @since 1.0.19
594
-	 * @param  string $context View or edit context.
595
-	 * @return string
596
-	 */
597
-	public function get_type( $context = 'view' ) {
591
+     * Get the invoice type.
592
+     *
593
+     * @since 1.0.19
594
+     * @param  string $context View or edit context.
595
+     * @return string
596
+     */
597
+    public function get_type( $context = 'view' ) {
598 598
         return $this->get_prop( 'type', $context );
599
-	}
599
+    }
600 600
 
601
-	/**
602
-	 * @deprecated
603
-	 */
604
-	public function get_invoice_quote_type() {
601
+    /**
602
+     * @deprecated
603
+     */
604
+    public function get_invoice_quote_type() {
605 605
         ucfirst( $this->get_type() );
606 606
     }
607 607
 
608 608
     /**
609
-	 * Get the invoice post type.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @param  string $context View or edit context.
613
-	 * @return string
614
-	 */
615
-	public function get_post_type( $context = 'view' ) {
609
+     * Get the invoice post type.
610
+     *
611
+     * @since 1.0.19
612
+     * @param  string $context View or edit context.
613
+     * @return string
614
+     */
615
+    public function get_post_type( $context = 'view' ) {
616 616
         return $this->get_prop( 'post_type', $context );
617 617
     }
618 618
 
619 619
     /**
620
-	 * Get the invoice mode.
621
-	 *
622
-	 * @since 1.0.19
623
-	 * @param  string $context View or edit context.
624
-	 * @return string
625
-	 */
626
-	public function get_mode( $context = 'view' ) {
620
+     * Get the invoice mode.
621
+     *
622
+     * @since 1.0.19
623
+     * @param  string $context View or edit context.
624
+     * @return string
625
+     */
626
+    public function get_mode( $context = 'view' ) {
627 627
         return $this->get_prop( 'mode', $context );
628 628
     }
629 629
 
630 630
     /**
631
-	 * Get the invoice path.
632
-	 *
633
-	 * @since 1.0.19
634
-	 * @param  string $context View or edit context.
635
-	 * @return string
636
-	 */
637
-	public function get_path( $context = 'view' ) {
631
+     * Get the invoice path.
632
+     *
633
+     * @since 1.0.19
634
+     * @param  string $context View or edit context.
635
+     * @return string
636
+     */
637
+    public function get_path( $context = 'view' ) {
638 638
         $path   = $this->get_prop( 'path', $context );
639
-		$prefix = wpinv_post_name_prefix( $this->get_post_type() );
639
+        $prefix = wpinv_post_name_prefix( $this->get_post_type() );
640 640
 
641
-		if ( 0 !== strpos( $path, $prefix ) ) {
642
-			$path = sanitize_title(  $prefix . $this->get_id()  );
643
-			$this->set_path( $path );
644
-		}
641
+        if ( 0 !== strpos( $path, $prefix ) ) {
642
+            $path = sanitize_title(  $prefix . $this->get_id()  );
643
+            $this->set_path( $path );
644
+        }
645 645
 
646
-		return $path;
646
+        return $path;
647 647
     }
648 648
 
649 649
     /**
650
-	 * Get the invoice name/title.
651
-	 *
652
-	 * @since 1.0.19
653
-	 * @param  string $context View or edit context.
654
-	 * @return string
655
-	 */
656
-	public function get_name( $context = 'view' ) {
650
+     * Get the invoice name/title.
651
+     *
652
+     * @since 1.0.19
653
+     * @param  string $context View or edit context.
654
+     * @return string
655
+     */
656
+    public function get_name( $context = 'view' ) {
657 657
         return $this->get_prop( 'title', $context );
658 658
     }
659 659
 
660 660
     /**
661
-	 * Alias of self::get_name().
662
-	 *
663
-	 * @since 1.0.19
664
-	 * @param  string $context View or edit context.
665
-	 * @return string
666
-	 */
667
-	public function get_title( $context = 'view' ) {
668
-		return $this->get_name( $context );
661
+     * Alias of self::get_name().
662
+     *
663
+     * @since 1.0.19
664
+     * @param  string $context View or edit context.
665
+     * @return string
666
+     */
667
+    public function get_title( $context = 'view' ) {
668
+        return $this->get_name( $context );
669 669
     }
670 670
 
671 671
     /**
672
-	 * Get the invoice description.
673
-	 *
674
-	 * @since 1.0.19
675
-	 * @param  string $context View or edit context.
676
-	 * @return string
677
-	 */
678
-	public function get_description( $context = 'view' ) {
679
-		return $this->get_prop( 'description', $context );
672
+     * Get the invoice description.
673
+     *
674
+     * @since 1.0.19
675
+     * @param  string $context View or edit context.
676
+     * @return string
677
+     */
678
+    public function get_description( $context = 'view' ) {
679
+        return $this->get_prop( 'description', $context );
680 680
     }
681 681
 
682 682
     /**
683
-	 * Alias of self::get_description().
684
-	 *
685
-	 * @since 1.0.19
686
-	 * @param  string $context View or edit context.
687
-	 * @return string
688
-	 */
689
-	public function get_excerpt( $context = 'view' ) {
690
-		return $this->get_description( $context );
683
+     * Alias of self::get_description().
684
+     *
685
+     * @since 1.0.19
686
+     * @param  string $context View or edit context.
687
+     * @return string
688
+     */
689
+    public function get_excerpt( $context = 'view' ) {
690
+        return $this->get_description( $context );
691 691
     }
692 692
 
693 693
     /**
694
-	 * Alias of self::get_description().
695
-	 *
696
-	 * @since 1.0.19
697
-	 * @param  string $context View or edit context.
698
-	 * @return string
699
-	 */
700
-	public function get_summary( $context = 'view' ) {
701
-		return $this->get_description( $context );
694
+     * Alias of self::get_description().
695
+     *
696
+     * @since 1.0.19
697
+     * @param  string $context View or edit context.
698
+     * @return string
699
+     */
700
+    public function get_summary( $context = 'view' ) {
701
+        return $this->get_description( $context );
702 702
     }
703 703
 
704 704
     /**
705
-	 * Returns the user info.
706
-	 *
707
-	 * @since 1.0.19
705
+     * Returns the user info.
706
+     *
707
+     * @since 1.0.19
708 708
      * @param  string $context View or edit context.
709
-	 * @return array
710
-	 */
709
+     * @return array
710
+     */
711 711
     public function get_user_info( $context = 'view' ) {
712 712
 
713 713
         $user_info = array(
@@ -724,605 +724,605 @@  discard block
 block discarded – undo
724 724
             'company'    => $this->get_company( $context ),
725 725
             'vat_number' => $this->get_vat_number( $context ),
726 726
             'discount'   => $this->get_discount_code( $context ),
727
-		);
727
+        );
728
+
729
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
730
+
731
+    }
732
+
733
+    /**
734
+     * Get the customer id.
735
+     *
736
+     * @since 1.0.19
737
+     * @param  string $context View or edit context.
738
+     * @return int
739
+     */
740
+    public function get_author( $context = 'view' ) {
741
+        return (int) $this->get_prop( 'author', $context );
742
+    }
728 743
 
729
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
744
+    /**
745
+     * Alias of self::get_author().
746
+     *
747
+     * @since 1.0.19
748
+     * @param  string $context View or edit context.
749
+     * @return int
750
+     */
751
+    public function get_user_id( $context = 'view' ) {
752
+        return $this->get_author( $context );
753
+    }
730 754
 
755
+        /**
756
+         * Alias of self::get_author().
757
+         *
758
+         * @since 1.0.19
759
+         * @param  string $context View or edit context.
760
+         * @return int
761
+         */
762
+    public function get_customer_id( $context = 'view' ) {
763
+        return $this->get_author( $context );
731 764
     }
732 765
 
733 766
     /**
734
-	 * Get the customer id.
735
-	 *
736
-	 * @since 1.0.19
737
-	 * @param  string $context View or edit context.
738
-	 * @return int
739
-	 */
740
-	public function get_author( $context = 'view' ) {
741
-		return (int) $this->get_prop( 'author', $context );
767
+     * Get the customer's ip.
768
+     *
769
+     * @since 1.0.19
770
+     * @param  string $context View or edit context.
771
+     * @return string
772
+     */
773
+    public function get_ip( $context = 'view' ) {
774
+        return $this->get_prop( 'user_ip', $context );
742 775
     }
743 776
 
744 777
     /**
745
-	 * Alias of self::get_author().
746
-	 *
747
-	 * @since 1.0.19
748
-	 * @param  string $context View or edit context.
749
-	 * @return int
750
-	 */
751
-	public function get_user_id( $context = 'view' ) {
752
-		return $this->get_author( $context );
778
+     * Alias of self::get_ip().
779
+     *
780
+     * @since 1.0.19
781
+     * @param  string $context View or edit context.
782
+     * @return string
783
+     */
784
+    public function get_user_ip( $context = 'view' ) {
785
+        return $this->get_ip( $context );
753 786
     }
754 787
 
755
-     /**
756
-	 * Alias of self::get_author().
757
-	 *
758
-	 * @since 1.0.19
759
-	 * @param  string $context View or edit context.
760
-	 * @return int
761
-	 */
762
-	public function get_customer_id( $context = 'view' ) {
763
-		return $this->get_author( $context );
788
+        /**
789
+         * Alias of self::get_ip().
790
+         *
791
+         * @since 1.0.19
792
+         * @param  string $context View or edit context.
793
+         * @return string
794
+         */
795
+    public function get_customer_ip( $context = 'view' ) {
796
+        return $this->get_ip( $context );
764 797
     }
765 798
 
766 799
     /**
767
-	 * Get the customer's ip.
768
-	 *
769
-	 * @since 1.0.19
770
-	 * @param  string $context View or edit context.
771
-	 * @return string
772
-	 */
773
-	public function get_ip( $context = 'view' ) {
774
-		return $this->get_prop( 'user_ip', $context );
800
+     * Get the customer's first name.
801
+     *
802
+     * @since 1.0.19
803
+     * @param  string $context View or edit context.
804
+     * @return string
805
+     */
806
+    public function get_first_name( $context = 'view' ) {
807
+        return $this->get_prop( 'first_name', $context );
775 808
     }
776 809
 
777 810
     /**
778
-	 * Alias of self::get_ip().
779
-	 *
780
-	 * @since 1.0.19
781
-	 * @param  string $context View or edit context.
782
-	 * @return string
783
-	 */
784
-	public function get_user_ip( $context = 'view' ) {
785
-		return $this->get_ip( $context );
811
+     * Alias of self::get_first_name().
812
+     *
813
+     * @since 1.0.19
814
+     * @param  string $context View or edit context.
815
+     * @return int
816
+     */
817
+    public function get_user_first_name( $context = 'view' ) {
818
+        return $this->get_first_name( $context );
786 819
     }
787 820
 
788
-     /**
789
-	 * Alias of self::get_ip().
790
-	 *
791
-	 * @since 1.0.19
792
-	 * @param  string $context View or edit context.
793
-	 * @return string
794
-	 */
795
-	public function get_customer_ip( $context = 'view' ) {
796
-		return $this->get_ip( $context );
821
+        /**
822
+         * Alias of self::get_first_name().
823
+         *
824
+         * @since 1.0.19
825
+         * @param  string $context View or edit context.
826
+         * @return int
827
+         */
828
+    public function get_customer_first_name( $context = 'view' ) {
829
+        return $this->get_first_name( $context );
797 830
     }
798 831
 
799 832
     /**
800
-	 * Get the customer's first name.
801
-	 *
802
-	 * @since 1.0.19
803
-	 * @param  string $context View or edit context.
804
-	 * @return string
805
-	 */
806
-	public function get_first_name( $context = 'view' ) {
807
-		return $this->get_prop( 'first_name', $context );
833
+     * Get the customer's last name.
834
+     *
835
+     * @since 1.0.19
836
+     * @param  string $context View or edit context.
837
+     * @return string
838
+     */
839
+    public function get_last_name( $context = 'view' ) {
840
+        return $this->get_prop( 'last_name', $context );
808 841
     }
809 842
 
810 843
     /**
811
-	 * Alias of self::get_first_name().
812
-	 *
813
-	 * @since 1.0.19
814
-	 * @param  string $context View or edit context.
815
-	 * @return int
816
-	 */
817
-	public function get_user_first_name( $context = 'view' ) {
818
-		return $this->get_first_name( $context );
844
+     * Alias of self::get_last_name().
845
+     *
846
+     * @since 1.0.19
847
+     * @param  string $context View or edit context.
848
+     * @return int
849
+     */
850
+    public function get_user_last_name( $context = 'view' ) {
851
+        return $this->get_last_name( $context );
819 852
     }
820 853
 
821
-     /**
822
-	 * Alias of self::get_first_name().
823
-	 *
824
-	 * @since 1.0.19
825
-	 * @param  string $context View or edit context.
826
-	 * @return int
827
-	 */
828
-	public function get_customer_first_name( $context = 'view' ) {
829
-		return $this->get_first_name( $context );
854
+    /**
855
+     * Alias of self::get_last_name().
856
+     *
857
+     * @since 1.0.19
858
+     * @param  string $context View or edit context.
859
+     * @return int
860
+     */
861
+    public function get_customer_last_name( $context = 'view' ) {
862
+        return $this->get_last_name( $context );
830 863
     }
831 864
 
832 865
     /**
833
-	 * Get the customer's last name.
834
-	 *
835
-	 * @since 1.0.19
836
-	 * @param  string $context View or edit context.
837
-	 * @return string
838
-	 */
839
-	public function get_last_name( $context = 'view' ) {
840
-		return $this->get_prop( 'last_name', $context );
866
+     * Get the customer's full name.
867
+     *
868
+     * @since 1.0.19
869
+     * @param  string $context View or edit context.
870
+     * @return string
871
+     */
872
+    public function get_full_name( $context = 'view' ) {
873
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
841 874
     }
842 875
 
843 876
     /**
844
-	 * Alias of self::get_last_name().
845
-	 *
846
-	 * @since 1.0.19
847
-	 * @param  string $context View or edit context.
848
-	 * @return int
849
-	 */
850
-	public function get_user_last_name( $context = 'view' ) {
851
-		return $this->get_last_name( $context );
877
+     * Alias of self::get_full_name().
878
+     *
879
+     * @since 1.0.19
880
+     * @param  string $context View or edit context.
881
+     * @return int
882
+     */
883
+    public function get_user_full_name( $context = 'view' ) {
884
+        return $this->get_full_name( $context );
852 885
     }
853 886
 
854 887
     /**
855
-	 * Alias of self::get_last_name().
856
-	 *
857
-	 * @since 1.0.19
858
-	 * @param  string $context View or edit context.
859
-	 * @return int
860
-	 */
861
-	public function get_customer_last_name( $context = 'view' ) {
862
-		return $this->get_last_name( $context );
888
+     * Alias of self::get_full_name().
889
+     *
890
+     * @since 1.0.19
891
+     * @param  string $context View or edit context.
892
+     * @return int
893
+     */
894
+    public function get_customer_full_name( $context = 'view' ) {
895
+        return $this->get_full_name( $context );
863 896
     }
864 897
 
865 898
     /**
866
-	 * Get the customer's full name.
867
-	 *
868
-	 * @since 1.0.19
869
-	 * @param  string $context View or edit context.
870
-	 * @return string
871
-	 */
872
-	public function get_full_name( $context = 'view' ) {
873
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
899
+     * Get the customer's phone number.
900
+     *
901
+     * @since 1.0.19
902
+     * @param  string $context View or edit context.
903
+     * @return string
904
+     */
905
+    public function get_phone( $context = 'view' ) {
906
+        return $this->get_prop( 'phone', $context );
874 907
     }
875 908
 
876 909
     /**
877
-	 * Alias of self::get_full_name().
878
-	 *
879
-	 * @since 1.0.19
880
-	 * @param  string $context View or edit context.
881
-	 * @return int
882
-	 */
883
-	public function get_user_full_name( $context = 'view' ) {
884
-		return $this->get_full_name( $context );
910
+     * Alias of self::get_phone().
911
+     *
912
+     * @since 1.0.19
913
+     * @param  string $context View or edit context.
914
+     * @return int
915
+     */
916
+    public function get_phone_number( $context = 'view' ) {
917
+        return $this->get_phone( $context );
885 918
     }
886 919
 
887 920
     /**
888
-	 * Alias of self::get_full_name().
889
-	 *
890
-	 * @since 1.0.19
891
-	 * @param  string $context View or edit context.
892
-	 * @return int
893
-	 */
894
-	public function get_customer_full_name( $context = 'view' ) {
895
-		return $this->get_full_name( $context );
921
+     * Alias of self::get_phone().
922
+     *
923
+     * @since 1.0.19
924
+     * @param  string $context View or edit context.
925
+     * @return int
926
+     */
927
+    public function get_user_phone( $context = 'view' ) {
928
+        return $this->get_phone( $context );
896 929
     }
897 930
 
898 931
     /**
899
-	 * Get the customer's phone number.
900
-	 *
901
-	 * @since 1.0.19
902
-	 * @param  string $context View or edit context.
903
-	 * @return string
904
-	 */
905
-	public function get_phone( $context = 'view' ) {
906
-		return $this->get_prop( 'phone', $context );
932
+     * Alias of self::get_phone().
933
+     *
934
+     * @since 1.0.19
935
+     * @param  string $context View or edit context.
936
+     * @return int
937
+     */
938
+    public function get_customer_phone( $context = 'view' ) {
939
+        return $this->get_phone( $context );
907 940
     }
908 941
 
909 942
     /**
910
-	 * Alias of self::get_phone().
911
-	 *
912
-	 * @since 1.0.19
913
-	 * @param  string $context View or edit context.
914
-	 * @return int
915
-	 */
916
-	public function get_phone_number( $context = 'view' ) {
917
-		return $this->get_phone( $context );
943
+     * Get the customer's email address.
944
+     *
945
+     * @since 1.0.19
946
+     * @param  string $context View or edit context.
947
+     * @return string
948
+     */
949
+    public function get_email( $context = 'view' ) {
950
+        return $this->get_prop( 'email', $context );
918 951
     }
919 952
 
920 953
     /**
921
-	 * Alias of self::get_phone().
922
-	 *
923
-	 * @since 1.0.19
924
-	 * @param  string $context View or edit context.
925
-	 * @return int
926
-	 */
927
-	public function get_user_phone( $context = 'view' ) {
928
-		return $this->get_phone( $context );
954
+     * Alias of self::get_email().
955
+     *
956
+     * @since 1.0.19
957
+     * @param  string $context View or edit context.
958
+     * @return string
959
+     */
960
+    public function get_email_address( $context = 'view' ) {
961
+        return $this->get_email( $context );
929 962
     }
930 963
 
931 964
     /**
932
-	 * Alias of self::get_phone().
933
-	 *
934
-	 * @since 1.0.19
935
-	 * @param  string $context View or edit context.
936
-	 * @return int
937
-	 */
938
-	public function get_customer_phone( $context = 'view' ) {
939
-		return $this->get_phone( $context );
965
+     * Alias of self::get_email().
966
+     *
967
+     * @since 1.0.19
968
+     * @param  string $context View or edit context.
969
+     * @return int
970
+     */
971
+    public function get_user_email( $context = 'view' ) {
972
+        return $this->get_email( $context );
940 973
     }
941 974
 
942 975
     /**
943
-	 * Get the customer's email address.
944
-	 *
945
-	 * @since 1.0.19
946
-	 * @param  string $context View or edit context.
947
-	 * @return string
948
-	 */
949
-	public function get_email( $context = 'view' ) {
950
-		return $this->get_prop( 'email', $context );
976
+     * Alias of self::get_email().
977
+     *
978
+     * @since 1.0.19
979
+     * @param  string $context View or edit context.
980
+     * @return int
981
+     */
982
+    public function get_customer_email( $context = 'view' ) {
983
+        return $this->get_email( $context );
951 984
     }
952 985
 
953 986
     /**
954
-	 * Alias of self::get_email().
955
-	 *
956
-	 * @since 1.0.19
957
-	 * @param  string $context View or edit context.
958
-	 * @return string
959
-	 */
960
-	public function get_email_address( $context = 'view' ) {
961
-		return $this->get_email( $context );
987
+     * Get the customer's country.
988
+     *
989
+     * @since 1.0.19
990
+     * @param  string $context View or edit context.
991
+     * @return string
992
+     */
993
+    public function get_country( $context = 'view' ) {
994
+        $country = $this->get_prop( 'country', $context );
995
+        return empty( $country ) ? wpinv_get_default_country() : $country;
962 996
     }
963 997
 
964 998
     /**
965
-	 * Alias of self::get_email().
966
-	 *
967
-	 * @since 1.0.19
968
-	 * @param  string $context View or edit context.
969
-	 * @return int
970
-	 */
971
-	public function get_user_email( $context = 'view' ) {
972
-		return $this->get_email( $context );
999
+     * Alias of self::get_country().
1000
+     *
1001
+     * @since 1.0.19
1002
+     * @param  string $context View or edit context.
1003
+     * @return int
1004
+     */
1005
+    public function get_user_country( $context = 'view' ) {
1006
+        return $this->get_country( $context );
973 1007
     }
974 1008
 
975 1009
     /**
976
-	 * Alias of self::get_email().
977
-	 *
978
-	 * @since 1.0.19
979
-	 * @param  string $context View or edit context.
980
-	 * @return int
981
-	 */
982
-	public function get_customer_email( $context = 'view' ) {
983
-		return $this->get_email( $context );
1010
+     * Alias of self::get_country().
1011
+     *
1012
+     * @since 1.0.19
1013
+     * @param  string $context View or edit context.
1014
+     * @return int
1015
+     */
1016
+    public function get_customer_country( $context = 'view' ) {
1017
+        return $this->get_country( $context );
984 1018
     }
985 1019
 
986 1020
     /**
987
-	 * Get the customer's country.
988
-	 *
989
-	 * @since 1.0.19
990
-	 * @param  string $context View or edit context.
991
-	 * @return string
992
-	 */
993
-	public function get_country( $context = 'view' ) {
994
-		$country = $this->get_prop( 'country', $context );
995
-		return empty( $country ) ? wpinv_get_default_country() : $country;
1021
+     * Get the customer's state.
1022
+     *
1023
+     * @since 1.0.19
1024
+     * @param  string $context View or edit context.
1025
+     * @return string
1026
+     */
1027
+    public function get_state( $context = 'view' ) {
1028
+        $state = $this->get_prop( 'state', $context );
1029
+        return empty( $state ) ? wpinv_get_default_state() : $state;
996 1030
     }
997 1031
 
998 1032
     /**
999
-	 * Alias of self::get_country().
1000
-	 *
1001
-	 * @since 1.0.19
1002
-	 * @param  string $context View or edit context.
1003
-	 * @return int
1004
-	 */
1005
-	public function get_user_country( $context = 'view' ) {
1006
-		return $this->get_country( $context );
1033
+     * Alias of self::get_state().
1034
+     *
1035
+     * @since 1.0.19
1036
+     * @param  string $context View or edit context.
1037
+     * @return int
1038
+     */
1039
+    public function get_user_state( $context = 'view' ) {
1040
+        return $this->get_state( $context );
1007 1041
     }
1008 1042
 
1009 1043
     /**
1010
-	 * Alias of self::get_country().
1011
-	 *
1012
-	 * @since 1.0.19
1013
-	 * @param  string $context View or edit context.
1014
-	 * @return int
1015
-	 */
1016
-	public function get_customer_country( $context = 'view' ) {
1017
-		return $this->get_country( $context );
1044
+     * Alias of self::get_state().
1045
+     *
1046
+     * @since 1.0.19
1047
+     * @param  string $context View or edit context.
1048
+     * @return int
1049
+     */
1050
+    public function get_customer_state( $context = 'view' ) {
1051
+        return $this->get_state( $context );
1018 1052
     }
1019 1053
 
1020 1054
     /**
1021
-	 * Get the customer's state.
1022
-	 *
1023
-	 * @since 1.0.19
1024
-	 * @param  string $context View or edit context.
1025
-	 * @return string
1026
-	 */
1027
-	public function get_state( $context = 'view' ) {
1028
-		$state = $this->get_prop( 'state', $context );
1029
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1055
+     * Get the customer's city.
1056
+     *
1057
+     * @since 1.0.19
1058
+     * @param  string $context View or edit context.
1059
+     * @return string
1060
+     */
1061
+    public function get_city( $context = 'view' ) {
1062
+        return $this->get_prop( 'city', $context );
1030 1063
     }
1031 1064
 
1032 1065
     /**
1033
-	 * Alias of self::get_state().
1034
-	 *
1035
-	 * @since 1.0.19
1036
-	 * @param  string $context View or edit context.
1037
-	 * @return int
1038
-	 */
1039
-	public function get_user_state( $context = 'view' ) {
1040
-		return $this->get_state( $context );
1066
+     * Alias of self::get_city().
1067
+     *
1068
+     * @since 1.0.19
1069
+     * @param  string $context View or edit context.
1070
+     * @return string
1071
+     */
1072
+    public function get_user_city( $context = 'view' ) {
1073
+        return $this->get_city( $context );
1041 1074
     }
1042 1075
 
1043 1076
     /**
1044
-	 * Alias of self::get_state().
1045
-	 *
1046
-	 * @since 1.0.19
1047
-	 * @param  string $context View or edit context.
1048
-	 * @return int
1049
-	 */
1050
-	public function get_customer_state( $context = 'view' ) {
1051
-		return $this->get_state( $context );
1077
+     * Alias of self::get_city().
1078
+     *
1079
+     * @since 1.0.19
1080
+     * @param  string $context View or edit context.
1081
+     * @return string
1082
+     */
1083
+    public function get_customer_city( $context = 'view' ) {
1084
+        return $this->get_city( $context );
1085
+    }
1086
+
1087
+    /**
1088
+     * Get the customer's zip.
1089
+     *
1090
+     * @since 1.0.19
1091
+     * @param  string $context View or edit context.
1092
+     * @return string
1093
+     */
1094
+    public function get_zip( $context = 'view' ) {
1095
+        return $this->get_prop( 'zip', $context );
1096
+    }
1097
+
1098
+    /**
1099
+     * Alias of self::get_zip().
1100
+     *
1101
+     * @since 1.0.19
1102
+     * @param  string $context View or edit context.
1103
+     * @return string
1104
+     */
1105
+    public function get_user_zip( $context = 'view' ) {
1106
+        return $this->get_zip( $context );
1107
+    }
1108
+
1109
+    /**
1110
+     * Alias of self::get_zip().
1111
+     *
1112
+     * @since 1.0.19
1113
+     * @param  string $context View or edit context.
1114
+     * @return string
1115
+     */
1116
+    public function get_customer_zip( $context = 'view' ) {
1117
+        return $this->get_zip( $context );
1052 1118
     }
1053 1119
 
1054 1120
     /**
1055
-	 * Get the customer's city.
1056
-	 *
1057
-	 * @since 1.0.19
1058
-	 * @param  string $context View or edit context.
1059
-	 * @return string
1060
-	 */
1061
-	public function get_city( $context = 'view' ) {
1062
-		return $this->get_prop( 'city', $context );
1121
+     * Get the customer's company.
1122
+     *
1123
+     * @since 1.0.19
1124
+     * @param  string $context View or edit context.
1125
+     * @return string
1126
+     */
1127
+    public function get_company( $context = 'view' ) {
1128
+        return $this->get_prop( 'company', $context );
1129
+    }
1130
+
1131
+    /**
1132
+     * Alias of self::get_company().
1133
+     *
1134
+     * @since 1.0.19
1135
+     * @param  string $context View or edit context.
1136
+     * @return string
1137
+     */
1138
+    public function get_user_company( $context = 'view' ) {
1139
+        return $this->get_company( $context );
1140
+    }
1141
+
1142
+    /**
1143
+     * Alias of self::get_company().
1144
+     *
1145
+     * @since 1.0.19
1146
+     * @param  string $context View or edit context.
1147
+     * @return string
1148
+     */
1149
+    public function get_customer_company( $context = 'view' ) {
1150
+        return $this->get_company( $context );
1151
+    }
1152
+
1153
+    /**
1154
+     * Get the customer's vat number.
1155
+     *
1156
+     * @since 1.0.19
1157
+     * @param  string $context View or edit context.
1158
+     * @return string
1159
+     */
1160
+    public function get_vat_number( $context = 'view' ) {
1161
+        return $this->get_prop( 'vat_number', $context );
1063 1162
     }
1064 1163
 
1065 1164
     /**
1066
-	 * Alias of self::get_city().
1067
-	 *
1068
-	 * @since 1.0.19
1069
-	 * @param  string $context View or edit context.
1070
-	 * @return string
1071
-	 */
1072
-	public function get_user_city( $context = 'view' ) {
1073
-		return $this->get_city( $context );
1165
+     * Alias of self::get_vat_number().
1166
+     *
1167
+     * @since 1.0.19
1168
+     * @param  string $context View or edit context.
1169
+     * @return string
1170
+     */
1171
+    public function get_user_vat_number( $context = 'view' ) {
1172
+        return $this->get_vat_number( $context );
1074 1173
     }
1075 1174
 
1076 1175
     /**
1077
-	 * Alias of self::get_city().
1078
-	 *
1079
-	 * @since 1.0.19
1080
-	 * @param  string $context View or edit context.
1081
-	 * @return string
1082
-	 */
1083
-	public function get_customer_city( $context = 'view' ) {
1084
-		return $this->get_city( $context );
1176
+     * Alias of self::get_vat_number().
1177
+     *
1178
+     * @since 1.0.19
1179
+     * @param  string $context View or edit context.
1180
+     * @return string
1181
+     */
1182
+    public function get_customer_vat_number( $context = 'view' ) {
1183
+        return $this->get_vat_number( $context );
1085 1184
     }
1086 1185
 
1087 1186
     /**
1088
-	 * Get the customer's zip.
1089
-	 *
1090
-	 * @since 1.0.19
1091
-	 * @param  string $context View or edit context.
1092
-	 * @return string
1093
-	 */
1094
-	public function get_zip( $context = 'view' ) {
1095
-		return $this->get_prop( 'zip', $context );
1187
+     * Get the customer's vat rate.
1188
+     *
1189
+     * @since 1.0.19
1190
+     * @param  string $context View or edit context.
1191
+     * @return string
1192
+     */
1193
+    public function get_vat_rate( $context = 'view' ) {
1194
+        return $this->get_prop( 'vat_rate', $context );
1096 1195
     }
1097 1196
 
1098 1197
     /**
1099
-	 * Alias of self::get_zip().
1100
-	 *
1101
-	 * @since 1.0.19
1102
-	 * @param  string $context View or edit context.
1103
-	 * @return string
1104
-	 */
1105
-	public function get_user_zip( $context = 'view' ) {
1106
-		return $this->get_zip( $context );
1198
+     * Alias of self::get_vat_rate().
1199
+     *
1200
+     * @since 1.0.19
1201
+     * @param  string $context View or edit context.
1202
+     * @return string
1203
+     */
1204
+    public function get_user_vat_rate( $context = 'view' ) {
1205
+        return $this->get_vat_rate( $context );
1107 1206
     }
1108 1207
 
1109 1208
     /**
1110
-	 * Alias of self::get_zip().
1111
-	 *
1112
-	 * @since 1.0.19
1113
-	 * @param  string $context View or edit context.
1114
-	 * @return string
1115
-	 */
1116
-	public function get_customer_zip( $context = 'view' ) {
1117
-		return $this->get_zip( $context );
1209
+     * Alias of self::get_vat_rate().
1210
+     *
1211
+     * @since 1.0.19
1212
+     * @param  string $context View or edit context.
1213
+     * @return string
1214
+     */
1215
+    public function get_customer_vat_rate( $context = 'view' ) {
1216
+        return $this->get_vat_rate( $context );
1118 1217
     }
1119 1218
 
1120 1219
     /**
1121
-	 * Get the customer's company.
1122
-	 *
1123
-	 * @since 1.0.19
1124
-	 * @param  string $context View or edit context.
1125
-	 * @return string
1126
-	 */
1127
-	public function get_company( $context = 'view' ) {
1128
-		return $this->get_prop( 'company', $context );
1220
+     * Get the customer's address.
1221
+     *
1222
+     * @since 1.0.19
1223
+     * @param  string $context View or edit context.
1224
+     * @return string
1225
+     */
1226
+    public function get_address( $context = 'view' ) {
1227
+        return $this->get_prop( 'address', $context );
1129 1228
     }
1130 1229
 
1131 1230
     /**
1132
-	 * Alias of self::get_company().
1133
-	 *
1134
-	 * @since 1.0.19
1135
-	 * @param  string $context View or edit context.
1136
-	 * @return string
1137
-	 */
1138
-	public function get_user_company( $context = 'view' ) {
1139
-		return $this->get_company( $context );
1231
+     * Alias of self::get_address().
1232
+     *
1233
+     * @since 1.0.19
1234
+     * @param  string $context View or edit context.
1235
+     * @return string
1236
+     */
1237
+    public function get_user_address( $context = 'view' ) {
1238
+        return $this->get_address( $context );
1140 1239
     }
1141 1240
 
1142 1241
     /**
1143
-	 * Alias of self::get_company().
1144
-	 *
1145
-	 * @since 1.0.19
1146
-	 * @param  string $context View or edit context.
1147
-	 * @return string
1148
-	 */
1149
-	public function get_customer_company( $context = 'view' ) {
1150
-		return $this->get_company( $context );
1242
+     * Alias of self::get_address().
1243
+     *
1244
+     * @since 1.0.19
1245
+     * @param  string $context View or edit context.
1246
+     * @return string
1247
+     */
1248
+    public function get_customer_address( $context = 'view' ) {
1249
+        return $this->get_address( $context );
1151 1250
     }
1152 1251
 
1153 1252
     /**
1154
-	 * Get the customer's vat number.
1155
-	 *
1156
-	 * @since 1.0.19
1157
-	 * @param  string $context View or edit context.
1158
-	 * @return string
1159
-	 */
1160
-	public function get_vat_number( $context = 'view' ) {
1161
-		return $this->get_prop( 'vat_number', $context );
1253
+     * Get whether the customer has viewed the invoice or not.
1254
+     *
1255
+     * @since 1.0.19
1256
+     * @param  string $context View or edit context.
1257
+     * @return bool
1258
+     */
1259
+    public function get_is_viewed( $context = 'view' ) {
1260
+        return (bool) $this->get_prop( 'is_viewed', $context );
1162 1261
     }
1163 1262
 
1164 1263
     /**
1165
-	 * Alias of self::get_vat_number().
1166
-	 *
1167
-	 * @since 1.0.19
1168
-	 * @param  string $context View or edit context.
1169
-	 * @return string
1170
-	 */
1171
-	public function get_user_vat_number( $context = 'view' ) {
1172
-		return $this->get_vat_number( $context );
1264
+     * Get other recipients for invoice communications.
1265
+     *
1266
+     * @since 1.0.19
1267
+     * @param  string $context View or edit context.
1268
+     * @return bool
1269
+     */
1270
+    public function get_email_cc( $context = 'view' ) {
1271
+        return $this->get_prop( 'email_cc', $context );
1173 1272
     }
1174 1273
 
1175 1274
     /**
1176
-	 * Alias of self::get_vat_number().
1177
-	 *
1178
-	 * @since 1.0.19
1179
-	 * @param  string $context View or edit context.
1180
-	 * @return string
1181
-	 */
1182
-	public function get_customer_vat_number( $context = 'view' ) {
1183
-		return $this->get_vat_number( $context );
1275
+     * Get invoice template.
1276
+     *
1277
+     * @since 1.0.19
1278
+     * @param  string $context View or edit context.
1279
+     * @return bool
1280
+     */
1281
+    public function get_template( $context = 'view' ) {
1282
+        return $this->get_prop( 'template', $context );
1184 1283
     }
1185 1284
 
1186 1285
     /**
1187
-	 * Get the customer's vat rate.
1188
-	 *
1189
-	 * @since 1.0.19
1190
-	 * @param  string $context View or edit context.
1191
-	 * @return string
1192
-	 */
1193
-	public function get_vat_rate( $context = 'view' ) {
1194
-		return $this->get_prop( 'vat_rate', $context );
1286
+     * Get whether the customer has confirmed their address.
1287
+     *
1288
+     * @since 1.0.19
1289
+     * @param  string $context View or edit context.
1290
+     * @return bool
1291
+     */
1292
+    public function get_address_confirmed( $context = 'view' ) {
1293
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1195 1294
     }
1196 1295
 
1197 1296
     /**
1198
-	 * Alias of self::get_vat_rate().
1199
-	 *
1200
-	 * @since 1.0.19
1201
-	 * @param  string $context View or edit context.
1202
-	 * @return string
1203
-	 */
1204
-	public function get_user_vat_rate( $context = 'view' ) {
1205
-		return $this->get_vat_rate( $context );
1297
+     * Alias of self::get_address_confirmed().
1298
+     *
1299
+     * @since 1.0.19
1300
+     * @param  string $context View or edit context.
1301
+     * @return bool
1302
+     */
1303
+    public function get_user_address_confirmed( $context = 'view' ) {
1304
+        return $this->get_address_confirmed( $context );
1206 1305
     }
1207 1306
 
1208 1307
     /**
1209
-	 * Alias of self::get_vat_rate().
1210
-	 *
1211
-	 * @since 1.0.19
1212
-	 * @param  string $context View or edit context.
1213
-	 * @return string
1214
-	 */
1215
-	public function get_customer_vat_rate( $context = 'view' ) {
1216
-		return $this->get_vat_rate( $context );
1308
+     * Alias of self::get_address().
1309
+     *
1310
+     * @since 1.0.19
1311
+     * @param  string $context View or edit context.
1312
+     * @return bool
1313
+     */
1314
+    public function get_customer_address_confirmed( $context = 'view' ) {
1315
+        return $this->get_address_confirmed( $context );
1217 1316
     }
1218 1317
 
1219 1318
     /**
1220
-	 * Get the customer's address.
1221
-	 *
1222
-	 * @since 1.0.19
1223
-	 * @param  string $context View or edit context.
1224
-	 * @return string
1225
-	 */
1226
-	public function get_address( $context = 'view' ) {
1227
-		return $this->get_prop( 'address', $context );
1228
-    }
1229
-
1230
-    /**
1231
-	 * Alias of self::get_address().
1232
-	 *
1233
-	 * @since 1.0.19
1234
-	 * @param  string $context View or edit context.
1235
-	 * @return string
1236
-	 */
1237
-	public function get_user_address( $context = 'view' ) {
1238
-		return $this->get_address( $context );
1239
-    }
1240
-
1241
-    /**
1242
-	 * Alias of self::get_address().
1243
-	 *
1244
-	 * @since 1.0.19
1245
-	 * @param  string $context View or edit context.
1246
-	 * @return string
1247
-	 */
1248
-	public function get_customer_address( $context = 'view' ) {
1249
-		return $this->get_address( $context );
1250
-    }
1251
-
1252
-    /**
1253
-	 * Get whether the customer has viewed the invoice or not.
1254
-	 *
1255
-	 * @since 1.0.19
1256
-	 * @param  string $context View or edit context.
1257
-	 * @return bool
1258
-	 */
1259
-	public function get_is_viewed( $context = 'view' ) {
1260
-		return (bool) $this->get_prop( 'is_viewed', $context );
1261
-	}
1262
-
1263
-	/**
1264
-	 * Get other recipients for invoice communications.
1265
-	 *
1266
-	 * @since 1.0.19
1267
-	 * @param  string $context View or edit context.
1268
-	 * @return bool
1269
-	 */
1270
-	public function get_email_cc( $context = 'view' ) {
1271
-		return $this->get_prop( 'email_cc', $context );
1272
-	}
1273
-
1274
-	/**
1275
-	 * Get invoice template.
1276
-	 *
1277
-	 * @since 1.0.19
1278
-	 * @param  string $context View or edit context.
1279
-	 * @return bool
1280
-	 */
1281
-	public function get_template( $context = 'view' ) {
1282
-		return $this->get_prop( 'template', $context );
1283
-	}
1284
-
1285
-	/**
1286
-	 * Get whether the customer has confirmed their address.
1287
-	 *
1288
-	 * @since 1.0.19
1289
-	 * @param  string $context View or edit context.
1290
-	 * @return bool
1291
-	 */
1292
-	public function get_address_confirmed( $context = 'view' ) {
1293
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1294
-    }
1295
-
1296
-    /**
1297
-	 * Alias of self::get_address_confirmed().
1298
-	 *
1299
-	 * @since 1.0.19
1300
-	 * @param  string $context View or edit context.
1301
-	 * @return bool
1302
-	 */
1303
-	public function get_user_address_confirmed( $context = 'view' ) {
1304
-		return $this->get_address_confirmed( $context );
1305
-    }
1306
-
1307
-    /**
1308
-	 * Alias of self::get_address().
1309
-	 *
1310
-	 * @since 1.0.19
1311
-	 * @param  string $context View or edit context.
1312
-	 * @return bool
1313
-	 */
1314
-	public function get_customer_address_confirmed( $context = 'view' ) {
1315
-		return $this->get_address_confirmed( $context );
1316
-    }
1317
-
1318
-    /**
1319
-	 * Get the invoice subtotal.
1320
-	 *
1321
-	 * @since 1.0.19
1322
-	 * @param  string $context View or edit context.
1323
-	 * @return float
1324
-	 */
1325
-	public function get_subtotal( $context = 'view' ) {
1319
+     * Get the invoice subtotal.
1320
+     *
1321
+     * @since 1.0.19
1322
+     * @param  string $context View or edit context.
1323
+     * @return float
1324
+     */
1325
+    public function get_subtotal( $context = 'view' ) {
1326 1326
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1327 1327
 
1328 1328
         // Backwards compatibility.
@@ -1334,165 +1334,165 @@  discard block
 block discarded – undo
1334 1334
     }
1335 1335
 
1336 1336
     /**
1337
-	 * Get the invoice discount total.
1338
-	 *
1339
-	 * @since 1.0.19
1340
-	 * @param  string $context View or edit context.
1341
-	 * @return float
1342
-	 */
1343
-	public function get_total_discount( $context = 'view' ) {
1344
-		return (float) $this->get_prop( 'total_discount', $context );
1337
+     * Get the invoice discount total.
1338
+     *
1339
+     * @since 1.0.19
1340
+     * @param  string $context View or edit context.
1341
+     * @return float
1342
+     */
1343
+    public function get_total_discount( $context = 'view' ) {
1344
+        return (float) $this->get_prop( 'total_discount', $context );
1345 1345
     }
1346 1346
 
1347 1347
     /**
1348
-	 * Get the invoice tax total.
1349
-	 *
1350
-	 * @since 1.0.19
1351
-	 * @param  string $context View or edit context.
1352
-	 * @return float
1353
-	 */
1354
-	public function get_total_tax( $context = 'view' ) {
1355
-		return (float) $this->get_prop( 'total_tax', $context );
1356
-	}
1348
+     * Get the invoice tax total.
1349
+     *
1350
+     * @since 1.0.19
1351
+     * @param  string $context View or edit context.
1352
+     * @return float
1353
+     */
1354
+    public function get_total_tax( $context = 'view' ) {
1355
+        return (float) $this->get_prop( 'total_tax', $context );
1356
+    }
1357 1357
 
1358
-	/**
1359
-	 * @deprecated
1360
-	 */
1361
-	public function get_final_tax( $currency = false ) {
1362
-		$tax = $this->get_total_tax();
1358
+    /**
1359
+     * @deprecated
1360
+     */
1361
+    public function get_final_tax( $currency = false ) {
1362
+        $tax = $this->get_total_tax();
1363 1363
 
1364 1364
         if ( $currency ) {
1365
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1365
+            return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1366 1366
         }
1367 1367
 
1368 1368
         return $tax;
1369 1369
     }
1370 1370
 
1371 1371
     /**
1372
-	 * Get the invoice fees total.
1373
-	 *
1374
-	 * @since 1.0.19
1375
-	 * @param  string $context View or edit context.
1376
-	 * @return float
1377
-	 */
1378
-	public function get_total_fees( $context = 'view' ) {
1379
-		return (float) $this->get_prop( 'total_fees', $context );
1372
+     * Get the invoice fees total.
1373
+     *
1374
+     * @since 1.0.19
1375
+     * @param  string $context View or edit context.
1376
+     * @return float
1377
+     */
1378
+    public function get_total_fees( $context = 'view' ) {
1379
+        return (float) $this->get_prop( 'total_fees', $context );
1380 1380
     }
1381 1381
 
1382 1382
     /**
1383
-	 * Alias for self::get_total_fees().
1384
-	 *
1385
-	 * @since 1.0.19
1386
-	 * @param  string $context View or edit context.
1387
-	 * @return float
1388
-	 */
1389
-	public function get_fees_total( $context = 'view' ) {
1390
-		return $this->get_total_fees( $context );
1383
+     * Alias for self::get_total_fees().
1384
+     *
1385
+     * @since 1.0.19
1386
+     * @param  string $context View or edit context.
1387
+     * @return float
1388
+     */
1389
+    public function get_fees_total( $context = 'view' ) {
1390
+        return $this->get_total_fees( $context );
1391 1391
     }
1392 1392
 
1393 1393
     /**
1394
-	 * Get the invoice total.
1395
-	 *
1396
-	 * @since 1.0.19
1394
+     * Get the invoice total.
1395
+     *
1396
+     * @since 1.0.19
1397 1397
      * @return float
1398
-	 */
1399
-	public function get_total() {
1400
-		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1401
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1402
-	}
1398
+     */
1399
+    public function get_total() {
1400
+        $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1401
+        return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1402
+    }
1403 1403
 	
1404
-	/**
1405
-	 * Get the invoice totals.
1406
-	 *
1407
-	 * @since 1.0.19
1404
+    /**
1405
+     * Get the invoice totals.
1406
+     *
1407
+     * @since 1.0.19
1408 1408
      * @return float
1409
-	 */
1410
-	public function get_totals() {
1411
-		return $this->totals;
1409
+     */
1410
+    public function get_totals() {
1411
+        return $this->totals;
1412 1412
     }
1413 1413
 
1414 1414
     /**
1415
-	 * Get the initial invoice total.
1416
-	 *
1417
-	 * @since 1.0.19
1415
+     * Get the initial invoice total.
1416
+     *
1417
+     * @since 1.0.19
1418 1418
      * @param  string $context View or edit context.
1419 1419
      * @return float
1420
-	 */
1420
+     */
1421 1421
     public function get_initial_total() {
1422 1422
 
1423
-		if ( empty( $this->totals ) ) {
1424
-			$this->recalculate_total();
1425
-		}
1423
+        if ( empty( $this->totals ) ) {
1424
+            $this->recalculate_total();
1425
+        }
1426 1426
 
1427
-		$tax      = $this->totals['tax']['initial'];
1428
-		$fee      = $this->totals['fee']['initial'];
1429
-		$discount = $this->totals['discount']['initial'];
1430
-		$subtotal = $this->totals['subtotal']['initial'];
1431
-		$total    = $tax + $fee - $discount + $subtotal;
1427
+        $tax      = $this->totals['tax']['initial'];
1428
+        $fee      = $this->totals['fee']['initial'];
1429
+        $discount = $this->totals['discount']['initial'];
1430
+        $subtotal = $this->totals['subtotal']['initial'];
1431
+        $total    = $tax + $fee - $discount + $subtotal;
1432 1432
 
1433
-		if ( 0 > $total ) {
1434
-			$total = 0;
1435
-		}
1433
+        if ( 0 > $total ) {
1434
+            $total = 0;
1435
+        }
1436 1436
 
1437 1437
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1438
-	}
1438
+    }
1439 1439
 
1440
-	/**
1441
-	 * Get the recurring invoice total.
1442
-	 *
1443
-	 * @since 1.0.19
1440
+    /**
1441
+     * Get the recurring invoice total.
1442
+     *
1443
+     * @since 1.0.19
1444 1444
      * @param  string $context View or edit context.
1445 1445
      * @return float
1446
-	 */
1446
+     */
1447 1447
     public function get_recurring_total() {
1448 1448
 
1449
-		if ( empty( $this->totals ) ) {
1450
-			$this->recalculate_total();
1451
-		}
1449
+        if ( empty( $this->totals ) ) {
1450
+            $this->recalculate_total();
1451
+        }
1452 1452
 
1453
-		$tax      = $this->totals['tax']['recurring'];
1454
-		$fee      = $this->totals['fee']['recurring'];
1455
-		$discount = $this->totals['discount']['recurring'];
1456
-		$subtotal = $this->totals['subtotal']['recurring'];
1457
-		$total    = $tax + $fee - $discount + $subtotal;
1453
+        $tax      = $this->totals['tax']['recurring'];
1454
+        $fee      = $this->totals['fee']['recurring'];
1455
+        $discount = $this->totals['discount']['recurring'];
1456
+        $subtotal = $this->totals['subtotal']['recurring'];
1457
+        $total    = $tax + $fee - $discount + $subtotal;
1458 1458
 
1459
-		if ( 0 > $total ) {
1460
-			$total = 0;
1461
-		}
1459
+        if ( 0 > $total ) {
1460
+            $total = 0;
1461
+        }
1462 1462
 
1463 1463
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1464
-	}
1464
+    }
1465 1465
 
1466
-	/**
1467
-	 * Returns recurring payment details.
1468
-	 *
1469
-	 * @since 1.0.19
1466
+    /**
1467
+     * Returns recurring payment details.
1468
+     *
1469
+     * @since 1.0.19
1470 1470
      * @param  string $field Optionally provide a field to return.
1471
-	 * @param string $currency Whether to include the currency.
1471
+     * @param string $currency Whether to include the currency.
1472 1472
      * @return float
1473
-	 */
1473
+     */
1474 1474
     public function get_recurring_details( $field = '', $currency = false ) {
1475 1475
 
1476
-		// Maybe recalculate totals.
1477
-		if ( empty( $this->totals ) ) {
1478
-			$this->recalculate_total();
1479
-		}
1476
+        // Maybe recalculate totals.
1477
+        if ( empty( $this->totals ) ) {
1478
+            $this->recalculate_total();
1479
+        }
1480 1480
 
1481
-		// Prepare recurring totals.
1481
+        // Prepare recurring totals.
1482 1482
         $data = apply_filters(
1483
-			'wpinv_get_invoice_recurring_details',
1484
-			array(
1485
-				'cart_details' => $this->get_cart_details(),
1486
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1487
-				'discount'     => $this->totals['discount']['recurring'],
1488
-				'tax'          => $this->totals['tax']['recurring'],
1489
-				'fee'          => $this->totals['fee']['recurring'],
1490
-				'total'        => $this->get_recurring_total(),
1491
-			),
1492
-			$this,
1493
-			$field,
1494
-			$currency
1495
-		);
1483
+            'wpinv_get_invoice_recurring_details',
1484
+            array(
1485
+                'cart_details' => $this->get_cart_details(),
1486
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1487
+                'discount'     => $this->totals['discount']['recurring'],
1488
+                'tax'          => $this->totals['tax']['recurring'],
1489
+                'fee'          => $this->totals['fee']['recurring'],
1490
+                'total'        => $this->get_recurring_total(),
1491
+            ),
1492
+            $this,
1493
+            $field,
1494
+            $currency
1495
+        );
1496 1496
 
1497 1497
         if ( isset( $data[$field] ) ) {
1498 1498
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1502,156 +1502,156 @@  discard block
 block discarded – undo
1502 1502
     }
1503 1503
 
1504 1504
     /**
1505
-	 * Get the invoice fees.
1506
-	 *
1507
-	 * @since 1.0.19
1508
-	 * @param  string $context View or edit context.
1509
-	 * @return array
1510
-	 */
1511
-	public function get_fees( $context = 'view' ) {
1512
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1505
+     * Get the invoice fees.
1506
+     *
1507
+     * @since 1.0.19
1508
+     * @param  string $context View or edit context.
1509
+     * @return array
1510
+     */
1511
+    public function get_fees( $context = 'view' ) {
1512
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1513 1513
     }
1514 1514
 
1515 1515
     /**
1516
-	 * Get the invoice discounts.
1517
-	 *
1518
-	 * @since 1.0.19
1519
-	 * @param  string $context View or edit context.
1520
-	 * @return array
1521
-	 */
1522
-	public function get_discounts( $context = 'view' ) {
1523
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1516
+     * Get the invoice discounts.
1517
+     *
1518
+     * @since 1.0.19
1519
+     * @param  string $context View or edit context.
1520
+     * @return array
1521
+     */
1522
+    public function get_discounts( $context = 'view' ) {
1523
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1524 1524
     }
1525 1525
 
1526 1526
     /**
1527
-	 * Get the invoice taxes.
1528
-	 *
1529
-	 * @since 1.0.19
1530
-	 * @param  string $context View or edit context.
1531
-	 * @return array
1532
-	 */
1533
-	public function get_taxes( $context = 'view' ) {
1534
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1527
+     * Get the invoice taxes.
1528
+     *
1529
+     * @since 1.0.19
1530
+     * @param  string $context View or edit context.
1531
+     * @return array
1532
+     */
1533
+    public function get_taxes( $context = 'view' ) {
1534
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1535 1535
     }
1536 1536
 
1537 1537
     /**
1538
-	 * Get the invoice items.
1539
-	 *
1540
-	 * @since 1.0.19
1541
-	 * @param  string $context View or edit context.
1542
-	 * @return GetPaid_Form_Item[]
1543
-	 */
1544
-	public function get_items( $context = 'view' ) {
1538
+     * Get the invoice items.
1539
+     *
1540
+     * @since 1.0.19
1541
+     * @param  string $context View or edit context.
1542
+     * @return GetPaid_Form_Item[]
1543
+     */
1544
+    public function get_items( $context = 'view' ) {
1545 1545
         return $this->get_prop( 'items', $context );
1546 1546
     }
1547 1547
 
1548 1548
     /**
1549
-	 * Get the invoice's payment form.
1550
-	 *
1551
-	 * @since 1.0.19
1552
-	 * @param  string $context View or edit context.
1553
-	 * @return int
1554
-	 */
1555
-	public function get_payment_form( $context = 'view' ) {
1556
-		return intval( $this->get_prop( 'payment_form', $context ) );
1549
+     * Get the invoice's payment form.
1550
+     *
1551
+     * @since 1.0.19
1552
+     * @param  string $context View or edit context.
1553
+     * @return int
1554
+     */
1555
+    public function get_payment_form( $context = 'view' ) {
1556
+        return intval( $this->get_prop( 'payment_form', $context ) );
1557 1557
     }
1558 1558
 
1559 1559
     /**
1560
-	 * Get the invoice's submission id.
1561
-	 *
1562
-	 * @since 1.0.19
1563
-	 * @param  string $context View or edit context.
1564
-	 * @return string
1565
-	 */
1566
-	public function get_submission_id( $context = 'view' ) {
1567
-		return $this->get_prop( 'submission_id', $context );
1560
+     * Get the invoice's submission id.
1561
+     *
1562
+     * @since 1.0.19
1563
+     * @param  string $context View or edit context.
1564
+     * @return string
1565
+     */
1566
+    public function get_submission_id( $context = 'view' ) {
1567
+        return $this->get_prop( 'submission_id', $context );
1568 1568
     }
1569 1569
 
1570 1570
     /**
1571
-	 * Get the invoice's discount code.
1572
-	 *
1573
-	 * @since 1.0.19
1574
-	 * @param  string $context View or edit context.
1575
-	 * @return string
1576
-	 */
1577
-	public function get_discount_code( $context = 'view' ) {
1578
-		return $this->get_prop( 'discount_code', $context );
1571
+     * Get the invoice's discount code.
1572
+     *
1573
+     * @since 1.0.19
1574
+     * @param  string $context View or edit context.
1575
+     * @return string
1576
+     */
1577
+    public function get_discount_code( $context = 'view' ) {
1578
+        return $this->get_prop( 'discount_code', $context );
1579 1579
     }
1580 1580
 
1581 1581
     /**
1582
-	 * Get the invoice's gateway.
1583
-	 *
1584
-	 * @since 1.0.19
1585
-	 * @param  string $context View or edit context.
1586
-	 * @return string
1587
-	 */
1588
-	public function get_gateway( $context = 'view' ) {
1589
-		return $this->get_prop( 'gateway', $context );
1582
+     * Get the invoice's gateway.
1583
+     *
1584
+     * @since 1.0.19
1585
+     * @param  string $context View or edit context.
1586
+     * @return string
1587
+     */
1588
+    public function get_gateway( $context = 'view' ) {
1589
+        return $this->get_prop( 'gateway', $context );
1590 1590
     }
1591 1591
 
1592 1592
     /**
1593
-	 * Get the invoice's gateway display title.
1594
-	 *
1595
-	 * @since 1.0.19
1596
-	 * @return string
1597
-	 */
1593
+     * Get the invoice's gateway display title.
1594
+     *
1595
+     * @since 1.0.19
1596
+     * @return string
1597
+     */
1598 1598
     public function get_gateway_title() {
1599 1599
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1600 1600
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1601 1601
     }
1602 1602
 
1603 1603
     /**
1604
-	 * Get the invoice's transaction id.
1605
-	 *
1606
-	 * @since 1.0.19
1607
-	 * @param  string $context View or edit context.
1608
-	 * @return string
1609
-	 */
1610
-	public function get_transaction_id( $context = 'view' ) {
1611
-		return $this->get_prop( 'transaction_id', $context );
1604
+     * Get the invoice's transaction id.
1605
+     *
1606
+     * @since 1.0.19
1607
+     * @param  string $context View or edit context.
1608
+     * @return string
1609
+     */
1610
+    public function get_transaction_id( $context = 'view' ) {
1611
+        return $this->get_prop( 'transaction_id', $context );
1612 1612
     }
1613 1613
 
1614 1614
     /**
1615
-	 * Get the invoice's currency.
1616
-	 *
1617
-	 * @since 1.0.19
1618
-	 * @param  string $context View or edit context.
1619
-	 * @return string
1620
-	 */
1621
-	public function get_currency( $context = 'view' ) {
1615
+     * Get the invoice's currency.
1616
+     *
1617
+     * @since 1.0.19
1618
+     * @param  string $context View or edit context.
1619
+     * @return string
1620
+     */
1621
+    public function get_currency( $context = 'view' ) {
1622 1622
         $currency = $this->get_prop( 'currency', $context );
1623 1623
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1624 1624
     }
1625 1625
 
1626 1626
     /**
1627
-	 * Checks if we are charging taxes for this invoice.
1628
-	 *
1629
-	 * @since 1.0.19
1630
-	 * @param  string $context View or edit context.
1631
-	 * @return bool
1632
-	 */
1633
-	public function get_disable_taxes( $context = 'view' ) {
1627
+     * Checks if we are charging taxes for this invoice.
1628
+     *
1629
+     * @since 1.0.19
1630
+     * @param  string $context View or edit context.
1631
+     * @return bool
1632
+     */
1633
+    public function get_disable_taxes( $context = 'view' ) {
1634 1634
         return (bool) $this->get_prop( 'disable_taxes', $context );
1635 1635
     }
1636 1636
 
1637 1637
     /**
1638
-	 * Retrieves the subscription id for an invoice.
1639
-	 *
1640
-	 * @since 1.0.19
1641
-	 * @param  string $context View or edit context.
1642
-	 * @return int
1643
-	 */
1638
+     * Retrieves the subscription id for an invoice.
1639
+     *
1640
+     * @since 1.0.19
1641
+     * @param  string $context View or edit context.
1642
+     * @return int
1643
+     */
1644 1644
     public function get_subscription_id( $context = 'view' ) {
1645
-		return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1646
-	}
1647
-
1648
-	/**
1649
-	 * Retrieves the remote subscription id for an invoice.
1650
-	 *
1651
-	 * @since 1.0.19
1652
-	 * @param  string $context View or edit context.
1653
-	 * @return int
1654
-	 */
1645
+        return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1646
+    }
1647
+
1648
+    /**
1649
+     * Retrieves the remote subscription id for an invoice.
1650
+     *
1651
+     * @since 1.0.19
1652
+     * @param  string $context View or edit context.
1653
+     * @return int
1654
+     */
1655 1655
     public function get_remote_subscription_id( $context = 'view' ) {
1656 1656
         $subscription_id = $this->get_prop( 'remote_subscription_id', $context );
1657 1657
 
@@ -1664,12 +1664,12 @@  discard block
 block discarded – undo
1664 1664
     }
1665 1665
 
1666 1666
     /**
1667
-	 * Retrieves the payment meta for an invoice.
1668
-	 *
1669
-	 * @since 1.0.19
1670
-	 * @param  string $context View or edit context.
1671
-	 * @return array
1672
-	 */
1667
+     * Retrieves the payment meta for an invoice.
1668
+     *
1669
+     * @since 1.0.19
1670
+     * @param  string $context View or edit context.
1671
+     * @return array
1672
+     */
1673 1673
     public function get_payment_meta( $context = 'view' ) {
1674 1674
 
1675 1675
         return array(
@@ -1689,31 +1689,31 @@  discard block
 block discarded – undo
1689 1689
     }
1690 1690
 
1691 1691
     /**
1692
-	 * Retrieves the cart details for an invoice.
1693
-	 *
1694
-	 * @since 1.0.19
1695
-	 * @return array
1696
-	 */
1692
+     * Retrieves the cart details for an invoice.
1693
+     *
1694
+     * @since 1.0.19
1695
+     * @return array
1696
+     */
1697 1697
     public function get_cart_details() {
1698 1698
         $items        = $this->get_items();
1699 1699
         $cart_details = array();
1700 1700
 
1701 1701
         foreach ( $items as $item_id => $item ) {
1702
-			$item->invoice_id = $this->get_id();
1702
+            $item->invoice_id = $this->get_id();
1703 1703
             $cart_details[]   = $item->prepare_data_for_saving();
1704 1704
         }
1705 1705
 
1706 1706
         return $cart_details;
1707
-	}
1707
+    }
1708 1708
 
1709
-	/**
1710
-	 * Retrieves the recurring item.
1711
-	 *
1712
-	 * @return null|GetPaid_Form_Item|int
1713
-	 */
1714
-	public function get_recurring( $object = false ) {
1709
+    /**
1710
+     * Retrieves the recurring item.
1711
+     *
1712
+     * @return null|GetPaid_Form_Item|int
1713
+     */
1714
+    public function get_recurring( $object = false ) {
1715 1715
 
1716
-		// Are we returning an object?
1716
+        // Are we returning an object?
1717 1717
         if ( $object ) {
1718 1718
             return $this->get_item( $this->recurring_item );
1719 1719
         }
@@ -1721,100 +1721,100 @@  discard block
 block discarded – undo
1721 1721
         return $this->recurring_item;
1722 1722
     }
1723 1723
 
1724
-	/**
1725
-	 * Retrieves the subscription name.
1726
-	 *
1727
-	 * @since 1.0.19
1728
-	 * @return string
1729
-	 */
1730
-	public function get_subscription_name() {
1724
+    /**
1725
+     * Retrieves the subscription name.
1726
+     *
1727
+     * @since 1.0.19
1728
+     * @return string
1729
+     */
1730
+    public function get_subscription_name() {
1731 1731
 
1732
-		// Retrieve the recurring name
1732
+        // Retrieve the recurring name
1733 1733
         $item = $this->get_recurring( true );
1734 1734
 
1735
-		// Abort if it does not exist.
1735
+        // Abort if it does not exist.
1736 1736
         if ( empty( $item ) ) {
1737 1737
             return '';
1738 1738
         }
1739 1739
 
1740
-		// Return the item name.
1740
+        // Return the item name.
1741 1741
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1742
-	}
1743
-
1744
-	/**
1745
-	 * Retrieves the view url.
1746
-	 *
1747
-	 * @since 1.0.19
1748
-	 * @return string
1749
-	 */
1750
-	public function get_view_url() {
1742
+    }
1743
+
1744
+    /**
1745
+     * Retrieves the view url.
1746
+     *
1747
+     * @since 1.0.19
1748
+     * @return string
1749
+     */
1750
+    public function get_view_url() {
1751 1751
         $invoice_url = get_permalink( $this->get_id() );
1752
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1752
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1753 1753
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1754
-	}
1754
+    }
1755 1755
 
1756
-	/**
1757
-	 * Retrieves the payment url.
1758
-	 *
1759
-	 * @since 1.0.19
1760
-	 * @return string
1761
-	 */
1762
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1756
+    /**
1757
+     * Retrieves the payment url.
1758
+     *
1759
+     * @since 1.0.19
1760
+     * @return string
1761
+     */
1762
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1763 1763
 
1764
-		// Retrieve the checkout url.
1764
+        // Retrieve the checkout url.
1765 1765
         $pay_url = wpinv_get_checkout_uri();
1766 1766
 
1767
-		// Maybe force ssl.
1767
+        // Maybe force ssl.
1768 1768
         if ( is_ssl() ) {
1769 1769
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1770 1770
         }
1771 1771
 
1772
-		// Add the invoice key.
1773
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1772
+        // Add the invoice key.
1773
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1774 1774
 
1775
-		// (Maybe?) add a secret
1775
+        // (Maybe?) add a secret
1776 1776
         if ( $secret ) {
1777 1777
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1778 1778
         }
1779 1779
 
1780 1780
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1781
-	}
1781
+    }
1782 1782
 	
1783
-	/**
1784
-	 * Retrieves the receipt url.
1785
-	 *
1786
-	 * @since 1.0.19
1787
-	 * @return string
1788
-	 */
1789
-	public function get_receipt_url() {
1790
-
1791
-		// Retrieve the checkout url.
1783
+    /**
1784
+     * Retrieves the receipt url.
1785
+     *
1786
+     * @since 1.0.19
1787
+     * @return string
1788
+     */
1789
+    public function get_receipt_url() {
1790
+
1791
+        // Retrieve the checkout url.
1792 1792
         $receipt_url = wpinv_get_success_page_uri();
1793 1793
 
1794
-		// Maybe force ssl.
1794
+        // Maybe force ssl.
1795 1795
         if ( is_ssl() ) {
1796 1796
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1797 1797
         }
1798 1798
 
1799
-		// Add the invoice key.
1800
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1799
+        // Add the invoice key.
1800
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1801 1801
 
1802 1802
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1803 1803
     }
1804 1804
 
1805 1805
     /**
1806
-	 * Magic method for accessing invoice properties.
1807
-	 *
1808
-	 * @since 1.0.15
1809
-	 * @access public
1810
-	 *
1811
-	 * @param string $key Discount data to retrieve
1812
-	 * @param  string $context View or edit context.
1813
-	 * @return mixed Value of the given invoice property (if set).
1814
-	 */
1815
-	public function get( $key, $context = 'view' ) {
1806
+     * Magic method for accessing invoice properties.
1807
+     *
1808
+     * @since 1.0.15
1809
+     * @access public
1810
+     *
1811
+     * @param string $key Discount data to retrieve
1812
+     * @param  string $context View or edit context.
1813
+     * @return mixed Value of the given invoice property (if set).
1814
+     */
1815
+    public function get( $key, $context = 'view' ) {
1816 1816
         return $this->get_prop( $key, $context );
1817
-	}
1817
+    }
1818 1818
 
1819 1819
     /*
1820 1820
 	|--------------------------------------------------------------------------
@@ -1827,130 +1827,130 @@  discard block
 block discarded – undo
1827 1827
     */
1828 1828
 
1829 1829
     /**
1830
-	 * Magic method for setting invoice properties.
1831
-	 *
1832
-	 * @since 1.0.19
1833
-	 * @access public
1834
-	 *
1835
-	 * @param string $key Discount data to retrieve
1836
-	 * @param  mixed $value new value.
1837
-	 * @return mixed Value of the given invoice property (if set).
1838
-	 */
1839
-	public function set( $key, $value ) {
1830
+     * Magic method for setting invoice properties.
1831
+     *
1832
+     * @since 1.0.19
1833
+     * @access public
1834
+     *
1835
+     * @param string $key Discount data to retrieve
1836
+     * @param  mixed $value new value.
1837
+     * @return mixed Value of the given invoice property (if set).
1838
+     */
1839
+    public function set( $key, $value ) {
1840 1840
 
1841 1841
         $setter = "set_$key";
1842 1842
         if ( is_callable( array( $this, $setter ) ) ) {
1843 1843
             $this->{$setter}( $value );
1844 1844
         }
1845 1845
 
1846
-	}
1846
+    }
1847 1847
 
1848
-	/**
1849
-	 * Sets item status.
1850
-	 *
1851
-	 * @since 1.0.19
1852
-	 * @param string $new_status    New status.
1853
-	 * @param string $note          Optional note to add.
1854
-	 * @param bool   $manual_update Is this a manual status change?.
1855
-	 * @return array details of change.
1856
-	 */
1857
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1858
-		$old_status = $this->get_status();
1848
+    /**
1849
+     * Sets item status.
1850
+     *
1851
+     * @since 1.0.19
1852
+     * @param string $new_status    New status.
1853
+     * @param string $note          Optional note to add.
1854
+     * @param bool   $manual_update Is this a manual status change?.
1855
+     * @return array details of change.
1856
+     */
1857
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1858
+        $old_status = $this->get_status();
1859 1859
 
1860
-		$statuses = $this->get_all_statuses();
1860
+        $statuses = $this->get_all_statuses();
1861 1861
 
1862
-		if ( isset( $statuses[ 'draft' ] ) ) {
1863
-			unset( $statuses[ 'draft' ] );
1864
-		}
1862
+        if ( isset( $statuses[ 'draft' ] ) ) {
1863
+            unset( $statuses[ 'draft' ] );
1864
+        }
1865 1865
 
1866
-		$this->set_prop( 'status', $new_status );
1866
+        $this->set_prop( 'status', $new_status );
1867 1867
 
1868
-		// If setting the status, ensure it's set to a valid status.
1869
-		if ( true === $this->object_read ) {
1868
+        // If setting the status, ensure it's set to a valid status.
1869
+        if ( true === $this->object_read ) {
1870 1870
 
1871
-			// Only allow valid new status.
1872
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1873
-				$new_status = 'wpi-pending';
1874
-			}
1871
+            // Only allow valid new status.
1872
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
1873
+                $new_status = 'wpi-pending';
1874
+            }
1875 1875
 
1876
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1877
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1878
-				$old_status = 'wpi-pending';
1879
-			}
1876
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1877
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1878
+                $old_status = 'wpi-pending';
1879
+            }
1880 1880
 
1881
-			// Paid - Renewal (i.e when duplicating a parent invoice )
1882
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1883
-				$old_status = 'wpi-pending';
1884
-			}
1881
+            // Paid - Renewal (i.e when duplicating a parent invoice )
1882
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1883
+                $old_status = 'wpi-pending';
1884
+            }
1885 1885
 
1886
-		}
1886
+        }
1887 1887
 
1888
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1889
-			$this->status_transition = array(
1890
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1891
-				'to'     => $new_status,
1892
-				'note'   => $note,
1893
-				'manual' => (bool) $manual_update,
1894
-			);
1888
+        if ( true === $this->object_read && $old_status !== $new_status ) {
1889
+            $this->status_transition = array(
1890
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1891
+                'to'     => $new_status,
1892
+                'note'   => $note,
1893
+                'manual' => (bool) $manual_update,
1894
+            );
1895 1895
 
1896
-			if ( $manual_update ) {
1897
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1898
-			}
1896
+            if ( $manual_update ) {
1897
+                do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1898
+            }
1899 1899
 
1900
-			$this->maybe_set_date_paid();
1900
+            $this->maybe_set_date_paid();
1901 1901
 
1902
-		}
1902
+        }
1903 1903
 
1904
-		return array(
1905
-			'from' => $old_status,
1906
-			'to'   => $new_status,
1907
-		);
1908
-	}
1904
+        return array(
1905
+            'from' => $old_status,
1906
+            'to'   => $new_status,
1907
+        );
1908
+    }
1909 1909
 
1910
-	/**
1911
-	 * Maybe set date paid.
1912
-	 *
1913
-	 * Sets the date paid variable when transitioning to the payment complete
1914
-	 * order status.
1915
-	 *
1916
-	 * @since 1.0.19
1917
-	 */
1918
-	public function maybe_set_date_paid() {
1910
+    /**
1911
+     * Maybe set date paid.
1912
+     *
1913
+     * Sets the date paid variable when transitioning to the payment complete
1914
+     * order status.
1915
+     *
1916
+     * @since 1.0.19
1917
+     */
1918
+    public function maybe_set_date_paid() {
1919 1919
 
1920
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1921
-			$this->set_date_completed( current_time( 'mysql' ) );
1922
-		}
1923
-	}
1920
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1921
+            $this->set_date_completed( current_time( 'mysql' ) );
1922
+        }
1923
+    }
1924 1924
 
1925 1925
     /**
1926
-	 * Set parent invoice ID.
1927
-	 *
1928
-	 * @since 1.0.19
1929
-	 */
1930
-	public function set_parent_id( $value ) {
1931
-		if ( $value && ( $value === $this->get_id() ) ) {
1932
-			return;
1933
-		}
1934
-		$this->set_prop( 'parent_id', absint( $value ) );
1926
+     * Set parent invoice ID.
1927
+     *
1928
+     * @since 1.0.19
1929
+     */
1930
+    public function set_parent_id( $value ) {
1931
+        if ( $value && ( $value === $this->get_id() ) ) {
1932
+            return;
1933
+        }
1934
+        $this->set_prop( 'parent_id', absint( $value ) );
1935 1935
     }
1936 1936
 
1937 1937
     /**
1938
-	 * Set plugin version when the invoice was created.
1939
-	 *
1940
-	 * @since 1.0.19
1941
-	 */
1942
-	public function set_version( $value ) {
1943
-		$this->set_prop( 'version', $value );
1938
+     * Set plugin version when the invoice was created.
1939
+     *
1940
+     * @since 1.0.19
1941
+     */
1942
+    public function set_version( $value ) {
1943
+        $this->set_prop( 'version', $value );
1944 1944
     }
1945
-
1946
-    /**
1947
-	 * Set date when the invoice was created.
1948
-	 *
1949
-	 * @since 1.0.19
1950
-	 * @param string $value Value to set.
1945
+
1946
+    /**
1947
+     * Set date when the invoice was created.
1948
+     *
1949
+     * @since 1.0.19
1950
+     * @param string $value Value to set.
1951 1951
      * @return bool Whether or not the date was set.
1952
-	 */
1953
-	public function set_date_created( $value ) {
1952
+     */
1953
+    public function set_date_created( $value ) {
1954 1954
         $date = strtotime( $value );
1955 1955
 
1956 1956
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1963,13 +1963,13 @@  discard block
 block discarded – undo
1963 1963
     }
1964 1964
 
1965 1965
     /**
1966
-	 * Set date invoice due date.
1967
-	 *
1968
-	 * @since 1.0.19
1969
-	 * @param string $value Value to set.
1966
+     * Set date invoice due date.
1967
+     *
1968
+     * @since 1.0.19
1969
+     * @param string $value Value to set.
1970 1970
      * @return bool Whether or not the date was set.
1971
-	 */
1972
-	public function set_due_date( $value ) {
1971
+     */
1972
+    public function set_due_date( $value ) {
1973 1973
         $date = strtotime( $value );
1974 1974
 
1975 1975
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1977,29 +1977,29 @@  discard block
 block discarded – undo
1977 1977
             return true;
1978 1978
         }
1979 1979
 
1980
-		$this->set_prop( 'due_date', '' );
1980
+        $this->set_prop( 'due_date', '' );
1981 1981
         return false;
1982 1982
 
1983 1983
     }
1984 1984
 
1985 1985
     /**
1986
-	 * Alias of self::set_due_date().
1987
-	 *
1988
-	 * @since 1.0.19
1989
-	 * @param  string $value New name.
1990
-	 */
1991
-	public function set_date_due( $value ) {
1992
-		$this->set_due_date( $value );
1986
+     * Alias of self::set_due_date().
1987
+     *
1988
+     * @since 1.0.19
1989
+     * @param  string $value New name.
1990
+     */
1991
+    public function set_date_due( $value ) {
1992
+        $this->set_due_date( $value );
1993 1993
     }
1994 1994
 
1995 1995
     /**
1996
-	 * Set date invoice was completed.
1997
-	 *
1998
-	 * @since 1.0.19
1999
-	 * @param string $value Value to set.
1996
+     * Set date invoice was completed.
1997
+     *
1998
+     * @since 1.0.19
1999
+     * @param string $value Value to set.
2000 2000
      * @return bool Whether or not the date was set.
2001
-	 */
2002
-	public function set_completed_date( $value ) {
2001
+     */
2002
+    public function set_completed_date( $value ) {
2003 2003
         $date = strtotime( $value );
2004 2004
 
2005 2005
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -2007,29 +2007,29 @@  discard block
 block discarded – undo
2007 2007
             return true;
2008 2008
         }
2009 2009
 
2010
-		$this->set_prop( 'completed_date', '' );
2010
+        $this->set_prop( 'completed_date', '' );
2011 2011
         return false;
2012 2012
 
2013 2013
     }
2014 2014
 
2015 2015
     /**
2016
-	 * Alias of self::set_completed_date().
2017
-	 *
2018
-	 * @since 1.0.19
2019
-	 * @param  string $value New name.
2020
-	 */
2021
-	public function set_date_completed( $value ) {
2022
-		$this->set_completed_date( $value );
2016
+     * Alias of self::set_completed_date().
2017
+     *
2018
+     * @since 1.0.19
2019
+     * @param  string $value New name.
2020
+     */
2021
+    public function set_date_completed( $value ) {
2022
+        $this->set_completed_date( $value );
2023 2023
     }
2024 2024
 
2025 2025
     /**
2026
-	 * Set date when the invoice was last modified.
2027
-	 *
2028
-	 * @since 1.0.19
2029
-	 * @param string $value Value to set.
2026
+     * Set date when the invoice was last modified.
2027
+     *
2028
+     * @since 1.0.19
2029
+     * @param string $value Value to set.
2030 2030
      * @return bool Whether or not the date was set.
2031
-	 */
2032
-	public function set_date_modified( $value ) {
2031
+     */
2032
+    public function set_date_modified( $value ) {
2033 2033
         $date = strtotime( $value );
2034 2034
 
2035 2035
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2037,706 +2037,706 @@  discard block
 block discarded – undo
2037 2037
             return true;
2038 2038
         }
2039 2039
 
2040
-		$this->set_prop( 'date_modified', '' );
2040
+        $this->set_prop( 'date_modified', '' );
2041 2041
         return false;
2042 2042
 
2043 2043
     }
2044 2044
 
2045 2045
     /**
2046
-	 * Set the invoice number.
2047
-	 *
2048
-	 * @since 1.0.19
2049
-	 * @param  string $value New number.
2050
-	 */
2051
-	public function set_number( $value ) {
2046
+     * Set the invoice number.
2047
+     *
2048
+     * @since 1.0.19
2049
+     * @param  string $value New number.
2050
+     */
2051
+    public function set_number( $value ) {
2052 2052
         $number = sanitize_text_field( $value );
2053
-		$this->set_prop( 'number', $number );
2053
+        $this->set_prop( 'number', $number );
2054 2054
     }
2055 2055
 
2056 2056
     /**
2057
-	 * Set the invoice type.
2058
-	 *
2059
-	 * @since 1.0.19
2060
-	 * @param  string $value Type.
2061
-	 */
2062
-	public function set_type( $value ) {
2057
+     * Set the invoice type.
2058
+     *
2059
+     * @since 1.0.19
2060
+     * @param  string $value Type.
2061
+     */
2062
+    public function set_type( $value ) {
2063 2063
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2064
-		$this->set_prop( 'type', $type );
2065
-	}
2064
+        $this->set_prop( 'type', $type );
2065
+    }
2066 2066
 
2067 2067
     /**
2068
-	 * Set the invoice post type.
2069
-	 *
2070
-	 * @since 1.0.19
2071
-	 * @param  string $value Post type.
2072
-	 */
2073
-	public function set_post_type( $value ) {
2068
+     * Set the invoice post type.
2069
+     *
2070
+     * @since 1.0.19
2071
+     * @param  string $value Post type.
2072
+     */
2073
+    public function set_post_type( $value ) {
2074 2074
         if ( getpaid_is_invoice_post_type( $value ) ) {
2075
-			$this->set_type( $value );
2075
+            $this->set_type( $value );
2076 2076
             $this->set_prop( 'post_type', $value );
2077 2077
         }
2078 2078
     }
2079 2079
 
2080 2080
     /**
2081
-	 * Set the invoice key.
2082
-	 *
2083
-	 * @since 1.0.19
2084
-	 * @param  string $value New key.
2085
-	 */
2086
-	public function set_key( $value ) {
2081
+     * Set the invoice key.
2082
+     *
2083
+     * @since 1.0.19
2084
+     * @param  string $value New key.
2085
+     */
2086
+    public function set_key( $value ) {
2087 2087
         $key = sanitize_text_field( $value );
2088
-		$this->set_prop( 'key', $key );
2088
+        $this->set_prop( 'key', $key );
2089 2089
     }
2090 2090
 
2091 2091
     /**
2092
-	 * Set the invoice mode.
2093
-	 *
2094
-	 * @since 1.0.19
2095
-	 * @param  string $value mode.
2096
-	 */
2097
-	public function set_mode( $value ) {
2092
+     * Set the invoice mode.
2093
+     *
2094
+     * @since 1.0.19
2095
+     * @param  string $value mode.
2096
+     */
2097
+    public function set_mode( $value ) {
2098 2098
         if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2099 2099
             $this->set_prop( 'value', $value );
2100 2100
         }
2101 2101
     }
2102 2102
 
2103 2103
     /**
2104
-	 * Set the invoice path.
2105
-	 *
2106
-	 * @since 1.0.19
2107
-	 * @param  string $value path.
2108
-	 */
2109
-	public function set_path( $value ) {
2104
+     * Set the invoice path.
2105
+     *
2106
+     * @since 1.0.19
2107
+     * @param  string $value path.
2108
+     */
2109
+    public function set_path( $value ) {
2110 2110
         $this->set_prop( 'path', $value );
2111 2111
     }
2112 2112
 
2113 2113
     /**
2114
-	 * Set the invoice name.
2115
-	 *
2116
-	 * @since 1.0.19
2117
-	 * @param  string $value New name.
2118
-	 */
2119
-	public function set_name( $value ) {
2114
+     * Set the invoice name.
2115
+     *
2116
+     * @since 1.0.19
2117
+     * @param  string $value New name.
2118
+     */
2119
+    public function set_name( $value ) {
2120 2120
         $name = sanitize_text_field( $value );
2121
-		$this->set_prop( 'name', $name );
2121
+        $this->set_prop( 'name', $name );
2122 2122
     }
2123 2123
 
2124 2124
     /**
2125
-	 * Alias of self::set_name().
2126
-	 *
2127
-	 * @since 1.0.19
2128
-	 * @param  string $value New name.
2129
-	 */
2130
-	public function set_title( $value ) {
2131
-		$this->set_name( $value );
2125
+     * Alias of self::set_name().
2126
+     *
2127
+     * @since 1.0.19
2128
+     * @param  string $value New name.
2129
+     */
2130
+    public function set_title( $value ) {
2131
+        $this->set_name( $value );
2132 2132
     }
2133 2133
 
2134 2134
     /**
2135
-	 * Set the invoice description.
2136
-	 *
2137
-	 * @since 1.0.19
2138
-	 * @param  string $value New description.
2139
-	 */
2140
-	public function set_description( $value ) {
2135
+     * Set the invoice description.
2136
+     *
2137
+     * @since 1.0.19
2138
+     * @param  string $value New description.
2139
+     */
2140
+    public function set_description( $value ) {
2141 2141
         $description = wp_kses_post( $value );
2142
-		return $this->set_prop( 'description', $description );
2142
+        return $this->set_prop( 'description', $description );
2143 2143
     }
2144 2144
 
2145 2145
     /**
2146
-	 * Alias of self::set_description().
2147
-	 *
2148
-	 * @since 1.0.19
2149
-	 * @param  string $value New description.
2150
-	 */
2151
-	public function set_excerpt( $value ) {
2152
-		$this->set_description( $value );
2146
+     * Alias of self::set_description().
2147
+     *
2148
+     * @since 1.0.19
2149
+     * @param  string $value New description.
2150
+     */
2151
+    public function set_excerpt( $value ) {
2152
+        $this->set_description( $value );
2153 2153
     }
2154 2154
 
2155 2155
     /**
2156
-	 * Alias of self::set_description().
2157
-	 *
2158
-	 * @since 1.0.19
2159
-	 * @param  string $value New description.
2160
-	 */
2161
-	public function set_summary( $value ) {
2162
-		$this->set_description( $value );
2156
+     * Alias of self::set_description().
2157
+     *
2158
+     * @since 1.0.19
2159
+     * @param  string $value New description.
2160
+     */
2161
+    public function set_summary( $value ) {
2162
+        $this->set_description( $value );
2163 2163
     }
2164 2164
 
2165 2165
     /**
2166
-	 * Set the receiver of the invoice.
2167
-	 *
2168
-	 * @since 1.0.19
2169
-	 * @param  int $value New author.
2170
-	 */
2171
-	public function set_author( $value ) {
2172
-		$user = get_user_by( 'id', (int) $value );
2166
+     * Set the receiver of the invoice.
2167
+     *
2168
+     * @since 1.0.19
2169
+     * @param  int $value New author.
2170
+     */
2171
+    public function set_author( $value ) {
2172
+        $user = get_user_by( 'id', (int) $value );
2173 2173
 
2174
-		if ( $user && $user->ID ) {
2175
-			$this->set_prop( 'author', $user->ID );
2176
-			$this->set_prop( 'email', $user->user_email );
2177
-		}
2174
+        if ( $user && $user->ID ) {
2175
+            $this->set_prop( 'author', $user->ID );
2176
+            $this->set_prop( 'email', $user->user_email );
2177
+        }
2178 2178
 		
2179 2179
     }
2180 2180
 
2181 2181
     /**
2182
-	 * Alias of self::set_author().
2183
-	 *
2184
-	 * @since 1.0.19
2185
-	 * @param  int $value New user id.
2186
-	 */
2187
-	public function set_user_id( $value ) {
2188
-		$this->set_author( $value );
2182
+     * Alias of self::set_author().
2183
+     *
2184
+     * @since 1.0.19
2185
+     * @param  int $value New user id.
2186
+     */
2187
+    public function set_user_id( $value ) {
2188
+        $this->set_author( $value );
2189
+    }
2190
+
2191
+    /**
2192
+     * Alias of self::set_author().
2193
+     *
2194
+     * @since 1.0.19
2195
+     * @param  int $value New user id.
2196
+     */
2197
+    public function set_customer_id( $value ) {
2198
+        $this->set_author( $value );
2199
+    }
2200
+
2201
+    /**
2202
+     * Set the customer's ip.
2203
+     *
2204
+     * @since 1.0.19
2205
+     * @param  string $value ip address.
2206
+     */
2207
+    public function set_ip( $value ) {
2208
+        $this->set_prop( 'ip', $value );
2209
+    }
2210
+
2211
+    /**
2212
+     * Alias of self::set_ip().
2213
+     *
2214
+     * @since 1.0.19
2215
+     * @param  string $value ip address.
2216
+     */
2217
+    public function set_user_ip( $value ) {
2218
+        $this->set_ip( $value );
2189 2219
     }
2190 2220
 
2191 2221
     /**
2192
-	 * Alias of self::set_author().
2193
-	 *
2194
-	 * @since 1.0.19
2195
-	 * @param  int $value New user id.
2196
-	 */
2197
-	public function set_customer_id( $value ) {
2198
-		$this->set_author( $value );
2222
+     * Set the customer's first name.
2223
+     *
2224
+     * @since 1.0.19
2225
+     * @param  string $value first name.
2226
+     */
2227
+    public function set_first_name( $value ) {
2228
+        $this->set_prop( 'first_name', $value );
2199 2229
     }
2200 2230
 
2201 2231
     /**
2202
-	 * Set the customer's ip.
2203
-	 *
2204
-	 * @since 1.0.19
2205
-	 * @param  string $value ip address.
2206
-	 */
2207
-	public function set_ip( $value ) {
2208
-		$this->set_prop( 'ip', $value );
2232
+     * Alias of self::set_first_name().
2233
+     *
2234
+     * @since 1.0.19
2235
+     * @param  string $value first name.
2236
+     */
2237
+    public function set_user_first_name( $value ) {
2238
+        $this->set_first_name( $value );
2209 2239
     }
2210 2240
 
2211 2241
     /**
2212
-	 * Alias of self::set_ip().
2213
-	 *
2214
-	 * @since 1.0.19
2215
-	 * @param  string $value ip address.
2216
-	 */
2217
-	public function set_user_ip( $value ) {
2218
-		$this->set_ip( $value );
2242
+     * Alias of self::set_first_name().
2243
+     *
2244
+     * @since 1.0.19
2245
+     * @param  string $value first name.
2246
+     */
2247
+    public function set_customer_first_name( $value ) {
2248
+        $this->set_first_name( $value );
2219 2249
     }
2220 2250
 
2221 2251
     /**
2222
-	 * Set the customer's first name.
2223
-	 *
2224
-	 * @since 1.0.19
2225
-	 * @param  string $value first name.
2226
-	 */
2227
-	public function set_first_name( $value ) {
2228
-		$this->set_prop( 'first_name', $value );
2252
+     * Set the customer's last name.
2253
+     *
2254
+     * @since 1.0.19
2255
+     * @param  string $value last name.
2256
+     */
2257
+    public function set_last_name( $value ) {
2258
+        $this->set_prop( 'last_name', $value );
2229 2259
     }
2230 2260
 
2231 2261
     /**
2232
-	 * Alias of self::set_first_name().
2233
-	 *
2234
-	 * @since 1.0.19
2235
-	 * @param  string $value first name.
2236
-	 */
2237
-	public function set_user_first_name( $value ) {
2238
-		$this->set_first_name( $value );
2262
+     * Alias of self::set_last_name().
2263
+     *
2264
+     * @since 1.0.19
2265
+     * @param  string $value last name.
2266
+     */
2267
+    public function set_user_last_name( $value ) {
2268
+        $this->set_last_name( $value );
2239 2269
     }
2240 2270
 
2241 2271
     /**
2242
-	 * Alias of self::set_first_name().
2243
-	 *
2244
-	 * @since 1.0.19
2245
-	 * @param  string $value first name.
2246
-	 */
2247
-	public function set_customer_first_name( $value ) {
2248
-		$this->set_first_name( $value );
2272
+     * Alias of self::set_last_name().
2273
+     *
2274
+     * @since 1.0.19
2275
+     * @param  string $value last name.
2276
+     */
2277
+    public function set_customer_last_name( $value ) {
2278
+        $this->set_last_name( $value );
2249 2279
     }
2250 2280
 
2251 2281
     /**
2252
-	 * Set the customer's last name.
2253
-	 *
2254
-	 * @since 1.0.19
2255
-	 * @param  string $value last name.
2256
-	 */
2257
-	public function set_last_name( $value ) {
2258
-		$this->set_prop( 'last_name', $value );
2282
+     * Set the customer's phone number.
2283
+     *
2284
+     * @since 1.0.19
2285
+     * @param  string $value phone.
2286
+     */
2287
+    public function set_phone( $value ) {
2288
+        $this->set_prop( 'phone', $value );
2259 2289
     }
2260 2290
 
2261 2291
     /**
2262
-	 * Alias of self::set_last_name().
2263
-	 *
2264
-	 * @since 1.0.19
2265
-	 * @param  string $value last name.
2266
-	 */
2267
-	public function set_user_last_name( $value ) {
2268
-		$this->set_last_name( $value );
2292
+     * Alias of self::set_phone().
2293
+     *
2294
+     * @since 1.0.19
2295
+     * @param  string $value phone.
2296
+     */
2297
+    public function set_user_phone( $value ) {
2298
+        $this->set_phone( $value );
2269 2299
     }
2270 2300
 
2271 2301
     /**
2272
-	 * Alias of self::set_last_name().
2273
-	 *
2274
-	 * @since 1.0.19
2275
-	 * @param  string $value last name.
2276
-	 */
2277
-	public function set_customer_last_name( $value ) {
2278
-		$this->set_last_name( $value );
2302
+     * Alias of self::set_phone().
2303
+     *
2304
+     * @since 1.0.19
2305
+     * @param  string $value phone.
2306
+     */
2307
+    public function set_customer_phone( $value ) {
2308
+        $this->set_phone( $value );
2279 2309
     }
2280 2310
 
2281 2311
     /**
2282
-	 * Set the customer's phone number.
2283
-	 *
2284
-	 * @since 1.0.19
2285
-	 * @param  string $value phone.
2286
-	 */
2287
-	public function set_phone( $value ) {
2288
-		$this->set_prop( 'phone', $value );
2312
+     * Alias of self::set_phone().
2313
+     *
2314
+     * @since 1.0.19
2315
+     * @param  string $value phone.
2316
+     */
2317
+    public function set_phone_number( $value ) {
2318
+        $this->set_phone( $value );
2289 2319
     }
2290 2320
 
2291 2321
     /**
2292
-	 * Alias of self::set_phone().
2293
-	 *
2294
-	 * @since 1.0.19
2295
-	 * @param  string $value phone.
2296
-	 */
2297
-	public function set_user_phone( $value ) {
2298
-		$this->set_phone( $value );
2322
+     * Set the customer's email address.
2323
+     *
2324
+     * @since 1.0.19
2325
+     * @param  string $value email address.
2326
+     */
2327
+    public function set_email( $value ) {
2328
+        $this->set_prop( 'email', $value );
2299 2329
     }
2300 2330
 
2301 2331
     /**
2302
-	 * Alias of self::set_phone().
2303
-	 *
2304
-	 * @since 1.0.19
2305
-	 * @param  string $value phone.
2306
-	 */
2307
-	public function set_customer_phone( $value ) {
2308
-		$this->set_phone( $value );
2332
+     * Alias of self::set_email().
2333
+     *
2334
+     * @since 1.0.19
2335
+     * @param  string $value email address.
2336
+     */
2337
+    public function set_user_email( $value ) {
2338
+        $this->set_email( $value );
2309 2339
     }
2310 2340
 
2311 2341
     /**
2312
-	 * Alias of self::set_phone().
2313
-	 *
2314
-	 * @since 1.0.19
2315
-	 * @param  string $value phone.
2316
-	 */
2317
-	public function set_phone_number( $value ) {
2318
-		$this->set_phone( $value );
2342
+     * Alias of self::set_email().
2343
+     *
2344
+     * @since 1.0.19
2345
+     * @param  string $value email address.
2346
+     */
2347
+    public function set_email_address( $value ) {
2348
+        $this->set_email( $value );
2319 2349
     }
2320 2350
 
2321 2351
     /**
2322
-	 * Set the customer's email address.
2323
-	 *
2324
-	 * @since 1.0.19
2325
-	 * @param  string $value email address.
2326
-	 */
2327
-	public function set_email( $value ) {
2328
-		$this->set_prop( 'email', $value );
2352
+     * Alias of self::set_email().
2353
+     *
2354
+     * @since 1.0.19
2355
+     * @param  string $value email address.
2356
+     */
2357
+    public function set_customer_email( $value ) {
2358
+        $this->set_email( $value );
2329 2359
     }
2330 2360
 
2331 2361
     /**
2332
-	 * Alias of self::set_email().
2333
-	 *
2334
-	 * @since 1.0.19
2335
-	 * @param  string $value email address.
2336
-	 */
2337
-	public function set_user_email( $value ) {
2338
-		$this->set_email( $value );
2362
+     * Set the customer's country.
2363
+     *
2364
+     * @since 1.0.19
2365
+     * @param  string $value country.
2366
+     */
2367
+    public function set_country( $value ) {
2368
+        $this->set_prop( 'country', $value );
2339 2369
     }
2340 2370
 
2341 2371
     /**
2342
-	 * Alias of self::set_email().
2343
-	 *
2344
-	 * @since 1.0.19
2345
-	 * @param  string $value email address.
2346
-	 */
2347
-	public function set_email_address( $value ) {
2348
-		$this->set_email( $value );
2372
+     * Alias of self::set_country().
2373
+     *
2374
+     * @since 1.0.19
2375
+     * @param  string $value country.
2376
+     */
2377
+    public function set_user_country( $value ) {
2378
+        $this->set_country( $value );
2349 2379
     }
2350 2380
 
2351 2381
     /**
2352
-	 * Alias of self::set_email().
2353
-	 *
2354
-	 * @since 1.0.19
2355
-	 * @param  string $value email address.
2356
-	 */
2357
-	public function set_customer_email( $value ) {
2358
-		$this->set_email( $value );
2382
+     * Alias of self::set_country().
2383
+     *
2384
+     * @since 1.0.19
2385
+     * @param  string $value country.
2386
+     */
2387
+    public function set_customer_country( $value ) {
2388
+        $this->set_country( $value );
2359 2389
     }
2360 2390
 
2361 2391
     /**
2362
-	 * Set the customer's country.
2363
-	 *
2364
-	 * @since 1.0.19
2365
-	 * @param  string $value country.
2366
-	 */
2367
-	public function set_country( $value ) {
2368
-		$this->set_prop( 'country', $value );
2392
+     * Set the customer's state.
2393
+     *
2394
+     * @since 1.0.19
2395
+     * @param  string $value state.
2396
+     */
2397
+    public function set_state( $value ) {
2398
+        $this->set_prop( 'state', $value );
2369 2399
     }
2370 2400
 
2371 2401
     /**
2372
-	 * Alias of self::set_country().
2373
-	 *
2374
-	 * @since 1.0.19
2375
-	 * @param  string $value country.
2376
-	 */
2377
-	public function set_user_country( $value ) {
2378
-		$this->set_country( $value );
2402
+     * Alias of self::set_state().
2403
+     *
2404
+     * @since 1.0.19
2405
+     * @param  string $value state.
2406
+     */
2407
+    public function set_user_state( $value ) {
2408
+        $this->set_state( $value );
2379 2409
     }
2380 2410
 
2381 2411
     /**
2382
-	 * Alias of self::set_country().
2383
-	 *
2384
-	 * @since 1.0.19
2385
-	 * @param  string $value country.
2386
-	 */
2387
-	public function set_customer_country( $value ) {
2388
-		$this->set_country( $value );
2412
+     * Alias of self::set_state().
2413
+     *
2414
+     * @since 1.0.19
2415
+     * @param  string $value state.
2416
+     */
2417
+    public function set_customer_state( $value ) {
2418
+        $this->set_state( $value );
2389 2419
     }
2390 2420
 
2391 2421
     /**
2392
-	 * Set the customer's state.
2393
-	 *
2394
-	 * @since 1.0.19
2395
-	 * @param  string $value state.
2396
-	 */
2397
-	public function set_state( $value ) {
2398
-		$this->set_prop( 'state', $value );
2422
+     * Set the customer's city.
2423
+     *
2424
+     * @since 1.0.19
2425
+     * @param  string $value city.
2426
+     */
2427
+    public function set_city( $value ) {
2428
+        $this->set_prop( 'city', $value );
2399 2429
     }
2400 2430
 
2401 2431
     /**
2402
-	 * Alias of self::set_state().
2403
-	 *
2404
-	 * @since 1.0.19
2405
-	 * @param  string $value state.
2406
-	 */
2407
-	public function set_user_state( $value ) {
2408
-		$this->set_state( $value );
2432
+     * Alias of self::set_city().
2433
+     *
2434
+     * @since 1.0.19
2435
+     * @param  string $value city.
2436
+     */
2437
+    public function set_user_city( $value ) {
2438
+        $this->set_city( $value );
2409 2439
     }
2410 2440
 
2411 2441
     /**
2412
-	 * Alias of self::set_state().
2413
-	 *
2414
-	 * @since 1.0.19
2415
-	 * @param  string $value state.
2416
-	 */
2417
-	public function set_customer_state( $value ) {
2418
-		$this->set_state( $value );
2442
+     * Alias of self::set_city().
2443
+     *
2444
+     * @since 1.0.19
2445
+     * @param  string $value city.
2446
+     */
2447
+    public function set_customer_city( $value ) {
2448
+        $this->set_city( $value );
2419 2449
     }
2420 2450
 
2421 2451
     /**
2422
-	 * Set the customer's city.
2423
-	 *
2424
-	 * @since 1.0.19
2425
-	 * @param  string $value city.
2426
-	 */
2427
-	public function set_city( $value ) {
2428
-		$this->set_prop( 'city', $value );
2452
+     * Set the customer's zip code.
2453
+     *
2454
+     * @since 1.0.19
2455
+     * @param  string $value zip.
2456
+     */
2457
+    public function set_zip( $value ) {
2458
+        $this->set_prop( 'zip', $value );
2429 2459
     }
2430 2460
 
2431 2461
     /**
2432
-	 * Alias of self::set_city().
2433
-	 *
2434
-	 * @since 1.0.19
2435
-	 * @param  string $value city.
2436
-	 */
2437
-	public function set_user_city( $value ) {
2438
-		$this->set_city( $value );
2462
+     * Alias of self::set_zip().
2463
+     *
2464
+     * @since 1.0.19
2465
+     * @param  string $value zip.
2466
+     */
2467
+    public function set_user_zip( $value ) {
2468
+        $this->set_zip( $value );
2439 2469
     }
2440 2470
 
2441 2471
     /**
2442
-	 * Alias of self::set_city().
2443
-	 *
2444
-	 * @since 1.0.19
2445
-	 * @param  string $value city.
2446
-	 */
2447
-	public function set_customer_city( $value ) {
2448
-		$this->set_city( $value );
2472
+     * Alias of self::set_zip().
2473
+     *
2474
+     * @since 1.0.19
2475
+     * @param  string $value zip.
2476
+     */
2477
+    public function set_customer_zip( $value ) {
2478
+        $this->set_zip( $value );
2449 2479
     }
2450 2480
 
2451 2481
     /**
2452
-	 * Set the customer's zip code.
2453
-	 *
2454
-	 * @since 1.0.19
2455
-	 * @param  string $value zip.
2456
-	 */
2457
-	public function set_zip( $value ) {
2458
-		$this->set_prop( 'zip', $value );
2482
+     * Set the customer's company.
2483
+     *
2484
+     * @since 1.0.19
2485
+     * @param  string $value company.
2486
+     */
2487
+    public function set_company( $value ) {
2488
+        $this->set_prop( 'company', $value );
2459 2489
     }
2460 2490
 
2461 2491
     /**
2462
-	 * Alias of self::set_zip().
2463
-	 *
2464
-	 * @since 1.0.19
2465
-	 * @param  string $value zip.
2466
-	 */
2467
-	public function set_user_zip( $value ) {
2468
-		$this->set_zip( $value );
2492
+     * Alias of self::set_company().
2493
+     *
2494
+     * @since 1.0.19
2495
+     * @param  string $value company.
2496
+     */
2497
+    public function set_user_company( $value ) {
2498
+        $this->set_company( $value );
2469 2499
     }
2470 2500
 
2471 2501
     /**
2472
-	 * Alias of self::set_zip().
2473
-	 *
2474
-	 * @since 1.0.19
2475
-	 * @param  string $value zip.
2476
-	 */
2477
-	public function set_customer_zip( $value ) {
2478
-		$this->set_zip( $value );
2502
+     * Alias of self::set_company().
2503
+     *
2504
+     * @since 1.0.19
2505
+     * @param  string $value company.
2506
+     */
2507
+    public function set_customer_company( $value ) {
2508
+        $this->set_company( $value );
2479 2509
     }
2480 2510
 
2481 2511
     /**
2482
-	 * Set the customer's company.
2483
-	 *
2484
-	 * @since 1.0.19
2485
-	 * @param  string $value company.
2486
-	 */
2487
-	public function set_company( $value ) {
2488
-		$this->set_prop( 'company', $value );
2512
+     * Set the customer's var number.
2513
+     *
2514
+     * @since 1.0.19
2515
+     * @param  string $value var number.
2516
+     */
2517
+    public function set_vat_number( $value ) {
2518
+        $this->set_prop( 'vat_number', $value );
2489 2519
     }
2490 2520
 
2491 2521
     /**
2492
-	 * Alias of self::set_company().
2493
-	 *
2494
-	 * @since 1.0.19
2495
-	 * @param  string $value company.
2496
-	 */
2497
-	public function set_user_company( $value ) {
2498
-		$this->set_company( $value );
2522
+     * Alias of self::set_vat_number().
2523
+     *
2524
+     * @since 1.0.19
2525
+     * @param  string $value var number.
2526
+     */
2527
+    public function set_user_vat_number( $value ) {
2528
+        $this->set_vat_number( $value );
2499 2529
     }
2500 2530
 
2501 2531
     /**
2502
-	 * Alias of self::set_company().
2503
-	 *
2504
-	 * @since 1.0.19
2505
-	 * @param  string $value company.
2506
-	 */
2507
-	public function set_customer_company( $value ) {
2508
-		$this->set_company( $value );
2532
+     * Alias of self::set_vat_number().
2533
+     *
2534
+     * @since 1.0.19
2535
+     * @param  string $value var number.
2536
+     */
2537
+    public function set_customer_vat_number( $value ) {
2538
+        $this->set_vat_number( $value );
2509 2539
     }
2510 2540
 
2511 2541
     /**
2512
-	 * Set the customer's var number.
2513
-	 *
2514
-	 * @since 1.0.19
2515
-	 * @param  string $value var number.
2516
-	 */
2517
-	public function set_vat_number( $value ) {
2518
-		$this->set_prop( 'vat_number', $value );
2542
+     * Set the customer's vat rate.
2543
+     *
2544
+     * @since 1.0.19
2545
+     * @param  string $value var rate.
2546
+     */
2547
+    public function set_vat_rate( $value ) {
2548
+        $this->set_prop( 'vat_rate', $value );
2519 2549
     }
2520 2550
 
2521 2551
     /**
2522
-	 * Alias of self::set_vat_number().
2523
-	 *
2524
-	 * @since 1.0.19
2525
-	 * @param  string $value var number.
2526
-	 */
2527
-	public function set_user_vat_number( $value ) {
2528
-		$this->set_vat_number( $value );
2552
+     * Alias of self::set_vat_rate().
2553
+     *
2554
+     * @since 1.0.19
2555
+     * @param  string $value var number.
2556
+     */
2557
+    public function set_user_vat_rate( $value ) {
2558
+        $this->set_vat_rate( $value );
2529 2559
     }
2530 2560
 
2531 2561
     /**
2532
-	 * Alias of self::set_vat_number().
2533
-	 *
2534
-	 * @since 1.0.19
2535
-	 * @param  string $value var number.
2536
-	 */
2537
-	public function set_customer_vat_number( $value ) {
2538
-		$this->set_vat_number( $value );
2562
+     * Alias of self::set_vat_rate().
2563
+     *
2564
+     * @since 1.0.19
2565
+     * @param  string $value var number.
2566
+     */
2567
+    public function set_customer_vat_rate( $value ) {
2568
+        $this->set_vat_rate( $value );
2539 2569
     }
2540 2570
 
2541 2571
     /**
2542
-	 * Set the customer's vat rate.
2543
-	 *
2544
-	 * @since 1.0.19
2545
-	 * @param  string $value var rate.
2546
-	 */
2547
-	public function set_vat_rate( $value ) {
2548
-		$this->set_prop( 'vat_rate', $value );
2572
+     * Set the customer's address.
2573
+     *
2574
+     * @since 1.0.19
2575
+     * @param  string $value address.
2576
+     */
2577
+    public function set_address( $value ) {
2578
+        $this->set_prop( 'address', $value );
2549 2579
     }
2550 2580
 
2551 2581
     /**
2552
-	 * Alias of self::set_vat_rate().
2553
-	 *
2554
-	 * @since 1.0.19
2555
-	 * @param  string $value var number.
2556
-	 */
2557
-	public function set_user_vat_rate( $value ) {
2558
-		$this->set_vat_rate( $value );
2582
+     * Alias of self::set_address().
2583
+     *
2584
+     * @since 1.0.19
2585
+     * @param  string $value address.
2586
+     */
2587
+    public function set_user_address( $value ) {
2588
+        $this->set_address( $value );
2559 2589
     }
2560 2590
 
2561 2591
     /**
2562
-	 * Alias of self::set_vat_rate().
2563
-	 *
2564
-	 * @since 1.0.19
2565
-	 * @param  string $value var number.
2566
-	 */
2567
-	public function set_customer_vat_rate( $value ) {
2568
-		$this->set_vat_rate( $value );
2592
+     * Alias of self::set_address().
2593
+     *
2594
+     * @since 1.0.19
2595
+     * @param  string $value address.
2596
+     */
2597
+    public function set_customer_address( $value ) {
2598
+        $this->set_address( $value );
2569 2599
     }
2570 2600
 
2571 2601
     /**
2572
-	 * Set the customer's address.
2573
-	 *
2574
-	 * @since 1.0.19
2575
-	 * @param  string $value address.
2576
-	 */
2577
-	public function set_address( $value ) {
2578
-		$this->set_prop( 'address', $value );
2602
+     * Set whether the customer has viewed the invoice or not.
2603
+     *
2604
+     * @since 1.0.19
2605
+     * @param  int|bool $value confirmed.
2606
+     */
2607
+    public function set_is_viewed( $value ) {
2608
+        $this->set_prop( 'is_viewed', $value );
2579 2609
     }
2580 2610
 
2581 2611
     /**
2582
-	 * Alias of self::set_address().
2583
-	 *
2584
-	 * @since 1.0.19
2585
-	 * @param  string $value address.
2586
-	 */
2587
-	public function set_user_address( $value ) {
2588
-		$this->set_address( $value );
2612
+     * Set extra email recipients.
2613
+     *
2614
+     * @since 1.0.19
2615
+     * @param  string $value email recipients.
2616
+     */
2617
+    public function set_email_cc( $value ) {
2618
+        $this->set_prop( 'email_cc', $value );
2589 2619
     }
2590 2620
 
2591 2621
     /**
2592
-	 * Alias of self::set_address().
2593
-	 *
2594
-	 * @since 1.0.19
2595
-	 * @param  string $value address.
2596
-	 */
2597
-	public function set_customer_address( $value ) {
2598
-		$this->set_address( $value );
2622
+     * Set the invoice template.
2623
+     *
2624
+     * @since 1.0.19
2625
+     * @param  string $value email recipients.
2626
+     */
2627
+    public function set_template( $value ) {
2628
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2629
+            $this->set_prop( 'template', $value );
2630
+        }
2599 2631
     }
2600 2632
 
2601 2633
     /**
2602
-	 * Set whether the customer has viewed the invoice or not.
2603
-	 *
2604
-	 * @since 1.0.19
2605
-	 * @param  int|bool $value confirmed.
2606
-	 */
2607
-	public function set_is_viewed( $value ) {
2608
-		$this->set_prop( 'is_viewed', $value );
2609
-	}
2610
-
2611
-	/**
2612
-	 * Set extra email recipients.
2613
-	 *
2614
-	 * @since 1.0.19
2615
-	 * @param  string $value email recipients.
2616
-	 */
2617
-	public function set_email_cc( $value ) {
2618
-		$this->set_prop( 'email_cc', $value );
2619
-	}
2620
-
2621
-	/**
2622
-	 * Set the invoice template.
2623
-	 *
2624
-	 * @since 1.0.19
2625
-	 * @param  string $value email recipients.
2626
-	 */
2627
-	public function set_template( $value ) {
2628
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2629
-			$this->set_prop( 'template', $value );
2630
-		}
2631
-	}
2632
-
2633
-	/**
2634
-	 * Set the customer's address confirmed status.
2635
-	 *
2636
-	 * @since 1.0.19
2637
-	 * @param  int|bool $value confirmed.
2638
-	 */
2639
-	public function set_address_confirmed( $value ) {
2640
-		$this->set_prop( 'address_confirmed', $value );
2634
+     * Set the customer's address confirmed status.
2635
+     *
2636
+     * @since 1.0.19
2637
+     * @param  int|bool $value confirmed.
2638
+     */
2639
+    public function set_address_confirmed( $value ) {
2640
+        $this->set_prop( 'address_confirmed', $value );
2641 2641
     }
2642 2642
 
2643 2643
     /**
2644
-	 * Alias of self::set_address_confirmed().
2645
-	 *
2646
-	 * @since 1.0.19
2647
-	 * @param  int|bool $value confirmed.
2648
-	 */
2649
-	public function set_user_address_confirmed( $value ) {
2650
-		$this->set_address_confirmed( $value );
2644
+     * Alias of self::set_address_confirmed().
2645
+     *
2646
+     * @since 1.0.19
2647
+     * @param  int|bool $value confirmed.
2648
+     */
2649
+    public function set_user_address_confirmed( $value ) {
2650
+        $this->set_address_confirmed( $value );
2651 2651
     }
2652 2652
 
2653 2653
     /**
2654
-	 * Alias of self::set_address_confirmed().
2655
-	 *
2656
-	 * @since 1.0.19
2657
-	 * @param  int|bool $value confirmed.
2658
-	 */
2659
-	public function set_customer_address_confirmed( $value ) {
2660
-		$this->set_address_confirmed( $value );
2654
+     * Alias of self::set_address_confirmed().
2655
+     *
2656
+     * @since 1.0.19
2657
+     * @param  int|bool $value confirmed.
2658
+     */
2659
+    public function set_customer_address_confirmed( $value ) {
2660
+        $this->set_address_confirmed( $value );
2661 2661
     }
2662 2662
 
2663 2663
     /**
2664
-	 * Set the invoice sub total.
2665
-	 *
2666
-	 * @since 1.0.19
2667
-	 * @param  float $value sub total.
2668
-	 */
2669
-	public function set_subtotal( $value ) {
2670
-		$this->set_prop( 'subtotal', $value );
2664
+     * Set the invoice sub total.
2665
+     *
2666
+     * @since 1.0.19
2667
+     * @param  float $value sub total.
2668
+     */
2669
+    public function set_subtotal( $value ) {
2670
+        $this->set_prop( 'subtotal', $value );
2671 2671
     }
2672 2672
 
2673 2673
     /**
2674
-	 * Set the invoice discount amount.
2675
-	 *
2676
-	 * @since 1.0.19
2677
-	 * @param  float $value discount total.
2678
-	 */
2679
-	public function set_total_discount( $value ) {
2680
-		$this->set_prop( 'total_discount', $value );
2674
+     * Set the invoice discount amount.
2675
+     *
2676
+     * @since 1.0.19
2677
+     * @param  float $value discount total.
2678
+     */
2679
+    public function set_total_discount( $value ) {
2680
+        $this->set_prop( 'total_discount', $value );
2681 2681
     }
2682 2682
 
2683 2683
     /**
2684
-	 * Alias of self::set_total_discount().
2685
-	 *
2686
-	 * @since 1.0.19
2687
-	 * @param  float $value discount total.
2688
-	 */
2689
-	public function set_discount( $value ) {
2690
-		$this->set_total_discount( $value );
2684
+     * Alias of self::set_total_discount().
2685
+     *
2686
+     * @since 1.0.19
2687
+     * @param  float $value discount total.
2688
+     */
2689
+    public function set_discount( $value ) {
2690
+        $this->set_total_discount( $value );
2691 2691
     }
2692 2692
 
2693 2693
     /**
2694
-	 * Set the invoice tax amount.
2695
-	 *
2696
-	 * @since 1.0.19
2697
-	 * @param  float $value tax total.
2698
-	 */
2699
-	public function set_total_tax( $value ) {
2700
-		$this->set_prop( 'total_tax', $value );
2694
+     * Set the invoice tax amount.
2695
+     *
2696
+     * @since 1.0.19
2697
+     * @param  float $value tax total.
2698
+     */
2699
+    public function set_total_tax( $value ) {
2700
+        $this->set_prop( 'total_tax', $value );
2701 2701
     }
2702 2702
 
2703 2703
     /**
2704
-	 * Alias of self::set_total_tax().
2705
-	 *
2706
-	 * @since 1.0.19
2707
-	 * @param  float $value tax total.
2708
-	 */
2709
-	public function set_tax_total( $value ) {
2710
-		$this->set_total_tax( $value );
2704
+     * Alias of self::set_total_tax().
2705
+     *
2706
+     * @since 1.0.19
2707
+     * @param  float $value tax total.
2708
+     */
2709
+    public function set_tax_total( $value ) {
2710
+        $this->set_total_tax( $value );
2711 2711
     }
2712 2712
 
2713 2713
     /**
2714
-	 * Set the invoice fees amount.
2715
-	 *
2716
-	 * @since 1.0.19
2717
-	 * @param  float $value fees total.
2718
-	 */
2719
-	public function set_total_fees( $value ) {
2720
-		$this->set_prop( 'total_fees', $value );
2714
+     * Set the invoice fees amount.
2715
+     *
2716
+     * @since 1.0.19
2717
+     * @param  float $value fees total.
2718
+     */
2719
+    public function set_total_fees( $value ) {
2720
+        $this->set_prop( 'total_fees', $value );
2721 2721
     }
2722 2722
 
2723 2723
     /**
2724
-	 * Alias of self::set_total_fees().
2725
-	 *
2726
-	 * @since 1.0.19
2727
-	 * @param  float $value fees total.
2728
-	 */
2729
-	public function set_fees_total( $value ) {
2730
-		$this->set_total_fees( $value );
2724
+     * Alias of self::set_total_fees().
2725
+     *
2726
+     * @since 1.0.19
2727
+     * @param  float $value fees total.
2728
+     */
2729
+    public function set_fees_total( $value ) {
2730
+        $this->set_total_fees( $value );
2731 2731
     }
2732 2732
 
2733 2733
     /**
2734
-	 * Set the invoice fees.
2735
-	 *
2736
-	 * @since 1.0.19
2737
-	 * @param  array $value fees.
2738
-	 */
2739
-	public function set_fees( $value ) {
2734
+     * Set the invoice fees.
2735
+     *
2736
+     * @since 1.0.19
2737
+     * @param  array $value fees.
2738
+     */
2739
+    public function set_fees( $value ) {
2740 2740
 
2741 2741
         $this->set_prop( 'fees', array() );
2742 2742
 
@@ -2754,23 +2754,23 @@  discard block
 block discarded – undo
2754 2754
     }
2755 2755
 
2756 2756
     /**
2757
-	 * Set the invoice taxes.
2758
-	 *
2759
-	 * @since 1.0.19
2760
-	 * @param  array $value taxes.
2761
-	 */
2762
-	public function set_taxes( $value ) {
2763
-		$this->set_prop( 'taxes', $value );
2757
+     * Set the invoice taxes.
2758
+     *
2759
+     * @since 1.0.19
2760
+     * @param  array $value taxes.
2761
+     */
2762
+    public function set_taxes( $value ) {
2763
+        $this->set_prop( 'taxes', $value );
2764 2764
     }
2765 2765
 
2766 2766
     /**
2767
-	 * Set the invoice discounts.
2768
-	 *
2769
-	 * @since 1.0.19
2770
-	 * @param  array $value discounts.
2771
-	 */
2772
-	public function set_discounts( $value ) {
2773
-		$this->set_prop( 'discounts', array() );
2767
+     * Set the invoice discounts.
2768
+     *
2769
+     * @since 1.0.19
2770
+     * @param  array $value discounts.
2771
+     */
2772
+    public function set_discounts( $value ) {
2773
+        $this->set_prop( 'discounts', array() );
2774 2774
 
2775 2775
         // Ensure that we have an array.
2776 2776
         if ( ! is_array( $value ) ) {
@@ -2785,12 +2785,12 @@  discard block
 block discarded – undo
2785 2785
     }
2786 2786
 
2787 2787
     /**
2788
-	 * Set the invoice items.
2789
-	 *
2790
-	 * @since 1.0.19
2791
-	 * @param  GetPaid_Form_Item[] $value items.
2792
-	 */
2793
-	public function set_items( $value ) {
2788
+     * Set the invoice items.
2789
+     *
2790
+     * @since 1.0.19
2791
+     * @param  GetPaid_Form_Item[] $value items.
2792
+     */
2793
+    public function set_items( $value ) {
2794 2794
 
2795 2795
         // Remove existing items.
2796 2796
         $this->set_prop( 'items', array() );
@@ -2807,95 +2807,95 @@  discard block
 block discarded – undo
2807 2807
     }
2808 2808
 
2809 2809
     /**
2810
-	 * Set the payment form.
2811
-	 *
2812
-	 * @since 1.0.19
2813
-	 * @param  int $value payment form.
2814
-	 */
2815
-	public function set_payment_form( $value ) {
2816
-		$this->set_prop( 'payment_form', $value );
2810
+     * Set the payment form.
2811
+     *
2812
+     * @since 1.0.19
2813
+     * @param  int $value payment form.
2814
+     */
2815
+    public function set_payment_form( $value ) {
2816
+        $this->set_prop( 'payment_form', $value );
2817 2817
     }
2818 2818
 
2819 2819
     /**
2820
-	 * Set the submission id.
2821
-	 *
2822
-	 * @since 1.0.19
2823
-	 * @param  string $value submission id.
2824
-	 */
2825
-	public function set_submission_id( $value ) {
2826
-		$this->set_prop( 'submission_id', $value );
2820
+     * Set the submission id.
2821
+     *
2822
+     * @since 1.0.19
2823
+     * @param  string $value submission id.
2824
+     */
2825
+    public function set_submission_id( $value ) {
2826
+        $this->set_prop( 'submission_id', $value );
2827 2827
     }
2828 2828
 
2829 2829
     /**
2830
-	 * Set the discount code.
2831
-	 *
2832
-	 * @since 1.0.19
2833
-	 * @param  string $value discount code.
2834
-	 */
2835
-	public function set_discount_code( $value ) {
2836
-		$this->set_prop( 'discount_code', $value );
2830
+     * Set the discount code.
2831
+     *
2832
+     * @since 1.0.19
2833
+     * @param  string $value discount code.
2834
+     */
2835
+    public function set_discount_code( $value ) {
2836
+        $this->set_prop( 'discount_code', $value );
2837 2837
     }
2838 2838
 
2839 2839
     /**
2840
-	 * Set the gateway.
2841
-	 *
2842
-	 * @since 1.0.19
2843
-	 * @param  string $value gateway.
2844
-	 */
2845
-	public function set_gateway( $value ) {
2846
-		$this->set_prop( 'gateway', $value );
2840
+     * Set the gateway.
2841
+     *
2842
+     * @since 1.0.19
2843
+     * @param  string $value gateway.
2844
+     */
2845
+    public function set_gateway( $value ) {
2846
+        $this->set_prop( 'gateway', $value );
2847 2847
     }
2848 2848
 
2849 2849
     /**
2850
-	 * Set the transaction id.
2851
-	 *
2852
-	 * @since 1.0.19
2853
-	 * @param  string $value transaction id.
2854
-	 */
2855
-	public function set_transaction_id( $value ) {
2856
-		if ( ! empty( $value ) ) {
2857
-			$this->set_prop( 'transaction_id', $value );
2858
-		}
2850
+     * Set the transaction id.
2851
+     *
2852
+     * @since 1.0.19
2853
+     * @param  string $value transaction id.
2854
+     */
2855
+    public function set_transaction_id( $value ) {
2856
+        if ( ! empty( $value ) ) {
2857
+            $this->set_prop( 'transaction_id', $value );
2858
+        }
2859 2859
     }
2860 2860
 
2861 2861
     /**
2862
-	 * Set the currency id.
2863
-	 *
2864
-	 * @since 1.0.19
2865
-	 * @param  string $value currency id.
2866
-	 */
2867
-	public function set_currency( $value ) {
2868
-		$this->set_prop( 'currency', $value );
2862
+     * Set the currency id.
2863
+     *
2864
+     * @since 1.0.19
2865
+     * @param  string $value currency id.
2866
+     */
2867
+    public function set_currency( $value ) {
2868
+        $this->set_prop( 'currency', $value );
2869 2869
     }
2870 2870
 
2871
-	/**
2872
-	 * Set whether to disable taxes.
2873
-	 *
2874
-	 * @since 1.0.19
2875
-	 * @param  bool $value value.
2876
-	 */
2877
-	public function set_disable_taxes( $value ) {
2878
-		$this->set_prop( 'disable_taxes', (bool) $value );
2879
-	}
2871
+    /**
2872
+     * Set whether to disable taxes.
2873
+     *
2874
+     * @since 1.0.19
2875
+     * @param  bool $value value.
2876
+     */
2877
+    public function set_disable_taxes( $value ) {
2878
+        $this->set_prop( 'disable_taxes', (bool) $value );
2879
+    }
2880 2880
 
2881 2881
     /**
2882
-	 * Set the subscription id.
2883
-	 *
2884
-	 * @since 1.0.19
2885
-	 * @param  string $value subscription id.
2886
-	 */
2887
-	public function set_subscription_id( $value ) {
2888
-		$this->set_prop( 'subscription_id', $value );
2889
-	}
2882
+     * Set the subscription id.
2883
+     *
2884
+     * @since 1.0.19
2885
+     * @param  string $value subscription id.
2886
+     */
2887
+    public function set_subscription_id( $value ) {
2888
+        $this->set_prop( 'subscription_id', $value );
2889
+    }
2890 2890
 	
2891
-	/**
2892
-	 * Set the remote subscription id.
2893
-	 *
2894
-	 * @since 1.0.19
2895
-	 * @param  string $value subscription id.
2896
-	 */
2897
-	public function set_remote_subscription_id( $value ) {
2898
-		$this->set_prop( 'remote_subscription_id', $value );
2891
+    /**
2892
+     * Set the remote subscription id.
2893
+     *
2894
+     * @since 1.0.19
2895
+     * @param  string $value subscription id.
2896
+     */
2897
+    public function set_remote_subscription_id( $value ) {
2898
+        $this->set_prop( 'remote_subscription_id', $value );
2899 2899
     }
2900 2900
 
2901 2901
     /*
@@ -2934,12 +2934,12 @@  discard block
 block discarded – undo
2934 2934
      */
2935 2935
     public function is_taxable() {
2936 2936
         return ! $this->get_disable_taxes();
2937
-	}
2937
+    }
2938 2938
 
2939
-	/**
2940
-	 * @deprecated
2941
-	 */
2942
-	public function has_vat() {
2939
+    /**
2940
+     * @deprecated
2941
+     */
2942
+    public function has_vat() {
2943 2943
         global $wpinv_euvat, $wpi_country;
2944 2944
 
2945 2945
         $requires_vat = false;
@@ -2950,17 +2950,17 @@  discard block
 block discarded – undo
2950 2950
         }
2951 2951
 
2952 2952
         return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2953
-	}
2953
+    }
2954 2954
 
2955
-	/**
2956
-	 * Checks to see if the invoice requires payment.
2957
-	 */
2958
-	public function is_free() {
2955
+    /**
2956
+     * Checks to see if the invoice requires payment.
2957
+     */
2958
+    public function is_free() {
2959 2959
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
2960 2960
 
2961
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2962
-			$is_free = false;
2963
-		}
2961
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2962
+            $is_free = false;
2963
+        }
2964 2964
 
2965 2965
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2966 2966
     }
@@ -2971,46 +2971,46 @@  discard block
 block discarded – undo
2971 2971
     public function is_paid() {
2972 2972
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2973 2973
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2974
-	}
2974
+    }
2975 2975
 
2976
-	/**
2976
+    /**
2977 2977
      * Checks if the invoice needs payment.
2978 2978
      */
2979
-	public function needs_payment() {
2980
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2979
+    public function needs_payment() {
2980
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2981 2981
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2982 2982
     }
2983 2983
 
2984
-	/**
2984
+    /**
2985 2985
      * Checks if the invoice is refunded.
2986 2986
      */
2987
-	public function is_refunded() {
2987
+    public function is_refunded() {
2988 2988
         $is_refunded = $this->has_status( 'wpi-refunded' );
2989 2989
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2990
-	}
2990
+    }
2991 2991
 
2992
-	/**
2992
+    /**
2993 2993
      * Checks if the invoice is held.
2994 2994
      */
2995
-	public function is_held() {
2995
+    public function is_held() {
2996 2996
         $is_held = $this->has_status( 'wpi-onhold' );
2997 2997
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
2998
-	}
2998
+    }
2999 2999
 
3000
-	/**
3000
+    /**
3001 3001
      * Checks if the invoice is due.
3002 3002
      */
3003
-	public function is_due() {
3004
-		$due_date = $this->get_due_date();
3005
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3006
-	}
3003
+    public function is_due() {
3004
+        $due_date = $this->get_due_date();
3005
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3006
+    }
3007 3007
 
3008
-	/**
3008
+    /**
3009 3009
      * Checks if the invoice is draft.
3010 3010
      */
3011
-	public function is_draft() {
3011
+    public function is_draft() {
3012 3012
         return $this->has_status( 'draft, auto-draft' );
3013
-	}
3013
+    }
3014 3014
 
3015 3015
     /**
3016 3016
      * Checks if the invoice has a given status.
@@ -3018,9 +3018,9 @@  discard block
 block discarded – undo
3018 3018
     public function has_status( $status ) {
3019 3019
         $status = wpinv_parse_list( $status );
3020 3020
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
3021
-	}
3021
+    }
3022 3022
 
3023
-	/**
3023
+    /**
3024 3024
      * Checks if the invoice is of a given type.
3025 3025
      */
3026 3026
     public function is_type( $type ) {
@@ -3043,25 +3043,25 @@  discard block
 block discarded – undo
3043 3043
      */
3044 3044
     public function has_free_trial() {
3045 3045
         return $this->is_recurring() && 0 == $this->get_initial_total();
3046
-	}
3046
+    }
3047 3047
 
3048
-	/**
3048
+    /**
3049 3049
      * @deprecated
3050 3050
      */
3051 3051
     public function is_free_trial() {
3052 3052
         $this->has_free_trial();
3053 3053
     }
3054 3054
 
3055
-	/**
3055
+    /**
3056 3056
      * Check if the initial payment if 0.
3057 3057
      *
3058 3058
      */
3059
-	public function is_initial_free() {
3059
+    public function is_initial_free() {
3060 3060
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3061 3061
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3062 3062
     }
3063 3063
 	
3064
-	/**
3064
+    /**
3065 3065
      * Check if the recurring item has a free trial.
3066 3066
      *
3067 3067
      */
@@ -3074,21 +3074,21 @@  discard block
 block discarded – undo
3074 3074
 
3075 3075
         $item = $this->get_recurring( true );
3076 3076
         return $item->has_free_trial();
3077
-	}
3077
+    }
3078 3078
 
3079
-	/**
3079
+    /**
3080 3080
      * Check if the free trial is a result of a discount.
3081 3081
      */
3082 3082
     public function is_free_trial_from_discount() {
3083
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3084
-	}
3083
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3084
+    }
3085 3085
 	
3086
-	/**
3086
+    /**
3087 3087
      * @deprecated
3088 3088
      */
3089 3089
     public function discount_first_payment_only() {
3090 3090
 
3091
-		$discount_code = $this->get_discount_code();
3091
+        $discount_code = $this->get_discount_code();
3092 3092
         if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
3093 3093
             return true;
3094 3094
         }
@@ -3119,28 +3119,28 @@  discard block
 block discarded – undo
3119 3119
      */
3120 3120
     public function add_item( $item ) {
3121 3121
 
3122
-		if ( is_array( $item ) ) {
3123
-			$item = $this->process_array_item( $item );
3124
-		}
3122
+        if ( is_array( $item ) ) {
3123
+            $item = $this->process_array_item( $item );
3124
+        }
3125 3125
 
3126
-		if ( is_numeric( $item ) ) {
3127
-			$item = new GetPaid_Form_Item( $item );
3128
-		}
3126
+        if ( is_numeric( $item ) ) {
3127
+            $item = new GetPaid_Form_Item( $item );
3128
+        }
3129 3129
 
3130 3130
         // Make sure that it is available for purchase.
3131
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3132
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3131
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3132
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3133 3133
         }
3134 3134
 
3135 3135
         // Do we have a recurring item?
3136
-		if ( $item->is_recurring() ) {
3136
+        if ( $item->is_recurring() ) {
3137 3137
 
3138
-			// An invoice can only contain one recurring item.
3139
-			if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3140
-				return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3141
-			}
3138
+            // An invoice can only contain one recurring item.
3139
+            if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3140
+                return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3141
+            }
3142 3142
 
3143
-			$this->recurring_item = $item->get_id();
3143
+            $this->recurring_item = $item->get_id();
3144 3144
         }
3145 3145
 
3146 3146
         // Invoice id.
@@ -3151,60 +3151,60 @@  discard block
 block discarded – undo
3151 3151
         $items[ (int) $item->get_id() ] = $item;
3152 3152
 
3153 3153
         $this->set_prop( 'items', $items );
3154
-		return true;
3155
-	}
3154
+        return true;
3155
+    }
3156 3156
 	
3157
-	/**
3158
-	 * Converts an array to an item.
3159
-	 *
3160
-	 * @since 1.0.19
3161
-	 * @return GetPaid_Form_Item
3162
-	 */
3163
-	protected function process_array_item( $array ) {
3164
-
3165
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3166
-		$item    = new GetPaid_Form_Item( $item_id );
3167
-
3168
-		// Set item data.
3169
-		foreach( array( 'name', 'price', 'description' ) as $key ) {
3170
-			if ( isset( $array[ "item_$key" ] ) ) {
3171
-				$method = "set_$key";
3172
-				$item->$method( $array[ "item_$key" ] );
3173
-			}
3174
-		}
3175
-
3176
-		if ( isset( $array['quantity'] ) ) {
3177
-			$item->set_quantity( $array['quantity'] );
3178
-		}
3179
-
3180
-		// Set item meta.
3181
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3182
-			$item->set_item_meta( $array['meta'] );
3183
-		}
3184
-
3185
-		return $item;
3186
-
3187
-	}
3188
-
3189
-    /**
3190
-	 * Retrieves a specific item.
3191
-	 *
3192
-	 * @since 1.0.19
3193
-	 */
3194
-	public function get_item( $item_id ) {
3195
-		$items   = $this->get_items();
3196
-		$item_id = (int) $item_id;
3197
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3198
-    }
3199
-
3200
-    /**
3201
-	 * Removes a specific item.
3202
-	 *
3203
-	 * @since 1.0.19
3204
-	 */
3205
-	public function remove_item( $item_id ) {
3206
-		$items   = $this->get_items();
3207
-		$item_id = (int) $item_id;
3157
+    /**
3158
+     * Converts an array to an item.
3159
+     *
3160
+     * @since 1.0.19
3161
+     * @return GetPaid_Form_Item
3162
+     */
3163
+    protected function process_array_item( $array ) {
3164
+
3165
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3166
+        $item    = new GetPaid_Form_Item( $item_id );
3167
+
3168
+        // Set item data.
3169
+        foreach( array( 'name', 'price', 'description' ) as $key ) {
3170
+            if ( isset( $array[ "item_$key" ] ) ) {
3171
+                $method = "set_$key";
3172
+                $item->$method( $array[ "item_$key" ] );
3173
+            }
3174
+        }
3175
+
3176
+        if ( isset( $array['quantity'] ) ) {
3177
+            $item->set_quantity( $array['quantity'] );
3178
+        }
3179
+
3180
+        // Set item meta.
3181
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3182
+            $item->set_item_meta( $array['meta'] );
3183
+        }
3184
+
3185
+        return $item;
3186
+
3187
+    }
3188
+
3189
+    /**
3190
+     * Retrieves a specific item.
3191
+     *
3192
+     * @since 1.0.19
3193
+     */
3194
+    public function get_item( $item_id ) {
3195
+        $items   = $this->get_items();
3196
+        $item_id = (int) $item_id;
3197
+        return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3198
+    }
3199
+
3200
+    /**
3201
+     * Removes a specific item.
3202
+     *
3203
+     * @since 1.0.19
3204
+     */
3205
+    public function remove_item( $item_id ) {
3206
+        $items   = $this->get_items();
3207
+        $item_id = (int) $item_id;
3208 3208
 
3209 3209
         if ( $item_id == $this->recurring_item ) {
3210 3210
             $this->recurring_item = null;
@@ -3231,38 +3231,38 @@  discard block
 block discarded – undo
3231 3231
         if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) {
3232 3232
 
3233 3233
             $amount = $fees[ $fee ]['amount'] += $amount;
3234
-			$fees[ $fee ] = array(
3235
-				'amount'    => $amount,
3234
+            $fees[ $fee ] = array(
3235
+                'amount'    => $amount,
3236 3236
                 'recurring' => (bool) $recurring,
3237 3237
             );
3238 3238
 
3239
-		} else {
3240
-			$fees[ $fee ] = array(
3239
+        } else {
3240
+            $fees[ $fee ] = array(
3241 3241
                 'amount'    => $amount,
3242 3242
                 'recurring' => (bool) $recurring,
3243 3243
             );
3244
-		}
3244
+        }
3245 3245
 
3246 3246
         $this->set_prop( 'fees', $fee );
3247 3247
 
3248 3248
     }
3249 3249
 
3250 3250
     /**
3251
-	 * Retrieves a specific fee.
3252
-	 *
3253
-	 * @since 1.0.19
3254
-	 */
3255
-	public function get_fee( $fee ) {
3251
+     * Retrieves a specific fee.
3252
+     *
3253
+     * @since 1.0.19
3254
+     */
3255
+    public function get_fee( $fee ) {
3256 3256
         $fees = $this->get_fees();
3257
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3257
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3258 3258
     }
3259 3259
 
3260 3260
     /**
3261
-	 * Removes a specific fee.
3262
-	 *
3263
-	 * @since 1.0.19
3264
-	 */
3265
-	public function remove_fee( $fee ) {
3261
+     * Removes a specific fee.
3262
+     *
3263
+     * @since 1.0.19
3264
+     */
3265
+    public function remove_fee( $fee ) {
3266 3266
         $fees = $this->get_fees();
3267 3267
         if ( isset( $fees[ $fee ] ) ) {
3268 3268
             unset( $fees[ $fee ] );
@@ -3285,44 +3285,44 @@  discard block
 block discarded – undo
3285 3285
         if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) {
3286 3286
 
3287 3287
             $amount = $discounts[ $discount ]['amount'] += $amount;
3288
-			$discounts[ $discount ] = array(
3288
+            $discounts[ $discount ] = array(
3289 3289
                 'amount'    => $amount,
3290 3290
                 'recurring' => (bool) $recurring,
3291 3291
             );
3292 3292
 
3293
-		} else {
3294
-			$discounts[ $discount ] = array(
3293
+        } else {
3294
+            $discounts[ $discount ] = array(
3295 3295
                 'amount'    => $amount,
3296 3296
                 'recurring' => (bool) $recurring,
3297 3297
             );
3298
-		}
3298
+        }
3299 3299
 
3300 3300
         $this->set_prop( 'discounts', $discount );
3301 3301
 
3302 3302
     }
3303 3303
 
3304 3304
     /**
3305
-	 * Retrieves a specific discount.
3306
-	 *
3307
-	 * @since 1.0.19
3308
-	 */
3309
-	public function get_discount( $discount = false ) {
3305
+     * Retrieves a specific discount.
3306
+     *
3307
+     * @since 1.0.19
3308
+     */
3309
+    public function get_discount( $discount = false ) {
3310 3310
 
3311
-		// Backwards compatibilty.
3312
-		if ( empty( $discount ) ) {
3313
-			return $this->get_total_discount();
3314
-		}
3311
+        // Backwards compatibilty.
3312
+        if ( empty( $discount ) ) {
3313
+            return $this->get_total_discount();
3314
+        }
3315 3315
 
3316 3316
         $discounts = $this->get_discounts();
3317
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3317
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3318 3318
     }
3319 3319
 
3320 3320
     /**
3321
-	 * Removes a specific discount.
3322
-	 *
3323
-	 * @since 1.0.19
3324
-	 */
3325
-	public function remove_discount( $discount ) {
3321
+     * Removes a specific discount.
3322
+     *
3323
+     * @since 1.0.19
3324
+     */
3325
+    public function remove_discount( $discount ) {
3326 3326
         $discounts = $this->get_discounts();
3327 3327
         if ( isset( $discounts[ $discount ] ) ) {
3328 3328
             unset( $discounts[ $discount ] );
@@ -3348,44 +3348,44 @@  discard block
 block discarded – undo
3348 3348
         if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) {
3349 3349
 
3350 3350
             $amount = $taxes[ $tax ]['amount'] += $amount;
3351
-			$taxes[ $tax ] = array(
3351
+            $taxes[ $tax ] = array(
3352 3352
                 'amount'    => $amount,
3353 3353
                 'recurring' => (bool) $recurring,
3354 3354
             );
3355 3355
 
3356
-		} else {
3357
-			$taxes[ $tax ] = array(
3356
+        } else {
3357
+            $taxes[ $tax ] = array(
3358 3358
                 'amount'    => $amount,
3359 3359
                 'recurring' => (bool) $recurring,
3360 3360
             );
3361
-		}
3361
+        }
3362 3362
 
3363 3363
         $this->set_prop( 'taxes', $tax );
3364 3364
 
3365 3365
     }
3366 3366
 
3367 3367
     /**
3368
-	 * Retrieves a specific tax.
3369
-	 *
3370
-	 * @since 1.0.19
3371
-	 */
3372
-	public function get_tax( $tax = null ) {
3368
+     * Retrieves a specific tax.
3369
+     *
3370
+     * @since 1.0.19
3371
+     */
3372
+    public function get_tax( $tax = null ) {
3373 3373
 
3374
-		// Backwards compatility.
3375
-		if ( empty( $tax ) ) {
3376
-			return $this->get_total_tax();
3377
-		}
3374
+        // Backwards compatility.
3375
+        if ( empty( $tax ) ) {
3376
+            return $this->get_total_tax();
3377
+        }
3378 3378
 
3379 3379
         $taxes = $this->get_taxes();
3380
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3380
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3381 3381
     }
3382 3382
 
3383 3383
     /**
3384
-	 * Removes a specific tax.
3385
-	 *
3386
-	 * @since 1.0.19
3387
-	 */
3388
-	public function remove_tax( $tax ) {
3384
+     * Removes a specific tax.
3385
+     *
3386
+     * @since 1.0.19
3387
+     */
3388
+    public function remove_tax( $tax ) {
3389 3389
         $taxes = $this->get_discounts();
3390 3390
         if ( isset( $taxes[ $tax ] ) ) {
3391 3391
             unset( $taxes[ $tax ] );
@@ -3394,160 +3394,160 @@  discard block
 block discarded – undo
3394 3394
     }
3395 3395
 
3396 3396
     /**
3397
-	 * Recalculates the invoice subtotal.
3398
-	 *
3399
-	 * @since 1.0.19
3400
-	 * @return float The recalculated subtotal
3401
-	 */
3402
-	public function recalculate_subtotal() {
3397
+     * Recalculates the invoice subtotal.
3398
+     *
3399
+     * @since 1.0.19
3400
+     * @return float The recalculated subtotal
3401
+     */
3402
+    public function recalculate_subtotal() {
3403 3403
         $items     = $this->get_items();
3404
-		$subtotal  = 0;
3405
-		$recurring = 0;
3404
+        $subtotal  = 0;
3405
+        $recurring = 0;
3406 3406
 
3407 3407
         foreach ( $items as $item ) {
3408
-			$subtotal  += $item->get_sub_total();
3409
-			$recurring += $item->get_recurring_sub_total();
3408
+            $subtotal  += $item->get_sub_total();
3409
+            $recurring += $item->get_recurring_sub_total();
3410 3410
         }
3411 3411
 
3412
-		if ( $this->is_renewal() ) {
3413
-			$this->set_subtotal( $recurring );
3414
-		} else {
3415
-			$this->set_subtotal( $subtotal );
3416
-		}
3412
+        if ( $this->is_renewal() ) {
3413
+            $this->set_subtotal( $recurring );
3414
+        } else {
3415
+            $this->set_subtotal( $subtotal );
3416
+        }
3417 3417
 
3418
-		$this->totals['subtotal'] = array(
3419
-			'initial'   => $subtotal,
3420
-			'recurring' => $recurring,
3421
-		);
3418
+        $this->totals['subtotal'] = array(
3419
+            'initial'   => $subtotal,
3420
+            'recurring' => $recurring,
3421
+        );
3422 3422
 
3423 3423
         return $this->is_renewal() ? $recurring : $subtotal;
3424 3424
     }
3425 3425
 
3426 3426
     /**
3427
-	 * Recalculates the invoice discount total.
3428
-	 *
3429
-	 * @since 1.0.19
3430
-	 * @return float The recalculated discount
3431
-	 */
3432
-	public function recalculate_total_discount() {
3427
+     * Recalculates the invoice discount total.
3428
+     *
3429
+     * @since 1.0.19
3430
+     * @return float The recalculated discount
3431
+     */
3432
+    public function recalculate_total_discount() {
3433 3433
         $discounts = $this->get_discounts();
3434
-		$discount  = 0;
3435
-		$recurring = 0;
3434
+        $discount  = 0;
3435
+        $recurring = 0;
3436 3436
 
3437 3437
         foreach ( $discounts as $data ) {
3438 3438
 
3439
-			if ( $data['recurring'] ) {
3440
-				$recurring += $data['amount'];
3441
-			} else {
3442
-				$discount += $data['amount'];
3443
-			}
3439
+            if ( $data['recurring'] ) {
3440
+                $recurring += $data['amount'];
3441
+            } else {
3442
+                $discount += $data['amount'];
3443
+            }
3444 3444
 
3445
-		}
3445
+        }
3446 3446
 
3447
-		if ( $this->is_renewal() ) {
3448
-			$this->set_total_discount( $recurring );
3449
-		} else {
3450
-			$this->set_total_discount( $discount );
3451
-		}
3447
+        if ( $this->is_renewal() ) {
3448
+            $this->set_total_discount( $recurring );
3449
+        } else {
3450
+            $this->set_total_discount( $discount );
3451
+        }
3452 3452
 
3453
-		$this->totals['discount'] = array(
3454
-			'initial'   => $discount,
3455
-			'recurring' => $recurring,
3456
-		);
3453
+        $this->totals['discount'] = array(
3454
+            'initial'   => $discount,
3455
+            'recurring' => $recurring,
3456
+        );
3457 3457
 
3458
-		return $this->is_renewal() ? $recurring : $discount;
3458
+        return $this->is_renewal() ? $recurring : $discount;
3459 3459
 
3460 3460
     }
3461 3461
 
3462 3462
     /**
3463
-	 * Recalculates the invoice tax total.
3464
-	 *
3465
-	 * @since 1.0.19
3466
-	 * @return float The recalculated tax
3467
-	 */
3468
-	public function recalculate_total_tax() {
3463
+     * Recalculates the invoice tax total.
3464
+     *
3465
+     * @since 1.0.19
3466
+     * @return float The recalculated tax
3467
+     */
3468
+    public function recalculate_total_tax() {
3469 3469
         $taxes     = $this->get_taxes();
3470
-		$tax       = 0;
3471
-		$recurring = 0;
3470
+        $tax       = 0;
3471
+        $recurring = 0;
3472 3472
 
3473 3473
         foreach ( $taxes as $data ) {
3474 3474
 
3475
-			if ( $data['recurring'] ) {
3476
-				$recurring += $data['amount'];
3477
-			} else {
3478
-				$tax += $data['amount'];
3479
-			}
3475
+            if ( $data['recurring'] ) {
3476
+                $recurring += $data['amount'];
3477
+            } else {
3478
+                $tax += $data['amount'];
3479
+            }
3480 3480
 
3481
-		}
3481
+        }
3482 3482
 
3483
-		if ( $this->is_renewal() ) {
3484
-			$this->set_total_tax( $recurring );
3485
-		} else {
3486
-			$this->set_total_tax( $tax );
3487
-		}
3483
+        if ( $this->is_renewal() ) {
3484
+            $this->set_total_tax( $recurring );
3485
+        } else {
3486
+            $this->set_total_tax( $tax );
3487
+        }
3488 3488
 
3489
-		$this->totals['tax'] = array(
3490
-			'initial'   => $tax,
3491
-			'recurring' => $recurring,
3492
-		);
3489
+        $this->totals['tax'] = array(
3490
+            'initial'   => $tax,
3491
+            'recurring' => $recurring,
3492
+        );
3493 3493
 
3494
-		return $this->is_renewal() ? $recurring : $tax;
3494
+        return $this->is_renewal() ? $recurring : $tax;
3495 3495
 
3496 3496
     }
3497 3497
 
3498 3498
     /**
3499
-	 * Recalculates the invoice fees total.
3500
-	 *
3501
-	 * @since 1.0.19
3502
-	 * @return float The recalculated fee
3503
-	 */
3504
-	public function recalculate_total_fees() {
3505
-		$fees      = $this->get_fees();
3506
-		$fee       = 0;
3507
-		$recurring = 0;
3499
+     * Recalculates the invoice fees total.
3500
+     *
3501
+     * @since 1.0.19
3502
+     * @return float The recalculated fee
3503
+     */
3504
+    public function recalculate_total_fees() {
3505
+        $fees      = $this->get_fees();
3506
+        $fee       = 0;
3507
+        $recurring = 0;
3508 3508
 
3509 3509
         foreach ( $fees as $data ) {
3510 3510
 
3511
-			if ( $data['recurring'] ) {
3512
-				$recurring += $data['amount'];
3513
-			} else {
3514
-				$fee += $data['amount'];
3515
-			}
3511
+            if ( $data['recurring'] ) {
3512
+                $recurring += $data['amount'];
3513
+            } else {
3514
+                $fee += $data['amount'];
3515
+            }
3516 3516
 
3517
-		}
3517
+        }
3518 3518
 
3519 3519
         if ( $this->is_renewal() ) {
3520
-			$this->set_total_fees( $recurring );
3521
-		} else {
3522
-			$this->set_total_fees( $fee );
3523
-		}
3520
+            $this->set_total_fees( $recurring );
3521
+        } else {
3522
+            $this->set_total_fees( $fee );
3523
+        }
3524 3524
 
3525
-		$this->totals['fee'] = array(
3526
-			'initial'   => $fee,
3527
-			'recurring' => $recurring,
3528
-		);
3525
+        $this->totals['fee'] = array(
3526
+            'initial'   => $fee,
3527
+            'recurring' => $recurring,
3528
+        );
3529 3529
 
3530 3530
         $this->set_total_fees( $fee );
3531 3531
         return $this->is_renewal() ? $recurring : $fee;
3532 3532
     }
3533 3533
 
3534 3534
     /**
3535
-	 * Recalculates the invoice total.
3536
-	 *
3537
-	 * @since 1.0.19
3535
+     * Recalculates the invoice total.
3536
+     *
3537
+     * @since 1.0.19
3538 3538
      * @return float The invoice total
3539
-	 */
3540
-	public function recalculate_total() {
3539
+     */
3540
+    public function recalculate_total() {
3541 3541
         $this->recalculate_subtotal();
3542 3542
         $this->recalculate_total_fees();
3543 3543
         $this->recalculate_total_discount();
3544 3544
         $this->recalculate_total_tax();
3545
-		return $this->get_total();
3546
-	}
3545
+        return $this->get_total();
3546
+    }
3547 3547
 
3548
-	/**
3549
-	 * @deprecated
3550
-	 */
3548
+    /**
3549
+     * @deprecated
3550
+     */
3551 3551
     public function recalculate_totals( $temp = false ) {
3552 3552
         $this->update_items( $temp );
3553 3553
         $this->save( true );
@@ -3565,7 +3565,7 @@  discard block
 block discarded – undo
3565 3565
      * Adds a note to an invoice.
3566 3566
      *
3567 3567
      * @param string $note The note being added.
3568
-	 * @return int|false The new note's ID on success, false on failure.
3568
+     * @return int|false The new note's ID on success, false on failure.
3569 3569
      *
3570 3570
      */
3571 3571
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3575,21 +3575,21 @@  discard block
 block discarded – undo
3575 3575
             return false;
3576 3576
         }
3577 3577
 
3578
-		$author       = 'System';
3579
-		$author_email = '[email protected]';
3578
+        $author       = 'System';
3579
+        $author_email = '[email protected]';
3580 3580
 
3581
-		// If this is an admin comment or it has been added by the user.
3582
-		if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3583
-			$user         = get_user_by( 'id', get_current_user_id() );
3581
+        // If this is an admin comment or it has been added by the user.
3582
+        if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3583
+            $user         = get_user_by( 'id', get_current_user_id() );
3584 3584
             $author       = $user->display_name;
3585 3585
             $author_email = $user->user_email;
3586
-		}
3586
+        }
3587 3587
 
3588
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3588
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3589 3589
 
3590
-	}
3590
+    }
3591 3591
 
3592
-	/**
3592
+    /**
3593 3593
      * Generates a unique key for the invoice.
3594 3594
      */
3595 3595
     public function generate_key( $string = '' ) {
@@ -3609,105 +3609,105 @@  discard block
 block discarded – undo
3609 3609
             $number = wpinv_get_next_invoice_number( $this->get_post_type() );
3610 3610
         }
3611 3611
 
3612
-		return wpinv_format_invoice_number( $number, $this->get_post_type() );
3612
+        return wpinv_format_invoice_number( $number, $this->get_post_type() );
3613 3613
 
3614
-	}
3614
+    }
3615 3615
 
3616
-	/**
3617
-	 * Handle the status transition.
3618
-	 */
3619
-	protected function status_transition() {
3620
-		$status_transition = $this->status_transition;
3616
+    /**
3617
+     * Handle the status transition.
3618
+     */
3619
+    protected function status_transition() {
3620
+        $status_transition = $this->status_transition;
3621 3621
 
3622
-		// Reset status transition variable.
3623
-		$this->status_transition = false;
3622
+        // Reset status transition variable.
3623
+        $this->status_transition = false;
3624 3624
 
3625
-		if ( $status_transition ) {
3626
-			try {
3625
+        if ( $status_transition ) {
3626
+            try {
3627 3627
 
3628
-				// Fire a hook for the status change.
3629
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3628
+                // Fire a hook for the status change.
3629
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3630 3630
 
3631
-				// @deprecated this is deprecated and will be removed in the future.
3632
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3631
+                // @deprecated this is deprecated and will be removed in the future.
3632
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3633 3633
 
3634
-				if ( ! empty( $status_transition['from'] ) ) {
3634
+                if ( ! empty( $status_transition['from'] ) ) {
3635 3635
 
3636
-					/* translators: 1: old invoice status 2: new invoice status */
3637
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3636
+                    /* translators: 1: old invoice status 2: new invoice status */
3637
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3638 3638
 
3639
-					// Fire another hook.
3640
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3641
-					do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3639
+                    // Fire another hook.
3640
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3641
+                    do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3642 3642
 
3643
-					// @deprecated this is deprecated and will be removed in the future.
3644
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3643
+                    // @deprecated this is deprecated and will be removed in the future.
3644
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3645 3645
 
3646
-					// Note the transition occurred.
3647
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3646
+                    // Note the transition occurred.
3647
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3648 3648
 
3649
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3650
-					if (
3651
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3652
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3653
-					) {
3654
-						do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3655
-					}
3656
-				} else {
3657
-					/* translators: %s: new invoice status */
3658
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3649
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3650
+                    if (
3651
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3652
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3653
+                    ) {
3654
+                        do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3655
+                    }
3656
+                } else {
3657
+                    /* translators: %s: new invoice status */
3658
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3659 3659
 
3660
-					// Note the transition occurred.
3661
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3660
+                    // Note the transition occurred.
3661
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3662 3662
 
3663
-				}
3664
-			} catch ( Exception $e ) {
3665
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3666
-			}
3667
-		}
3668
-	}
3663
+                }
3664
+            } catch ( Exception $e ) {
3665
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3666
+            }
3667
+        }
3668
+    }
3669 3669
 
3670
-	/**
3671
-	 * Updates an invoice status.
3672
-	 */
3673
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3670
+    /**
3671
+     * Updates an invoice status.
3672
+     */
3673
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3674 3674
 
3675
-		// Fires before updating a status.
3676
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3675
+        // Fires before updating a status.
3676
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3677 3677
 
3678
-		// Update the status.
3679
-		$this->set_status( $new_status, $note, $manual );
3678
+        // Update the status.
3679
+        $this->set_status( $new_status, $note, $manual );
3680 3680
 
3681
-		// Save the order.
3682
-		return $this->save();
3681
+        // Save the order.
3682
+        return $this->save();
3683 3683
 
3684
-	}
3684
+    }
3685 3685
 
3686
-	/**
3687
-	 * @deprecated
3688
-	 */
3689
-	public function refresh_item_ids() {
3686
+    /**
3687
+     * @deprecated
3688
+     */
3689
+    public function refresh_item_ids() {
3690 3690
         $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3691 3691
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3692
-	}
3692
+    }
3693 3693
 
3694
-	/**
3695
-	 * @deprecated
3696
-	 */
3697
-	public function update_items( $temp = false ) {
3694
+    /**
3695
+     * @deprecated
3696
+     */
3697
+    public function update_items( $temp = false ) {
3698 3698
 
3699
-		$this->set_items( $this->get_items() );
3699
+        $this->set_items( $this->get_items() );
3700 3700
 
3701
-		if ( ! $temp ) {
3702
-			$this->save();
3703
-		}
3701
+        if ( ! $temp ) {
3702
+            $this->save();
3703
+        }
3704 3704
 
3705 3705
         return $this;
3706
-	}
3706
+    }
3707 3707
 
3708
-	/**
3709
-	 * @deprecated
3710
-	 */
3708
+    /**
3709
+     * @deprecated
3710
+     */
3711 3711
     public function validate_discount() {
3712 3712
 
3713 3713
         $discount_code = $this->get_discount_code();
@@ -3723,97 +3723,97 @@  discard block
 block discarded – undo
3723 3723
 
3724 3724
     }
3725 3725
 
3726
-	/**
3727
-	 * Refunds an invoice.
3728
-	 */
3726
+    /**
3727
+     * Refunds an invoice.
3728
+     */
3729 3729
     public function refund() {
3730
-		$this->set_status( 'wpi-refunded' );
3730
+        $this->set_status( 'wpi-refunded' );
3731 3731
         $this->save();
3732
-	}
3732
+    }
3733 3733
 
3734
-	/**
3735
-	 * Marks an invoice as paid.
3736
-	 * 
3737
-	 * @param string $transaction_id
3738
-	 */
3734
+    /**
3735
+     * Marks an invoice as paid.
3736
+     * 
3737
+     * @param string $transaction_id
3738
+     */
3739 3739
     public function mark_paid( $transaction_id = null, $note = '' ) {
3740 3740
 
3741
-		// Set the transaction id.
3742
-		if ( empty( $transaction_id ) ) {
3743
-			$transaction_id = $this->generate_key('trans_');
3744
-		}
3741
+        // Set the transaction id.
3742
+        if ( empty( $transaction_id ) ) {
3743
+            $transaction_id = $this->generate_key('trans_');
3744
+        }
3745 3745
 
3746
-		if ( ! $this->get_transaction_id() ) {
3747
-			$this->set_transaction_id( $transaction_id );
3748
-		}
3746
+        if ( ! $this->get_transaction_id() ) {
3747
+            $this->set_transaction_id( $transaction_id );
3748
+        }
3749 3749
 
3750
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3751
-			return $this->save();
3752
-		}
3750
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3751
+            return $this->save();
3752
+        }
3753 3753
 
3754
-		// Set the completed date.
3755
-		$this->set_date_completed( current_time( 'mysql' ) );
3754
+        // Set the completed date.
3755
+        $this->set_date_completed( current_time( 'mysql' ) );
3756 3756
 
3757
-		// Set the new status.
3758
-		if ( $this->is_renewal() ) {
3757
+        // Set the new status.
3758
+        if ( $this->is_renewal() ) {
3759 3759
 
3760
-			$_note = sprintf(
3761
-				__( 'Renewed via %s', 'invoicing' ),
3762
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3763
-			);
3760
+            $_note = sprintf(
3761
+                __( 'Renewed via %s', 'invoicing' ),
3762
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3763
+            );
3764 3764
 
3765
-			if ( 'none' == $this->get_gateway() ) {
3766
-				$_note = $note;
3767
-			}
3765
+            if ( 'none' == $this->get_gateway() ) {
3766
+                $_note = $note;
3767
+            }
3768 3768
 
3769
-			$this->set_status( 'wpi-renewal', $_note );
3769
+            $this->set_status( 'wpi-renewal', $_note );
3770 3770
 
3771
-		} else {
3771
+        } else {
3772 3772
 
3773
-			$_note = sprintf(
3774
-				__( 'Paid via %s', 'invoicing' ),
3775
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3776
-			);
3773
+            $_note = sprintf(
3774
+                __( 'Paid via %s', 'invoicing' ),
3775
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3776
+            );
3777 3777
 
3778
-			if ( 'none' == $this->get_gateway() ) {
3779
-				$_note = $note;
3780
-			}
3778
+            if ( 'none' == $this->get_gateway() ) {
3779
+                $_note = $note;
3780
+            }
3781 3781
 
3782
-			$this->set_status( 'publish',$_note );
3782
+            $this->set_status( 'publish',$_note );
3783 3783
 
3784
-		}
3784
+        }
3785 3785
 
3786
-		// Set checkout mode.
3787
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3788
-		$this->set_mode( $mode );
3786
+        // Set checkout mode.
3787
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3788
+        $this->set_mode( $mode );
3789 3789
 
3790
-		// Save the invoice.
3790
+        // Save the invoice.
3791 3791
         $this->save();
3792
-	}
3793
-
3794
-
3795
-	/**
3796
-	 * Save data to the database.
3797
-	 *
3798
-	 * @since 1.0.19
3799
-	 * @return int invoice ID
3800
-	 */
3801
-	public function save() {
3802
-		$this->maybe_set_date_paid();
3803
-		$this->maybe_set_key();
3804
-		parent::save();
3805
-		$this->clear_cache();
3806
-		$this->status_transition();
3807
-		return $this->get_id();
3808
-	}
3809
-
3810
-	/**
3792
+    }
3793
+
3794
+
3795
+    /**
3796
+     * Save data to the database.
3797
+     *
3798
+     * @since 1.0.19
3799
+     * @return int invoice ID
3800
+     */
3801
+    public function save() {
3802
+        $this->maybe_set_date_paid();
3803
+        $this->maybe_set_key();
3804
+        parent::save();
3805
+        $this->clear_cache();
3806
+        $this->status_transition();
3807
+        return $this->get_id();
3808
+    }
3809
+
3810
+    /**
3811 3811
      * Clears the subscription's cache.
3812 3812
      */
3813 3813
     public function clear_cache() {
3814
-		wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3815
-		wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3816
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3817
-	}
3814
+        wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3815
+        wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3816
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3817
+    }
3818 3818
 
3819 3819
 }
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +371 added lines, -371 removed lines patch added patch discarded remove patch
@@ -12,423 +12,423 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => 'new_invoice',
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_invoice'                   => 'user_invoice',
40
-				'getpaid_new_customer_note'             => 'user_note',
41
-				'getpaid_daily_maintenance'             => 'overdue',
42
-
43
-			)
44
-		);
45
-
46
-		$this->init_hooks();
47
-
48
-	}
49
-
50
-	/**
51
-	 * Registers email hooks.
52
-	 */
53
-	public function init_hooks() {
54
-
55
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
56
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
57
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
58
-
59
-			$email = new GetPaid_Notification_Email( $email_type );
60
-
61
-			if ( ! $email->is_active() ) {
62
-				continue;
63
-			}
64
-
65
-			if ( method_exists( $this, $email_type ) ) {
66
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
67
-				continue;
68
-			}
69
-
70
-			do_action( 'getpaid_invoice_notification_email_register_hook', $email );
71
-
72
-		}
73
-
74
-	}
75
-
76
-	/**
77
-	 * Filters invoice merge tags.
78
-	 *
79
-	 * @param array $merge_tags
80
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
81
-	 */
82
-	public function invoice_merge_tags( $merge_tags, $object ) {
83
-
84
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
85
-			return array_merge(
86
-				$merge_tags,
87
-				$this->get_invoice_merge_tags( $object )
88
-			);
89
-		}
90
-
91
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
92
-			return array_merge(
93
-				$merge_tags,
94
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
95
-			);
96
-		}
97
-
98
-		return $merge_tags;
99
-
100
-	}
101
-
102
-	/**
103
-	 * Generates invoice merge tags.
104
-	 *
105
-	 * @param WPInv_Invoice $invoice
106
-	 * @return array
107
-	 */
108
-	public function get_invoice_merge_tags( $invoice ) {
109
-
110
-		// Abort if it does not exist.
111
-		if ( ! $invoice->get_id() ) {
112
-			return array();
113
-		}
114
-
115
-		return array(
116
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
117
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
118
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
119
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
120
-			'{email}'               => sanitize_email( $invoice->get_email() ),
121
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
122
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
123
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
124
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
125
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
126
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
127
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
128
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
129
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
130
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
131
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
132
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
133
-		);
134
-
135
-	}
136
-
137
-	/**
138
-	 * Helper function to send an email.
139
-	 *
140
-	 * @param WPInv_Invoice $invoice
141
-	 * @param GetPaid_Notification_Email $email
142
-	 * @param string $type
143
-	 * @param string|array $recipients
144
-	 * @param array $extra_args Extra template args.
145
-	 */
146
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
147
-
148
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
149
-
150
-		$mailer     = new GetPaid_Notification_Email_Sender();
151
-		$merge_tags = $email->get_merge_tags();
152
-
153
-		$result = $mailer->send(
154
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
155
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
156
-			$email->get_content( $merge_tags, $extra_args ),
157
-			$email->get_attachments()
158
-		);
159
-
160
-		// Maybe send a copy to the admin.
161
-		if ( $email->include_admin_bcc() ) {
162
-			$mailer->send(
163
-				wpinv_get_admin_email(),
164
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
165
-				$email->get_content( $merge_tags ),
166
-				$email->get_attachments()
167
-			);
168
-		}
169
-
170
-		if ( ! $result ) {
171
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
172
-		}
173
-
174
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
175
-
176
-		return $result;
177
-	}
178
-
179
-	/**
180
-	 * Also send emails to any cc users.
181
-	 *
182
-	 * @param array $recipients
183
-	 * @param GetPaid_Notification_Email $email
184
-	 */
185
-	public function filter_email_recipients( $recipients, $email ) {
186
-
187
-		if ( ! $email->is_admin_email() ) {
188
-			$cc = $email->object->get_email_cc();
189
-
190
-			if ( ! empty( $cc ) ) {
191
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
192
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
193
-			}
194
-
195
-		}
196
-
197
-		return $recipients;
198
-
199
-	}
200
-
201
-	/**
202
-	 * Sends a new invoice notification.
203
-	 *
204
-	 * @param WPInv_Invoice $invoice
205
-	 */
206
-	public function new_invoice( $invoice ) {
207
-
208
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
209
-		$recipient = wpinv_get_admin_email();
210
-
211
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
212
-
213
-	}
214
-
215
-	/**
216
-	 * Sends a cancelled invoice notification.
217
-	 *
218
-	 * @param WPInv_Invoice $invoice
219
-	 */
220
-	public function cancelled_invoice( $invoice ) {
221
-
222
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
223
-		$recipient = wpinv_get_admin_email();
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => 'new_invoice',
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_invoice'                   => 'user_invoice',
40
+                'getpaid_new_customer_note'             => 'user_note',
41
+                'getpaid_daily_maintenance'             => 'overdue',
42
+
43
+            )
44
+        );
45
+
46
+        $this->init_hooks();
47
+
48
+    }
49
+
50
+    /**
51
+     * Registers email hooks.
52
+     */
53
+    public function init_hooks() {
54
+
55
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
56
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
57
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
58
+
59
+            $email = new GetPaid_Notification_Email( $email_type );
60
+
61
+            if ( ! $email->is_active() ) {
62
+                continue;
63
+            }
64
+
65
+            if ( method_exists( $this, $email_type ) ) {
66
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
67
+                continue;
68
+            }
69
+
70
+            do_action( 'getpaid_invoice_notification_email_register_hook', $email );
71
+
72
+        }
73
+
74
+    }
75
+
76
+    /**
77
+     * Filters invoice merge tags.
78
+     *
79
+     * @param array $merge_tags
80
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
81
+     */
82
+    public function invoice_merge_tags( $merge_tags, $object ) {
83
+
84
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
85
+            return array_merge(
86
+                $merge_tags,
87
+                $this->get_invoice_merge_tags( $object )
88
+            );
89
+        }
90
+
91
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
92
+            return array_merge(
93
+                $merge_tags,
94
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
95
+            );
96
+        }
97
+
98
+        return $merge_tags;
99
+
100
+    }
101
+
102
+    /**
103
+     * Generates invoice merge tags.
104
+     *
105
+     * @param WPInv_Invoice $invoice
106
+     * @return array
107
+     */
108
+    public function get_invoice_merge_tags( $invoice ) {
109
+
110
+        // Abort if it does not exist.
111
+        if ( ! $invoice->get_id() ) {
112
+            return array();
113
+        }
114
+
115
+        return array(
116
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
117
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
118
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
119
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
120
+            '{email}'               => sanitize_email( $invoice->get_email() ),
121
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
122
+            '{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
123
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
124
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
125
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
126
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
127
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
128
+            '{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
129
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
130
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
131
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
132
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
133
+        );
134
+
135
+    }
136
+
137
+    /**
138
+     * Helper function to send an email.
139
+     *
140
+     * @param WPInv_Invoice $invoice
141
+     * @param GetPaid_Notification_Email $email
142
+     * @param string $type
143
+     * @param string|array $recipients
144
+     * @param array $extra_args Extra template args.
145
+     */
146
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
147
+
148
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
149
+
150
+        $mailer     = new GetPaid_Notification_Email_Sender();
151
+        $merge_tags = $email->get_merge_tags();
152
+
153
+        $result = $mailer->send(
154
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
155
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
156
+            $email->get_content( $merge_tags, $extra_args ),
157
+            $email->get_attachments()
158
+        );
159
+
160
+        // Maybe send a copy to the admin.
161
+        if ( $email->include_admin_bcc() ) {
162
+            $mailer->send(
163
+                wpinv_get_admin_email(),
164
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
165
+                $email->get_content( $merge_tags ),
166
+                $email->get_attachments()
167
+            );
168
+        }
169
+
170
+        if ( ! $result ) {
171
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
172
+        }
173
+
174
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
175
+
176
+        return $result;
177
+    }
178
+
179
+    /**
180
+     * Also send emails to any cc users.
181
+     *
182
+     * @param array $recipients
183
+     * @param GetPaid_Notification_Email $email
184
+     */
185
+    public function filter_email_recipients( $recipients, $email ) {
186
+
187
+        if ( ! $email->is_admin_email() ) {
188
+            $cc = $email->object->get_email_cc();
189
+
190
+            if ( ! empty( $cc ) ) {
191
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
192
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
193
+            }
194
+
195
+        }
196
+
197
+        return $recipients;
198
+
199
+    }
200
+
201
+    /**
202
+     * Sends a new invoice notification.
203
+     *
204
+     * @param WPInv_Invoice $invoice
205
+     */
206
+    public function new_invoice( $invoice ) {
207
+
208
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
209
+        $recipient = wpinv_get_admin_email();
210
+
211
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
212
+
213
+    }
214
+
215
+    /**
216
+     * Sends a cancelled invoice notification.
217
+     *
218
+     * @param WPInv_Invoice $invoice
219
+     */
220
+    public function cancelled_invoice( $invoice ) {
221
+
222
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
223
+        $recipient = wpinv_get_admin_email();
224 224
 
225
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
225
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
226 226
 
227
-	}
227
+    }
228 228
 
229
-	/**
230
-	 * Sends a failed invoice notification.
231
-	 *
232
-	 * @param WPInv_Invoice $invoice
233
-	 */
234
-	public function failed_invoice( $invoice ) {
229
+    /**
230
+     * Sends a failed invoice notification.
231
+     *
232
+     * @param WPInv_Invoice $invoice
233
+     */
234
+    public function failed_invoice( $invoice ) {
235 235
 
236
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
237
-		$recipient = wpinv_get_admin_email();
238
-
239
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
236
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
237
+        $recipient = wpinv_get_admin_email();
238
+
239
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
240 240
 
241
-	}
241
+    }
242 242
 
243
-	/**
244
-	 * Sends a notification whenever an invoice is put on hold.
245
-	 *
246
-	 * @param WPInv_Invoice $invoice
247
-	 */
248
-	public function onhold_invoice( $invoice ) {
243
+    /**
244
+     * Sends a notification whenever an invoice is put on hold.
245
+     *
246
+     * @param WPInv_Invoice $invoice
247
+     */
248
+    public function onhold_invoice( $invoice ) {
249 249
 
250
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
251
-		$recipient = $invoice->get_email();
250
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
251
+        $recipient = $invoice->get_email();
252 252
 
253
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
253
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
254 254
 
255
-	}
255
+    }
256 256
 
257
-	/**
258
-	 * Sends a notification whenever an invoice is marked as processing payment.
259
-	 *
260
-	 * @param WPInv_Invoice $invoice
261
-	 */
262
-	public function processing_invoice( $invoice ) {
257
+    /**
258
+     * Sends a notification whenever an invoice is marked as processing payment.
259
+     *
260
+     * @param WPInv_Invoice $invoice
261
+     */
262
+    public function processing_invoice( $invoice ) {
263 263
 
264
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
265
-		$recipient = $invoice->get_email();
264
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
265
+        $recipient = $invoice->get_email();
266 266
 
267
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
267
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
268 268
 
269
-	}
269
+    }
270 270
 
271
-	/**
272
-	 * Sends a notification whenever an invoice is paid.
273
-	 *
274
-	 * @param WPInv_Invoice $invoice
275
-	 */
276
-	public function completed_invoice( $invoice ) {
271
+    /**
272
+     * Sends a notification whenever an invoice is paid.
273
+     *
274
+     * @param WPInv_Invoice $invoice
275
+     */
276
+    public function completed_invoice( $invoice ) {
277 277
 
278
-		// (Maybe) abort if it is a renewal invoice.
279
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
280
-			return;
281
-		}
278
+        // (Maybe) abort if it is a renewal invoice.
279
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
280
+            return;
281
+        }
282 282
 
283
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
-		$recipient = $invoice->get_email();
283
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
+        $recipient = $invoice->get_email();
285 285
 
286
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
286
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287 287
 
288
-	}
288
+    }
289 289
 
290
-	/**
291
-	 * Sends a notification whenever an invoice is refunded.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice
294
-	 */
295
-	public function refunded_invoice( $invoice ) {
290
+    /**
291
+     * Sends a notification whenever an invoice is refunded.
292
+     *
293
+     * @param WPInv_Invoice $invoice
294
+     */
295
+    public function refunded_invoice( $invoice ) {
296 296
 
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
-		$recipient = $invoice->get_email();
297
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+        $recipient = $invoice->get_email();
299 299
 
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
300
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301 301
 
302
-	}
302
+    }
303 303
 
304
-	/**
305
-	 * Notifies a user about new invoices
306
-	 *
307
-	 * @param WPInv_Invoice $invoice
308
-	 */
309
-	public function user_invoice( $invoice ) {
304
+    /**
305
+     * Notifies a user about new invoices
306
+     *
307
+     * @param WPInv_Invoice $invoice
308
+     */
309
+    public function user_invoice( $invoice ) {
310 310
 
311
-		// Only send this email for invoices created via the admin page.
312
-		if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
313
-			return;
314
-		}
311
+        // Only send this email for invoices created via the admin page.
312
+        if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
313
+            return;
314
+        }
315 315
 
316
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
-		$recipient = $invoice->get_email();
316
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
+        $recipient = $invoice->get_email();
318 318
 
319
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
319
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
320 320
 
321
-	}
321
+    }
322 322
 
323
-	/**
324
-	 * Checks if an invoice is a payment form invoice.
325
-	 *
326
-	 * @param int $invoice
327
-	 * @return bool
328
-	 */
329
-	public function is_payment_form_invoice( $invoice ) {
330
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
331
-	}
323
+    /**
324
+     * Checks if an invoice is a payment form invoice.
325
+     *
326
+     * @param int $invoice
327
+     * @return bool
328
+     */
329
+    public function is_payment_form_invoice( $invoice ) {
330
+        return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
331
+    }
332 332
 
333
-	/**
334
-	 * Notifies admin about new invoice notes
335
-	 *
336
-	 * @param WPInv_Invoice $invoice
337
-	 * @param string $note
338
-	 */
339
-	public function user_note( $invoice, $note ) {
333
+    /**
334
+     * Notifies admin about new invoice notes
335
+     *
336
+     * @param WPInv_Invoice $invoice
337
+     * @param string $note
338
+     */
339
+    public function user_note( $invoice, $note ) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
-		$recipient = $invoice->get_email();
343
-
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
345
-
346
-	}
341
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+        $recipient = $invoice->get_email();
343
+
344
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
345
+
346
+    }
347 347
 
348
-	/**
349
-	 * (Force) Sends overdue notices.
350
-	 *
351
-	 * @param WPInv_Invoice $invoice
352
-	 */
353
-	public function force_send_overdue_notice( $invoice ) {
354
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
355
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
356
-	}
357
-
358
-	/**
359
-	 * Sends overdue notices.
360
-	 *
361
-	 * @TODO: Create an invoices query class.
362
-	 */
363
-	public function overdue() {
364
-		global $wpdb;
365
-
366
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
367
-
368
-		// Fetch reminder days.
369
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
370
-
371
-		// Abort if non is set.
372
-		if ( empty( $reminder_days ) ) {
373
-			return;
374
-		}
375
-
376
-		// Retrieve date query.
377
-		$date_query = $this->get_date_query( $reminder_days );
378
-
379
-		// Invoices table.
380
-		$table = $wpdb->prefix . 'getpaid_invoices';
381
-
382
-		// Fetch invoices.
383
-		$invoices  = $wpdb->get_col(
384
-			"SELECT posts.ID FROM $wpdb->posts as posts
348
+    /**
349
+     * (Force) Sends overdue notices.
350
+     *
351
+     * @param WPInv_Invoice $invoice
352
+     */
353
+    public function force_send_overdue_notice( $invoice ) {
354
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
355
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
356
+    }
357
+
358
+    /**
359
+     * Sends overdue notices.
360
+     *
361
+     * @TODO: Create an invoices query class.
362
+     */
363
+    public function overdue() {
364
+        global $wpdb;
365
+
366
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
367
+
368
+        // Fetch reminder days.
369
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
370
+
371
+        // Abort if non is set.
372
+        if ( empty( $reminder_days ) ) {
373
+            return;
374
+        }
375
+
376
+        // Retrieve date query.
377
+        $date_query = $this->get_date_query( $reminder_days );
378
+
379
+        // Invoices table.
380
+        $table = $wpdb->prefix . 'getpaid_invoices';
381
+
382
+        // Fetch invoices.
383
+        $invoices  = $wpdb->get_col(
384
+            "SELECT posts.ID FROM $wpdb->posts as posts
385 385
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
386 386
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
387 387
 
388
-		foreach ( $invoices as $invoice ) {
388
+        foreach ( $invoices as $invoice ) {
389 389
 
390
-			// Only send this email for invoices created via the admin page.
391
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
392
-				$invoice       = new WPInv_Invoice( $invoice );
393
-				$email->object = $invoice;
390
+            // Only send this email for invoices created via the admin page.
391
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
392
+                $invoice       = new WPInv_Invoice( $invoice );
393
+                $email->object = $invoice;
394 394
 
395
-				if ( $invoice->needs_payment() ) {
396
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
397
-				}
395
+                if ( $invoice->needs_payment() ) {
396
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
397
+                }
398 398
 
399
-			}
399
+            }
400 400
 
401
-		}
401
+        }
402 402
 
403
-	}
403
+    }
404 404
 
405
-	/**
406
-	 * Calculates the date query for an invoices query
407
-	 *
408
-	 * @param array $reminder_days
409
-	 * @return string
410
-	 */
411
-	public function get_date_query( $reminder_days ) {
405
+    /**
406
+     * Calculates the date query for an invoices query
407
+     *
408
+     * @param array $reminder_days
409
+     * @return string
410
+     */
411
+    public function get_date_query( $reminder_days ) {
412 412
 
413
-		$date_query = array(
414
-			'relation'  => 'OR'
415
-		);
413
+        $date_query = array(
414
+            'relation'  => 'OR'
415
+        );
416 416
 
417
-		foreach ( $reminder_days as $days ) {
418
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
417
+        foreach ( $reminder_days as $days ) {
418
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
419 419
 
420
-			$date_query[] = array(
421
-				'year'  => $date['year'],
422
-				'month' => $date['month'],
423
-				'day'   => $date['day'],
424
-			);
420
+            $date_query[] = array(
421
+                'year'  => $date['year'],
422
+                'month' => $date['month'],
423
+                'day'   => $date['day'],
424
+            );
425 425
 
426
-		}
426
+        }
427 427
 
428
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
428
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
429 429
 
430
-		return $date_query->get_sql();
430
+        return $date_query->get_sql();
431 431
 
432
-	}
432
+    }
433 433
 
434 434
 }
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 1 patch
Indentation   +986 added lines, -986 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,996 +11,996 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Input {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function input($args = array()){
22
-		$defaults = array(
23
-			'type'       => 'text',
24
-			'name'       => '',
25
-			'class'      => '',
26
-			'id'         => '',
27
-			'placeholder'=> '',
28
-			'title'      => '',
29
-			'value'      => '',
30
-			'required'   => false,
31
-			'label'      => '',
32
-			'label_after'=> false,
33
-			'label_class'=> '',
34
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
35
-			'help_text'  => '',
36
-			'validation_text'   => '',
37
-			'validation_pattern' => '',
38
-			'no_wrap'    => false,
39
-			'input_group_right' => '',
40
-			'input_group_left' => '',
41
-			'input_group_right_inside' => false, // forces the input group inside the input
42
-			'input_group_left_inside' => false, // forces the input group inside the input
43
-			'step'       => '',
44
-			'switch'     => false, // to show checkbox as a switch
45
-			'checked'   => false, // set a checkbox or radio as selected
46
-			'password_toggle' => true, // toggle view/hide password
47
-			'element_require'   => '', // [%element_id%] == "1"
48
-			'extra_attributes'  => array() // an array of extra attributes
49
-		);
50
-
51
-		/**
52
-		 * Parse incoming $args into an array and merge it with $defaults
53
-		 */
54
-		$args   = wp_parse_args( $args, $defaults );
55
-		$output = '';
56
-		if ( ! empty( $args['type'] ) ) {
57
-			// hidden label option needs to be empty
58
-			$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
59
-
60
-			$type = sanitize_html_class( $args['type'] );
61
-
62
-			$help_text = '';
63
-			$label = '';
64
-			$label_after = $args['label_after'];
65
-			$label_args = array(
66
-				'title'=> $args['label'],
67
-				'for'=> $args['id'],
68
-				'class' => $args['label_class']." ",
69
-				'label_type' => $args['label_type']
70
-			);
71
-
72
-			// floating labels need label after
73
-			if( $args['label_type'] == 'floating' && $type != 'checkbox' ){
74
-				$label_after = true;
75
-				$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
76
-			}
77
-
78
-			// Some special sauce for files
79
-			if($type=='file' ){
80
-				$label_after = true; // if type file we need the label after
81
-				$args['class'] .= ' custom-file-input ';
82
-			}elseif($type=='checkbox'){
83
-				$label_after = true; // if type file we need the label after
84
-				$args['class'] .= ' custom-control-input ';
85
-			}elseif($type=='datepicker' || $type=='timepicker'){
86
-				$type = 'text';
87
-				//$args['class'] .= ' aui-flatpickr bg-initial ';
88
-				$args['class'] .= ' bg-initial ';
89
-
90
-				$args['extra_attributes']['data-aui-init'] = 'flatpickr';
91
-				// enqueue the script
92
-				$aui_settings = AyeCode_UI_Settings::instance();
93
-				$aui_settings->enqueue_flatpickr();
94
-			}
95
-
96
-
97
-			// open/type
98
-			$output .= '<input type="' . $type . '" ';
99
-
100
-			// name
101
-			if(!empty($args['name'])){
102
-				$output .= ' name="'.esc_attr($args['name']).'" ';
103
-			}
104
-
105
-			// id
106
-			if(!empty($args['id'])){
107
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
108
-			}
109
-
110
-			// placeholder
111
-			if(!empty($args['placeholder'])){
112
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
113
-			}
114
-
115
-			// title
116
-			if(!empty($args['title'])){
117
-				$output .= ' title="'.esc_attr($args['title']).'" ';
118
-			}
119
-
120
-			// value
121
-			if(!empty($args['value'])){
122
-				$output .= ' value="'.sanitize_text_field($args['value']).'" ';
123
-			}
124
-
125
-			// checked, for radio and checkboxes
126
-			if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
127
-				$output .= ' checked ';
128
-			}
129
-
130
-			// validation text
131
-			if(!empty($args['validation_text'])){
132
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
133
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
134
-			}
135
-
136
-			// validation_pattern
137
-			if(!empty($args['validation_pattern'])){
138
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
139
-			}
140
-
141
-			// step (for numbers)
142
-			if(!empty($args['step'])){
143
-				$output .= ' step="'.$args['step'].'" ';
144
-			}
145
-
146
-			// required
147
-			if(!empty($args['required'])){
148
-				$output .= ' required ';
149
-			}
150
-
151
-			// class
152
-			$class = !empty($args['class']) ? $args['class'] : '';
153
-			$output .= ' class="form-control '.$class.'" ';
154
-
155
-			// data-attributes
156
-			$output .= AUI_Component_Helper::data_attributes($args);
157
-
158
-			// extra attributes
159
-			if(!empty($args['extra_attributes'])){
160
-				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
161
-			}
162
-
163
-			// close
164
-			$output .= ' >';
165
-
166
-
167
-			// label
168
-			if(!empty($args['label'])){
169
-				if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
170
-				elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
171
-				$label = self::label( $label_args, $type );
172
-			}
173
-
174
-			// help text
175
-			if(!empty($args['help_text'])){
176
-				$help_text = AUI_Component_Helper::help_text($args['help_text']);
177
-			}
178
-
179
-
180
-			// set help text in the correct possition
181
-			if($label_after){
182
-				$output .= $label . $help_text;
183
-			}
184
-
185
-			// some input types need a separate wrap
186
-			if($type == 'file') {
187
-				$output = self::wrap( array(
188
-					'content' => $output,
189
-					'class'   => 'form-group custom-file'
190
-				) );
191
-			}elseif($type == 'checkbox'){
192
-				$wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
193
-				$output = self::wrap( array(
194
-					'content' => $output,
195
-					'class'   => 'custom-control '.$wrap_class
196
-				) );
197
-
198
-				if($args['label_type']=='horizontal'){
199
-					$output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
200
-				}
201
-			}elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
202
-
203
-
204
-				// allow password field to toggle view
205
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function input($args = array()){
22
+        $defaults = array(
23
+            'type'       => 'text',
24
+            'name'       => '',
25
+            'class'      => '',
26
+            'id'         => '',
27
+            'placeholder'=> '',
28
+            'title'      => '',
29
+            'value'      => '',
30
+            'required'   => false,
31
+            'label'      => '',
32
+            'label_after'=> false,
33
+            'label_class'=> '',
34
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
35
+            'help_text'  => '',
36
+            'validation_text'   => '',
37
+            'validation_pattern' => '',
38
+            'no_wrap'    => false,
39
+            'input_group_right' => '',
40
+            'input_group_left' => '',
41
+            'input_group_right_inside' => false, // forces the input group inside the input
42
+            'input_group_left_inside' => false, // forces the input group inside the input
43
+            'step'       => '',
44
+            'switch'     => false, // to show checkbox as a switch
45
+            'checked'   => false, // set a checkbox or radio as selected
46
+            'password_toggle' => true, // toggle view/hide password
47
+            'element_require'   => '', // [%element_id%] == "1"
48
+            'extra_attributes'  => array() // an array of extra attributes
49
+        );
50
+
51
+        /**
52
+         * Parse incoming $args into an array and merge it with $defaults
53
+         */
54
+        $args   = wp_parse_args( $args, $defaults );
55
+        $output = '';
56
+        if ( ! empty( $args['type'] ) ) {
57
+            // hidden label option needs to be empty
58
+            $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
59
+
60
+            $type = sanitize_html_class( $args['type'] );
61
+
62
+            $help_text = '';
63
+            $label = '';
64
+            $label_after = $args['label_after'];
65
+            $label_args = array(
66
+                'title'=> $args['label'],
67
+                'for'=> $args['id'],
68
+                'class' => $args['label_class']." ",
69
+                'label_type' => $args['label_type']
70
+            );
71
+
72
+            // floating labels need label after
73
+            if( $args['label_type'] == 'floating' && $type != 'checkbox' ){
74
+                $label_after = true;
75
+                $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
76
+            }
77
+
78
+            // Some special sauce for files
79
+            if($type=='file' ){
80
+                $label_after = true; // if type file we need the label after
81
+                $args['class'] .= ' custom-file-input ';
82
+            }elseif($type=='checkbox'){
83
+                $label_after = true; // if type file we need the label after
84
+                $args['class'] .= ' custom-control-input ';
85
+            }elseif($type=='datepicker' || $type=='timepicker'){
86
+                $type = 'text';
87
+                //$args['class'] .= ' aui-flatpickr bg-initial ';
88
+                $args['class'] .= ' bg-initial ';
89
+
90
+                $args['extra_attributes']['data-aui-init'] = 'flatpickr';
91
+                // enqueue the script
92
+                $aui_settings = AyeCode_UI_Settings::instance();
93
+                $aui_settings->enqueue_flatpickr();
94
+            }
95
+
96
+
97
+            // open/type
98
+            $output .= '<input type="' . $type . '" ';
99
+
100
+            // name
101
+            if(!empty($args['name'])){
102
+                $output .= ' name="'.esc_attr($args['name']).'" ';
103
+            }
104
+
105
+            // id
106
+            if(!empty($args['id'])){
107
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
108
+            }
109
+
110
+            // placeholder
111
+            if(!empty($args['placeholder'])){
112
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
113
+            }
114
+
115
+            // title
116
+            if(!empty($args['title'])){
117
+                $output .= ' title="'.esc_attr($args['title']).'" ';
118
+            }
119
+
120
+            // value
121
+            if(!empty($args['value'])){
122
+                $output .= ' value="'.sanitize_text_field($args['value']).'" ';
123
+            }
124
+
125
+            // checked, for radio and checkboxes
126
+            if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
127
+                $output .= ' checked ';
128
+            }
129
+
130
+            // validation text
131
+            if(!empty($args['validation_text'])){
132
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
133
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
134
+            }
135
+
136
+            // validation_pattern
137
+            if(!empty($args['validation_pattern'])){
138
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
139
+            }
140
+
141
+            // step (for numbers)
142
+            if(!empty($args['step'])){
143
+                $output .= ' step="'.$args['step'].'" ';
144
+            }
145
+
146
+            // required
147
+            if(!empty($args['required'])){
148
+                $output .= ' required ';
149
+            }
150
+
151
+            // class
152
+            $class = !empty($args['class']) ? $args['class'] : '';
153
+            $output .= ' class="form-control '.$class.'" ';
154
+
155
+            // data-attributes
156
+            $output .= AUI_Component_Helper::data_attributes($args);
157
+
158
+            // extra attributes
159
+            if(!empty($args['extra_attributes'])){
160
+                $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
161
+            }
162
+
163
+            // close
164
+            $output .= ' >';
165
+
166
+
167
+            // label
168
+            if(!empty($args['label'])){
169
+                if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
170
+                elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
171
+                $label = self::label( $label_args, $type );
172
+            }
173
+
174
+            // help text
175
+            if(!empty($args['help_text'])){
176
+                $help_text = AUI_Component_Helper::help_text($args['help_text']);
177
+            }
178
+
179
+
180
+            // set help text in the correct possition
181
+            if($label_after){
182
+                $output .= $label . $help_text;
183
+            }
184
+
185
+            // some input types need a separate wrap
186
+            if($type == 'file') {
187
+                $output = self::wrap( array(
188
+                    'content' => $output,
189
+                    'class'   => 'form-group custom-file'
190
+                ) );
191
+            }elseif($type == 'checkbox'){
192
+                $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
193
+                $output = self::wrap( array(
194
+                    'content' => $output,
195
+                    'class'   => 'custom-control '.$wrap_class
196
+                ) );
197
+
198
+                if($args['label_type']=='horizontal'){
199
+                    $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
200
+                }
201
+            }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
202
+
203
+
204
+                // allow password field to toggle view
205
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
206 206
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
207 207
 var $eli = jQuery(this).parent().parent().find(\'input\');
208 208
 if($el.hasClass(\'fa-eye\'))
209 209
 {$eli.attr(\'type\',\'text\');}
210 210
 else{$eli.attr(\'type\',\'password\');}"
211 211
 ><i class="far fa-fw fa-eye-slash"></i></span>';
212
-			}
213
-
214
-			// input group wraps
215
-			if($args['input_group_left'] || $args['input_group_right']){
216
-				$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
217
-				if($args['input_group_left']){
218
-					$output = self::wrap( array(
219
-						'content' => $output,
220
-						'class'   => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100  : 'input-group',
221
-						'input_group_left' => $args['input_group_left'],
222
-						'input_group_left_inside'    => $args['input_group_left_inside']
223
-					) );
224
-				}
225
-				if($args['input_group_right']){
226
-					$output = self::wrap( array(
227
-						'content' => $output,
228
-						'class'   => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group',
229
-						'input_group_right' => $args['input_group_right'],
230
-						'input_group_right_inside'    => $args['input_group_right_inside']
231
-					) );
232
-				}
233
-
234
-			}
235
-
236
-			if(!$label_after){
237
-				$output .= $help_text;
238
-			}
239
-
240
-
241
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
242
-				$output = self::wrap( array(
243
-					'content' => $output,
244
-					'class'   => 'col-sm-10',
245
-				) );
246
-			}
247
-
248
-			if(!$label_after){
249
-				$output = $label . $output;
250
-			}
251
-
252
-			// wrap
253
-			if(!$args['no_wrap']){
254
-
255
-				$form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
256
-				$wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
257
-				$output = self::wrap(array(
258
-					'content' => $output,
259
-					'class'   => $wrap_class,
260
-					'element_require'   => $args['element_require'],
261
-					'argument_id'  => $args['id']
262
-				));
263
-			}
264
-
265
-
266
-
267
-		}
268
-
269
-		return $output;
270
-	}
271
-
272
-	/**
273
-	 * Build the component.
274
-	 *
275
-	 * @param array $args
276
-	 *
277
-	 * @return string The rendered component.
278
-	 */
279
-	public static function textarea($args = array()){
280
-		$defaults = array(
281
-			'name'       => '',
282
-			'class'      => '',
283
-			'id'         => '',
284
-			'placeholder'=> '',
285
-			'title'      => '',
286
-			'value'      => '',
287
-			'required'   => false,
288
-			'label'      => '',
289
-			'label_after'=> false,
290
-			'label_class'      => '',
291
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
292
-			'help_text'  => '',
293
-			'validation_text'   => '',
294
-			'validation_pattern' => '',
295
-			'no_wrap'    => false,
296
-			'rows'      => '',
297
-			'wysiwyg'   => false,
298
-			'element_require'   => '', // [%element_id%] == "1"
299
-		);
300
-
301
-		/**
302
-		 * Parse incoming $args into an array and merge it with $defaults
303
-		 */
304
-		$args   = wp_parse_args( $args, $defaults );
305
-		$output = '';
306
-
307
-		// hidden label option needs to be empty
308
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
309
-
310
-		// floating labels don't work with wysiwyg so set it as top
311
-		if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){
312
-			$args['label_type'] = 'top';
313
-		}
314
-
315
-		$label_after = $args['label_after'];
316
-
317
-		// floating labels need label after
318
-		if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){
319
-			$label_after = true;
320
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
321
-		}
322
-
323
-		// label
324
-		if(!empty($args['label']) && is_array($args['label'])){
325
-		}elseif(!empty($args['label']) && !$label_after){
326
-			$label_args = array(
327
-				'title'=> $args['label'],
328
-				'for'=> $args['id'],
329
-				'class' => $args['label_class']." ",
330
-				'label_type' => $args['label_type']
331
-			);
332
-			$output .= self::label( $label_args );
333
-		}
334
-
335
-		// maybe horizontal label
336
-		if($args['label_type']=='horizontal'){
337
-			$output .= '<div class="col-sm-10">';
338
-		}
339
-
340
-		if(!empty($args['wysiwyg'])){
341
-			ob_start();
342
-			$content = $args['value'];
343
-			$editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
344
-			$settings = array(
345
-				'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
346
-				'quicktags'     => false,
347
-				'media_buttons' => false,
348
-				'editor_class'  => 'form-control',
349
-				'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
350
-				'teeny'         => true,
351
-			);
352
-
353
-			// maybe set settings if array
354
-			if(is_array($args['wysiwyg'])){
355
-				$settings  = wp_parse_args( $args['wysiwyg'], $settings );
356
-			}
357
-
358
-			wp_editor( $content, $editor_id, $settings );
359
-			$output .= ob_get_clean();
360
-		}else{
361
-
362
-			// open
363
-			$output .= '<textarea ';
364
-
365
-			// name
366
-			if(!empty($args['name'])){
367
-				$output .= ' name="'.sanitize_html_class($args['name']).'" ';
368
-			}
369
-
370
-			// id
371
-			if(!empty($args['id'])){
372
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
373
-			}
374
-
375
-			// placeholder
376
-			if(!empty($args['placeholder'])){
377
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
378
-			}
379
-
380
-			// title
381
-			if(!empty($args['title'])){
382
-				$output .= ' title="'.esc_attr($args['title']).'" ';
383
-			}
384
-
385
-			// validation text
386
-			if(!empty($args['validation_text'])){
387
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
388
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
389
-			}
390
-
391
-			// validation_pattern
392
-			if(!empty($args['validation_pattern'])){
393
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
394
-			}
395
-
396
-			// required
397
-			if(!empty($args['required'])){
398
-				$output .= ' required ';
399
-			}
400
-
401
-			// rows
402
-			if(!empty($args['rows'])){
403
-				$output .= ' rows="'.absint($args['rows']).'" ';
404
-			}
405
-
406
-
407
-			// class
408
-			$class = !empty($args['class']) ? $args['class'] : '';
409
-			$output .= ' class="form-control '.$class.'" ';
410
-
411
-
412
-			// close tag
413
-			$output .= ' >';
414
-
415
-			// value
416
-			if(!empty($args['value'])){
417
-				$output .= sanitize_textarea_field($args['value']);
418
-			}
419
-
420
-			// closing tag
421
-			$output .= '</textarea>';
422
-
423
-		}
424
-
425
-		if(!empty($args['label']) && $label_after){
426
-			$label_args = array(
427
-				'title'=> $args['label'],
428
-				'for'=> $args['id'],
429
-				'class' => $args['label_class']." ",
430
-				'label_type' => $args['label_type']
431
-			);
432
-			$output .= self::label( $label_args );
433
-		}
434
-
435
-		// help text
436
-		if(!empty($args['help_text'])){
437
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
438
-		}
439
-
440
-		// maybe horizontal label
441
-		if($args['label_type']=='horizontal'){
442
-			$output .= '</div>';
443
-		}
444
-
445
-
446
-		// wrap
447
-		if(!$args['no_wrap']){
448
-			$form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group';
449
-			$wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
450
-			$output = self::wrap(array(
451
-				'content' => $output,
452
-				'class'   => $wrap_class,
453
-				'element_require'   => $args['element_require'],
454
-				'argument_id'  => $args['id']
455
-			));
456
-		}
457
-
458
-
459
-		return $output;
460
-	}
461
-
462
-	public static function label($args = array(), $type = ''){
463
-		//<label for="exampleInputEmail1">Email address</label>
464
-		$defaults = array(
465
-			'title'       => 'div',
466
-			'for'      => '',
467
-			'class'      => '',
468
-			'label_type'    => '', // empty = hidden, top, horizontal
469
-		);
470
-
471
-		/**
472
-		 * Parse incoming $args into an array and merge it with $defaults
473
-		 */
474
-		$args   = wp_parse_args( $args, $defaults );
475
-		$output = '';
476
-
477
-		if($args['title']){
478
-
479
-			// maybe hide labels //@todo set a global option for visibility class
480
-			if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
481
-				$class = $args['class'];
482
-			}else{
483
-				$class = 'sr-only '.$args['class'];
484
-			}
485
-
486
-			// maybe horizontal
487
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
488
-				$class .= ' col-sm-2 col-form-label';
489
-			}
490
-
491
-			// open
492
-			$output .= '<label ';
493
-
494
-			// for
495
-			if(!empty($args['for'])){
496
-				$output .= ' for="'.sanitize_text_field($args['for']).'" ';
497
-			}
498
-
499
-			// class
500
-			$output .= ' class="'.$class.'" ';
501
-
502
-			// close
503
-			$output .= '>';
504
-
505
-
506
-			// title, don't escape fully as can contain html
507
-			if(!empty($args['title'])){
508
-				$output .= wp_kses_post($args['title']);
509
-			}
510
-
511
-			// close wrap
512
-			$output .= '</label>';
513
-
514
-
515
-		}
516
-
517
-
518
-		return $output;
519
-	}
520
-
521
-	public static function wrap($args = array()){
522
-		$defaults = array(
523
-			'type'       => 'div',
524
-			'class'      => 'form-group',
525
-			'content'   => '',
526
-			'input_group_left' => '',
527
-			'input_group_right' => '',
528
-			'input_group_left_inside' => false,
529
-			'input_group_right_inside' => false,
530
-			'element_require'   => '',
531
-			'argument_id'   => '',
532
-		);
533
-
534
-		/**
535
-		 * Parse incoming $args into an array and merge it with $defaults
536
-		 */
537
-		$args   = wp_parse_args( $args, $defaults );
538
-		$output = '';
539
-		if($args['type']){
540
-
541
-			// open
542
-			$output .= '<'.sanitize_html_class($args['type']);
543
-
544
-			// element require
545
-			if(!empty($args['element_require'])){
546
-				$output .= AUI_Component_Helper::element_require($args['element_require']);
547
-				$args['class'] .= " aui-conditional-field";
548
-			}
549
-
550
-			// argument_id
551
-			if( !empty($args['argument_id']) ){
552
-				$output .= ' data-argument="'.esc_attr($args['argument_id']).'"';
553
-			}
554
-
555
-			// class
556
-			$class = !empty($args['class']) ? $args['class'] : '';
557
-			$output .= ' class="'.$class.'" ';
558
-
559
-			// close wrap
560
-			$output .= ' >';
561
-
562
-
563
-			// Input group left
564
-			if(!empty($args['input_group_left'])){
565
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
566
-				$input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
567
-				$output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
568
-			}
569
-
570
-			// content
571
-			$output .= $args['content'];
572
-
573
-			// Input group right
574
-			if(!empty($args['input_group_right'])){
575
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
576
-				$input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
577
-				$output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
578
-			}
579
-
580
-
581
-			// close wrap
582
-			$output .= '</'.sanitize_html_class($args['type']).'>';
583
-
584
-
585
-		}else{
586
-			$output = $args['content'];
587
-		}
588
-
589
-		return $output;
590
-	}
591
-
592
-	/**
593
-	 * Build the component.
594
-	 *
595
-	 * @param array $args
596
-	 *
597
-	 * @return string The rendered component.
598
-	 */
599
-	public static function select($args = array()){
600
-		$defaults = array(
601
-			'class'      => '',
602
-			'id'         => '',
603
-			'title'      => '',
604
-			'value'      => '', // can be an array or a string
605
-			'required'   => false,
606
-			'label'      => '',
607
-			'label_after'=> false,
608
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
609
-			'label_class'      => '',
610
-			'help_text'  => '',
611
-			'placeholder'=> '',
612
-			'options'    => array(), // array or string
613
-			'icon'       => '',
614
-			'multiple'   => false,
615
-			'select2'    => false,
616
-			'no_wrap'    => false,
617
-			'element_require'   => '', // [%element_id%] == "1"
618
-			'extra_attributes'  => array(), // an array of extra attributes
619
-		);
620
-
621
-		/**
622
-		 * Parse incoming $args into an array and merge it with $defaults
623
-		 */
624
-		$args   = wp_parse_args( $args, $defaults );
625
-		$output = '';
626
-
627
-		// for now lets hide floating labels
628
-		if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';}
629
-
630
-		// hidden label option needs to be empty
631
-		$args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
632
-
633
-
634
-		$label_after = $args['label_after'];
635
-
636
-		// floating labels need label after
637
-		if( $args['label_type'] == 'floating' ){
638
-			$label_after = true;
639
-			$args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
640
-		}
641
-
642
-		// Maybe setup select2
643
-		$is_select2 = false;
644
-		if(!empty($args['select2'])){
645
-			$args['class'] .= ' aui-select2';
646
-			$is_select2 = true;
647
-		}elseif( strpos($args['class'], 'aui-select2') !== false){
648
-			$is_select2 = true;
649
-		}
650
-
651
-		// select2 tags
652
-		if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason
653
-			$args['data-tags'] = 'true';
654
-			$args['data-token-separators'] = "[',']";
655
-			$args['multiple'] = true;
656
-		}
657
-
658
-		// select2 placeholder
659
-		if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){
660
-			$args['data-placeholder'] = esc_attr($args['placeholder']);
661
-			$args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']);
662
-		}
663
-
664
-		// label
665
-		if(!empty($args['label']) && is_array($args['label'])){
666
-		}elseif(!empty($args['label']) && !$label_after){
667
-			$label_args = array(
668
-				'title'=> $args['label'],
669
-				'for'=> $args['id'],
670
-				'class' => $args['label_class']." ",
671
-				'label_type' => $args['label_type']
672
-			);
673
-			$output .= self::label($label_args);
674
-		}
675
-
676
-		// maybe horizontal label
677
-		if($args['label_type']=='horizontal'){
678
-			$output .= '<div class="col-sm-10">';
679
-		}
680
-
681
-		// open/type
682
-		$output .= '<select ';
683
-
684
-		// style
685
-		if($is_select2){
686
-			$output .= " style='width:100%;' ";
687
-		}
688
-
689
-		// element require
690
-		if(!empty($args['element_require'])){
691
-			$output .= AUI_Component_Helper::element_require($args['element_require']);
692
-			$args['class'] .= " aui-conditional-field";
693
-		}
694
-
695
-		// class
696
-		$class = !empty($args['class']) ? $args['class'] : '';
697
-		$output .= AUI_Component_Helper::class_attr('custom-select '.$class);
698
-
699
-		// name
700
-		if(!empty($args['name'])){
701
-			$output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
702
-		}
703
-
704
-		// id
705
-		if(!empty($args['id'])){
706
-			$output .= AUI_Component_Helper::id($args['id']);
707
-		}
708
-
709
-		// title
710
-		if(!empty($args['title'])){
711
-			$output .= AUI_Component_Helper::title($args['title']);
712
-		}
713
-
714
-		// data-attributes
715
-		$output .= AUI_Component_Helper::data_attributes($args);
716
-
717
-		// aria-attributes
718
-		$output .= AUI_Component_Helper::aria_attributes($args);
719
-
720
-		// extra attributes
721
-		if(!empty($args['extra_attributes'])){
722
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
723
-		}
724
-
725
-		// required
726
-		if(!empty($args['required'])){
727
-			$output .= ' required ';
728
-		}
729
-
730
-		// multiple
731
-		if(!empty($args['multiple'])){
732
-			$output .= ' multiple ';
733
-		}
734
-
735
-		// close opening tag
736
-		$output .= ' >';
737
-
738
-		// placeholder
739
-		if(!empty($args['placeholder']) && !$is_select2){
740
-			$output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
741
-		}elseif($is_select2 && !empty($args['placeholder'])){
742
-			$output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
743
-		}
744
-
745
-		// Options
746
-		if(!empty($args['options'])){
747
-
748
-			if(!is_array($args['options'])){
749
-				$output .= $args['options']; // not the preferred way but an option
750
-			}else{
751
-				foreach($args['options'] as $val => $name){
752
-					$selected = '';
753
-					if(is_array($name)){
754
-						if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
755
-							$option_label = isset($name['label']) ? $name['label'] : '';
756
-
757
-							$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
758
-						} else {
759
-							$option_label = isset($name['label']) ? $name['label'] : '';
760
-							$option_value = isset($name['value']) ? $name['value'] : '';
761
-							if(!empty($args['multiple']) && !empty($args['value'])){
762
-								$selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
763
-							} elseif(!empty($args['value'])) {
764
-								$selected = selected($option_value,stripslashes_deep($args['value']), false);
765
-							}
766
-
767
-							$output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
768
-						}
769
-					}else{
770
-						if(!empty($args['value'])){
771
-							if(is_array($args['value'])){
772
-								$selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
773
-							} elseif(!empty($args['value'])) {
774
-								$selected = selected( $args['value'], $val, false);
775
-							}
776
-						}
777
-						$output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
778
-					}
779
-				}
780
-			}
781
-
782
-		}
783
-
784
-		// closing tag
785
-		$output .= '</select>';
786
-
787
-		if(!empty($args['label']) && $label_after){
788
-			$label_args = array(
789
-				'title'=> $args['label'],
790
-				'for'=> $args['id'],
791
-				'class' => $args['label_class']." ",
792
-				'label_type' => $args['label_type']
793
-			);
794
-			$output .= self::label($label_args);
795
-		}
796
-
797
-		// help text
798
-		if(!empty($args['help_text'])){
799
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
800
-		}
801
-
802
-		// maybe horizontal label
803
-		if($args['label_type']=='horizontal'){
804
-			$output .= '</div>';
805
-		}
806
-
807
-
808
-		// wrap
809
-		if(!$args['no_wrap']){
810
-			$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
811
-			$output = self::wrap(array(
812
-				'content' => $output,
813
-				'class'   => $wrap_class,
814
-				'element_require'   => $args['element_require'],
815
-				'argument_id'  => $args['id']
816
-			));
817
-		}
818
-
819
-
820
-		return $output;
821
-	}
822
-
823
-	/**
824
-	 * Build the component.
825
-	 *
826
-	 * @param array $args
827
-	 *
828
-	 * @return string The rendered component.
829
-	 */
830
-	public static function radio($args = array()){
831
-		$defaults = array(
832
-			'class'      => '',
833
-			'id'         => '',
834
-			'title'      => '',
835
-			'horizontal' => false, // sets the lable horizontal
836
-			'value'      => '',
837
-			'label'      => '',
838
-			'label_class'=> '',
839
-			'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
840
-			'inline'     => true,
841
-			'required'   => false,
842
-			'options'    => array(),
843
-			'icon'       => '',
844
-			'no_wrap'    => false,
845
-			'element_require'   => '', // [%element_id%] == "1"
846
-			'extra_attributes'  => array() // an array of extra attributes
847
-		);
848
-
849
-		/**
850
-		 * Parse incoming $args into an array and merge it with $defaults
851
-		 */
852
-		$args   = wp_parse_args( $args, $defaults );
853
-
854
-		// for now lets use horizontal for floating
855
-		if( $args['label_type'] != 'hidden' ){$args['label_type'] = 'horizontal';}
856
-
857
-		$label_args = array(
858
-			'title'=> $args['label'],
859
-			'class' => $args['label_class']." pt-0 ",
860
-			'label_type' => $args['label_type']
861
-		);
862
-
863
-		$output = '';
864
-
865
-
866
-
867
-		// label before
868
-		if(!empty($args['label'])){
869
-			$output .= self::label( $label_args, 'radio' );
870
-		}
871
-
872
-		// maybe horizontal label
873
-		if($args['label_type']=='horizontal'){
874
-			$output .= '<div class="col-sm-10">';
875
-		}
876
-
877
-		if(!empty($args['options'])){
878
-			$count = 0;
879
-			foreach($args['options'] as $value => $label){
880
-				$option_args = $args;
881
-				$option_args['value'] = $value;
882
-				$option_args['label'] = $label;
883
-				$option_args['checked'] = $value == $args['value'] ? true : false;
884
-				$output .= self::radio_option($option_args,$count);
885
-				$count++;
886
-			}
887
-		}
888
-
889
-		// maybe horizontal label
890
-		if($args['label_type']=='horizontal'){
891
-			$output .= '</div>';
892
-		}
893
-
894
-
895
-		// wrap
896
-		$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
897
-		$output = self::wrap(array(
898
-			'content' => $output,
899
-			'class'   => $wrap_class,
900
-			'element_require'   => $args['element_require'],
901
-			'argument_id'  => $args['id']
902
-		));
903
-
904
-
905
-		return $output;
906
-	}
907
-
908
-	/**
909
-	 * Build the component.
910
-	 *
911
-	 * @param array $args
912
-	 *
913
-	 * @return string The rendered component.
914
-	 */
915
-	public static function radio_option($args = array(),$count = ''){
916
-		$defaults = array(
917
-			'class'      => '',
918
-			'id'         => '',
919
-			'title'      => '',
920
-			'value'      => '',
921
-			'required'   => false,
922
-			'inline'     => true,
923
-			'label'      => '',
924
-			'options'    => array(),
925
-			'icon'       => '',
926
-			'no_wrap'    => false,
927
-			'extra_attributes'  => array() // an array of extra attributes
928
-		);
929
-
930
-		/**
931
-		 * Parse incoming $args into an array and merge it with $defaults
932
-		 */
933
-		$args   = wp_parse_args( $args, $defaults );
934
-
935
-		$output = '';
936
-
937
-		// open/type
938
-		$output .= '<input type="radio"';
939
-
940
-		// class
941
-		$output .= ' class="form-check-input" ';
942
-
943
-		// name
944
-		if(!empty($args['name'])){
945
-			$output .= AUI_Component_Helper::name($args['name']);
946
-		}
947
-
948
-		// id
949
-		if(!empty($args['id'])){
950
-			$output .= AUI_Component_Helper::id($args['id'].$count);
951
-		}
952
-
953
-		// title
954
-		if(!empty($args['title'])){
955
-			$output .= AUI_Component_Helper::title($args['title']);
956
-		}
957
-
958
-		// value
959
-		if(isset($args['value'])){
960
-			$output .= ' value="'.sanitize_text_field($args['value']).'" ';
961
-		}
962
-
963
-		// checked, for radio and checkboxes
964
-		if( $args['checked'] ){
965
-			$output .= ' checked ';
966
-		}
967
-
968
-		// data-attributes
969
-		$output .= AUI_Component_Helper::data_attributes($args);
970
-
971
-		// aria-attributes
972
-		$output .= AUI_Component_Helper::aria_attributes($args);
973
-
974
-		// extra attributes
975
-		if(!empty($args['extra_attributes'])){
976
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
977
-		}
978
-
979
-		// required
980
-		if(!empty($args['required'])){
981
-			$output .= ' required ';
982
-		}
983
-
984
-		// close opening tag
985
-		$output .= ' >';
986
-
987
-		// label
988
-		if(!empty($args['label']) && is_array($args['label'])){
989
-		}elseif(!empty($args['label'])){
990
-			$output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
991
-		}
992
-
993
-		// wrap
994
-		if(!$args['no_wrap']){
995
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
996
-			$output = self::wrap(array(
997
-				'content' => $output,
998
-				'class' => $wrap_class
999
-			));
1000
-		}
1001
-
1002
-
1003
-		return $output;
1004
-	}
212
+            }
213
+
214
+            // input group wraps
215
+            if($args['input_group_left'] || $args['input_group_right']){
216
+                $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
217
+                if($args['input_group_left']){
218
+                    $output = self::wrap( array(
219
+                        'content' => $output,
220
+                        'class'   => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100  : 'input-group',
221
+                        'input_group_left' => $args['input_group_left'],
222
+                        'input_group_left_inside'    => $args['input_group_left_inside']
223
+                    ) );
224
+                }
225
+                if($args['input_group_right']){
226
+                    $output = self::wrap( array(
227
+                        'content' => $output,
228
+                        'class'   => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group',
229
+                        'input_group_right' => $args['input_group_right'],
230
+                        'input_group_right_inside'    => $args['input_group_right_inside']
231
+                    ) );
232
+                }
233
+
234
+            }
235
+
236
+            if(!$label_after){
237
+                $output .= $help_text;
238
+            }
239
+
240
+
241
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
242
+                $output = self::wrap( array(
243
+                    'content' => $output,
244
+                    'class'   => 'col-sm-10',
245
+                ) );
246
+            }
247
+
248
+            if(!$label_after){
249
+                $output = $label . $output;
250
+            }
251
+
252
+            // wrap
253
+            if(!$args['no_wrap']){
254
+
255
+                $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group';
256
+                $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
257
+                $output = self::wrap(array(
258
+                    'content' => $output,
259
+                    'class'   => $wrap_class,
260
+                    'element_require'   => $args['element_require'],
261
+                    'argument_id'  => $args['id']
262
+                ));
263
+            }
264
+
265
+
266
+
267
+        }
268
+
269
+        return $output;
270
+    }
271
+
272
+    /**
273
+     * Build the component.
274
+     *
275
+     * @param array $args
276
+     *
277
+     * @return string The rendered component.
278
+     */
279
+    public static function textarea($args = array()){
280
+        $defaults = array(
281
+            'name'       => '',
282
+            'class'      => '',
283
+            'id'         => '',
284
+            'placeholder'=> '',
285
+            'title'      => '',
286
+            'value'      => '',
287
+            'required'   => false,
288
+            'label'      => '',
289
+            'label_after'=> false,
290
+            'label_class'      => '',
291
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
292
+            'help_text'  => '',
293
+            'validation_text'   => '',
294
+            'validation_pattern' => '',
295
+            'no_wrap'    => false,
296
+            'rows'      => '',
297
+            'wysiwyg'   => false,
298
+            'element_require'   => '', // [%element_id%] == "1"
299
+        );
300
+
301
+        /**
302
+         * Parse incoming $args into an array and merge it with $defaults
303
+         */
304
+        $args   = wp_parse_args( $args, $defaults );
305
+        $output = '';
306
+
307
+        // hidden label option needs to be empty
308
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
309
+
310
+        // floating labels don't work with wysiwyg so set it as top
311
+        if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){
312
+            $args['label_type'] = 'top';
313
+        }
314
+
315
+        $label_after = $args['label_after'];
316
+
317
+        // floating labels need label after
318
+        if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){
319
+            $label_after = true;
320
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
321
+        }
322
+
323
+        // label
324
+        if(!empty($args['label']) && is_array($args['label'])){
325
+        }elseif(!empty($args['label']) && !$label_after){
326
+            $label_args = array(
327
+                'title'=> $args['label'],
328
+                'for'=> $args['id'],
329
+                'class' => $args['label_class']." ",
330
+                'label_type' => $args['label_type']
331
+            );
332
+            $output .= self::label( $label_args );
333
+        }
334
+
335
+        // maybe horizontal label
336
+        if($args['label_type']=='horizontal'){
337
+            $output .= '<div class="col-sm-10">';
338
+        }
339
+
340
+        if(!empty($args['wysiwyg'])){
341
+            ob_start();
342
+            $content = $args['value'];
343
+            $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
344
+            $settings = array(
345
+                'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
346
+                'quicktags'     => false,
347
+                'media_buttons' => false,
348
+                'editor_class'  => 'form-control',
349
+                'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
350
+                'teeny'         => true,
351
+            );
352
+
353
+            // maybe set settings if array
354
+            if(is_array($args['wysiwyg'])){
355
+                $settings  = wp_parse_args( $args['wysiwyg'], $settings );
356
+            }
357
+
358
+            wp_editor( $content, $editor_id, $settings );
359
+            $output .= ob_get_clean();
360
+        }else{
361
+
362
+            // open
363
+            $output .= '<textarea ';
364
+
365
+            // name
366
+            if(!empty($args['name'])){
367
+                $output .= ' name="'.sanitize_html_class($args['name']).'" ';
368
+            }
369
+
370
+            // id
371
+            if(!empty($args['id'])){
372
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
373
+            }
374
+
375
+            // placeholder
376
+            if(!empty($args['placeholder'])){
377
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
378
+            }
379
+
380
+            // title
381
+            if(!empty($args['title'])){
382
+                $output .= ' title="'.esc_attr($args['title']).'" ';
383
+            }
384
+
385
+            // validation text
386
+            if(!empty($args['validation_text'])){
387
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
388
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
389
+            }
390
+
391
+            // validation_pattern
392
+            if(!empty($args['validation_pattern'])){
393
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
394
+            }
395
+
396
+            // required
397
+            if(!empty($args['required'])){
398
+                $output .= ' required ';
399
+            }
400
+
401
+            // rows
402
+            if(!empty($args['rows'])){
403
+                $output .= ' rows="'.absint($args['rows']).'" ';
404
+            }
405
+
406
+
407
+            // class
408
+            $class = !empty($args['class']) ? $args['class'] : '';
409
+            $output .= ' class="form-control '.$class.'" ';
410
+
411
+
412
+            // close tag
413
+            $output .= ' >';
414
+
415
+            // value
416
+            if(!empty($args['value'])){
417
+                $output .= sanitize_textarea_field($args['value']);
418
+            }
419
+
420
+            // closing tag
421
+            $output .= '</textarea>';
422
+
423
+        }
424
+
425
+        if(!empty($args['label']) && $label_after){
426
+            $label_args = array(
427
+                'title'=> $args['label'],
428
+                'for'=> $args['id'],
429
+                'class' => $args['label_class']." ",
430
+                'label_type' => $args['label_type']
431
+            );
432
+            $output .= self::label( $label_args );
433
+        }
434
+
435
+        // help text
436
+        if(!empty($args['help_text'])){
437
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
438
+        }
439
+
440
+        // maybe horizontal label
441
+        if($args['label_type']=='horizontal'){
442
+            $output .= '</div>';
443
+        }
444
+
445
+
446
+        // wrap
447
+        if(!$args['no_wrap']){
448
+            $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group';
449
+            $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class;
450
+            $output = self::wrap(array(
451
+                'content' => $output,
452
+                'class'   => $wrap_class,
453
+                'element_require'   => $args['element_require'],
454
+                'argument_id'  => $args['id']
455
+            ));
456
+        }
457
+
458
+
459
+        return $output;
460
+    }
461
+
462
+    public static function label($args = array(), $type = ''){
463
+        //<label for="exampleInputEmail1">Email address</label>
464
+        $defaults = array(
465
+            'title'       => 'div',
466
+            'for'      => '',
467
+            'class'      => '',
468
+            'label_type'    => '', // empty = hidden, top, horizontal
469
+        );
470
+
471
+        /**
472
+         * Parse incoming $args into an array and merge it with $defaults
473
+         */
474
+        $args   = wp_parse_args( $args, $defaults );
475
+        $output = '';
476
+
477
+        if($args['title']){
478
+
479
+            // maybe hide labels //@todo set a global option for visibility class
480
+            if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
481
+                $class = $args['class'];
482
+            }else{
483
+                $class = 'sr-only '.$args['class'];
484
+            }
485
+
486
+            // maybe horizontal
487
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
488
+                $class .= ' col-sm-2 col-form-label';
489
+            }
490
+
491
+            // open
492
+            $output .= '<label ';
493
+
494
+            // for
495
+            if(!empty($args['for'])){
496
+                $output .= ' for="'.sanitize_text_field($args['for']).'" ';
497
+            }
498
+
499
+            // class
500
+            $output .= ' class="'.$class.'" ';
501
+
502
+            // close
503
+            $output .= '>';
504
+
505
+
506
+            // title, don't escape fully as can contain html
507
+            if(!empty($args['title'])){
508
+                $output .= wp_kses_post($args['title']);
509
+            }
510
+
511
+            // close wrap
512
+            $output .= '</label>';
513
+
514
+
515
+        }
516
+
517
+
518
+        return $output;
519
+    }
520
+
521
+    public static function wrap($args = array()){
522
+        $defaults = array(
523
+            'type'       => 'div',
524
+            'class'      => 'form-group',
525
+            'content'   => '',
526
+            'input_group_left' => '',
527
+            'input_group_right' => '',
528
+            'input_group_left_inside' => false,
529
+            'input_group_right_inside' => false,
530
+            'element_require'   => '',
531
+            'argument_id'   => '',
532
+        );
533
+
534
+        /**
535
+         * Parse incoming $args into an array and merge it with $defaults
536
+         */
537
+        $args   = wp_parse_args( $args, $defaults );
538
+        $output = '';
539
+        if($args['type']){
540
+
541
+            // open
542
+            $output .= '<'.sanitize_html_class($args['type']);
543
+
544
+            // element require
545
+            if(!empty($args['element_require'])){
546
+                $output .= AUI_Component_Helper::element_require($args['element_require']);
547
+                $args['class'] .= " aui-conditional-field";
548
+            }
549
+
550
+            // argument_id
551
+            if( !empty($args['argument_id']) ){
552
+                $output .= ' data-argument="'.esc_attr($args['argument_id']).'"';
553
+            }
554
+
555
+            // class
556
+            $class = !empty($args['class']) ? $args['class'] : '';
557
+            $output .= ' class="'.$class.'" ';
558
+
559
+            // close wrap
560
+            $output .= ' >';
561
+
562
+
563
+            // Input group left
564
+            if(!empty($args['input_group_left'])){
565
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
566
+                $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
567
+                $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
568
+            }
569
+
570
+            // content
571
+            $output .= $args['content'];
572
+
573
+            // Input group right
574
+            if(!empty($args['input_group_right'])){
575
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : '';
576
+                $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
577
+                $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
578
+            }
579
+
580
+
581
+            // close wrap
582
+            $output .= '</'.sanitize_html_class($args['type']).'>';
583
+
584
+
585
+        }else{
586
+            $output = $args['content'];
587
+        }
588
+
589
+        return $output;
590
+    }
591
+
592
+    /**
593
+     * Build the component.
594
+     *
595
+     * @param array $args
596
+     *
597
+     * @return string The rendered component.
598
+     */
599
+    public static function select($args = array()){
600
+        $defaults = array(
601
+            'class'      => '',
602
+            'id'         => '',
603
+            'title'      => '',
604
+            'value'      => '', // can be an array or a string
605
+            'required'   => false,
606
+            'label'      => '',
607
+            'label_after'=> false,
608
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
609
+            'label_class'      => '',
610
+            'help_text'  => '',
611
+            'placeholder'=> '',
612
+            'options'    => array(), // array or string
613
+            'icon'       => '',
614
+            'multiple'   => false,
615
+            'select2'    => false,
616
+            'no_wrap'    => false,
617
+            'element_require'   => '', // [%element_id%] == "1"
618
+            'extra_attributes'  => array(), // an array of extra attributes
619
+        );
620
+
621
+        /**
622
+         * Parse incoming $args into an array and merge it with $defaults
623
+         */
624
+        $args   = wp_parse_args( $args, $defaults );
625
+        $output = '';
626
+
627
+        // for now lets hide floating labels
628
+        if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';}
629
+
630
+        // hidden label option needs to be empty
631
+        $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type'];
632
+
633
+
634
+        $label_after = $args['label_after'];
635
+
636
+        // floating labels need label after
637
+        if( $args['label_type'] == 'floating' ){
638
+            $label_after = true;
639
+            $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works.
640
+        }
641
+
642
+        // Maybe setup select2
643
+        $is_select2 = false;
644
+        if(!empty($args['select2'])){
645
+            $args['class'] .= ' aui-select2';
646
+            $is_select2 = true;
647
+        }elseif( strpos($args['class'], 'aui-select2') !== false){
648
+            $is_select2 = true;
649
+        }
650
+
651
+        // select2 tags
652
+        if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason
653
+            $args['data-tags'] = 'true';
654
+            $args['data-token-separators'] = "[',']";
655
+            $args['multiple'] = true;
656
+        }
657
+
658
+        // select2 placeholder
659
+        if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){
660
+            $args['data-placeholder'] = esc_attr($args['placeholder']);
661
+            $args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']);
662
+        }
663
+
664
+        // label
665
+        if(!empty($args['label']) && is_array($args['label'])){
666
+        }elseif(!empty($args['label']) && !$label_after){
667
+            $label_args = array(
668
+                'title'=> $args['label'],
669
+                'for'=> $args['id'],
670
+                'class' => $args['label_class']." ",
671
+                'label_type' => $args['label_type']
672
+            );
673
+            $output .= self::label($label_args);
674
+        }
675
+
676
+        // maybe horizontal label
677
+        if($args['label_type']=='horizontal'){
678
+            $output .= '<div class="col-sm-10">';
679
+        }
680
+
681
+        // open/type
682
+        $output .= '<select ';
683
+
684
+        // style
685
+        if($is_select2){
686
+            $output .= " style='width:100%;' ";
687
+        }
688
+
689
+        // element require
690
+        if(!empty($args['element_require'])){
691
+            $output .= AUI_Component_Helper::element_require($args['element_require']);
692
+            $args['class'] .= " aui-conditional-field";
693
+        }
694
+
695
+        // class
696
+        $class = !empty($args['class']) ? $args['class'] : '';
697
+        $output .= AUI_Component_Helper::class_attr('custom-select '.$class);
698
+
699
+        // name
700
+        if(!empty($args['name'])){
701
+            $output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
702
+        }
703
+
704
+        // id
705
+        if(!empty($args['id'])){
706
+            $output .= AUI_Component_Helper::id($args['id']);
707
+        }
708
+
709
+        // title
710
+        if(!empty($args['title'])){
711
+            $output .= AUI_Component_Helper::title($args['title']);
712
+        }
713
+
714
+        // data-attributes
715
+        $output .= AUI_Component_Helper::data_attributes($args);
716
+
717
+        // aria-attributes
718
+        $output .= AUI_Component_Helper::aria_attributes($args);
719
+
720
+        // extra attributes
721
+        if(!empty($args['extra_attributes'])){
722
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
723
+        }
724
+
725
+        // required
726
+        if(!empty($args['required'])){
727
+            $output .= ' required ';
728
+        }
729
+
730
+        // multiple
731
+        if(!empty($args['multiple'])){
732
+            $output .= ' multiple ';
733
+        }
734
+
735
+        // close opening tag
736
+        $output .= ' >';
737
+
738
+        // placeholder
739
+        if(!empty($args['placeholder']) && !$is_select2){
740
+            $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
741
+        }elseif($is_select2 && !empty($args['placeholder'])){
742
+            $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder
743
+        }
744
+
745
+        // Options
746
+        if(!empty($args['options'])){
747
+
748
+            if(!is_array($args['options'])){
749
+                $output .= $args['options']; // not the preferred way but an option
750
+            }else{
751
+                foreach($args['options'] as $val => $name){
752
+                    $selected = '';
753
+                    if(is_array($name)){
754
+                        if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
755
+                            $option_label = isset($name['label']) ? $name['label'] : '';
756
+
757
+                            $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
758
+                        } else {
759
+                            $option_label = isset($name['label']) ? $name['label'] : '';
760
+                            $option_value = isset($name['value']) ? $name['value'] : '';
761
+                            if(!empty($args['multiple']) && !empty($args['value'])){
762
+                                $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
763
+                            } elseif(!empty($args['value'])) {
764
+                                $selected = selected($option_value,stripslashes_deep($args['value']), false);
765
+                            }
766
+
767
+                            $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
768
+                        }
769
+                    }else{
770
+                        if(!empty($args['value'])){
771
+                            if(is_array($args['value'])){
772
+                                $selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
773
+                            } elseif(!empty($args['value'])) {
774
+                                $selected = selected( $args['value'], $val, false);
775
+                            }
776
+                        }
777
+                        $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
778
+                    }
779
+                }
780
+            }
781
+
782
+        }
783
+
784
+        // closing tag
785
+        $output .= '</select>';
786
+
787
+        if(!empty($args['label']) && $label_after){
788
+            $label_args = array(
789
+                'title'=> $args['label'],
790
+                'for'=> $args['id'],
791
+                'class' => $args['label_class']." ",
792
+                'label_type' => $args['label_type']
793
+            );
794
+            $output .= self::label($label_args);
795
+        }
796
+
797
+        // help text
798
+        if(!empty($args['help_text'])){
799
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
800
+        }
801
+
802
+        // maybe horizontal label
803
+        if($args['label_type']=='horizontal'){
804
+            $output .= '</div>';
805
+        }
806
+
807
+
808
+        // wrap
809
+        if(!$args['no_wrap']){
810
+            $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
811
+            $output = self::wrap(array(
812
+                'content' => $output,
813
+                'class'   => $wrap_class,
814
+                'element_require'   => $args['element_require'],
815
+                'argument_id'  => $args['id']
816
+            ));
817
+        }
818
+
819
+
820
+        return $output;
821
+    }
822
+
823
+    /**
824
+     * Build the component.
825
+     *
826
+     * @param array $args
827
+     *
828
+     * @return string The rendered component.
829
+     */
830
+    public static function radio($args = array()){
831
+        $defaults = array(
832
+            'class'      => '',
833
+            'id'         => '',
834
+            'title'      => '',
835
+            'horizontal' => false, // sets the lable horizontal
836
+            'value'      => '',
837
+            'label'      => '',
838
+            'label_class'=> '',
839
+            'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating
840
+            'inline'     => true,
841
+            'required'   => false,
842
+            'options'    => array(),
843
+            'icon'       => '',
844
+            'no_wrap'    => false,
845
+            'element_require'   => '', // [%element_id%] == "1"
846
+            'extra_attributes'  => array() // an array of extra attributes
847
+        );
848
+
849
+        /**
850
+         * Parse incoming $args into an array and merge it with $defaults
851
+         */
852
+        $args   = wp_parse_args( $args, $defaults );
853
+
854
+        // for now lets use horizontal for floating
855
+        if( $args['label_type'] != 'hidden' ){$args['label_type'] = 'horizontal';}
856
+
857
+        $label_args = array(
858
+            'title'=> $args['label'],
859
+            'class' => $args['label_class']." pt-0 ",
860
+            'label_type' => $args['label_type']
861
+        );
862
+
863
+        $output = '';
864
+
865
+
866
+
867
+        // label before
868
+        if(!empty($args['label'])){
869
+            $output .= self::label( $label_args, 'radio' );
870
+        }
871
+
872
+        // maybe horizontal label
873
+        if($args['label_type']=='horizontal'){
874
+            $output .= '<div class="col-sm-10">';
875
+        }
876
+
877
+        if(!empty($args['options'])){
878
+            $count = 0;
879
+            foreach($args['options'] as $value => $label){
880
+                $option_args = $args;
881
+                $option_args['value'] = $value;
882
+                $option_args['label'] = $label;
883
+                $option_args['checked'] = $value == $args['value'] ? true : false;
884
+                $output .= self::radio_option($option_args,$count);
885
+                $count++;
886
+            }
887
+        }
888
+
889
+        // maybe horizontal label
890
+        if($args['label_type']=='horizontal'){
891
+            $output .= '</div>';
892
+        }
893
+
894
+
895
+        // wrap
896
+        $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
897
+        $output = self::wrap(array(
898
+            'content' => $output,
899
+            'class'   => $wrap_class,
900
+            'element_require'   => $args['element_require'],
901
+            'argument_id'  => $args['id']
902
+        ));
903
+
904
+
905
+        return $output;
906
+    }
907
+
908
+    /**
909
+     * Build the component.
910
+     *
911
+     * @param array $args
912
+     *
913
+     * @return string The rendered component.
914
+     */
915
+    public static function radio_option($args = array(),$count = ''){
916
+        $defaults = array(
917
+            'class'      => '',
918
+            'id'         => '',
919
+            'title'      => '',
920
+            'value'      => '',
921
+            'required'   => false,
922
+            'inline'     => true,
923
+            'label'      => '',
924
+            'options'    => array(),
925
+            'icon'       => '',
926
+            'no_wrap'    => false,
927
+            'extra_attributes'  => array() // an array of extra attributes
928
+        );
929
+
930
+        /**
931
+         * Parse incoming $args into an array and merge it with $defaults
932
+         */
933
+        $args   = wp_parse_args( $args, $defaults );
934
+
935
+        $output = '';
936
+
937
+        // open/type
938
+        $output .= '<input type="radio"';
939
+
940
+        // class
941
+        $output .= ' class="form-check-input" ';
942
+
943
+        // name
944
+        if(!empty($args['name'])){
945
+            $output .= AUI_Component_Helper::name($args['name']);
946
+        }
947
+
948
+        // id
949
+        if(!empty($args['id'])){
950
+            $output .= AUI_Component_Helper::id($args['id'].$count);
951
+        }
952
+
953
+        // title
954
+        if(!empty($args['title'])){
955
+            $output .= AUI_Component_Helper::title($args['title']);
956
+        }
957
+
958
+        // value
959
+        if(isset($args['value'])){
960
+            $output .= ' value="'.sanitize_text_field($args['value']).'" ';
961
+        }
962
+
963
+        // checked, for radio and checkboxes
964
+        if( $args['checked'] ){
965
+            $output .= ' checked ';
966
+        }
967
+
968
+        // data-attributes
969
+        $output .= AUI_Component_Helper::data_attributes($args);
970
+
971
+        // aria-attributes
972
+        $output .= AUI_Component_Helper::aria_attributes($args);
973
+
974
+        // extra attributes
975
+        if(!empty($args['extra_attributes'])){
976
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
977
+        }
978
+
979
+        // required
980
+        if(!empty($args['required'])){
981
+            $output .= ' required ';
982
+        }
983
+
984
+        // close opening tag
985
+        $output .= ' >';
986
+
987
+        // label
988
+        if(!empty($args['label']) && is_array($args['label'])){
989
+        }elseif(!empty($args['label'])){
990
+            $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
991
+        }
992
+
993
+        // wrap
994
+        if(!$args['no_wrap']){
995
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
996
+            $output = self::wrap(array(
997
+                'content' => $output,
998
+                'class' => $wrap_class
999
+            ));
1000
+        }
1001
+
1002
+
1003
+        return $output;
1004
+    }
1005 1005
 
1006 1006
 }
1007 1007
\ No newline at end of file
Please login to merge, or discard this patch.
wp-ayecode-ui/includes/components/class-aui-component-pagination.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,77 +11,77 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Pagination {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function get( $args = array() ) {
22
-		global $wp_query;
23
-
24
-		$defaults = array(
25
-			'class'              => '',
26
-			'mid_size'           => 2,
27
-			'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
-			'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
-			'screen_reader_text' => __( 'Posts navigation' ),
30
-			'before_paging' => '',
31
-			'after_paging'  => '',
32
-			'type'               => 'array',
33
-			'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
-			'links'              => array() // an array of links if using custom links, this includes the a tag.
35
-		);
36
-
37
-		/**
38
-		 * Parse incoming $args into an array and merge it with $defaults
39
-		 */
40
-		$args = wp_parse_args( $args, $defaults );
41
-
42
-		$output = '';
43
-
44
-		// Don't print empty markup if there's only one page.
45
-		if ( $args['total'] > 1 ) {
46
-
47
-			// Set up paginated links.
48
-			$links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
49
-
50
-			$class = !empty($args['class']) ? $args['class'] : '';
51
-
52
-			// make the output bootstrap ready
53
-			$links_html = "<ul class='pagination m-0 p-0 $class'>";
54
-			if ( ! empty( $links ) ) {
55
-				foreach ( $links as $link ) {
56
-					$active = strpos( $link, 'current' ) !== false ? 'active' : '';
57
-					$links_html .= "<li class='page-item $active'>";
58
-					$links_html .= str_replace( "page-numbers", "page-link", $link );
59
-					$links_html .= "</li>";
60
-				}
61
-			}
62
-			$links_html .= "</ul>";
63
-
64
-			if ( $links ) {
65
-				$output .= '<section class="px-0 py-2 w-100">';
66
-				$output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
67
-				$output .= '</section>';
68
-			}
69
-
70
-			$output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output );
71
-			$output = str_replace( "nav-links", "aui-nav-links", $output );
72
-		}
73
-
74
-		if ( $output ) {
75
-			if ( ! empty( $args['before_paging'] ) ) {
76
-				$output = $args['before_paging'] . $output;
77
-			}
78
-
79
-			if ( ! empty( $args['after_paging'] ) ) {
80
-				$output = $output . $args['after_paging'];
81
-			}
82
-		}
83
-
84
-		return $output;
85
-	}
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function get( $args = array() ) {
22
+        global $wp_query;
23
+
24
+        $defaults = array(
25
+            'class'              => '',
26
+            'mid_size'           => 2,
27
+            'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
+            'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
+            'screen_reader_text' => __( 'Posts navigation' ),
30
+            'before_paging' => '',
31
+            'after_paging'  => '',
32
+            'type'               => 'array',
33
+            'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
+            'links'              => array() // an array of links if using custom links, this includes the a tag.
35
+        );
36
+
37
+        /**
38
+         * Parse incoming $args into an array and merge it with $defaults
39
+         */
40
+        $args = wp_parse_args( $args, $defaults );
41
+
42
+        $output = '';
43
+
44
+        // Don't print empty markup if there's only one page.
45
+        if ( $args['total'] > 1 ) {
46
+
47
+            // Set up paginated links.
48
+            $links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
49
+
50
+            $class = !empty($args['class']) ? $args['class'] : '';
51
+
52
+            // make the output bootstrap ready
53
+            $links_html = "<ul class='pagination m-0 p-0 $class'>";
54
+            if ( ! empty( $links ) ) {
55
+                foreach ( $links as $link ) {
56
+                    $active = strpos( $link, 'current' ) !== false ? 'active' : '';
57
+                    $links_html .= "<li class='page-item $active'>";
58
+                    $links_html .= str_replace( "page-numbers", "page-link", $link );
59
+                    $links_html .= "</li>";
60
+                }
61
+            }
62
+            $links_html .= "</ul>";
63
+
64
+            if ( $links ) {
65
+                $output .= '<section class="px-0 py-2 w-100">';
66
+                $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
67
+                $output .= '</section>';
68
+            }
69
+
70
+            $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output );
71
+            $output = str_replace( "nav-links", "aui-nav-links", $output );
72
+        }
73
+
74
+        if ( $output ) {
75
+            if ( ! empty( $args['before_paging'] ) ) {
76
+                $output = $args['before_paging'] . $output;
77
+            }
78
+
79
+            if ( ! empty( $args['after_paging'] ) ) {
80
+                $output = $output . $args['after_paging'];
81
+            }
82
+        }
83
+
84
+        return $output;
85
+    }
86 86
 
87 87
 }
88 88
\ No newline at end of file
Please login to merge, or discard this patch.