Passed
Push — master ( 5a5a47...c0eaca )
by Brian
04:37
created
includes/data-stores/class-getpaid-item-data-store.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,228 +14,228 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for an item.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'_wpinv_price',
25
-		'_wpinv_vat_rule',
26
-		'_wpinv_vat_class',
27
-		'_wpinv_type',
28
-		'_wpinv_custom_id',
29
-		'_wpinv_custom_name',
30
-		'_wpinv_custom_singular_name',
31
-		'_wpinv_editable',
32
-		'_wpinv_dynamic_pricing',
33
-		'_minimum_price',
34
-		'_wpinv_is_recurring',
35
-		'_wpinv_recurring_period',
36
-		'_wpinv_recurring_interval',
37
-		'_wpinv_recurring_limit',
38
-		'_wpinv_free_trial',
39
-		'_wpinv_trial_period',
40
-		'_wpinv_trial_interval'
41
-	);
42
-
43
-	/**
44
-	 * A map of meta keys to data props.
45
-	 *
46
-	 * @since 1.0.19
47
-	 *
48
-	 * @var array
49
-	 */
50
-	protected $meta_key_to_props = array(
51
-		'_wpinv_price'                => 'price',
52
-		'_wpinv_vat_rule'             => 'vat_rule',
53
-		'_wpinv_vat_class'            => 'vat_class',
54
-		'_wpinv_type'                 => 'type',
55
-		'_wpinv_custom_id'            => 'custom_id',
56
-		'_wpinv_custom_name'          => 'custom_name',
57
-		'_wpinv_custom_singular_name' => 'custom_singular_name',
58
-		'_wpinv_editable'             => 'is_editable',
59
-		'_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
-		'_minimum_price'              => 'minimum_price',
61
-		'_wpinv_custom_name'          => 'custom_name',
62
-		'_wpinv_is_recurring'         => 'is_recurring',
63
-		'_wpinv_recurring_period'     => 'recurring_period',
64
-		'_wpinv_recurring_interval'   => 'recurring_interval',
65
-		'_wpinv_recurring_limit'      => 'recurring_limit',
66
-		'_wpinv_free_trial'           => 'is_free_trial',
67
-		'_wpinv_trial_period'         => 'trial_period',
68
-		'_wpinv_trial_interval'       => 'trial_interval',
69
-		'_wpinv_version'              => 'version',
70
-	);
71
-
72
-	/*
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for an item.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        '_wpinv_price',
25
+        '_wpinv_vat_rule',
26
+        '_wpinv_vat_class',
27
+        '_wpinv_type',
28
+        '_wpinv_custom_id',
29
+        '_wpinv_custom_name',
30
+        '_wpinv_custom_singular_name',
31
+        '_wpinv_editable',
32
+        '_wpinv_dynamic_pricing',
33
+        '_minimum_price',
34
+        '_wpinv_is_recurring',
35
+        '_wpinv_recurring_period',
36
+        '_wpinv_recurring_interval',
37
+        '_wpinv_recurring_limit',
38
+        '_wpinv_free_trial',
39
+        '_wpinv_trial_period',
40
+        '_wpinv_trial_interval'
41
+    );
42
+
43
+    /**
44
+     * A map of meta keys to data props.
45
+     *
46
+     * @since 1.0.19
47
+     *
48
+     * @var array
49
+     */
50
+    protected $meta_key_to_props = array(
51
+        '_wpinv_price'                => 'price',
52
+        '_wpinv_vat_rule'             => 'vat_rule',
53
+        '_wpinv_vat_class'            => 'vat_class',
54
+        '_wpinv_type'                 => 'type',
55
+        '_wpinv_custom_id'            => 'custom_id',
56
+        '_wpinv_custom_name'          => 'custom_name',
57
+        '_wpinv_custom_singular_name' => 'custom_singular_name',
58
+        '_wpinv_editable'             => 'is_editable',
59
+        '_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
+        '_minimum_price'              => 'minimum_price',
61
+        '_wpinv_custom_name'          => 'custom_name',
62
+        '_wpinv_is_recurring'         => 'is_recurring',
63
+        '_wpinv_recurring_period'     => 'recurring_period',
64
+        '_wpinv_recurring_interval'   => 'recurring_interval',
65
+        '_wpinv_recurring_limit'      => 'recurring_limit',
66
+        '_wpinv_free_trial'           => 'is_free_trial',
67
+        '_wpinv_trial_period'         => 'trial_period',
68
+        '_wpinv_trial_interval'       => 'trial_interval',
69
+        '_wpinv_version'              => 'version',
70
+    );
71
+
72
+    /*
73 73
 	|--------------------------------------------------------------------------
74 74
 	| CRUD Methods
75 75
 	|--------------------------------------------------------------------------
76 76
 	*/
77 77
 
78
-	/**
79
-	 * Method to create a new item in the database.
80
-	 *
81
-	 * @param WPInv_Item $item Item object.
82
-	 */
83
-	public function create( &$item ) {
84
-		$item->set_version( WPINV_VERSION );
85
-		$item->set_date_created( current_time('mysql') );
86
-
87
-		// Create a new post.
88
-		$id = wp_insert_post(
89
-			apply_filters(
90
-				'getpaid_new_item_data',
91
-				array(
92
-					'post_date'     => $item->get_date_created( 'edit' ),
93
-					'post_type'     => 'wpi_item',
94
-					'post_status'   => $this->get_post_status( $item ),
95
-					'ping_status'   => 'closed',
96
-					'post_author'   => $item->get_author( 'edit' ),
97
-					'post_title'    => $item->get_name( 'edit' ),
98
-					'post_parent'   => 0,
99
-					'post_excerpt'  => $item->get_description( 'edit' ),
100
-				)
101
-			),
102
-			true
103
-		);
104
-
105
-		if ( $id && ! is_wp_error( $id ) ) {
106
-			$item->set_id( $id );
107
-			$this->update_post_meta( $item );
108
-			$item->save_meta_data();
109
-			$item->apply_changes();
110
-			$this->clear_caches( $item );
111
-			do_action( 'getpaid_new_item', $item );
112
-			return true;
113
-		}
114
-
115
-		if ( is_wp_error( $id ) ) {
116
-			$item->last_error = $id->get_error_message();
117
-		}
78
+    /**
79
+     * Method to create a new item in the database.
80
+     *
81
+     * @param WPInv_Item $item Item object.
82
+     */
83
+    public function create( &$item ) {
84
+        $item->set_version( WPINV_VERSION );
85
+        $item->set_date_created( current_time('mysql') );
86
+
87
+        // Create a new post.
88
+        $id = wp_insert_post(
89
+            apply_filters(
90
+                'getpaid_new_item_data',
91
+                array(
92
+                    'post_date'     => $item->get_date_created( 'edit' ),
93
+                    'post_type'     => 'wpi_item',
94
+                    'post_status'   => $this->get_post_status( $item ),
95
+                    'ping_status'   => 'closed',
96
+                    'post_author'   => $item->get_author( 'edit' ),
97
+                    'post_title'    => $item->get_name( 'edit' ),
98
+                    'post_parent'   => 0,
99
+                    'post_excerpt'  => $item->get_description( 'edit' ),
100
+                )
101
+            ),
102
+            true
103
+        );
104
+
105
+        if ( $id && ! is_wp_error( $id ) ) {
106
+            $item->set_id( $id );
107
+            $this->update_post_meta( $item );
108
+            $item->save_meta_data();
109
+            $item->apply_changes();
110
+            $this->clear_caches( $item );
111
+            do_action( 'getpaid_new_item', $item );
112
+            return true;
113
+        }
114
+
115
+        if ( is_wp_error( $id ) ) {
116
+            $item->last_error = $id->get_error_message();
117
+        }
118 118
 		
119
-		return false;
120
-	}
121
-
122
-	/**
123
-	 * Method to read an item from the database.
124
-	 *
125
-	 * @param WPInv_Item $item Item object.
126
-	 *
127
-	 */
128
-	public function read( &$item ) {
129
-
130
-		$item->set_defaults();
131
-		$item_object = get_post( $item->get_id() );
132
-
133
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
135
-			$item->set_id( 0 );
136
-			return false;
137
-		}
138
-
139
-		$item->set_props(
140
-			array(
141
-				'parent_id'     => $item_object->post_parent,
142
-				'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
143
-				'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
144
-				'status'        => $item_object->post_status,
145
-				'name'          => $item_object->post_title,
146
-				'description'   => $item_object->post_excerpt,
147
-				'author'        => $item_object->post_author,
148
-			)
149
-		);
150
-
151
-		$this->read_object_data( $item, $item_object );
152
-		$item->read_meta_data();
153
-		$item->set_object_read( true );
154
-		do_action( 'getpaid_read_item', $item );
155
-
156
-	}
157
-
158
-	/**
159
-	 * Method to update an item in the database.
160
-	 *
161
-	 * @param WPInv_Item $item Item object.
162
-	 */
163
-	public function update( &$item ) {
164
-		$item->save_meta_data();
165
-		$item->set_version( WPINV_VERSION );
166
-
167
-		if ( null === $item->get_date_created( 'edit' ) ) {
168
-			$item->set_date_created(  current_time('mysql') );
169
-		}
170
-
171
-		// Grab the current status so we can compare.
172
-		$previous_status = get_post_status( $item->get_id() );
173
-
174
-		$changes = $item->get_changes();
175
-
176
-		// Only update the post when the post data changes.
177
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
178
-			$post_data = array(
179
-				'post_date'         => $item->get_date_created( 'edit' ),
180
-				'post_status'       => $item->get_status( 'edit' ),
181
-				'post_parent'       => $item->get_parent_id( 'edit' ),
182
-				'post_excerpt'      => $item->get_description( 'edit' ),
183
-				'post_modified'     => $item->get_date_modified( 'edit' ),
184
-				'post_title'        => $item->get_name( 'edit' ),
185
-				'post_author'       => $item->get_author( 'edit' ),
186
-			);
187
-
188
-			/**
189
-			 * When updating this object, to prevent infinite loops, use $wpdb
190
-			 * to update data, since wp_update_post spawns more calls to the
191
-			 * save_post action.
192
-			 *
193
-			 * This ensures hooks are fired by either WP itself (admin screen save),
194
-			 * or an update purely from CRUD.
195
-			 */
196
-			if ( doing_action( 'save_post' ) ) {
197
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
198
-				clean_post_cache( $item->get_id() );
199
-			} else {
200
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
201
-			}
202
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
203
-		}
204
-		$this->update_post_meta( $item );
205
-		$item->apply_changes();
206
-		$this->clear_caches( $item );
207
-
208
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
209
-		$new_status = $item->get_status( 'edit' );
210
-
211
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
212
-			do_action( 'getpaid_new_item', $item );
213
-		} else {
214
-			do_action( 'getpaid_update_item', $item );
215
-		}
216
-
217
-	}
218
-
219
-	/*
119
+        return false;
120
+    }
121
+
122
+    /**
123
+     * Method to read an item from the database.
124
+     *
125
+     * @param WPInv_Item $item Item object.
126
+     *
127
+     */
128
+    public function read( &$item ) {
129
+
130
+        $item->set_defaults();
131
+        $item_object = get_post( $item->get_id() );
132
+
133
+        if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
+            $item->last_error = __( 'Invalid item.', 'invoicing' );
135
+            $item->set_id( 0 );
136
+            return false;
137
+        }
138
+
139
+        $item->set_props(
140
+            array(
141
+                'parent_id'     => $item_object->post_parent,
142
+                'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
143
+                'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
144
+                'status'        => $item_object->post_status,
145
+                'name'          => $item_object->post_title,
146
+                'description'   => $item_object->post_excerpt,
147
+                'author'        => $item_object->post_author,
148
+            )
149
+        );
150
+
151
+        $this->read_object_data( $item, $item_object );
152
+        $item->read_meta_data();
153
+        $item->set_object_read( true );
154
+        do_action( 'getpaid_read_item', $item );
155
+
156
+    }
157
+
158
+    /**
159
+     * Method to update an item in the database.
160
+     *
161
+     * @param WPInv_Item $item Item object.
162
+     */
163
+    public function update( &$item ) {
164
+        $item->save_meta_data();
165
+        $item->set_version( WPINV_VERSION );
166
+
167
+        if ( null === $item->get_date_created( 'edit' ) ) {
168
+            $item->set_date_created(  current_time('mysql') );
169
+        }
170
+
171
+        // Grab the current status so we can compare.
172
+        $previous_status = get_post_status( $item->get_id() );
173
+
174
+        $changes = $item->get_changes();
175
+
176
+        // Only update the post when the post data changes.
177
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
178
+            $post_data = array(
179
+                'post_date'         => $item->get_date_created( 'edit' ),
180
+                'post_status'       => $item->get_status( 'edit' ),
181
+                'post_parent'       => $item->get_parent_id( 'edit' ),
182
+                'post_excerpt'      => $item->get_description( 'edit' ),
183
+                'post_modified'     => $item->get_date_modified( 'edit' ),
184
+                'post_title'        => $item->get_name( 'edit' ),
185
+                'post_author'       => $item->get_author( 'edit' ),
186
+            );
187
+
188
+            /**
189
+             * When updating this object, to prevent infinite loops, use $wpdb
190
+             * to update data, since wp_update_post spawns more calls to the
191
+             * save_post action.
192
+             *
193
+             * This ensures hooks are fired by either WP itself (admin screen save),
194
+             * or an update purely from CRUD.
195
+             */
196
+            if ( doing_action( 'save_post' ) ) {
197
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
198
+                clean_post_cache( $item->get_id() );
199
+            } else {
200
+                wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
201
+            }
202
+            $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
203
+        }
204
+        $this->update_post_meta( $item );
205
+        $item->apply_changes();
206
+        $this->clear_caches( $item );
207
+
208
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
209
+        $new_status = $item->get_status( 'edit' );
210
+
211
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
212
+            do_action( 'getpaid_new_item', $item );
213
+        } else {
214
+            do_action( 'getpaid_update_item', $item );
215
+        }
216
+
217
+    }
218
+
219
+    /*
220 220
 	|--------------------------------------------------------------------------
221 221
 	| Additional Methods
222 222
 	|--------------------------------------------------------------------------
223 223
 	*/
224 224
 
225
-	/**
226
-	 * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
227
-	 *
228
-	 * @param WPInv_Item $item WPInv_Item object.
229
-	 * @since 1.0.19
230
-	 */
231
-	protected function update_post_meta( &$item ) {
225
+    /**
226
+     * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
227
+     *
228
+     * @param WPInv_Item $item WPInv_Item object.
229
+     * @since 1.0.19
230
+     */
231
+    protected function update_post_meta( &$item ) {
232 232
 
233
-		// Ensure that we have a custom id.
233
+        // Ensure that we have a custom id.
234 234
         if ( ! $item->get_custom_id() ) {
235 235
             $item->set_custom_id( $item->get_id() );
236
-		}
236
+        }
237 237
 
238
-		parent::update_post_meta( $item );
239
-	}
238
+        parent::update_post_meta( $item );
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 1 patch
Indentation   +533 added lines, -533 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'               => 'draft',
34
-		'version'              => '',
35
-		'date_created'         => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'               => 'draft',
34
+        'version'              => '',
35
+        'date_created'         => null,
36 36
         'date_modified'        => null,
37 37
         'name'                 => '',
38 38
         'author'               => 1,
39 39
         'elements'             => null,
40
-		'items'                => null,
41
-		'earned'               => 0,
42
-		'refunded'             => 0,
43
-		'cancelled'            => 0,
44
-		'failed'               => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,358 +114,358 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'          => 'gtscicd',
237
-					'name'        => 'gtscicd',
238
-					'type'        => 'gateway_select',
239
-					'premade'     => true
234
+                $_elements[] = array(
235
+                    'text'        => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'          => 'gtscicd',
237
+                    'name'        => 'gtscicd',
238
+                    'type'        => 'gateway_select',
239
+                    'premade'     => true
240 240
 			
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266
+
267
+        // Convert the items.
268
+        $prepared = array();
266 269
 
267
-		// Convert the items.
268
-		$prepared = array();
270
+        foreach ( $items as $key => $value ) {
269 271
 
270
-		foreach ( $items as $key => $value ) {
272
+            // Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
271 274
 
272
-			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
274 278
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
279
+                continue;
278 280
 
279
-				continue;
281
+            }
280 282
 
281
-			}
283
+            // $item_id => $quantity (buy buttons)
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
282 286
 
283
-			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
287
+                if ( $item->can_purchase() ) {
286 288
 
287
-				if ( $item->can_purchase() ) {
289
+                    $value = (float) $value;
290
+                    $item->set_quantity( $value );
291
+                    if ( 0 == $value ) {
292
+                        $item->set_quantity( 1 );
293
+                        $item->set_allow_quantities( true );
294
+                    }
288 295
 
289
-					$value = (float) $value;
290
-					$item->set_quantity( $value );
291
-					if ( 0 == $value ) {
292
-						$item->set_quantity( 1 );
293
-						$item->set_allow_quantities( true );
294
-					}
296
+                    $prepared[] = $item;
297
+                }
295 298
 
296
-					$prepared[] = $item;
297
-				}
299
+                continue;
300
+            }
298 301
 
299
-				continue;
300
-			}
302
+            // Items saved via payment forms editor.
303
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
301 304
 
302
-			// Items saved via payment forms editor.
303
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
305
+                $item = new GetPaid_Form_Item( $value['id'] );
304 306
 
305
-				$item = new GetPaid_Form_Item( $value['id'] );
307
+                if ( ! $item->can_purchase() ) {
308
+                    continue;
309
+                }
306 310
 
307
-				if ( ! $item->can_purchase() ) {
308
-					continue;
309
-				}
311
+                // Sub-total (Cart items).
312
+                if ( isset( $value['subtotal'] ) ) {
313
+                    $item->set_price( $value['subtotal'] );
314
+                }
310 315
 
311
-				// Sub-total (Cart items).
312
-				if ( isset( $value['subtotal'] ) ) {
313
-					$item->set_price( $value['subtotal'] );
314
-				}
316
+                if ( isset( $value['quantity'] ) ) {
317
+                    $item->set_quantity( $value['quantity'] );
318
+                }
315 319
 
316
-				if ( isset( $value['quantity'] ) ) {
317
-					$item->set_quantity( $value['quantity'] );
318
-				}
320
+                if ( isset( $value['allow_quantities'] ) ) {
321
+                    $item->set_allow_quantities( $value['allow_quantities'] );
322
+                }
319 323
 
320
-				if ( isset( $value['allow_quantities'] ) ) {
321
-					$item->set_allow_quantities( $value['allow_quantities'] );
322
-				}
324
+                if ( isset( $value['required'] ) ) {
325
+                    $item->set_is_required( $value['required'] );
326
+                }
323 327
 
324
-				if ( isset( $value['required'] ) ) {
325
-					$item->set_is_required( $value['required'] );
326
-				}
328
+                if ( isset( $value['description'] ) ) {
329
+                    $item->set_custom_description( $value['description'] );
330
+                }
327 331
 
328
-				if ( isset( $value['description'] ) ) {
329
-					$item->set_custom_description( $value['description'] );
330
-				}
332
+                $prepared[] = $item;
333
+                continue;
331 334
 
332
-				$prepared[] = $item;
333
-				continue;
335
+            }
336
+
337
+            // $item_id => array( 'price' => 10 ) (item variations)
338
+            if ( is_numeric( $key ) && is_array( $value ) ) {
339
+                $item = new GetPaid_Form_Item( $key );
340
+
341
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
+                    $item->set_price( $value['price'] );
343
+                }
344
+
345
+                if ( $item->can_purchase() ) {
346
+                    $prepared[] = $item;
347
+                }
348
+
349
+                continue;
350
+            }
351
+
352
+        }
353
+
354
+        if ( 'objects' == $return && 'view' == $context ) {
355
+            return $prepared;
356
+        }
357
+
358
+        $items = array();
359
+        foreach ( $prepared as $item ) {
360
+            $items[] = $item->prepare_data_for_use();
361
+        }
362
+
363
+        return $items;
364
+    }
365
+
366
+    /**
367
+     * Get a single item belonging to the form.
368
+     *
369
+     * @since 1.0.19
370
+     * @param  int $item_id The item id to return.
371
+     * @return GetPaid_Form_Item|bool
372
+     */
373
+    public function get_item( $item_id ) {
374
+
375
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
376
+            return false;
377
+        }
378
+
379
+        foreach( $this->get_items() as $item ) {
380
+            if ( $item->get_id() == (int) $item_id ) {
381
+                return $item;
382
+            }
383
+        }
384
+
385
+        return false;
386
+
387
+    }
388
+
389
+    /**
390
+     * Gets a single element.
391
+     *
392
+     * @since 1.0.19
393
+     * @param  string $element_type The element type to return.
394
+     * @return array|bool
395
+     */
396
+    public function get_element_type( $element_type ) {
397
+
398
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
399
+            return false;
400
+        }
401
+
402
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
403
+
404
+            if ( $element['type'] == $element_type ) {
405
+                return $element;
406
+            }
407
+
408
+        }
409
+
410
+        return false;
411
+
412
+    }
413
+
414
+    /**
415
+     * Get the total amount earned via this form.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return float
420
+     */
421
+    public function get_earned( $context = 'view' ) {
422
+        return $this->get_prop( 'earned', $context );
423
+    }
424
+
425
+    /**
426
+     * Get the total amount refunded via this form.
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return float
431
+     */
432
+    public function get_refunded( $context = 'view' ) {
433
+        return $this->get_prop( 'refunded', $context );
434
+    }
334 435
 
335
-			}
436
+    /**
437
+     * Get the total amount cancelled via this form.
438
+     *
439
+     * @since 1.0.19
440
+     * @param  string $context View or edit context.
441
+     * @return float
442
+     */
443
+    public function get_cancelled( $context = 'view' ) {
444
+        return $this->get_prop( 'cancelled', $context );
445
+    }
336 446
 
337
-			// $item_id => array( 'price' => 10 ) (item variations)
338
-			if ( is_numeric( $key ) && is_array( $value ) ) {
339
-				$item = new GetPaid_Form_Item( $key );
447
+    /**
448
+     * Get the total amount failed via this form.
449
+     *
450
+     * @since 1.0.19
451
+     * @param  string $context View or edit context.
452
+     * @return float
453
+     */
454
+    public function get_failed( $context = 'view' ) {
455
+        return $this->get_prop( 'failed', $context );
456
+    }
340 457
 
341
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
-					$item->set_price( $value['price'] );
343
-				}
344
-
345
-				if ( $item->can_purchase() ) {
346
-					$prepared[] = $item;
347
-				}
348
-
349
-				continue;
350
-			}
351
-
352
-		}
353
-
354
-		if ( 'objects' == $return && 'view' == $context ) {
355
-			return $prepared;
356
-		}
357
-
358
-		$items = array();
359
-		foreach ( $prepared as $item ) {
360
-			$items[] = $item->prepare_data_for_use();
361
-		}
362
-
363
-		return $items;
364
-	}
365
-
366
-	/**
367
-	 * Get a single item belonging to the form.
368
-	 *
369
-	 * @since 1.0.19
370
-	 * @param  int $item_id The item id to return.
371
-	 * @return GetPaid_Form_Item|bool
372
-	 */
373
-	public function get_item( $item_id ) {
374
-
375
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
376
-			return false;
377
-		}
378
-
379
-		foreach( $this->get_items() as $item ) {
380
-			if ( $item->get_id() == (int) $item_id ) {
381
-				return $item;
382
-			}
383
-		}
384
-
385
-		return false;
386
-
387
-	}
388
-
389
-	/**
390
-	 * Gets a single element.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @param  string $element_type The element type to return.
394
-	 * @return array|bool
395
-	 */
396
-	public function get_element_type( $element_type ) {
397
-
398
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
399
-			return false;
400
-		}
401
-
402
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
403
-
404
-			if ( $element['type'] == $element_type ) {
405
-				return $element;
406
-			}
407
-
408
-		}
409
-
410
-		return false;
411
-
412
-	}
413
-
414
-	/**
415
-	 * Get the total amount earned via this form.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return float
420
-	 */
421
-	public function get_earned( $context = 'view' ) {
422
-		return $this->get_prop( 'earned', $context );
423
-	}
424
-
425
-	/**
426
-	 * Get the total amount refunded via this form.
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return float
431
-	 */
432
-	public function get_refunded( $context = 'view' ) {
433
-		return $this->get_prop( 'refunded', $context );
434
-	}
435
-
436
-	/**
437
-	 * Get the total amount cancelled via this form.
438
-	 *
439
-	 * @since 1.0.19
440
-	 * @param  string $context View or edit context.
441
-	 * @return float
442
-	 */
443
-	public function get_cancelled( $context = 'view' ) {
444
-		return $this->get_prop( 'cancelled', $context );
445
-	}
446
-
447
-	/**
448
-	 * Get the total amount failed via this form.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @param  string $context View or edit context.
452
-	 * @return float
453
-	 */
454
-	public function get_failed( $context = 'view' ) {
455
-		return $this->get_prop( 'failed', $context );
456
-	}
457
-
458
-	/**
459
-	 * Get the currency.
460
-	 *
461
-	 * @since 1.0.19
462
-	 * @param  string $context View or edit context.
463
-	 * @return string
464
-	 */
465
-	public function get_currency() {
466
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
467
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
468
-	}
458
+    /**
459
+     * Get the currency.
460
+     *
461
+     * @since 1.0.19
462
+     * @param  string $context View or edit context.
463
+     * @return string
464
+     */
465
+    public function get_currency() {
466
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
467
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
468
+    }
469 469
 
470 470
     /*
471 471
 	|--------------------------------------------------------------------------
@@ -478,22 +478,22 @@  discard block
 block discarded – undo
478 478
     */
479 479
 
480 480
     /**
481
-	 * Set plugin version when the item was created.
482
-	 *
483
-	 * @since 1.0.19
484
-	 */
485
-	public function set_version( $value ) {
486
-		$this->set_prop( 'version', $value );
481
+     * Set plugin version when the item was created.
482
+     *
483
+     * @since 1.0.19
484
+     */
485
+    public function set_version( $value ) {
486
+        $this->set_prop( 'version', $value );
487 487
     }
488 488
 
489 489
     /**
490
-	 * Set date when the item was created.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param string $value Value to set.
490
+     * Set date when the item was created.
491
+     *
492
+     * @since 1.0.19
493
+     * @param string $value Value to set.
494 494
      * @return bool Whether or not the date was set.
495
-	 */
496
-	public function set_date_created( $value ) {
495
+     */
496
+    public function set_date_created( $value ) {
497 497
         $date = strtotime( $value );
498 498
 
499 499
         if ( $date ) {
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
     }
507 507
 
508 508
     /**
509
-	 * Set date when the item was last modified.
510
-	 *
511
-	 * @since 1.0.19
512
-	 * @param string $value Value to set.
509
+     * Set date when the item was last modified.
510
+     *
511
+     * @since 1.0.19
512
+     * @param string $value Value to set.
513 513
      * @return bool Whether or not the date was set.
514
-	 */
515
-	public function set_date_modified( $value ) {
514
+     */
515
+    public function set_date_modified( $value ) {
516 516
         $date = strtotime( $value );
517 517
 
518 518
         if ( $date ) {
@@ -525,118 +525,118 @@  discard block
 block discarded – undo
525 525
     }
526 526
 
527 527
     /**
528
-	 * Set the item name.
529
-	 *
530
-	 * @since 1.0.19
531
-	 * @param  string $value New name.
532
-	 */
533
-	public function set_name( $value ) {
534
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
535
-    }
536
-
537
-    /**
538
-	 * Alias of self::set_name().
539
-	 *
540
-	 * @since 1.0.19
541
-	 * @param  string $value New name.
542
-	 */
543
-	public function set_title( $value ) {
544
-		$this->set_name( $value );
545
-    }
546
-
547
-    /**
548
-	 * Set the owner of the item.
549
-	 *
550
-	 * @since 1.0.19
551
-	 * @param  int $value New author.
552
-	 */
553
-	public function set_author( $value ) {
554
-		$this->set_prop( 'author', (int) $value );
555
-	}
556
-
557
-	/**
558
-	 * Set the form elements.
559
-	 *
560
-	 * @since 1.0.19
561
-	 * @param  array $value Form elements.
562
-	 */
563
-	public function set_elements( $value ) {
564
-		if ( is_array( $value ) ) {
565
-			$this->set_prop( 'elements', $value );
566
-		}
567
-	}
568
-
569
-	/**
570
-	 * Set the form items.
571
-	 *
572
-	 * @since 1.0.19
573
-	 * @param  array $value Form elements.
574
-	 */
575
-	public function set_items( $value ) {
576
-		if ( is_array( $value ) ) {
577
-			$this->set_prop( 'items', $value );
578
-		}
579
-	}
580
-
581
-	/**
582
-	 * Set the total amount earned via this form.
583
-	 *
584
-	 * @since 1.0.19
585
-	 * @param  float $value Amount earned.
586
-	 */
587
-	public function set_earned( $value ) {
588
-		$value = max( (float) $value, 0 );
589
-		$this->set_prop( 'earned', $value );
590
-	}
591
-
592
-	/**
593
-	 * Set the total amount refunded via this form.
594
-	 *
595
-	 * @since 1.0.19
596
-	 * @param  float $value Amount refunded.
597
-	 */
598
-	public function set_refunded( $value ) {
599
-		$value = max( (float) $value, 0 );
600
-		$this->set_prop( 'refunded', $value );
601
-	}
602
-
603
-	/**
604
-	 * Set the total amount cancelled via this form.
605
-	 *
606
-	 * @since 1.0.19
607
-	 * @param  float $value Amount cancelled.
608
-	 */
609
-	public function set_cancelled( $value ) {
610
-		$value = max( (float) $value, 0 );
611
-		$this->set_prop( 'cancelled', $value );
612
-	}
613
-
614
-	/**
615
-	 * Set the total amount failed via this form.
616
-	 *
617
-	 * @since 1.0.19
618
-	 * @param  float $value Amount cancelled.
619
-	 */
620
-	public function set_failed( $value ) {
621
-		$value = max( (float) $value, 0 );
622
-		$this->set_prop( 'failed', $value );
623
-	}
528
+     * Set the item name.
529
+     *
530
+     * @since 1.0.19
531
+     * @param  string $value New name.
532
+     */
533
+    public function set_name( $value ) {
534
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
535
+    }
536
+
537
+    /**
538
+     * Alias of self::set_name().
539
+     *
540
+     * @since 1.0.19
541
+     * @param  string $value New name.
542
+     */
543
+    public function set_title( $value ) {
544
+        $this->set_name( $value );
545
+    }
546
+
547
+    /**
548
+     * Set the owner of the item.
549
+     *
550
+     * @since 1.0.19
551
+     * @param  int $value New author.
552
+     */
553
+    public function set_author( $value ) {
554
+        $this->set_prop( 'author', (int) $value );
555
+    }
556
+
557
+    /**
558
+     * Set the form elements.
559
+     *
560
+     * @since 1.0.19
561
+     * @param  array $value Form elements.
562
+     */
563
+    public function set_elements( $value ) {
564
+        if ( is_array( $value ) ) {
565
+            $this->set_prop( 'elements', $value );
566
+        }
567
+    }
568
+
569
+    /**
570
+     * Set the form items.
571
+     *
572
+     * @since 1.0.19
573
+     * @param  array $value Form elements.
574
+     */
575
+    public function set_items( $value ) {
576
+        if ( is_array( $value ) ) {
577
+            $this->set_prop( 'items', $value );
578
+        }
579
+    }
580
+
581
+    /**
582
+     * Set the total amount earned via this form.
583
+     *
584
+     * @since 1.0.19
585
+     * @param  float $value Amount earned.
586
+     */
587
+    public function set_earned( $value ) {
588
+        $value = max( (float) $value, 0 );
589
+        $this->set_prop( 'earned', $value );
590
+    }
591
+
592
+    /**
593
+     * Set the total amount refunded via this form.
594
+     *
595
+     * @since 1.0.19
596
+     * @param  float $value Amount refunded.
597
+     */
598
+    public function set_refunded( $value ) {
599
+        $value = max( (float) $value, 0 );
600
+        $this->set_prop( 'refunded', $value );
601
+    }
602
+
603
+    /**
604
+     * Set the total amount cancelled via this form.
605
+     *
606
+     * @since 1.0.19
607
+     * @param  float $value Amount cancelled.
608
+     */
609
+    public function set_cancelled( $value ) {
610
+        $value = max( (float) $value, 0 );
611
+        $this->set_prop( 'cancelled', $value );
612
+    }
613
+
614
+    /**
615
+     * Set the total amount failed via this form.
616
+     *
617
+     * @since 1.0.19
618
+     * @param  float $value Amount cancelled.
619
+     */
620
+    public function set_failed( $value ) {
621
+        $value = max( (float) $value, 0 );
622
+        $this->set_prop( 'failed', $value );
623
+    }
624 624
 
625 625
     /**
626 626
      * Create an item. For backwards compatibilty.
627 627
      *
628 628
      * @deprecated
629
-	 * @return int item id
629
+     * @return int item id
630 630
      */
631 631
     public function create( $data = array() ) {
632 632
 
633
-		// Set the properties.
634
-		if ( is_array( $data ) ) {
635
-			$this->set_props( $data );
636
-		}
633
+        // Set the properties.
634
+        if ( is_array( $data ) ) {
635
+            $this->set_props( $data );
636
+        }
637 637
 
638
-		// Save the item.
639
-		return $this->save();
638
+        // Save the item.
639
+        return $this->save();
640 640
 
641 641
     }
642 642
 
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
      * Updates an item. For backwards compatibilty.
645 645
      *
646 646
      * @deprecated
647
-	 * @return int item id
647
+     * @return int item id
648 648
      */
649 649
     public function update( $data = array() ) {
650 650
         return $this->create( $data );
@@ -660,22 +660,22 @@  discard block
 block discarded – undo
660 660
 	*/
661 661
 
662 662
     /**
663
-	 * Checks whether this is the default payment form.
664
-	 *
665
-	 * @since 1.0.19
666
-	 * @return bool
667
-	 */
663
+     * Checks whether this is the default payment form.
664
+     *
665
+     * @since 1.0.19
666
+     * @return bool
667
+     */
668 668
     public function is_default() {
669 669
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
670 670
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
671
-	}
671
+    }
672 672
 
673 673
     /**
674
-	 * Checks whether the form is active.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @return bool
678
-	 */
674
+     * Checks whether the form is active.
675
+     *
676
+     * @since 1.0.19
677
+     * @return bool
678
+     */
679 679
     public function is_active() {
680 680
         $is_active = 0 !== (int) $this->get_id();
681 681
 
@@ -684,76 +684,76 @@  discard block
 block discarded – undo
684 684
         }
685 685
 
686 686
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
687
-	}
688
-
689
-	/**
690
-	 * Checks whether the form has a given item.
691
-	 *
692
-	 * @since 1.0.19
693
-	 * @return bool
694
-	 */
687
+    }
688
+
689
+    /**
690
+     * Checks whether the form has a given item.
691
+     *
692
+     * @since 1.0.19
693
+     * @return bool
694
+     */
695 695
     public function has_item( $item_id ) {
696 696
         return false !== $this->get_item( $item_id );
697
-	}
698
-
699
-	/**
700
-	 * Checks whether the form has a given element.
701
-	 *
702
-	 * @since 1.0.19
703
-	 * @return bool
704
-	 */
697
+    }
698
+
699
+    /**
700
+     * Checks whether the form has a given element.
701
+     *
702
+     * @since 1.0.19
703
+     * @return bool
704
+     */
705 705
     public function has_element_type( $element_type ) {
706 706
         return false !== $this->get_element_type( $element_type );
707
-	}
708
-
709
-	/**
710
-	 * Checks whether this form is recurring or not.
711
-	 *
712
-	 * @since 1.0.19
713
-	 * @return bool
714
-	 */
707
+    }
708
+
709
+    /**
710
+     * Checks whether this form is recurring or not.
711
+     *
712
+     * @since 1.0.19
713
+     * @return bool
714
+     */
715 715
     public function is_recurring() {
716 716
 
717
-		if ( ! empty( $this->invoice ) ) {
718
-			return $this->invoice->is_recurring();
719
-		}
717
+        if ( ! empty( $this->invoice ) ) {
718
+            return $this->invoice->is_recurring();
719
+        }
720 720
 
721
-		foreach ( $this->get_items() as $item ) {
721
+        foreach ( $this->get_items() as $item ) {
722 722
 
723
-			if ( $item->is_recurring() ) {
724
-				return true;
725
-			}
723
+            if ( $item->is_recurring() ) {
724
+                return true;
725
+            }
726 726
 
727
-		}
727
+        }
728 728
 
729 729
         return false;
730
-	}
730
+    }
731 731
 
732
-	/**
733
-	 * Retrieves the form's html.
734
-	 *
735
-	 * @since 1.0.19
736
-	 */
732
+    /**
733
+     * Retrieves the form's html.
734
+     *
735
+     * @since 1.0.19
736
+     */
737 737
     public function get_html( $extra_markup = '' ) {
738 738
 
739
-		// Return the HTML.
740
-		return wpinv_get_template_html(
741
-			'payment-forms/form.php',
742
-			array(
743
-				'form'         => $this,
744
-				'extra_markup' => $extra_markup,
745
-			)
746
-		);
747
-
748
-	}
749
-
750
-	/**
751
-	 * Displays the payment form.
752
-	 *
753
-	 * @since 1.0.19
754
-	 */
739
+        // Return the HTML.
740
+        return wpinv_get_template_html(
741
+            'payment-forms/form.php',
742
+            array(
743
+                'form'         => $this,
744
+                'extra_markup' => $extra_markup,
745
+            )
746
+        );
747
+
748
+    }
749
+
750
+    /**
751
+     * Displays the payment form.
752
+     *
753
+     * @since 1.0.19
754
+     */
755 755
     public function display( $extra_markup = '' ) {
756
-		echo $this->get_html( $extra_markup );
756
+        echo $this->get_html( $extra_markup );
757 757
     }
758 758
 
759 759
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +607 added lines, -607 removed lines patch added patch discarded remove patch
@@ -13,467 +13,467 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a user's saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-
141
-		// Register gateway.
142
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
-
144
-		$this->enabled = wpinv_is_gateway_active( $this->id );
145
-
146
-		// Enable Subscriptions.
147
-		if ( $this->supports( 'subscription' ) ) {
148
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
149
-		}
150
-
151
-		// Enable sandbox.
152
-		if ( $this->supports( 'sandbox' ) ) {
153
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
154
-		}
155
-
156
-		// Invoice addons.
157
-		if ( $this->supports( 'addons' ) ) {
158
-			add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
160
-		}
161
-
162
-		// Gateway settings.
163
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a user's saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+
141
+        // Register gateway.
142
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
+
144
+        $this->enabled = wpinv_is_gateway_active( $this->id );
145
+
146
+        // Enable Subscriptions.
147
+        if ( $this->supports( 'subscription' ) ) {
148
+            add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
149
+        }
150
+
151
+        // Enable sandbox.
152
+        if ( $this->supports( 'sandbox' ) ) {
153
+            add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
154
+        }
155
+
156
+        // Invoice addons.
157
+        if ( $this->supports( 'addons' ) ) {
158
+            add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
+            add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
160
+        }
161
+
162
+        // Gateway settings.
163
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
164 164
 		
165 165
 
166
-		// Gateway checkout fiellds.
167
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
168
-
169
-		// Process payment.
170
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
166
+        // Gateway checkout fiellds.
167
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
168
+
169
+        // Process payment.
170
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
171
+
172
+        // Change the checkout button text.
173
+        if ( ! empty( $this->checkout_button_text ) ) {
174
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
175
+        }
176
+
177
+        // Check if a gateway is valid for a given currency.
178
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
179
+
180
+        // Generate the transaction url.
181
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
182
+
183
+        // Generate the subscription url.
184
+        add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
185
+
186
+        // Confirm payments.
187
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
188
+
189
+        // Verify IPNs.
190
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
191
+
192
+    }
193
+
194
+    /**
195
+     * Checks if this gateway is a given gateway.
196
+     *
197
+     * @since 1.0.19
198
+     * @return bool
199
+     */
200
+    public function is( $gateway ) {
201
+        return $gateway == $this->id;
202
+    }
203
+
204
+    /**
205
+     * Returns a users saved tokens for this gateway.
206
+     *
207
+     * @since 1.0.19
208
+     * @return array
209
+     */
210
+    public function get_tokens( $sandbox = null ) {
211
+
212
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
214
+
215
+            if ( is_array( $tokens ) ) {
216
+                $this->tokens = $tokens;
217
+            }
218
+
219
+        }
220
+
221
+        if ( ! is_bool( $sandbox ) ) {
222
+            return $this->tokens;
223
+        }
224
+
225
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
+        return wp_list_filter( $this->tokens, $args );
227
+
228
+    }
229
+
230
+    /**
231
+     * Saves a token for this gateway.
232
+     *
233
+     * @since 1.0.19
234
+     */
235
+    public function save_token( $token ) {
236
+
237
+        $tokens   = $this->get_tokens();
238
+        $tokens[] = $token;
239
+
240
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
241
+
242
+        $this->tokens = $tokens;
243
+
244
+    }
245
+
246
+    /**
247
+     * Return the title for admin screens.
248
+     *
249
+     * @return string
250
+     */
251
+    public function get_method_title() {
252
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
253
+    }
254
+
255
+    /**
256
+     * Return the description for admin screens.
257
+     *
258
+     * @return string
259
+     */
260
+    public function get_method_description() {
261
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
262
+    }
263
+
264
+    /**
265
+     * Get the success url.
266
+     *
267
+     * @param WPInv_Invoice $invoice Invoice object.
268
+     * @return string
269
+     */
270
+    public function get_return_url( $invoice ) {
271
+
272
+        // Payment success url
273
+        $return_url = add_query_arg(
274
+            array(
275
+                'payment-confirm' => $this->id,
276
+                'invoice_key'     => $invoice->get_key(),
277
+                'utm_nooverride'  => 1
278
+            ),
279
+            wpinv_get_success_page_uri()
280
+        );
281
+
282
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
283
+    }
284
+
285
+    /**
286
+     * Confirms payments when rendering the success page.
287
+     *
288
+     * @param string $content Success page content.
289
+     * @return string
290
+     */
291
+    public function confirm_payment( $content ) {
292
+
293
+        // Retrieve the invoice.
294
+        $invoice_id = getpaid_get_current_invoice_id();
295
+        $invoice    = wpinv_get_invoice( $invoice_id );
296
+
297
+        // Ensure that it exists and that it is pending payment.
298
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
299
+            return $content;
300
+        }
301
+
302
+        // Can the user view this invoice??
303
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
304
+            return $content;
305
+        }
306
+
307
+        // Show payment processing indicator.
308
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
309
+    }
310
+
311
+    /**
312
+     * Processes ipns and marks payments as complete.
313
+     *
314
+     * @return void
315
+     */
316
+    public function verify_ipn() {}
317
+
318
+    /**
319
+     * Processes invoice addons.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     * @param GetPaid_Form_Item[] $items
323
+     * @return WPInv_Invoice
324
+     */
325
+    public function process_addons( $invoice, $items ) {
326
+
327
+    }
328
+
329
+    /**
330
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
331
+     *
332
+     * @param string $transaction_url transaction url.
333
+     * @param WPInv_Invoice $invoice Invoice object.
334
+     * @return string transaction URL, or empty string.
335
+     */
336
+    public function filter_transaction_url( $transaction_url, $invoice ) {
337
+
338
+        $transaction_id  = $invoice->get_transaction_id();
339
+
340
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
344
+        }
345
+
346
+        return $transaction_url;
347
+    }
348
+
349
+    /**
350
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
351
+     *
352
+     * @param string $subscription_url transaction url.
353
+     * @param WPInv_Invoice $invoice Invoice object.
354
+     * @return string subscription URL, or empty string.
355
+     */
356
+    public function filter_subscription_url( $subscription_url, $invoice ) {
171 357
 
172
-		// Change the checkout button text.
173
-		if ( ! empty( $this->checkout_button_text ) ) {
174
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
175
-		}
176
-
177
-		// Check if a gateway is valid for a given currency.
178
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
179
-
180
-		// Generate the transaction url.
181
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
182
-
183
-		// Generate the subscription url.
184
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
185
-
186
-		// Confirm payments.
187
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
188
-
189
-		// Verify IPNs.
190
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
191
-
192
-	}
193
-
194
-	/**
195
-	 * Checks if this gateway is a given gateway.
196
-	 *
197
-	 * @since 1.0.19
198
-	 * @return bool
199
-	 */
200
-	public function is( $gateway ) {
201
-		return $gateway == $this->id;
202
-	}
203
-
204
-	/**
205
-	 * Returns a users saved tokens for this gateway.
206
-	 *
207
-	 * @since 1.0.19
208
-	 * @return array
209
-	 */
210
-	public function get_tokens( $sandbox = null ) {
211
-
212
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
214
-
215
-			if ( is_array( $tokens ) ) {
216
-				$this->tokens = $tokens;
217
-			}
218
-
219
-		}
220
-
221
-		if ( ! is_bool( $sandbox ) ) {
222
-			return $this->tokens;
223
-		}
224
-
225
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
-		return wp_list_filter( $this->tokens, $args );
227
-
228
-	}
229
-
230
-	/**
231
-	 * Saves a token for this gateway.
232
-	 *
233
-	 * @since 1.0.19
234
-	 */
235
-	public function save_token( $token ) {
236
-
237
-		$tokens   = $this->get_tokens();
238
-		$tokens[] = $token;
239
-
240
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
241
-
242
-		$this->tokens = $tokens;
243
-
244
-	}
245
-
246
-	/**
247
-	 * Return the title for admin screens.
248
-	 *
249
-	 * @return string
250
-	 */
251
-	public function get_method_title() {
252
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
253
-	}
254
-
255
-	/**
256
-	 * Return the description for admin screens.
257
-	 *
258
-	 * @return string
259
-	 */
260
-	public function get_method_description() {
261
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
262
-	}
263
-
264
-	/**
265
-	 * Get the success url.
266
-	 *
267
-	 * @param WPInv_Invoice $invoice Invoice object.
268
-	 * @return string
269
-	 */
270
-	public function get_return_url( $invoice ) {
271
-
272
-		// Payment success url
273
-		$return_url = add_query_arg(
274
-			array(
275
-				'payment-confirm' => $this->id,
276
-				'invoice_key'     => $invoice->get_key(),
277
-				'utm_nooverride'  => 1
278
-			),
279
-			wpinv_get_success_page_uri()
280
-		);
281
-
282
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
283
-	}
284
-
285
-	/**
286
-	 * Confirms payments when rendering the success page.
287
-	 *
288
-	 * @param string $content Success page content.
289
-	 * @return string
290
-	 */
291
-	public function confirm_payment( $content ) {
292
-
293
-		// Retrieve the invoice.
294
-		$invoice_id = getpaid_get_current_invoice_id();
295
-		$invoice    = wpinv_get_invoice( $invoice_id );
296
-
297
-		// Ensure that it exists and that it is pending payment.
298
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
299
-			return $content;
300
-		}
301
-
302
-		// Can the user view this invoice??
303
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
304
-			return $content;
305
-		}
306
-
307
-		// Show payment processing indicator.
308
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
309
-	}
310
-
311
-	/**
312
-	 * Processes ipns and marks payments as complete.
313
-	 *
314
-	 * @return void
315
-	 */
316
-	public function verify_ipn() {}
317
-
318
-	/**
319
-	 * Processes invoice addons.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 * @param GetPaid_Form_Item[] $items
323
-	 * @return WPInv_Invoice
324
-	 */
325
-	public function process_addons( $invoice, $items ) {
326
-
327
-	}
328
-
329
-	/**
330
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
331
-	 *
332
-	 * @param string $transaction_url transaction url.
333
-	 * @param WPInv_Invoice $invoice Invoice object.
334
-	 * @return string transaction URL, or empty string.
335
-	 */
336
-	public function filter_transaction_url( $transaction_url, $invoice ) {
337
-
338
-		$transaction_id  = $invoice->get_transaction_id();
339
-
340
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
344
-		}
345
-
346
-		return $transaction_url;
347
-	}
348
-
349
-	/**
350
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
351
-	 *
352
-	 * @param string $subscription_url transaction url.
353
-	 * @param WPInv_Invoice $invoice Invoice object.
354
-	 * @return string subscription URL, or empty string.
355
-	 */
356
-	public function filter_subscription_url( $subscription_url, $invoice ) {
357
-
358
-		$profile_id      = $invoice->get_subscription_id();
359
-
360
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
361
-
362
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
364
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
365
-
366
-		}
367
-
368
-		return $subscription_url;
369
-	}
370
-
371
-	/**
372
-	 * Check if the gateway is available for use.
373
-	 *
374
-	 * @return bool
375
-	 */
376
-	public function is_available() {
377
-		return ! empty( $this->enabled );
378
-	}
379
-
380
-	/**
381
-	 * Return the gateway's title.
382
-	 *
383
-	 * @return string
384
-	 */
385
-	public function get_title() {
386
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
387
-	}
388
-
389
-	/**
390
-	 * Return the gateway's description.
391
-	 *
392
-	 * @return string
393
-	 */
394
-	public function get_description() {
395
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
396
-	}
397
-
398
-	/**
399
-	 * Process Payment.
400
-	 *
401
-	 *
402
-	 * @param WPInv_Invoice $invoice Invoice.
403
-	 * @param array $submission_data Posted checkout fields.
404
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405
-	 * @return void
406
-	 */
407
-	public function process_payment( $invoice, $submission_data, $submission ) {
408
-		// Process the payment then either redirect to the success page or the gateway.
409
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
410
-	}
411
-
412
-	/**
413
-	 * Process refund.
414
-	 *
415
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
416
-	 * a passed in amount.
417
-	 *
418
-	 * @param WPInv_Invoice $invoice Invoice.
419
-	 * @param  float  $amount Refund amount.
420
-	 * @param  string $reason Refund reason.
421
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
422
-	 */
423
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
425
-	}
426
-
427
-	/**
428
-	 * Displays the payment fields, credit cards etc.
429
-	 * 
430
-	 * @param int $invoice_id 0 or invoice id.
431
-	 * @param GetPaid_Payment_Form $form Current payment form.
432
-	 */
433
-	public function payment_fields( $invoice_id, $form ) {
434
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
435
-	}
436
-
437
-	/**
438
-	 * Filters the gateway settings.
439
-	 * 
440
-	 * @param array $admin_settings
441
-	 */
442
-	public function admin_settings( $admin_settings ) {
443
-		return $admin_settings;
444
-	}
445
-
446
-	/**
447
-	 * Retrieves the value of a gateway setting.
448
-	 * 
449
-	 * @param string $option
450
-	 */
451
-	public function get_option( $option, $default = false ) {
452
-		return wpinv_get_option( $this->id . '_' . $option, $default );
453
-	}
454
-
455
-	/**
456
-	 * Check if a gateway supports a given feature.
457
-	 *
458
-	 * Gateways should override this to declare support (or lack of support) for a feature.
459
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
460
-	 *
461
-	 * @param string $feature string The name of a feature to test support for.
462
-	 * @return bool True if the gateway supports the feature, false otherwise.
463
-	 * @since 1.0.19
464
-	 */
465
-	public function supports( $feature ) {
466
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
467
-	}
468
-
469
-	/**
470
-	 * Returns the credit card form html.
471
-	 * 
472
-	 * @param bool $save whether or not to display the save button.
473
-	 */
358
+        $profile_id      = $invoice->get_subscription_id();
359
+
360
+        if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
361
+
362
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
+            $replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
364
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
365
+
366
+        }
367
+
368
+        return $subscription_url;
369
+    }
370
+
371
+    /**
372
+     * Check if the gateway is available for use.
373
+     *
374
+     * @return bool
375
+     */
376
+    public function is_available() {
377
+        return ! empty( $this->enabled );
378
+    }
379
+
380
+    /**
381
+     * Return the gateway's title.
382
+     *
383
+     * @return string
384
+     */
385
+    public function get_title() {
386
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
387
+    }
388
+
389
+    /**
390
+     * Return the gateway's description.
391
+     *
392
+     * @return string
393
+     */
394
+    public function get_description() {
395
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
396
+    }
397
+
398
+    /**
399
+     * Process Payment.
400
+     *
401
+     *
402
+     * @param WPInv_Invoice $invoice Invoice.
403
+     * @param array $submission_data Posted checkout fields.
404
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405
+     * @return void
406
+     */
407
+    public function process_payment( $invoice, $submission_data, $submission ) {
408
+        // Process the payment then either redirect to the success page or the gateway.
409
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
410
+    }
411
+
412
+    /**
413
+     * Process refund.
414
+     *
415
+     * If the gateway declares 'refunds' support, this will allow it to refund.
416
+     * a passed in amount.
417
+     *
418
+     * @param WPInv_Invoice $invoice Invoice.
419
+     * @param  float  $amount Refund amount.
420
+     * @param  string $reason Refund reason.
421
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
422
+     */
423
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
425
+    }
426
+
427
+    /**
428
+     * Displays the payment fields, credit cards etc.
429
+     * 
430
+     * @param int $invoice_id 0 or invoice id.
431
+     * @param GetPaid_Payment_Form $form Current payment form.
432
+     */
433
+    public function payment_fields( $invoice_id, $form ) {
434
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
435
+    }
436
+
437
+    /**
438
+     * Filters the gateway settings.
439
+     * 
440
+     * @param array $admin_settings
441
+     */
442
+    public function admin_settings( $admin_settings ) {
443
+        return $admin_settings;
444
+    }
445
+
446
+    /**
447
+     * Retrieves the value of a gateway setting.
448
+     * 
449
+     * @param string $option
450
+     */
451
+    public function get_option( $option, $default = false ) {
452
+        return wpinv_get_option( $this->id . '_' . $option, $default );
453
+    }
454
+
455
+    /**
456
+     * Check if a gateway supports a given feature.
457
+     *
458
+     * Gateways should override this to declare support (or lack of support) for a feature.
459
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
460
+     *
461
+     * @param string $feature string The name of a feature to test support for.
462
+     * @return bool True if the gateway supports the feature, false otherwise.
463
+     * @since 1.0.19
464
+     */
465
+    public function supports( $feature ) {
466
+        return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
467
+    }
468
+
469
+    /**
470
+     * Returns the credit card form html.
471
+     * 
472
+     * @param bool $save whether or not to display the save button.
473
+     */
474 474
     public function get_cc_form( $save = false ) {
475 475
 
476
-		ob_start();
476
+        ob_start();
477 477
 
478 478
         $id_prefix = esc_attr( uniqid( $this->id ) );
479 479
 
@@ -568,11 +568,11 @@  discard block
 block discarded – undo
568 568
                                         'name'              => $this->id . '[cc_cvv2]',
569 569
                                         'id'                => "$id_prefix-cc-cvv2",
570 570
                                         'label'             => __( 'CCV', 'invoicing' ),
571
-										'label_type'        => 'vertical',
572
-										'class'             => 'form-control-sm',
573
-										'extra_attributes'  => array(
574
-											'autocomplete'  => "cc-csc",
575
-										),
571
+                                        'label_type'        => 'vertical',
572
+                                        'class'             => 'form-control-sm',
573
+                                        'extra_attributes'  => array(
574
+                                            'autocomplete'  => "cc-csc",
575
+                                        ),
576 576
                                     )
577 577
                                 );
578 578
                             ?>
@@ -582,191 +582,191 @@  discard block
 block discarded – undo
582 582
 					
583 583
 					<?php
584 584
 
585
-						if ( $save ) {
586
-							echo $this->save_payment_method_checkbox();
587
-						}
585
+                        if ( $save ) {
586
+                            echo $this->save_payment_method_checkbox();
587
+                        }
588 588
 
589
-					?>
589
+                    ?>
590 590
                 </div>
591 591
 
592 592
             </div>
593 593
 		<?php
594 594
 		
595
-		return ob_get_clean();
595
+        return ob_get_clean();
596 596
 
597 597
     }
598 598
 
599
-	/**
600
-	 * Displays a new payment method entry form.
601
-	 *
602
-	 * @since 1.0.19
603
-	 */
604
-	public function new_payment_method_entry( $form ) {
605
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
606
-	}
607
-
608
-	/**
609
-	 * Grab and display our saved payment methods.
610
-	 *
611
-	 * @since 1.0.19
612
-	 */
613
-	public function saved_payment_methods() {
614
-		$html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
615
-
616
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
617
-			$html .= $this->get_saved_payment_method_option_html( $token );
618
-		}
619
-
620
-		$html .= $this->get_new_payment_method_option_html();
621
-		$html .= '</ul>';
622
-
623
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
624
-	}
625
-
626
-	/**
627
-	 * Gets saved payment method HTML from a token.
628
-	 *
629
-	 * @since 1.0.19
630
-	 * @param  array $token Payment Token.
631
-	 * @return string Generated payment method HTML
632
-	 */
633
-	public function get_saved_payment_method_option_html( $token ) {
634
-
635
-		return sprintf(
636
-			'<li class="getpaid-payment-method form-group">
599
+    /**
600
+     * Displays a new payment method entry form.
601
+     *
602
+     * @since 1.0.19
603
+     */
604
+    public function new_payment_method_entry( $form ) {
605
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
606
+    }
607
+
608
+    /**
609
+     * Grab and display our saved payment methods.
610
+     *
611
+     * @since 1.0.19
612
+     */
613
+    public function saved_payment_methods() {
614
+        $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
615
+
616
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
617
+            $html .= $this->get_saved_payment_method_option_html( $token );
618
+        }
619
+
620
+        $html .= $this->get_new_payment_method_option_html();
621
+        $html .= '</ul>';
622
+
623
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
624
+    }
625
+
626
+    /**
627
+     * Gets saved payment method HTML from a token.
628
+     *
629
+     * @since 1.0.19
630
+     * @param  array $token Payment Token.
631
+     * @return string Generated payment method HTML
632
+     */
633
+    public function get_saved_payment_method_option_html( $token ) {
634
+
635
+        return sprintf(
636
+            '<li class="getpaid-payment-method form-group">
637 637
 				<label>
638 638
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
639 639
 					<span>%3$s</span>
640 640
 				</label>
641 641
 			</li>',
642
-			esc_attr( $this->id ),
643
-			esc_attr( $token['id'] ),
644
-			esc_html( $token['name'] ),
645
-			checked( empty( $token['default'] ), false, false )
646
-		);
642
+            esc_attr( $this->id ),
643
+            esc_attr( $token['id'] ),
644
+            esc_html( $token['name'] ),
645
+            checked( empty( $token['default'] ), false, false )
646
+        );
647 647
 
648
-	}
648
+    }
649 649
 
650
-	/**
651
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
652
-	 *
653
-	 * @since 1.0.19
654
-	 */
655
-	public function get_new_payment_method_option_html() {
650
+    /**
651
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
652
+     *
653
+     * @since 1.0.19
654
+     */
655
+    public function get_new_payment_method_option_html() {
656 656
 
657
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
657
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
658 658
 
659
-		return sprintf(
660
-			'<li class="getpaid-new-payment-method">
659
+        return sprintf(
660
+            '<li class="getpaid-new-payment-method">
661 661
 				<label>
662 662
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
663 663
 					<span>%2$s</span>
664 664
 				</label>
665 665
 			</li>',
666
-			esc_attr( $this->id ),
667
-			esc_html( $label )
668
-		);
669
-
670
-	}
671
-
672
-	/**
673
-	 * Outputs a checkbox for saving a new payment method to the database.
674
-	 *
675
-	 * @since 1.0.19
676
-	 */
677
-	public function save_payment_method_checkbox() {
678
-
679
-		return aui()->input(
680
-			array(
681
-				'type'       => 'checkbox',
682
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
683
-				'id'         => esc_attr( uniqid( $this->id ) ),
684
-				'required'   => false,
685
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
686
-				'value'      => 'true',
687
-				'checked'    => true,
688
-				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
689
-			)
690
-		);
691
-
692
-	}
693
-
694
-	/**
695
-	 * Registers the gateway.
696
-	 *
697
-	 * @return array
698
-	 */
699
-	public function register_gateway( $gateways ) {
700
-
701
-		$gateways[ $this->id ] = array(
702
-
703
-			'admin_label'    => $this->method_title,
666
+            esc_attr( $this->id ),
667
+            esc_html( $label )
668
+        );
669
+
670
+    }
671
+
672
+    /**
673
+     * Outputs a checkbox for saving a new payment method to the database.
674
+     *
675
+     * @since 1.0.19
676
+     */
677
+    public function save_payment_method_checkbox() {
678
+
679
+        return aui()->input(
680
+            array(
681
+                'type'       => 'checkbox',
682
+                'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
683
+                'id'         => esc_attr( uniqid( $this->id ) ),
684
+                'required'   => false,
685
+                'label'      => esc_html__( 'Save payment method', 'invoicing' ),
686
+                'value'      => 'true',
687
+                'checked'    => true,
688
+                'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
689
+            )
690
+        );
691
+
692
+    }
693
+
694
+    /**
695
+     * Registers the gateway.
696
+     *
697
+     * @return array
698
+     */
699
+    public function register_gateway( $gateways ) {
700
+
701
+        $gateways[ $this->id ] = array(
702
+
703
+            'admin_label'    => $this->method_title,
704 704
             'checkout_label' => $this->title,
705
-			'ordering'       => $this->order,
705
+            'ordering'       => $this->order,
706 706
 
707
-		);
707
+        );
708 708
 
709
-		return $gateways;
709
+        return $gateways;
710 710
 
711
-	}
711
+    }
712 712
 
713
-	/**
714
-	 * Checks whether or not this is a sandbox request.
715
-	 *
716
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
717
-	 * @return bool
718
-	 */
719
-	public function is_sandbox( $invoice = null ) {
713
+    /**
714
+     * Checks whether or not this is a sandbox request.
715
+     *
716
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
717
+     * @return bool
718
+     */
719
+    public function is_sandbox( $invoice = null ) {
720 720
 
721
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
722
-			return $invoice->get_mode() == 'test';
723
-		}
721
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
722
+            return $invoice->get_mode() == 'test';
723
+        }
724 724
 
725
-		return wpinv_is_test_mode( $this->id );
725
+        return wpinv_is_test_mode( $this->id );
726 726
 
727
-	}
727
+    }
728 728
 
729
-	/**
730
-	 * Renames the checkout button
731
-	 *
732
-	 * @return string
733
-	 */
734
-	public function rename_checkout_button() {
735
-		return $this->checkout_button_text;
736
-	}
729
+    /**
730
+     * Renames the checkout button
731
+     *
732
+     * @return string
733
+     */
734
+    public function rename_checkout_button() {
735
+        return $this->checkout_button_text;
736
+    }
737 737
 
738
-	/**
739
-	 * Validate gateway currency
740
-	 *
741
-	 * @return bool
742
-	 */
743
-	public function validate_currency( $validation, $currency ) {
738
+    /**
739
+     * Validate gateway currency
740
+     *
741
+     * @return bool
742
+     */
743
+    public function validate_currency( $validation, $currency ) {
744 744
 
745
-		// Required currencies.
746
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
747
-			return false;
748
-		}
745
+        // Required currencies.
746
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
747
+            return false;
748
+        }
749 749
 
750
-		// Excluded currencies.
751
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
752
-			return false;
753
-		}
750
+        // Excluded currencies.
751
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
752
+            return false;
753
+        }
754 754
 
755
-		return $validation;
756
-	}
755
+        return $validation;
756
+    }
757 757
 
758
-	/**
759
-	 * Displays an error
760
-	 *
761
-	 */
762
-	public function show_error( $code, $message, $type ) {
758
+    /**
759
+     * Displays an error
760
+     *
761
+     */
762
+    public function show_error( $code, $message, $type ) {
763 763
 
764
-		if ( is_admin() ) {
765
-			getpaid_admin()->{"show_$type"}( $message );
766
-		}
764
+        if ( is_admin() ) {
765
+            getpaid_admin()->{"show_$type"}( $message );
766
+        }
767 767
 
768
-		wpinv_set_error( $code, $message, $type );
768
+        wpinv_set_error( $code, $message, $type );
769 769
 
770
-	}
770
+    }
771 771
 
772 772
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -12,180 +12,180 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
133 117
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
138 125
 
139
-		return $invoice;
140
-	}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
141 131
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
132
+        $invoice = $submission->get_invoice();
150 133
 
151
-		$submission = $this->payment_form_submission;
152
-		$data       = $submission->get_data();
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
138
+
139
+        return $invoice;
140
+    }
141
+
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
153 150
 
154
-		// Set-up the invoice details.
155
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
-		$invoice->set_user_id( $this->get_submission_customer() );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
151
+        $submission = $this->payment_form_submission;
152
+        $data       = $submission->get_data();
153
+
154
+        // Set-up the invoice details.
155
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
156
+        $invoice->set_user_id( $this->get_submission_customer() );
157
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158 158
         $invoice->set_items( $items );
159 159
         $invoice->set_fees( $submission->get_fees() );
160 160
         $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $data['wpi-gateway'] );
161
+        $invoice->set_discounts( $submission->get_discounts() );
162
+        $invoice->set_gateway( $data['wpi-gateway'] );
163 163
 
164
-		$address_confirmed = $submission->get_field( 'confirm-address' );
165
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
164
+        $address_confirmed = $submission->get_field( 'confirm-address' );
165
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
166 166
 
167
-		if ( $submission->has_discount_code() ) {
167
+        if ( $submission->has_discount_code() ) {
168 168
             $invoice->set_discount_code( $submission->get_discount_code() );
169
-		}
170
-
171
-		getpaid_maybe_add_default_address( $invoice );
172
-		return $invoice;
173
-	}
174
-
175
-	/**
176
-	 * Retrieves the submission's customer.
177
-	 *
178
-	 * @return int The customer id.
179
-	 */
180
-	protected function get_submission_customer() {
181
-		$submission = $this->payment_form_submission;
182
-
183
-		// If this is an existing invoice...
184
-		if ( $submission->has_invoice() ) {
185
-			return $submission->get_invoice()->get_user_id();
186
-		}
187
-
188
-		// (Maybe) create the user.
169
+        }
170
+
171
+        getpaid_maybe_add_default_address( $invoice );
172
+        return $invoice;
173
+    }
174
+
175
+    /**
176
+     * Retrieves the submission's customer.
177
+     *
178
+     * @return int The customer id.
179
+     */
180
+    protected function get_submission_customer() {
181
+        $submission = $this->payment_form_submission;
182
+
183
+        // If this is an existing invoice...
184
+        if ( $submission->has_invoice() ) {
185
+            return $submission->get_invoice()->get_user_id();
186
+        }
187
+
188
+        // (Maybe) create the user.
189 189
         $user = get_current_user_id();
190 190
 
191 191
         if ( empty( $user ) ) {
@@ -202,31 +202,31 @@  discard block
 block discarded – undo
202 202
 
203 203
         if ( is_numeric( $user ) ) {
204 204
             return $user;
205
-		}
205
+        }
206 206
 
207
-		return $user->ID;
207
+        return $user->ID;
208 208
 
209
-	}
209
+    }
210 210
 
211
-	/**
211
+    /**
212 212
      * Prepares submission data for saving to the database.
213 213
      *
214
-	 * @return array
214
+     * @return array
215 215
      */
216 216
     public function prepare_submission_data_for_saving() {
217 217
 
218
-		$submission = $this->payment_form_submission;
218
+        $submission = $this->payment_form_submission;
219 219
 
220
-		// Prepared submission details.
220
+        // Prepared submission details.
221 221
         $prepared = array();
222 222
 
223 223
         // Raw submission details.
224
-		$data     = $submission->get_data();
224
+        $data     = $submission->get_data();
225 225
 
226
-		// Loop through the submitted details.
226
+        // Loop through the submitted details.
227 227
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
228 228
 
229
-			// Skip premade fields.
229
+            // Skip premade fields.
230 230
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
231 231
                 continue;
232 232
             }
@@ -244,176 +244,176 @@  discard block
 block discarded – undo
244 244
                     $label = $field['label'];
245 245
                 }
246 246
 
247
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
247
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
248 248
 
249 249
             }
250 250
 
251
-		}
251
+        }
252 252
 
253
-		return $prepared;
253
+        return $prepared;
254 254
 
255
-	}
255
+    }
256 256
 
257
-	/**
257
+    /**
258 258
      * Retrieves address details.
259 259
      *
260
-	 * @return array
261
-	 * @param WPInv_Invoice $invoice
262
-	 * @param string $type
260
+     * @return array
261
+     * @param WPInv_Invoice $invoice
262
+     * @param string $type
263 263
      */
264 264
     public function prepare_address_details( $invoice, $type = 'billing' ) {
265 265
 
266
-		$data     = $this->payment_form_submission->get_data();
267
-		$type     = sanitize_key( $type );
268
-		$address  = array();
269
-		$prepared = array();
266
+        $data     = $this->payment_form_submission->get_data();
267
+        $type     = sanitize_key( $type );
268
+        $address  = array();
269
+        $prepared = array();
270 270
 
271
-		if ( ! empty( $data[ $type ] ) ) {
272
-			$address = $data[ $type ];
273
-		}
271
+        if ( ! empty( $data[ $type ] ) ) {
272
+            $address = $data[ $type ];
273
+        }
274 274
 
275
-		// Clean address details.
276
-		foreach ( $address as $key => $value ) {
277
-			$key             = sanitize_key( $key );
278
-			$key             = str_replace( 'wpinv_', '', $key );
279
-			$value           = wpinv_clean( $value );
280
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
281
-		}
275
+        // Clean address details.
276
+        foreach ( $address as $key => $value ) {
277
+            $key             = sanitize_key( $key );
278
+            $key             = str_replace( 'wpinv_', '', $key );
279
+            $value           = wpinv_clean( $value );
280
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
281
+        }
282 282
 
283
-		// Filter address details.
284
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
283
+        // Filter address details.
284
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
285 285
 
286
-		// Remove non-whitelisted values.
287
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
286
+        // Remove non-whitelisted values.
287
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
288 288
 
289
-	}
289
+    }
290 290
 
291
-	/**
291
+    /**
292 292
      * Prepares the billing details.
293 293
      *
294
-	 * @return array
295
-	 * @param WPInv_Invoice $invoice
294
+     * @return array
295
+     * @param WPInv_Invoice $invoice
296 296
      */
297 297
     protected function prepare_billing_info( &$invoice ) {
298 298
 
299
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
299
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
300 300
 
301
-		// Update the invoice with the billing details.
302
-		$invoice->set_props( $billing_address );
301
+        // Update the invoice with the billing details.
302
+        $invoice->set_props( $billing_address );
303 303
 
304
-	}
304
+    }
305 305
 
306
-	/**
306
+    /**
307 307
      * Prepares the shipping details.
308 308
      *
309
-	 * @return array
310
-	 * @param WPInv_Invoice $invoice
309
+     * @return array
310
+     * @param WPInv_Invoice $invoice
311 311
      */
312 312
     protected function prepare_shipping_info( $invoice ) {
313 313
 
314
-		$data = $this->payment_form_submission->get_data();
314
+        $data = $this->payment_form_submission->get_data();
315 315
 
316
-		if ( empty( $data['same-shipping-address'] ) ) {
317
-			return $this->prepare_address_details( $invoice, 'shipping' );
318
-		}
316
+        if ( empty( $data['same-shipping-address'] ) ) {
317
+            return $this->prepare_address_details( $invoice, 'shipping' );
318
+        }
319 319
 
320
-		return $this->prepare_address_details( $invoice, 'billing' );
320
+        return $this->prepare_address_details( $invoice, 'billing' );
321 321
 
322
-	}
322
+    }
323 323
 
324
-	/**
325
-	 * Confirms the submission is valid and send users to the gateway.
326
-	 *
327
-	 * @param WPInv_Invoice $invoice
328
-	 * @param array $prepared_payment_form_data
329
-	 * @param array $shipping
330
-	 */
331
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
324
+    /**
325
+     * Confirms the submission is valid and send users to the gateway.
326
+     *
327
+     * @param WPInv_Invoice $invoice
328
+     * @param array $prepared_payment_form_data
329
+     * @param array $shipping
330
+     */
331
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
332 332
 
333
-		// Ensure the invoice exists.
333
+        // Ensure the invoice exists.
334 334
         if ( ! $invoice->exists() ) {
335 335
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
336 336
         }
337 337
 
338
-		// Save payment form data.
339
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
338
+        // Save payment form data.
339
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
340 340
         if ( ! empty( $prepared_payment_form_data ) ) {
341 341
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
342
-		}
342
+        }
343 343
 
344
-		// Save payment form data.
344
+        // Save payment form data.
345 345
         if ( ! empty( $shipping ) ) {
346 346
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
347
-		}
347
+        }
348 348
 
349
-		// Backwards compatibility.
349
+        // Backwards compatibility.
350 350
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
351 351
 
352
-		$this->process_payment( $invoice );
352
+        $this->process_payment( $invoice );
353 353
 
354 354
         // If we are here, there was an error.
355
-		wpinv_send_back_to_checkout( $invoice );
355
+        wpinv_send_back_to_checkout( $invoice );
356 356
 
357
-	}
357
+    }
358 358
 
359
-	/**
360
-	 * Processes the actual payment.
361
-	 *
362
-	 * @param WPInv_Invoice $invoice
363
-	 */
364
-	protected function process_payment( $invoice ) {
359
+    /**
360
+     * Processes the actual payment.
361
+     *
362
+     * @param WPInv_Invoice $invoice
363
+     */
364
+    protected function process_payment( $invoice ) {
365 365
 
366
-		// Clear any checkout errors.
367
-		wpinv_clear_errors();
366
+        // Clear any checkout errors.
367
+        wpinv_clear_errors();
368 368
 
369
-		// No need to send free invoices to the gateway.
370
-		if ( $invoice->is_free() ) {
371
-			$this->process_free_payment( $invoice );
372
-		}
369
+        // No need to send free invoices to the gateway.
370
+        if ( $invoice->is_free() ) {
371
+            $this->process_free_payment( $invoice );
372
+        }
373 373
 
374
-		$submission = $this->payment_form_submission;
374
+        $submission = $this->payment_form_submission;
375 375
 
376
-		// Fires before sending to the gateway.
377
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
376
+        // Fires before sending to the gateway.
377
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
378 378
 
379
-		// Allow the sumission data to be modified before it is sent to the gateway.
380
-		$submission_data    = $submission->get_data();
381
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
382
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
379
+        // Allow the sumission data to be modified before it is sent to the gateway.
380
+        $submission_data    = $submission->get_data();
381
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
382
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
383 383
 
384
-		// Validate the currency.
385
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
386
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
387
-		}
384
+        // Validate the currency.
385
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
386
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
387
+        }
388 388
 
389
-		// Check to see if we have any errors.
390
-		if ( wpinv_get_errors() ) {
391
-			wpinv_send_back_to_checkout( $invoice );
392
-		}
389
+        // Check to see if we have any errors.
390
+        if ( wpinv_get_errors() ) {
391
+            wpinv_send_back_to_checkout( $invoice );
392
+        }
393 393
 
394
-		// Send info to the gateway for payment processing
395
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
394
+        // Send info to the gateway for payment processing
395
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
396 396
 
397
-		// Backwards compatibility.
398
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
397
+        // Backwards compatibility.
398
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
399 399
 
400
-	}
400
+    }
401 401
 
402
-	/**
403
-	 * Marks the invoice as paid in case the checkout is free.
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 */
407
-	protected function process_free_payment( $invoice ) {
402
+    /**
403
+     * Marks the invoice as paid in case the checkout is free.
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     */
407
+    protected function process_free_payment( $invoice ) {
408 408
 
409
-		$invoice->set_gateway( 'none' );
410
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
411
-		$invoice->mark_paid();
412
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
409
+        $invoice->set_gateway( 'none' );
410
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
411
+        $invoice->mark_paid();
412
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
413 413
 
414
-	}
414
+    }
415 415
 
416
-	/**
416
+    /**
417 417
      * Sends a redrect response to payment details.
418 418
      *
419 419
      */
Please login to merge, or discard this patch.
vendor/composer/installers/src/Composer/Installers/OxidInstaller.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 
6 6
 class OxidInstaller extends BaseInstaller
7 7
 {
8
-	const VENDOR_PATTERN = '/^modules\/(?P<vendor>.+)\/.+/';
8
+    const VENDOR_PATTERN = '/^modules\/(?P<vendor>.+)\/.+/';
9 9
 
10 10
     protected $locations = array(
11 11
         'module'    => 'modules/{$name}/',
@@ -13,47 +13,47 @@  discard block
 block discarded – undo
13 13
         'out'    => 'out/{$name}/',
14 14
     );
15 15
 
16
-	/**
17
-	 * getInstallPath
18
-	 *
19
-	 * @param PackageInterface $package
20
-	 * @param string $frameworkType
21
-	 * @return string
22
-	 */
23
-	public function getInstallPath(PackageInterface $package, $frameworkType = '')
24
-	{
25
-		$installPath = parent::getInstallPath($package, $frameworkType);
26
-		$type = $this->package->getType();
27
-		if ($type === 'oxid-module') {
28
-			$this->prepareVendorDirectory($installPath);
29
-		}
30
-		return $installPath;
31
-	}
16
+    /**
17
+     * getInstallPath
18
+     *
19
+     * @param PackageInterface $package
20
+     * @param string $frameworkType
21
+     * @return string
22
+     */
23
+    public function getInstallPath(PackageInterface $package, $frameworkType = '')
24
+    {
25
+        $installPath = parent::getInstallPath($package, $frameworkType);
26
+        $type = $this->package->getType();
27
+        if ($type === 'oxid-module') {
28
+            $this->prepareVendorDirectory($installPath);
29
+        }
30
+        return $installPath;
31
+    }
32 32
 
33
-	/**
34
-	 * prepareVendorDirectory
35
-	 *
36
-	 * Makes sure there is a vendormetadata.php file inside
37
-	 * the vendor folder if there is a vendor folder.
38
-	 *
39
-	 * @param string $installPath
40
-	 * @return void
41
-	 */
42
-	protected function prepareVendorDirectory($installPath)
43
-	{
44
-		$matches = '';
45
-		$hasVendorDirectory = preg_match(self::VENDOR_PATTERN, $installPath, $matches);
46
-		if (!$hasVendorDirectory) {
47
-			return;
48
-		}
33
+    /**
34
+     * prepareVendorDirectory
35
+     *
36
+     * Makes sure there is a vendormetadata.php file inside
37
+     * the vendor folder if there is a vendor folder.
38
+     *
39
+     * @param string $installPath
40
+     * @return void
41
+     */
42
+    protected function prepareVendorDirectory($installPath)
43
+    {
44
+        $matches = '';
45
+        $hasVendorDirectory = preg_match(self::VENDOR_PATTERN, $installPath, $matches);
46
+        if (!$hasVendorDirectory) {
47
+            return;
48
+        }
49 49
 
50
-		$vendorDirectory = $matches['vendor'];
51
-		$vendorPath = getcwd() . '/modules/' . $vendorDirectory;
52
-		if (!file_exists($vendorPath)) {
53
-			mkdir($vendorPath, 0755, true);
54
-		}
50
+        $vendorDirectory = $matches['vendor'];
51
+        $vendorPath = getcwd() . '/modules/' . $vendorDirectory;
52
+        if (!file_exists($vendorPath)) {
53
+            mkdir($vendorPath, 0755, true);
54
+        }
55 55
 
56
-		$vendorMetaDataPath = $vendorPath . '/vendormetadata.php';
57
-		touch($vendorMetaDataPath);
58
-	}
56
+        $vendorMetaDataPath = $vendorPath . '/vendormetadata.php';
57
+        touch($vendorMetaDataPath);
58
+    }
59 59
 }
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-helper.php 1 patch
Indentation   +369 added lines, -369 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,372 +11,372 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Helper {
13 13
 
14
-	/**
15
-	 * A component helper for generating a input name.
16
-	 *
17
-	 * @param $text
18
-	 * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
-	 *
20
-	 * @return string
21
-	 */
22
-	public static function name($text,$multiple = false){
23
-		$output = '';
24
-
25
-		if($text){
26
-			$is_multiple = strpos($text, '[') === false && $multiple  ? '[]' : '';
27
-			$output = ' name="'.esc_attr($text).$is_multiple.'" ';
28
-		}
29
-
30
-		return $output;
31
-	}
32
-
33
-	/**
34
-	 * A component helper for generating a item id.
35
-	 *
36
-	 * @param $text string The text to be used as the value.
37
-	 *
38
-	 * @return string The sanitized item.
39
-	 */
40
-	public static function id($text){
41
-		$output = '';
42
-
43
-		if($text){
44
-			$output = ' id="'.sanitize_html_class($text).'" ';
45
-		}
46
-
47
-		return $output;
48
-	}
49
-
50
-	/**
51
-	 * A component helper for generating a item title.
52
-	 *
53
-	 * @param $text string The text to be used as the value.
54
-	 *
55
-	 * @return string The sanitized item.
56
-	 */
57
-	public static function title($text){
58
-		$output = '';
59
-
60
-		if($text){
61
-			$output = ' title="'.esc_attr($text).'" ';
62
-		}
63
-
64
-		return $output;
65
-	}
66
-
67
-	/**
68
-	 * A component helper for generating a item value.
69
-	 *
70
-	 * @param $text string The text to be used as the value.
71
-	 *
72
-	 * @return string The sanitized item.
73
-	 */
74
-	public static function value($text){
75
-		$output = '';
76
-
77
-		if($text){
78
-			$output = ' value="'.sanitize_text_field($text).'" ';
79
-		}
80
-
81
-		return $output;
82
-	}
83
-
84
-	/**
85
-	 * A component helper for generating a item class attribute.
86
-	 *
87
-	 * @param $text string The text to be used as the value.
88
-	 *
89
-	 * @return string The sanitized item.
90
-	 */
91
-	public static function class_attr($text){
92
-		$output = '';
93
-
94
-		if($text){
95
-			$classes = self::esc_classes($text);
96
-			if(!empty($classes)){
97
-				$output = ' class="'.$classes.'" ';
98
-			}
99
-		}
100
-
101
-		return $output;
102
-	}
103
-
104
-	/**
105
-	 * Escape a string of classes.
106
-	 *
107
-	 * @param $text
108
-	 *
109
-	 * @return string
110
-	 */
111
-	public static function esc_classes($text){
112
-		$output = '';
113
-
114
-		if($text){
115
-			$classes = explode(" ",$text);
116
-			$classes = array_map("trim",$classes);
117
-			$classes = array_map("sanitize_html_class",$classes);
118
-			if(!empty($classes)){
119
-				$output = implode(" ",$classes);
120
-			}
121
-		}
122
-
123
-		return $output;
124
-
125
-	}
126
-
127
-	/**
128
-	 * @param $args
129
-	 *
130
-	 * @return string
131
-	 */
132
-	public static function data_attributes($args){
133
-		$output = '';
134
-
135
-		if(!empty($args)){
136
-
137
-			foreach($args as $key => $val){
138
-				if(substr( $key, 0, 5 ) === "data-"){
139
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
140
-				}
141
-			}
142
-		}
143
-
144
-		return $output;
145
-	}
146
-
147
-	/**
148
-	 * @param $args
149
-	 *
150
-	 * @return string
151
-	 */
152
-	public static function aria_attributes($args){
153
-		$output = '';
154
-
155
-		if(!empty($args)){
156
-
157
-			foreach($args as $key => $val){
158
-				if(substr( $key, 0, 5 ) === "aria-"){
159
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
160
-				}
161
-			}
162
-		}
163
-
164
-		return $output;
165
-	}
166
-
167
-	/**
168
-	 * Build a font awesome icon from a class.
169
-	 *
170
-	 * @param $class
171
-	 * @param bool $space_after
172
-	 * @param array $extra_attributes An array of extra attributes.
173
-	 *
174
-	 * @return string
175
-	 */
176
-	public static function icon($class,$space_after = false, $extra_attributes = array()){
177
-		$output = '';
178
-
179
-		if($class){
180
-			$classes = self::esc_classes($class);
181
-			if(!empty($classes)){
182
-				$output = '<i class="'.$classes.'" ';
183
-				// extra attributes
184
-				if(!empty($extra_attributes)){
185
-					$output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186
-				}
187
-				$output .= '></i>';
188
-				if($space_after){
189
-					$output .= " ";
190
-				}
191
-			}
192
-		}
193
-
194
-		return $output;
195
-	}
196
-
197
-	/**
198
-	 * @param $args
199
-	 *
200
-	 * @return string
201
-	 */
202
-	public static function extra_attributes($args){
203
-		$output = '';
204
-
205
-		if(!empty($args)){
206
-
207
-			if( is_array($args) ){
208
-				foreach($args as $key => $val){
209
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
210
-				}
211
-			}else{
212
-				$output .= ' '.$args.' ';
213
-			}
214
-
215
-		}
216
-
217
-		return $output;
218
-	}
219
-
220
-	/**
221
-	 * @param $args
222
-	 *
223
-	 * @return string
224
-	 */
225
-	public static function help_text($text){
226
-		$output = '';
227
-
228
-		if($text){
229
-			$output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>';
230
-		}
231
-
232
-
233
-		return $output;
234
-	}
235
-
236
-	/**
237
-	 * Replace element require context with JS.
238
-	 *
239
-	 * @param $input
240
-	 *
241
-	 * @return string|void
242
-	 */
243
-	public static function element_require( $input ) {
244
-
245
-		$input = str_replace( "'", '"', $input );// we only want double quotes
246
-
247
-		$output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
-			"jQuery(form).find('[data-argument=\"",
249
-			"\"]').find('input,select,textarea').val()",
250
-			"\"]').find('input:checked').val()",
251
-		), $input ) );
252
-
253
-		if($output){
254
-			$output = ' data-element-require="'.$output.'" ';
255
-		}
256
-
257
-		return $output;
258
-	}
259
-
260
-	/**
261
-	 * Returns an array of allowed HTML tags and attributes for a given context.
262
-	 *
263
-	 * @since 0.1.41
264
-	 *
265
-	 * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
266
-	 *                              'strip', 'data', 'entities', or the name of a field filter such as
267
-	 *                              'pre_user_description'.
268
-	 * @param array $input Input.
269
-	 * @return array Array of allowed HTML tags and their allowed attributes.
270
-	 */
271
-	public static function kses_allowed_html( $context = 'post', $input = array() ) {
272
-		$allowed_html = wp_kses_allowed_html( $context );
273
-
274
-		if ( is_array( $allowed_html ) ) {
275
-			// <iframe>
276
-			if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
277
-				$allowed_html['iframe']     = array(
278
-					'class'        => true,
279
-					'id'           => true,
280
-					'src'          => true,
281
-					'width'        => true,
282
-					'height'       => true,
283
-					'frameborder'  => true,
284
-					'marginwidth'  => true,
285
-					'marginheight' => true,
286
-					'scrolling'    => true,
287
-					'style'        => true,
288
-					'title'        => true,
289
-					'allow'        => true,
290
-					'allowfullscreen' => true,
291
-					'data-*'       => true,
292
-				);
293
-			}
294
-		}
295
-
296
-		/**
297
-		 * Filters the allowed html tags.
298
-		 *
299
-		 * @since 0.1.41
300
-		 *
301
-		 * @param array[]|string $allowed_html Allowed html tags.
302
-		 * @param @param string|array $context The context for which to retrieve tags.
303
-		 * @param array $input Input field.
304
-		 */
305
-		return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
306
-	}
307
-
308
-	/**
309
-	 * Filters content and keeps only allowable HTML elements.
310
-	 *
311
-	 * This function makes sure that only the allowed HTML element names, attribute
312
-	 * names and attribute values plus only sane HTML entities will occur in
313
-	 * $string. You have to remove any slashes from PHP's magic quotes before you
314
-	 * call this function.
315
-	 *
316
-	 * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
317
-	 * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
318
-	 * covers all common link protocols, except for 'javascript' which should not
319
-	 * be allowed for untrusted users.
320
-	 *
321
-	 * @since 0.1.41
322
-	 *
323
-	 * @param string|array $value Content to filter through kses.
324
-	 * @param array  $input       Input Field.
325
-	 * @return string Filtered content with only allowed HTML elements.
326
-	 */
327
-	public static function _sanitize_html_field( $value, $input = array() ) {
328
-		if ( $value === '' ) {
329
-			return $value;
330
-		}
331
-
332
-		$allowed_html = self::kses_allowed_html( 'post', $input );
333
-
334
-		if ( ! is_array( $allowed_html ) ) {
335
-			$allowed_html = wp_kses_allowed_html( 'post' );
336
-		}
337
-
338
-		$filtered = trim( wp_unslash( $value ) );
339
-		$filtered = wp_kses( $filtered, $allowed_html );
340
-		$filtered = balanceTags( $filtered ); // Balances tags
341
-
342
-		return $filtered;
343
-	}
344
-
345
-	/**
346
-	 * Navigates through an array, object, or scalar, and removes slashes from the values.
347
-	 *
348
-	 * @since 0.1.41
349
-	 *
350
-	 * @param mixed $value The value to be stripped.
351
-	 * @param array  $input Input Field.
352
-	 * @return mixed Stripped value.
353
-	 */
354
-	public static function sanitize_html_field( $value, $input = array() ) {
355
-		$original = $value;
356
-
357
-		if ( is_array( $value ) ) {
358
-			foreach ( $value as $index => $item ) {
359
-				$value[ $index ] = self::_sanitize_html_field( $value, $input );
360
-			}
361
-		} elseif ( is_object( $value ) ) {
362
-			$object_vars = get_object_vars( $value );
363
-
364
-			foreach ( $object_vars as $property_name => $property_value ) {
365
-				$value->$property_name = self::_sanitize_html_field( $property_value, $input );
366
-			}
367
-		} else {
368
-			$value = self::_sanitize_html_field( $value, $input );
369
-		}
370
-
371
-		/**
372
-		 * Filters content and keeps only allowable HTML elements.
373
-		 *
374
-		 * @since 0.1.41
375
-		 *
376
-		 * @param string|array $value Content to filter through kses.
377
-		 * @param string|array $value Original content without filter.
378
-		 * @param array  $input       Input Field.
379
-		 */
380
-		return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
381
-	}
14
+    /**
15
+     * A component helper for generating a input name.
16
+     *
17
+     * @param $text
18
+     * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
+     *
20
+     * @return string
21
+     */
22
+    public static function name($text,$multiple = false){
23
+        $output = '';
24
+
25
+        if($text){
26
+            $is_multiple = strpos($text, '[') === false && $multiple  ? '[]' : '';
27
+            $output = ' name="'.esc_attr($text).$is_multiple.'" ';
28
+        }
29
+
30
+        return $output;
31
+    }
32
+
33
+    /**
34
+     * A component helper for generating a item id.
35
+     *
36
+     * @param $text string The text to be used as the value.
37
+     *
38
+     * @return string The sanitized item.
39
+     */
40
+    public static function id($text){
41
+        $output = '';
42
+
43
+        if($text){
44
+            $output = ' id="'.sanitize_html_class($text).'" ';
45
+        }
46
+
47
+        return $output;
48
+    }
49
+
50
+    /**
51
+     * A component helper for generating a item title.
52
+     *
53
+     * @param $text string The text to be used as the value.
54
+     *
55
+     * @return string The sanitized item.
56
+     */
57
+    public static function title($text){
58
+        $output = '';
59
+
60
+        if($text){
61
+            $output = ' title="'.esc_attr($text).'" ';
62
+        }
63
+
64
+        return $output;
65
+    }
66
+
67
+    /**
68
+     * A component helper for generating a item value.
69
+     *
70
+     * @param $text string The text to be used as the value.
71
+     *
72
+     * @return string The sanitized item.
73
+     */
74
+    public static function value($text){
75
+        $output = '';
76
+
77
+        if($text){
78
+            $output = ' value="'.sanitize_text_field($text).'" ';
79
+        }
80
+
81
+        return $output;
82
+    }
83
+
84
+    /**
85
+     * A component helper for generating a item class attribute.
86
+     *
87
+     * @param $text string The text to be used as the value.
88
+     *
89
+     * @return string The sanitized item.
90
+     */
91
+    public static function class_attr($text){
92
+        $output = '';
93
+
94
+        if($text){
95
+            $classes = self::esc_classes($text);
96
+            if(!empty($classes)){
97
+                $output = ' class="'.$classes.'" ';
98
+            }
99
+        }
100
+
101
+        return $output;
102
+    }
103
+
104
+    /**
105
+     * Escape a string of classes.
106
+     *
107
+     * @param $text
108
+     *
109
+     * @return string
110
+     */
111
+    public static function esc_classes($text){
112
+        $output = '';
113
+
114
+        if($text){
115
+            $classes = explode(" ",$text);
116
+            $classes = array_map("trim",$classes);
117
+            $classes = array_map("sanitize_html_class",$classes);
118
+            if(!empty($classes)){
119
+                $output = implode(" ",$classes);
120
+            }
121
+        }
122
+
123
+        return $output;
124
+
125
+    }
126
+
127
+    /**
128
+     * @param $args
129
+     *
130
+     * @return string
131
+     */
132
+    public static function data_attributes($args){
133
+        $output = '';
134
+
135
+        if(!empty($args)){
136
+
137
+            foreach($args as $key => $val){
138
+                if(substr( $key, 0, 5 ) === "data-"){
139
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
140
+                }
141
+            }
142
+        }
143
+
144
+        return $output;
145
+    }
146
+
147
+    /**
148
+     * @param $args
149
+     *
150
+     * @return string
151
+     */
152
+    public static function aria_attributes($args){
153
+        $output = '';
154
+
155
+        if(!empty($args)){
156
+
157
+            foreach($args as $key => $val){
158
+                if(substr( $key, 0, 5 ) === "aria-"){
159
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
160
+                }
161
+            }
162
+        }
163
+
164
+        return $output;
165
+    }
166
+
167
+    /**
168
+     * Build a font awesome icon from a class.
169
+     *
170
+     * @param $class
171
+     * @param bool $space_after
172
+     * @param array $extra_attributes An array of extra attributes.
173
+     *
174
+     * @return string
175
+     */
176
+    public static function icon($class,$space_after = false, $extra_attributes = array()){
177
+        $output = '';
178
+
179
+        if($class){
180
+            $classes = self::esc_classes($class);
181
+            if(!empty($classes)){
182
+                $output = '<i class="'.$classes.'" ';
183
+                // extra attributes
184
+                if(!empty($extra_attributes)){
185
+                    $output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186
+                }
187
+                $output .= '></i>';
188
+                if($space_after){
189
+                    $output .= " ";
190
+                }
191
+            }
192
+        }
193
+
194
+        return $output;
195
+    }
196
+
197
+    /**
198
+     * @param $args
199
+     *
200
+     * @return string
201
+     */
202
+    public static function extra_attributes($args){
203
+        $output = '';
204
+
205
+        if(!empty($args)){
206
+
207
+            if( is_array($args) ){
208
+                foreach($args as $key => $val){
209
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
210
+                }
211
+            }else{
212
+                $output .= ' '.$args.' ';
213
+            }
214
+
215
+        }
216
+
217
+        return $output;
218
+    }
219
+
220
+    /**
221
+     * @param $args
222
+     *
223
+     * @return string
224
+     */
225
+    public static function help_text($text){
226
+        $output = '';
227
+
228
+        if($text){
229
+            $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>';
230
+        }
231
+
232
+
233
+        return $output;
234
+    }
235
+
236
+    /**
237
+     * Replace element require context with JS.
238
+     *
239
+     * @param $input
240
+     *
241
+     * @return string|void
242
+     */
243
+    public static function element_require( $input ) {
244
+
245
+        $input = str_replace( "'", '"', $input );// we only want double quotes
246
+
247
+        $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
+            "jQuery(form).find('[data-argument=\"",
249
+            "\"]').find('input,select,textarea').val()",
250
+            "\"]').find('input:checked').val()",
251
+        ), $input ) );
252
+
253
+        if($output){
254
+            $output = ' data-element-require="'.$output.'" ';
255
+        }
256
+
257
+        return $output;
258
+    }
259
+
260
+    /**
261
+     * Returns an array of allowed HTML tags and attributes for a given context.
262
+     *
263
+     * @since 0.1.41
264
+     *
265
+     * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
266
+     *                              'strip', 'data', 'entities', or the name of a field filter such as
267
+     *                              'pre_user_description'.
268
+     * @param array $input Input.
269
+     * @return array Array of allowed HTML tags and their allowed attributes.
270
+     */
271
+    public static function kses_allowed_html( $context = 'post', $input = array() ) {
272
+        $allowed_html = wp_kses_allowed_html( $context );
273
+
274
+        if ( is_array( $allowed_html ) ) {
275
+            // <iframe>
276
+            if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
277
+                $allowed_html['iframe']     = array(
278
+                    'class'        => true,
279
+                    'id'           => true,
280
+                    'src'          => true,
281
+                    'width'        => true,
282
+                    'height'       => true,
283
+                    'frameborder'  => true,
284
+                    'marginwidth'  => true,
285
+                    'marginheight' => true,
286
+                    'scrolling'    => true,
287
+                    'style'        => true,
288
+                    'title'        => true,
289
+                    'allow'        => true,
290
+                    'allowfullscreen' => true,
291
+                    'data-*'       => true,
292
+                );
293
+            }
294
+        }
295
+
296
+        /**
297
+         * Filters the allowed html tags.
298
+         *
299
+         * @since 0.1.41
300
+         *
301
+         * @param array[]|string $allowed_html Allowed html tags.
302
+         * @param @param string|array $context The context for which to retrieve tags.
303
+         * @param array $input Input field.
304
+         */
305
+        return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
306
+    }
307
+
308
+    /**
309
+     * Filters content and keeps only allowable HTML elements.
310
+     *
311
+     * This function makes sure that only the allowed HTML element names, attribute
312
+     * names and attribute values plus only sane HTML entities will occur in
313
+     * $string. You have to remove any slashes from PHP's magic quotes before you
314
+     * call this function.
315
+     *
316
+     * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
317
+     * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
318
+     * covers all common link protocols, except for 'javascript' which should not
319
+     * be allowed for untrusted users.
320
+     *
321
+     * @since 0.1.41
322
+     *
323
+     * @param string|array $value Content to filter through kses.
324
+     * @param array  $input       Input Field.
325
+     * @return string Filtered content with only allowed HTML elements.
326
+     */
327
+    public static function _sanitize_html_field( $value, $input = array() ) {
328
+        if ( $value === '' ) {
329
+            return $value;
330
+        }
331
+
332
+        $allowed_html = self::kses_allowed_html( 'post', $input );
333
+
334
+        if ( ! is_array( $allowed_html ) ) {
335
+            $allowed_html = wp_kses_allowed_html( 'post' );
336
+        }
337
+
338
+        $filtered = trim( wp_unslash( $value ) );
339
+        $filtered = wp_kses( $filtered, $allowed_html );
340
+        $filtered = balanceTags( $filtered ); // Balances tags
341
+
342
+        return $filtered;
343
+    }
344
+
345
+    /**
346
+     * Navigates through an array, object, or scalar, and removes slashes from the values.
347
+     *
348
+     * @since 0.1.41
349
+     *
350
+     * @param mixed $value The value to be stripped.
351
+     * @param array  $input Input Field.
352
+     * @return mixed Stripped value.
353
+     */
354
+    public static function sanitize_html_field( $value, $input = array() ) {
355
+        $original = $value;
356
+
357
+        if ( is_array( $value ) ) {
358
+            foreach ( $value as $index => $item ) {
359
+                $value[ $index ] = self::_sanitize_html_field( $value, $input );
360
+            }
361
+        } elseif ( is_object( $value ) ) {
362
+            $object_vars = get_object_vars( $value );
363
+
364
+            foreach ( $object_vars as $property_name => $property_value ) {
365
+                $value->$property_name = self::_sanitize_html_field( $property_value, $input );
366
+            }
367
+        } else {
368
+            $value = self::_sanitize_html_field( $value, $input );
369
+        }
370
+
371
+        /**
372
+         * Filters content and keeps only allowable HTML elements.
373
+         *
374
+         * @since 0.1.41
375
+         *
376
+         * @param string|array $value Content to filter through kses.
377
+         * @param string|array $value Original content without filter.
378
+         * @param array  $input       Input Field.
379
+         */
380
+        return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
381
+    }
382 382
 }
383 383
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +639 added lines, -639 removed lines patch added patch discarded remove patch
@@ -13,646 +13,646 @@  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
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-
34
-		// Items table columns.
35
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
36
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
37
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
38
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
39
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
40
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
41
-
42
-		// Payment forms columns.
43
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
44
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
45
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
46
-
47
-		// Discount table columns.
48
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
49
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
-
51
-		// Deleting posts.
52
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
53
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
-	}
55
-
56
-	/**
57
-	 * Post updated messages.
58
-	 */
59
-	public static function post_updated_messages( $messages ) {
60
-		global $post;
61
-
62
-		$messages['wpi_discount'] = array(
63
-			0   => '',
64
-			1   => __( 'Discount updated.', 'invoicing' ),
65
-			2   => __( 'Custom field updated.', 'invoicing' ),
66
-			3   => __( 'Custom field deleted.', 'invoicing' ),
67
-			4   => __( 'Discount updated.', 'invoicing' ),
68
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
69
-			6   => __( 'Discount updated.', 'invoicing' ),
70
-			7   => __( 'Discount saved.', 'invoicing' ),
71
-			8   => __( 'Discount submitted.', 'invoicing' ),
72
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
73
-			10  => __( 'Discount draft updated.', 'invoicing' ),
74
-		);
75
-
76
-		$messages['wpi_payment_form'] = array(
77
-			0   => '',
78
-			1   => __( 'Payment Form updated.', 'invoicing' ),
79
-			2   => __( 'Custom field updated.', 'invoicing' ),
80
-			3   => __( 'Custom field deleted.', 'invoicing' ),
81
-			4   => __( 'Payment Form updated.', 'invoicing' ),
82
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
83
-			6   => __( 'Payment Form updated.', 'invoicing' ),
84
-			7   => __( 'Payment Form saved.', 'invoicing' ),
85
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
86
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
87
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
88
-		);
89
-
90
-		return $messages;
91
-
92
-	}
93
-
94
-	/**
95
-	 * Post row actions.
96
-	 */
97
-	public static function post_row_actions( $actions, $post ) {
98
-
99
-		$post = get_post( $post );
100
-
101
-		// We do not want to edit the default payment form.
102
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
103
-			unset( $actions['trash'] );
104
-			unset( $actions['inline hide-if-no-js'] );
105
-		}
106
-
107
-		return $actions;
108
-	}
109
-
110
-	/**
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
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+
34
+        // Items table columns.
35
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
36
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
37
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
38
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
39
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
40
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
41
+
42
+        // Payment forms columns.
43
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
44
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
45
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
46
+
47
+        // Discount table columns.
48
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
49
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
+
51
+        // Deleting posts.
52
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
53
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
+    }
55
+
56
+    /**
57
+     * Post updated messages.
58
+     */
59
+    public static function post_updated_messages( $messages ) {
60
+        global $post;
61
+
62
+        $messages['wpi_discount'] = array(
63
+            0   => '',
64
+            1   => __( 'Discount updated.', 'invoicing' ),
65
+            2   => __( 'Custom field updated.', 'invoicing' ),
66
+            3   => __( 'Custom field deleted.', 'invoicing' ),
67
+            4   => __( 'Discount updated.', 'invoicing' ),
68
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
69
+            6   => __( 'Discount updated.', 'invoicing' ),
70
+            7   => __( 'Discount saved.', 'invoicing' ),
71
+            8   => __( 'Discount submitted.', 'invoicing' ),
72
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
73
+            10  => __( 'Discount draft updated.', 'invoicing' ),
74
+        );
75
+
76
+        $messages['wpi_payment_form'] = array(
77
+            0   => '',
78
+            1   => __( 'Payment Form updated.', 'invoicing' ),
79
+            2   => __( 'Custom field updated.', 'invoicing' ),
80
+            3   => __( 'Custom field deleted.', 'invoicing' ),
81
+            4   => __( 'Payment Form updated.', 'invoicing' ),
82
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
83
+            6   => __( 'Payment Form updated.', 'invoicing' ),
84
+            7   => __( 'Payment Form saved.', 'invoicing' ),
85
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
86
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
87
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
88
+        );
89
+
90
+        return $messages;
91
+
92
+    }
93
+
94
+    /**
95
+     * Post row actions.
96
+     */
97
+    public static function post_row_actions( $actions, $post ) {
98
+
99
+        $post = get_post( $post );
100
+
101
+        // We do not want to edit the default payment form.
102
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
103
+            unset( $actions['trash'] );
104
+            unset( $actions['inline hide-if-no-js'] );
105
+        }
106
+
107
+        return $actions;
108
+    }
109
+
110
+    /**
111 111
      * Remove bulk edit option from admin side quote listing
112 112
      *
113 113
      * @since    1.0.0
114 114
      * @param array $actions post actions
115
-	 * @param WP_Post $post
115
+     * @param WP_Post $post
116 116
      * @return array $actions actions without edit option
117 117
      */
118 118
     public static function filter_invoice_row_actions( $actions, $post ) {
119 119
 
120 120
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
121 121
 
122
-			$actions = array();
123
-			$invoice = new WPInv_Invoice( $post );
124
-
125
-			$actions['edit'] =  sprintf(
126
-				'<a href="%1$s">%2$s</a>',
127
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
128
-				esc_html( __( 'Edit', 'invoicing' ) )
129
-			);
130
-
131
-			if ( ! $invoice->is_draft() ) {
132
-
133
-				$actions['view'] =  sprintf(
134
-					'<a href="%1$s">%2$s</a>',
135
-					esc_url( $invoice->get_view_url() ),
136
-					sprintf(
137
-						esc_html( __( 'View %s', 'invoicing' ) ),
138
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
139
-					)
140
-				);
141
-
142
-				$actions['send'] =  sprintf(
143
-					'<a href="%1$s">%2$s</a>',
144
-					esc_url(
145
-						wp_nonce_url(
146
-							add_query_arg(
147
-								array(
148
-									'getpaid-admin-action' => 'send_invoice',
149
-									'invoice_id'           => $invoice->get_id()
150
-								)
151
-							),
152
-							'getpaid-nonce',
153
-							'getpaid-nonce'
154
-						)
155
-					),
156
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
157
-				);
158
-
159
-			}
122
+            $actions = array();
123
+            $invoice = new WPInv_Invoice( $post );
124
+
125
+            $actions['edit'] =  sprintf(
126
+                '<a href="%1$s">%2$s</a>',
127
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
128
+                esc_html( __( 'Edit', 'invoicing' ) )
129
+            );
130
+
131
+            if ( ! $invoice->is_draft() ) {
132
+
133
+                $actions['view'] =  sprintf(
134
+                    '<a href="%1$s">%2$s</a>',
135
+                    esc_url( $invoice->get_view_url() ),
136
+                    sprintf(
137
+                        esc_html( __( 'View %s', 'invoicing' ) ),
138
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
139
+                    )
140
+                );
141
+
142
+                $actions['send'] =  sprintf(
143
+                    '<a href="%1$s">%2$s</a>',
144
+                    esc_url(
145
+                        wp_nonce_url(
146
+                            add_query_arg(
147
+                                array(
148
+                                    'getpaid-admin-action' => 'send_invoice',
149
+                                    'invoice_id'           => $invoice->get_id()
150
+                                )
151
+                            ),
152
+                            'getpaid-nonce',
153
+                            'getpaid-nonce'
154
+                        )
155
+                    ),
156
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
157
+                );
158
+
159
+            }
160 160
 
161 161
         }
162 162
 
163 163
         return $actions;
164
-	}
165
-
166
-	/**
167
-	 * Returns an array of invoice table columns.
168
-	 */
169
-	public static function invoice_columns( $columns ) {
170
-
171
-		$columns = array(
172
-			'cb'                => $columns['cb'],
173
-			'number'            => __( 'Invoice', 'invoicing' ),
174
-			'customer'          => __( 'Customer', 'invoicing' ),
175
-			'invoice_date'      => __( 'Created', 'invoicing' ),
176
-			'payment_date'      => __( 'Completed', 'invoicing' ),
177
-			'amount'            => __( 'Amount', 'invoicing' ),
178
-			'recurring'         => __( 'Recurring', 'invoicing' ),
179
-			'status'            => __( 'Status', 'invoicing' ),
180
-		);
181
-
182
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
183
-	}
184
-
185
-	/**
186
-	 * Displays invoice table columns.
187
-	 */
188
-	public static function display_invoice_columns( $column_name, $post_id ) {
189
-
190
-		$invoice = new WPInv_Invoice( $post_id );
191
-
192
-		switch ( $column_name ) {
193
-
194
-			case 'invoice_date' :
195
-				$date_time = esc_attr( $invoice->get_created_date() );
196
-				$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
197
-				echo "<span title='$date_time'>$date</span>";
198
-				break;
199
-
200
-			case 'payment_date' :
201
-
202
-				if ( $invoice->is_paid() ) {
203
-					$date_time = esc_attr( $invoice->get_completed_date() );
204
-					$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
205
-					echo "<span title='$date_time'>$date</span>";
206
-				} else {
207
-					echo "&mdash;";
208
-				}
164
+    }
165
+
166
+    /**
167
+     * Returns an array of invoice table columns.
168
+     */
169
+    public static function invoice_columns( $columns ) {
170
+
171
+        $columns = array(
172
+            'cb'                => $columns['cb'],
173
+            'number'            => __( 'Invoice', 'invoicing' ),
174
+            'customer'          => __( 'Customer', 'invoicing' ),
175
+            'invoice_date'      => __( 'Created', 'invoicing' ),
176
+            'payment_date'      => __( 'Completed', 'invoicing' ),
177
+            'amount'            => __( 'Amount', 'invoicing' ),
178
+            'recurring'         => __( 'Recurring', 'invoicing' ),
179
+            'status'            => __( 'Status', 'invoicing' ),
180
+        );
181
+
182
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
183
+    }
184
+
185
+    /**
186
+     * Displays invoice table columns.
187
+     */
188
+    public static function display_invoice_columns( $column_name, $post_id ) {
189
+
190
+        $invoice = new WPInv_Invoice( $post_id );
191
+
192
+        switch ( $column_name ) {
193
+
194
+            case 'invoice_date' :
195
+                $date_time = esc_attr( $invoice->get_created_date() );
196
+                $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
197
+                echo "<span title='$date_time'>$date</span>";
198
+                break;
199
+
200
+            case 'payment_date' :
201
+
202
+                if ( $invoice->is_paid() ) {
203
+                    $date_time = esc_attr( $invoice->get_completed_date() );
204
+                    $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
205
+                    echo "<span title='$date_time'>$date</span>";
206
+                } else {
207
+                    echo "&mdash;";
208
+                }
209 209
 				
210
-				break;
210
+                break;
211 211
 
212
-			case 'amount' :
212
+            case 'amount' :
213 213
 
214
-				$amount = $invoice->get_total();
215
-				$formated_amount = wpinv_price( $amount, $invoice->get_currency() );
214
+                $amount = $invoice->get_total();
215
+                $formated_amount = wpinv_price( $amount, $invoice->get_currency() );
216 216
 
217
-				if ( $invoice->is_refunded() ) {
218
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
219
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
220
-				} else {
217
+                if ( $invoice->is_refunded() ) {
218
+                    $refunded_amount = wpinv_price( 0, $invoice->get_currency() );
219
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
220
+                } else {
221 221
 
222
-					$discount = $invoice->get_total_discount();
222
+                    $discount = $invoice->get_total_discount();
223 223
 
224
-					if ( ! empty( $discount ) ) {
225
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
226
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
227
-					} else {
228
-						echo $formated_amount;
229
-					}
224
+                    if ( ! empty( $discount ) ) {
225
+                        $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
226
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
227
+                    } else {
228
+                        echo $formated_amount;
229
+                    }
230 230
 
231
-				}
231
+                }
232 232
 
233
-				break;
233
+                break;
234 234
 
235
-			case 'status' :
236
-				$status       = sanitize_text_field( $invoice->get_status() );
237
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
235
+            case 'status' :
236
+                $status       = sanitize_text_field( $invoice->get_status() );
237
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
238 238
 
239
-				// If it is paid, show the gateway title.
240
-				if ( $invoice->is_paid() ) {
241
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
242
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
239
+                // If it is paid, show the gateway title.
240
+                if ( $invoice->is_paid() ) {
241
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
242
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
243 243
 
244
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
245
-				} else {
246
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
247
-				}
244
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
245
+                } else {
246
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
247
+                }
248 248
 
249
-				// If it is not paid, display the overdue and view status.
250
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
249
+                // If it is not paid, display the overdue and view status.
250
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
251 251
 
252
-					// Invoice view status.
253
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
254
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
255
-					} else {
256
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
257
-					}
252
+                    // Invoice view status.
253
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
254
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
255
+                    } else {
256
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
257
+                    }
258 258
 
259
-					// Display the overview status.
260
-					if ( wpinv_get_option( 'overdue_active' ) ) {
261
-						$due_date = $invoice->get_due_date();
262
-						$fomatted = getpaid_format_date( $due_date );
259
+                    // Display the overview status.
260
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
261
+                        $due_date = $invoice->get_due_date();
262
+                        $fomatted = getpaid_format_date( $due_date );
263 263
 
264
-						if ( ! empty( $fomatted ) ) {
265
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
266
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
267
-						}
268
-					}
264
+                        if ( ! empty( $fomatted ) ) {
265
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
266
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
267
+                        }
268
+                    }
269 269
 
270
-				}
270
+                }
271 271
 
272
-				break;
272
+                break;
273 273
 
274
-			case 'recurring':
274
+            case 'recurring':
275 275
 
276
-				if ( $invoice->is_recurring() ) {
277
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
278
-				} else {
279
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
280
-				}
281
-				break;
276
+                if ( $invoice->is_recurring() ) {
277
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
278
+                } else {
279
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
280
+                }
281
+                break;
282 282
 
283
-			case 'number' :
283
+            case 'number' :
284 284
 
285
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
286
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
287
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
285
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
286
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
287
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
288 288
 
289
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
289
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
290 290
 
291
-				break;
291
+                break;
292 292
 
293
-			case 'customer' :
293
+            case 'customer' :
294 294
 	
295
-				$customer_name = $invoice->get_user_full_name();
295
+                $customer_name = $invoice->get_user_full_name();
296 296
 	
297
-				if ( empty( $customer_name ) ) {
298
-					$customer_name = $invoice->get_email();
299
-				}
297
+                if ( empty( $customer_name ) ) {
298
+                    $customer_name = $invoice->get_email();
299
+                }
300 300
 	
301
-				if ( ! empty( $customer_name ) ) {
302
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
303
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
304
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
305
-				} else {
306
-					echo '<div>&mdash;</div>';
307
-				}
301
+                if ( ! empty( $customer_name ) ) {
302
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
303
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
304
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
305
+                } else {
306
+                    echo '<div>&mdash;</div>';
307
+                }
308 308
 
309
-				break;
309
+                break;
310 310
 
311
-		}
311
+        }
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
316
-	 * Returns an array of payment forms table columns.
317
-	 */
318
-	public static function payment_form_columns( $columns ) {
315
+    /**
316
+     * Returns an array of payment forms table columns.
317
+     */
318
+    public static function payment_form_columns( $columns ) {
319 319
 
320
-		$columns = array(
321
-			'cb'                => $columns['cb'],
322
-			'title'             => __( 'Name', 'invoicing' ),
323
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
324
-			'earnings'          => __( 'Revenue', 'invoicing' ),
325
-			'refunds'           => __( 'Refunded', 'invoicing' ),
326
-			'items'             => __( 'Items', 'invoicing' ),
327
-			'date'              => __( 'Date', 'invoicing' ),
328
-		);
320
+        $columns = array(
321
+            'cb'                => $columns['cb'],
322
+            'title'             => __( 'Name', 'invoicing' ),
323
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
324
+            'earnings'          => __( 'Revenue', 'invoicing' ),
325
+            'refunds'           => __( 'Refunded', 'invoicing' ),
326
+            'items'             => __( 'Items', 'invoicing' ),
327
+            'date'              => __( 'Date', 'invoicing' ),
328
+        );
329 329
 
330
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
330
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
331 331
 
332
-	}
332
+    }
333 333
 
334
-	/**
335
-	 * Displays payment form table columns.
336
-	 */
337
-	public static function display_payment_form_columns( $column_name, $post_id ) {
334
+    /**
335
+     * Displays payment form table columns.
336
+     */
337
+    public static function display_payment_form_columns( $column_name, $post_id ) {
338 338
 
339
-		// Retrieve the payment form.
340
-		$form = new GetPaid_Payment_Form( $post_id );
339
+        // Retrieve the payment form.
340
+        $form = new GetPaid_Payment_Form( $post_id );
341 341
 
342
-		switch ( $column_name ) {
342
+        switch ( $column_name ) {
343 343
 
344
-			case 'earnings' :
345
-				echo wpinv_price( $form->get_earned() );
346
-				break;
344
+            case 'earnings' :
345
+                echo wpinv_price( $form->get_earned() );
346
+                break;
347 347
 
348
-			case 'refunds' :
349
-				echo wpinv_price( $form->get_refunded() );
350
-				break;
348
+            case 'refunds' :
349
+                echo wpinv_price( $form->get_refunded() );
350
+                break;
351 351
 
352
-			case 'refunds' :
353
-				echo wpinv_price( $form->get_refunded() );
354
-				break;
352
+            case 'refunds' :
353
+                echo wpinv_price( $form->get_refunded() );
354
+                break;
355 355
 
356
-			case 'shortcode' :
356
+            case 'shortcode' :
357 357
 
358
-				if ( $form->is_default() ) {
359
-					echo '&mdash;';
360
-				} else {
361
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
362
-				}
358
+                if ( $form->is_default() ) {
359
+                    echo '&mdash;';
360
+                } else {
361
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
362
+                }
363 363
 
364
-				break;
364
+                break;
365 365
 
366
-			case 'items' :
366
+            case 'items' :
367 367
 
368
-				$items = $form->get_items();
368
+                $items = $form->get_items();
369 369
 
370
-				if ( $form->is_default() || empty( $items ) ) {
371
-					echo '&mdash;';
372
-					return;
373
-				}
370
+                if ( $form->is_default() || empty( $items ) ) {
371
+                    echo '&mdash;';
372
+                    return;
373
+                }
374 374
 
375
-				$_items = array();
375
+                $_items = array();
376 376
 
377
-				foreach ( $items as $item ) {
378
-					$url = $item->get_edit_url();
377
+                foreach ( $items as $item ) {
378
+                    $url = $item->get_edit_url();
379 379
 
380
-					if ( empty( $url ) ) {
381
-						$_items[] = sanitize_text_field( $item->get_name() );
382
-					} else {
383
-						$_items[] = sprintf(
384
-							'<a href="%s">%s</a>',
385
-							esc_url( $url ),
386
-							sanitize_text_field( $item->get_name() )
387
-						);
388
-					}
380
+                    if ( empty( $url ) ) {
381
+                        $_items[] = sanitize_text_field( $item->get_name() );
382
+                    } else {
383
+                        $_items[] = sprintf(
384
+                            '<a href="%s">%s</a>',
385
+                            esc_url( $url ),
386
+                            sanitize_text_field( $item->get_name() )
387
+                        );
388
+                    }
389 389
 
390
-				}
390
+                }
391 391
 
392
-				echo implode( '<br>', $_items );
392
+                echo implode( '<br>', $_items );
393 393
 
394
-				break;
394
+                break;
395 395
 
396
-		}
396
+        }
397 397
 
398
-	}
398
+    }
399 399
 
400
-	/**
401
-	 * Filters post states.
402
-	 */
403
-	public static function filter_payment_form_state( $post_states, $post ) {
400
+    /**
401
+     * Filters post states.
402
+     */
403
+    public static function filter_payment_form_state( $post_states, $post ) {
404 404
 
405
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
406
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
407
-		}
405
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
406
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
407
+        }
408 408
 	
409
-		return $post_states;
410
-
411
-	}
412
-
413
-	/**
414
-	 * Returns an array of coupon table columns.
415
-	 */
416
-	public static function discount_columns( $columns ) {
417
-
418
-		$columns = array(
419
-			'cb'                => $columns['cb'],
420
-			'title'             => __( 'Name', 'invoicing' ),
421
-			'code'              => __( 'Code', 'invoicing' ),
422
-			'amount'            => __( 'Amount', 'invoicing' ),
423
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
424
-			'start_date'        => __( 'Start Date', 'invoicing' ),
425
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
426
-		);
427
-
428
-		return apply_filters( 'wpi_discount_table_columns', $columns );
429
-	}
430
-
431
-	/**
432
-	 * Filters post states.
433
-	 */
434
-	public static function filter_discount_state( $post_states, $post ) {
435
-
436
-		if ( 'wpi_discount' == $post->post_type ) {
437
-
438
-			$discount = new WPInv_Discount( $post );
439
-
440
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
441
-
442
-			if ( $status != 'publish' ) {
443
-				return array(
444
-					'discount_status' => wpinv_discount_status( $status ),
445
-				);
446
-			}
447
-
448
-			return array();
449
-
450
-		}
451
-
452
-		return $post_states;
453
-
454
-	}
455
-
456
-	/**
457
-	 * Returns an array of items table columns.
458
-	 */
459
-	public static function item_columns( $columns ) {
460
-
461
-		$columns = array(
462
-			'cb'                => $columns['cb'],
463
-			'title'             => __( 'Name', 'invoicing' ),
464
-			'price'             => __( 'Price', 'invoicing' ),
465
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
466
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
467
-			'type'              => __( 'Type', 'invoicing' ),
468
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
469
-		);
470
-
471
-		if ( ! wpinv_use_taxes() ) {
472
-			unset( $columns['vat_rule'] );
473
-			unset( $columns['vat_class'] );
474
-		}
475
-
476
-		return apply_filters( 'wpi_item_table_columns', $columns );
477
-	}
478
-
479
-	/**
480
-	 * Returns an array of sortable items table columns.
481
-	 */
482
-	public static function sortable_item_columns( $columns ) {
483
-
484
-		return array_merge(
485
-			$columns,
486
-			array(
487
-				'price'     => 'price',
488
-				'vat_rule'  => 'vat_rule',
489
-				'vat_class' => 'vat_class',
490
-				'type'      => 'type',
491
-			)
492
-		);
493
-
494
-	}
495
-
496
-	/**
497
-	 * Displays items table columns.
498
-	 */
499
-	public static function display_item_columns( $column_name, $post_id ) {
409
+        return $post_states;
410
+
411
+    }
412
+
413
+    /**
414
+     * Returns an array of coupon table columns.
415
+     */
416
+    public static function discount_columns( $columns ) {
417
+
418
+        $columns = array(
419
+            'cb'                => $columns['cb'],
420
+            'title'             => __( 'Name', 'invoicing' ),
421
+            'code'              => __( 'Code', 'invoicing' ),
422
+            'amount'            => __( 'Amount', 'invoicing' ),
423
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
424
+            'start_date'        => __( 'Start Date', 'invoicing' ),
425
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
426
+        );
427
+
428
+        return apply_filters( 'wpi_discount_table_columns', $columns );
429
+    }
430
+
431
+    /**
432
+     * Filters post states.
433
+     */
434
+    public static function filter_discount_state( $post_states, $post ) {
435
+
436
+        if ( 'wpi_discount' == $post->post_type ) {
437
+
438
+            $discount = new WPInv_Discount( $post );
439
+
440
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
441
+
442
+            if ( $status != 'publish' ) {
443
+                return array(
444
+                    'discount_status' => wpinv_discount_status( $status ),
445
+                );
446
+            }
447
+
448
+            return array();
449
+
450
+        }
451
+
452
+        return $post_states;
453
+
454
+    }
455
+
456
+    /**
457
+     * Returns an array of items table columns.
458
+     */
459
+    public static function item_columns( $columns ) {
460
+
461
+        $columns = array(
462
+            'cb'                => $columns['cb'],
463
+            'title'             => __( 'Name', 'invoicing' ),
464
+            'price'             => __( 'Price', 'invoicing' ),
465
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
466
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
467
+            'type'              => __( 'Type', 'invoicing' ),
468
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
469
+        );
470
+
471
+        if ( ! wpinv_use_taxes() ) {
472
+            unset( $columns['vat_rule'] );
473
+            unset( $columns['vat_class'] );
474
+        }
475
+
476
+        return apply_filters( 'wpi_item_table_columns', $columns );
477
+    }
478
+
479
+    /**
480
+     * Returns an array of sortable items table columns.
481
+     */
482
+    public static function sortable_item_columns( $columns ) {
483
+
484
+        return array_merge(
485
+            $columns,
486
+            array(
487
+                'price'     => 'price',
488
+                'vat_rule'  => 'vat_rule',
489
+                'vat_class' => 'vat_class',
490
+                'type'      => 'type',
491
+            )
492
+        );
493
+
494
+    }
495
+
496
+    /**
497
+     * Displays items table columns.
498
+     */
499
+    public static function display_item_columns( $column_name, $post_id ) {
500 500
  
501
-		$item = new WPInv_Item( $post_id );
501
+        $item = new WPInv_Item( $post_id );
502 502
 
503
-		switch ( $column_name ) {
503
+        switch ( $column_name ) {
504 504
 
505
-			case 'price' :
505
+            case 'price' :
506 506
 
507
-				if ( ! $item->is_recurring() ) {
508
-					echo $item->get_the_price();
509
-					break;
510
-				}
507
+                if ( ! $item->is_recurring() ) {
508
+                    echo $item->get_the_price();
509
+                    break;
510
+                }
511 511
 
512
-				$price = wp_sprintf(
513
-					__( '%s / %s', 'invoicing' ),
514
-					$item->get_the_price(),
515
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
516
-				);
512
+                $price = wp_sprintf(
513
+                    __( '%s / %s', 'invoicing' ),
514
+                    $item->get_the_price(),
515
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
516
+                );
517 517
 
518
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
519
-					echo $price;
520
-					break;
521
-				}
518
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
519
+                    echo $price;
520
+                    break;
521
+                }
522 522
 
523
-				echo $item->get_the_initial_price();
523
+                echo $item->get_the_initial_price();
524 524
 
525
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
526
-				break;
525
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
526
+                break;
527 527
 
528
-			case 'vat_rule' :
529
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
530
-				break;
528
+            case 'vat_rule' :
529
+                echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
530
+                break;
531 531
 
532
-			case 'vat_class' :
533
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
534
-				break;
532
+            case 'vat_class' :
533
+                echo getpaid_get_tax_class_label( $item->get_vat_class() );
534
+                break;
535 535
 
536
-			case 'shortcode' :
537
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
538
-				break;
536
+            case 'shortcode' :
537
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
538
+                break;
539 539
 
540
-			case 'type' :
541
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
542
-				break;
540
+            case 'type' :
541
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
542
+                break;
543 543
 
544
-		}
544
+        }
545 545
 
546
-	}
546
+    }
547 547
 
548
-	/**
549
-	 * Lets users filter items using taxes.
550
-	 */
551
-	public static function add_item_filters( $post_type ) {
548
+    /**
549
+     * Lets users filter items using taxes.
550
+     */
551
+    public static function add_item_filters( $post_type ) {
552 552
 
553
-		// Abort if we're not dealing with items.
554
-		if ( $post_type != 'wpi_item' ) {
555
-			return;
556
-		}
553
+        // Abort if we're not dealing with items.
554
+        if ( $post_type != 'wpi_item' ) {
555
+            return;
556
+        }
557 557
 
558
-		// Filter by vat rules.
559
-		if ( wpinv_use_taxes() ) {
558
+        // Filter by vat rules.
559
+        if ( wpinv_use_taxes() ) {
560 560
 	
561
-			// Sanitize selected vat rule.
562
-			$vat_rule   = '';
563
-			$vat_rules  = getpaid_get_tax_rules();
564
-			if ( isset( $_GET['vat_rule'] ) ) {
565
-				$vat_rule   =  $_GET['vat_rule'];
566
-			}
567
-
568
-			// Filter by VAT rule.
569
-			echo wpinv_html_select(
570
-				array(
571
-					'options'          => array_merge(
572
-						array(
573
-							'' => __( 'All VAT rules', 'invoicing' )
574
-						),
575
-						$vat_rules
576
-					),
577
-					'name'             => 'vat_rule',
578
-					'id'               => 'vat_rule',
579
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
580
-					'show_option_all'  => false,
581
-					'show_option_none' => false,
582
-				)
583
-			);
584
-
585
-			// Filter by VAT class.
561
+            // Sanitize selected vat rule.
562
+            $vat_rule   = '';
563
+            $vat_rules  = getpaid_get_tax_rules();
564
+            if ( isset( $_GET['vat_rule'] ) ) {
565
+                $vat_rule   =  $_GET['vat_rule'];
566
+            }
567
+
568
+            // Filter by VAT rule.
569
+            echo wpinv_html_select(
570
+                array(
571
+                    'options'          => array_merge(
572
+                        array(
573
+                            '' => __( 'All VAT rules', 'invoicing' )
574
+                        ),
575
+                        $vat_rules
576
+                    ),
577
+                    'name'             => 'vat_rule',
578
+                    'id'               => 'vat_rule',
579
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
580
+                    'show_option_all'  => false,
581
+                    'show_option_none' => false,
582
+                )
583
+            );
584
+
585
+            // Filter by VAT class.
586 586
 	
587
-			// Sanitize selected vat rule.
588
-			$vat_class   = '';
589
-			$vat_classes = getpaid_get_tax_classes();
590
-			if ( isset( $_GET['vat_class'] ) ) {
591
-				$vat_class   =  $_GET['vat_class'];
592
-			}
593
-
594
-			echo wpinv_html_select(
595
-				array(
596
-					'options'          => array_merge(
597
-						array(
598
-							'' => __( 'All VAT classes', 'invoicing' )
599
-						),
600
-						$vat_classes
601
-					),
602
-					'name'             => 'vat_class',
603
-					'id'               => 'vat_class',
604
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
605
-					'show_option_all'  => false,
606
-					'show_option_none' => false,
607
-				)
608
-			);
609
-
610
-		}
611
-
612
-		// Filter by item type.
613
-		$type   = '';
614
-		if ( isset( $_GET['type'] ) ) {
615
-			$type   =  $_GET['type'];
616
-		}
617
-
618
-		echo wpinv_html_select(
619
-			array(
620
-				'options'          => array_merge(
621
-					array(
622
-						'' => __( 'All item types', 'invoicing' )
623
-					),
624
-					wpinv_get_item_types()
625
-				),
626
-				'name'             => 'type',
627
-				'id'               => 'type',
628
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
629
-				'show_option_all'  => false,
630
-				'show_option_none' => false,
631
-			)
632
-		);
633
-
634
-	}
635
-
636
-	/**
637
-	 * Filters the item query.
638
-	 */
639
-	public static function filter_item_query( $query ) {
640
-
641
-		// modify the query only if it admin and main query.
642
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
643
-			return $query;
644
-		}
645
-
646
-		// we want to modify the query for our items.
647
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
648
-			return $query;
649
-		}
650
-
651
-		if ( empty( $query->query_vars['meta_query'] ) ) {
652
-			$query->query_vars['meta_query'] = array();
653
-		}
654
-
655
-		// Filter vat rule type
587
+            // Sanitize selected vat rule.
588
+            $vat_class   = '';
589
+            $vat_classes = getpaid_get_tax_classes();
590
+            if ( isset( $_GET['vat_class'] ) ) {
591
+                $vat_class   =  $_GET['vat_class'];
592
+            }
593
+
594
+            echo wpinv_html_select(
595
+                array(
596
+                    'options'          => array_merge(
597
+                        array(
598
+                            '' => __( 'All VAT classes', 'invoicing' )
599
+                        ),
600
+                        $vat_classes
601
+                    ),
602
+                    'name'             => 'vat_class',
603
+                    'id'               => 'vat_class',
604
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
605
+                    'show_option_all'  => false,
606
+                    'show_option_none' => false,
607
+                )
608
+            );
609
+
610
+        }
611
+
612
+        // Filter by item type.
613
+        $type   = '';
614
+        if ( isset( $_GET['type'] ) ) {
615
+            $type   =  $_GET['type'];
616
+        }
617
+
618
+        echo wpinv_html_select(
619
+            array(
620
+                'options'          => array_merge(
621
+                    array(
622
+                        '' => __( 'All item types', 'invoicing' )
623
+                    ),
624
+                    wpinv_get_item_types()
625
+                ),
626
+                'name'             => 'type',
627
+                'id'               => 'type',
628
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
629
+                'show_option_all'  => false,
630
+                'show_option_none' => false,
631
+            )
632
+        );
633
+
634
+    }
635
+
636
+    /**
637
+     * Filters the item query.
638
+     */
639
+    public static function filter_item_query( $query ) {
640
+
641
+        // modify the query only if it admin and main query.
642
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
643
+            return $query;
644
+        }
645
+
646
+        // we want to modify the query for our items.
647
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
648
+            return $query;
649
+        }
650
+
651
+        if ( empty( $query->query_vars['meta_query'] ) ) {
652
+            $query->query_vars['meta_query'] = array();
653
+        }
654
+
655
+        // Filter vat rule type
656 656
         if ( ! empty( $_GET['vat_rule'] ) ) {
657 657
             $query->query_vars['meta_query'][] = array(
658 658
                 'key'     => '_wpinv_vat_rule',
@@ -677,94 +677,94 @@  discard block
 block discarded – undo
677 677
                 'value'   => sanitize_text_field( $_GET['type'] ),
678 678
                 'compare' => '='
679 679
             );
680
-		}
681
-
682
-	}
683
-
684
-	/**
685
-	 * Reorders items.
686
-	 */
687
-	public static function reorder_items( $vars ) {
688
-		global $typenow;
689
-
690
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
691
-			return $vars;
692
-		}
693
-
694
-		// By item type.
695
-		if ( 'type' == $vars['orderby'] ) {
696
-			return array_merge(
697
-				$vars,
698
-				array(
699
-					'meta_key' => '_wpinv_type',
700
-					'orderby'  => 'meta_value'
701
-				)
702
-			);
703
-		}
704
-
705
-		// By vat class.
706
-		if ( 'vat_class' == $vars['orderby'] ) {
707
-			return array_merge(
708
-				$vars,
709
-				array(
710
-					'meta_key' => '_wpinv_vat_class',
711
-					'orderby'  => 'meta_value'
712
-				)
713
-			);
714
-		}
715
-
716
-		// By vat rule.
717
-		if ( 'vat_rule' == $vars['orderby'] ) {
718
-			return array_merge(
719
-				$vars,
720
-				array(
721
-					'meta_key' => '_wpinv_vat_rule',
722
-					'orderby'  => 'meta_value'
723
-				)
724
-			);
725
-		}
726
-
727
-		// By price.
728
-		if ( 'price' == $vars['orderby'] ) {
729
-			return array_merge(
730
-				$vars,
731
-				array(
732
-					'meta_key' => '_wpinv_price',
733
-					'orderby'  => 'meta_value_num'
734
-				)
735
-			);
736
-		}
737
-
738
-		return $vars;
739
-
740
-	}
741
-
742
-	/**
743
-	 * Fired when deleting a post.
744
-	 */
745
-	public static function delete_post( $post_id ) {
746
-
747
-		switch ( get_post_type( $post_id ) ) {
748
-
749
-			case 'wpi_item' :
750
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
751
-				break;
752
-
753
-			case 'wpi_payment_form' :
754
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
755
-				break;
756
-
757
-			case 'wpi_discount' :
758
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
759
-				break;
760
-
761
-			case 'wpi_invoice' :
762
-				$invoice = new WPInv_Invoice( $post_id );
763
-				do_action( "getpaid_before_delete_invoice", $invoice );
764
-				$invoice->get_data_store()->delete_items( $invoice );
765
-				$invoice->get_data_store()->delete_special_fields( $invoice );
766
-				break;
767
-		}
768
-	}
680
+        }
681
+
682
+    }
683
+
684
+    /**
685
+     * Reorders items.
686
+     */
687
+    public static function reorder_items( $vars ) {
688
+        global $typenow;
689
+
690
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
691
+            return $vars;
692
+        }
693
+
694
+        // By item type.
695
+        if ( 'type' == $vars['orderby'] ) {
696
+            return array_merge(
697
+                $vars,
698
+                array(
699
+                    'meta_key' => '_wpinv_type',
700
+                    'orderby'  => 'meta_value'
701
+                )
702
+            );
703
+        }
704
+
705
+        // By vat class.
706
+        if ( 'vat_class' == $vars['orderby'] ) {
707
+            return array_merge(
708
+                $vars,
709
+                array(
710
+                    'meta_key' => '_wpinv_vat_class',
711
+                    'orderby'  => 'meta_value'
712
+                )
713
+            );
714
+        }
715
+
716
+        // By vat rule.
717
+        if ( 'vat_rule' == $vars['orderby'] ) {
718
+            return array_merge(
719
+                $vars,
720
+                array(
721
+                    'meta_key' => '_wpinv_vat_rule',
722
+                    'orderby'  => 'meta_value'
723
+                )
724
+            );
725
+        }
726
+
727
+        // By price.
728
+        if ( 'price' == $vars['orderby'] ) {
729
+            return array_merge(
730
+                $vars,
731
+                array(
732
+                    'meta_key' => '_wpinv_price',
733
+                    'orderby'  => 'meta_value_num'
734
+                )
735
+            );
736
+        }
737
+
738
+        return $vars;
739
+
740
+    }
741
+
742
+    /**
743
+     * Fired when deleting a post.
744
+     */
745
+    public static function delete_post( $post_id ) {
746
+
747
+        switch ( get_post_type( $post_id ) ) {
748
+
749
+            case 'wpi_item' :
750
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
751
+                break;
752
+
753
+            case 'wpi_payment_form' :
754
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
755
+                break;
756
+
757
+            case 'wpi_discount' :
758
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
759
+                break;
760
+
761
+            case 'wpi_invoice' :
762
+                $invoice = new WPInv_Invoice( $post_id );
763
+                do_action( "getpaid_before_delete_invoice", $invoice );
764
+                $invoice->get_data_store()->delete_items( $invoice );
765
+                $invoice->get_data_store()->delete_special_fields( $invoice );
766
+                break;
767
+        }
768
+    }
769 769
 
770 770
 }
Please login to merge, or discard this patch.
includes/data/eu-states.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,31 +9,31 @@
 block discarded – undo
9 9
 defined( 'ABSPATH' ) || exit;
10 10
 
11 11
 return array(
12
-	'AT',
13
-	'BE',
14
-	'BG',
15
-	'HR',
16
-	'CY',
17
-	'CZ',
18
-	'DK',
19
-	'EE',
20
-	'FI',
21
-	'FR',
22
-	'DE',
23
-	'GR',
24
-	'HU',
25
-	'IE',
26
-	'IT',
27
-	'LV',
28
-	'LT',
29
-	'LU',
30
-	'MT',
31
-	'NL',
32
-	'PL',
33
-	'PT',
34
-	'RO',
35
-	'SK',
36
-	'SI',
37
-	'ES',
38
-	'SE'
12
+    'AT',
13
+    'BE',
14
+    'BG',
15
+    'HR',
16
+    'CY',
17
+    'CZ',
18
+    'DK',
19
+    'EE',
20
+    'FI',
21
+    'FR',
22
+    'DE',
23
+    'GR',
24
+    'HU',
25
+    'IE',
26
+    'IT',
27
+    'LV',
28
+    'LT',
29
+    'LU',
30
+    'MT',
31
+    'NL',
32
+    'PL',
33
+    'PT',
34
+    'RO',
35
+    'SK',
36
+    'SI',
37
+    'ES',
38
+    'SE'
39 39
 );
Please login to merge, or discard this patch.
includes/user-functions.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
36 36
 
37
-	if ( current_user_can( 'manage_options' ) ) {
38
-		return 'manage_options';
39
-	};
37
+    if ( current_user_can( 'manage_options' ) ) {
38
+        return 'manage_options';
39
+    };
40 40
 
41
-	return $capalibilty;
41
+    return $capalibilty;
42 42
 }
43 43
 
44 44
 /**
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
     // Prepare user values.
63 63
     $prefix = preg_replace( '/\s+/', '', $prefix );
64 64
     $prefix = empty( $prefix ) ? $email : $prefix;
65
-	$args   = array(
66
-		'user_login' => wpinv_generate_user_name( $prefix ),
67
-		'user_pass'  => wp_generate_password(),
68
-		'user_email' => $email,
65
+    $args   = array(
66
+        'user_login' => wpinv_generate_user_name( $prefix ),
67
+        'user_pass'  => wp_generate_password(),
68
+        'user_email' => $email,
69 69
         'role'       => 'subscriber',
70 70
     );
71 71
 
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
 function wpinv_generate_user_name( $prefix = '' ) {
83 83
 
84 84
     // If prefix is an email, retrieve the part before the email.
85
-	$prefix = strtok( $prefix, '@' );
85
+    $prefix = strtok( $prefix, '@' );
86 86
     $prefix = trim( $prefix, '.' );
87 87
 
88
-	// Sanitize the username.
89
-	$prefix = sanitize_user( $prefix, true );
88
+    // Sanitize the username.
89
+    $prefix = sanitize_user( $prefix, true );
90 90
 
91
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
92
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
93
-		$prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
94
-	}
91
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
92
+    if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
93
+        $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 );
94
+    }
95 95
 
96 96
     $username = $prefix;
97 97
     $postfix  = 2;
Please login to merge, or discard this patch.