Passed
Push — master ( eadd35...968588 )
by Brian
04:42
created
includes/data-stores/class-getpaid-discount-data-store.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,198 +15,198 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Discount_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpi_discount_code',
26
-		'_wpi_discount_amount',
27
-		'_wpi_discount_start',
28
-		'_wpi_discount_expiration',
29
-		'_wpi_discount_type',
30
-		'_wpi_discount_uses',
31
-		'_wpi_discount_is_single_use',
32
-		'_wpi_discount_items',
33
-		'_wpi_discount_excluded_items',
34
-		'_wpi_discount_required_items',
35
-		'_wpi_discount_max_uses',
36
-		'_wpi_discount_is_recurring',
37
-		'_wpi_discount_min_total',
38
-		'_wpi_discount_max_total',
39
-	);
40
-
41
-	/**
42
-	 * A map of meta keys to data props.
43
-	 *
44
-	 * @since 1.0.19
45
-	 *
46
-	 * @var array
47
-	 */
48
-	protected $meta_key_to_props = array(
49
-		'_wpi_discount_code'           => 'code',
50
-		'_wpi_discount_amount'         => 'amount',
51
-		'_wpi_discount_start'          => 'start',
52
-		'_wpi_discount_expiration'     => 'expiration',
53
-		'_wpi_discount_type'           => 'type',
54
-		'_wpi_discount_uses'           => 'uses',
55
-		'_wpi_discount_is_single_use'  => 'is_single_use',
56
-		'_wpi_discount_items'          => 'items',
57
-		'_wpi_discount_excluded_items' => 'excluded_items',
58
-		'_wpi_discount_required_items' => 'required_items',
59
-		'_wpi_discount_max_uses'       => 'max_uses',
60
-		'_wpi_discount_is_recurring'   => 'is_recurring',
61
-		'_wpi_discount_min_total'      => 'min_total',
62
-		'_wpi_discount_max_total'      => 'max_total',
63
-	);
64
-
65
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpi_discount_code',
26
+        '_wpi_discount_amount',
27
+        '_wpi_discount_start',
28
+        '_wpi_discount_expiration',
29
+        '_wpi_discount_type',
30
+        '_wpi_discount_uses',
31
+        '_wpi_discount_is_single_use',
32
+        '_wpi_discount_items',
33
+        '_wpi_discount_excluded_items',
34
+        '_wpi_discount_required_items',
35
+        '_wpi_discount_max_uses',
36
+        '_wpi_discount_is_recurring',
37
+        '_wpi_discount_min_total',
38
+        '_wpi_discount_max_total',
39
+    );
40
+
41
+    /**
42
+     * A map of meta keys to data props.
43
+     *
44
+     * @since 1.0.19
45
+     *
46
+     * @var array
47
+     */
48
+    protected $meta_key_to_props = array(
49
+        '_wpi_discount_code'           => 'code',
50
+        '_wpi_discount_amount'         => 'amount',
51
+        '_wpi_discount_start'          => 'start',
52
+        '_wpi_discount_expiration'     => 'expiration',
53
+        '_wpi_discount_type'           => 'type',
54
+        '_wpi_discount_uses'           => 'uses',
55
+        '_wpi_discount_is_single_use'  => 'is_single_use',
56
+        '_wpi_discount_items'          => 'items',
57
+        '_wpi_discount_excluded_items' => 'excluded_items',
58
+        '_wpi_discount_required_items' => 'required_items',
59
+        '_wpi_discount_max_uses'       => 'max_uses',
60
+        '_wpi_discount_is_recurring'   => 'is_recurring',
61
+        '_wpi_discount_min_total'      => 'min_total',
62
+        '_wpi_discount_max_total'      => 'max_total',
63
+    );
64
+
65
+    /*
66 66
 	|--------------------------------------------------------------------------
67 67
 	| CRUD Methods
68 68
 	|--------------------------------------------------------------------------
69 69
 	*/
70 70
 
71
-	/**
72
-	 * Method to create a new discount in the database.
73
-	 *
74
-	 * @param WPInv_Discount $discount Discount object.
75
-	 */
76
-	public function create( &$discount ) {
77
-		$discount->set_version( WPINV_VERSION );
78
-		$discount->set_date_created( current_time('mysql') );
79
-
80
-		// Create a new post.
81
-		$id = wp_insert_post(
82
-			apply_filters(
83
-				'getpaid_new_discount_data',
84
-				array(
85
-					'post_date'     => $discount->get_date_created( 'edit' ),
86
-					'post_type'     => 'wpi_discount',
87
-					'post_status'   => $this->get_post_status( $discount ),
88
-					'ping_status'   => 'closed',
89
-					'post_author'   => $discount->get_author( 'edit' ),
90
-					'post_title'    => $discount->get_name( 'edit' ),
91
-					'post_excerpt'  => $discount->get_description( 'edit' ),
92
-				)
93
-			),
94
-			true
95
-		);
96
-
97
-		if ( $id && ! is_wp_error( $id ) ) {
98
-			$discount->set_id( $id );
99
-			$this->update_post_meta( $discount );
100
-			$discount->save_meta_data();
101
-			$discount->apply_changes();
102
-			$this->clear_caches( $discount );
103
-			do_action( 'getpaid_new_discount', $discount );
104
-			return true;
105
-		}
106
-
107
-		if ( is_wp_error( $id ) ) {
108
-			$discount->last_error = $id->get_error_message();
109
-		}
110
-
111
-		return false;
112
-	}
113
-
114
-	/**
115
-	 * Method to read a discount from the database.
116
-	 *
117
-	 * @param WPInv_Discount $discount Discount object.
118
-	 *
119
-	 */
120
-	public function read( &$discount ) {
121
-
122
-		$discount->set_defaults();
123
-		$discount_object = get_post( $discount->get_id() );
124
-
125
-		if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
126
-			$discount->last_error = __( 'Invalid discount.', 'invoicing' );
127
-			$discount->set_id( 0 );
128
-			return false;
129
-		}
130
-
131
-		$discount->set_props(
132
-			array(
133
-				'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
134
-				'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
135
-				'status'        => $discount_object->post_status,
136
-				'name'          => $discount_object->post_title,
137
-				'author'        => $discount_object->post_author,
138
-				'description'   => $discount_object->post_excerpt,
139
-			)
140
-		);
141
-
142
-		$this->read_object_data( $discount, $discount_object );
143
-		$discount->read_meta_data();
144
-		$discount->set_object_read( true );
145
-		do_action( 'getpaid_read_discount', $discount );
146
-
147
-	}
148
-
149
-	/**
150
-	 * Method to update a discount in the database.
151
-	 *
152
-	 * @param WPInv_Discount $discount Discount object.
153
-	 */
154
-	public function update( &$discount ) {
155
-		$discount->save_meta_data();
156
-		$discount->set_version( WPINV_VERSION );
157
-
158
-		if ( null === $discount->get_date_created( 'edit' ) ) {
159
-			$discount->set_date_created(  current_time('mysql') );
160
-		}
161
-
162
-		// Grab the current status so we can compare.
163
-		$previous_status = get_post_status( $discount->get_id() );
164
-
165
-		$changes = $discount->get_changes();
166
-
167
-		// Only update the post when the post data changes.
168
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
169
-			$post_data = array(
170
-				'post_date'         => $discount->get_date_created( 'edit' ),
171
-				'post_status'       => $discount->get_status( 'edit' ),
172
-				'post_title'        => $discount->get_name( 'edit' ),
173
-				'post_author'       => $discount->get_author( 'edit' ),
174
-				'post_modified'     => $discount->get_date_modified( 'edit' ),
175
-				'post_excerpt'      => $discount->get_description( 'edit' ),
176
-			);
177
-
178
-			/**
179
-			 * When updating this object, to prevent infinite loops, use $wpdb
180
-			 * to update data, since wp_update_post spawns more calls to the
181
-			 * save_post action.
182
-			 *
183
-			 * This ensures hooks are fired by either WP itself (admin screen save),
184
-			 * or an update purely from CRUD.
185
-			 */
186
-			if ( doing_action( 'save_post' ) ) {
187
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
188
-				clean_post_cache( $discount->get_id() );
189
-			} else {
190
-				wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
191
-			}
192
-			$discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
193
-		}
194
-		$this->update_post_meta( $discount );
195
-		$discount->apply_changes();
196
-		$this->clear_caches( $discount );
197
-
198
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
199
-		$new_status = $discount->get_status( 'edit' );
200
-
201
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
202
-			do_action( 'getpaid_new_discount', $discount );
203
-		} else {
204
-			do_action( 'getpaid_update_discount', $discount );
205
-		}
206
-
207
-	}
208
-
209
-	/*
71
+    /**
72
+     * Method to create a new discount in the database.
73
+     *
74
+     * @param WPInv_Discount $discount Discount object.
75
+     */
76
+    public function create( &$discount ) {
77
+        $discount->set_version( WPINV_VERSION );
78
+        $discount->set_date_created( current_time('mysql') );
79
+
80
+        // Create a new post.
81
+        $id = wp_insert_post(
82
+            apply_filters(
83
+                'getpaid_new_discount_data',
84
+                array(
85
+                    'post_date'     => $discount->get_date_created( 'edit' ),
86
+                    'post_type'     => 'wpi_discount',
87
+                    'post_status'   => $this->get_post_status( $discount ),
88
+                    'ping_status'   => 'closed',
89
+                    'post_author'   => $discount->get_author( 'edit' ),
90
+                    'post_title'    => $discount->get_name( 'edit' ),
91
+                    'post_excerpt'  => $discount->get_description( 'edit' ),
92
+                )
93
+            ),
94
+            true
95
+        );
96
+
97
+        if ( $id && ! is_wp_error( $id ) ) {
98
+            $discount->set_id( $id );
99
+            $this->update_post_meta( $discount );
100
+            $discount->save_meta_data();
101
+            $discount->apply_changes();
102
+            $this->clear_caches( $discount );
103
+            do_action( 'getpaid_new_discount', $discount );
104
+            return true;
105
+        }
106
+
107
+        if ( is_wp_error( $id ) ) {
108
+            $discount->last_error = $id->get_error_message();
109
+        }
110
+
111
+        return false;
112
+    }
113
+
114
+    /**
115
+     * Method to read a discount from the database.
116
+     *
117
+     * @param WPInv_Discount $discount Discount object.
118
+     *
119
+     */
120
+    public function read( &$discount ) {
121
+
122
+        $discount->set_defaults();
123
+        $discount_object = get_post( $discount->get_id() );
124
+
125
+        if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
126
+            $discount->last_error = __( 'Invalid discount.', 'invoicing' );
127
+            $discount->set_id( 0 );
128
+            return false;
129
+        }
130
+
131
+        $discount->set_props(
132
+            array(
133
+                'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
134
+                'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
135
+                'status'        => $discount_object->post_status,
136
+                'name'          => $discount_object->post_title,
137
+                'author'        => $discount_object->post_author,
138
+                'description'   => $discount_object->post_excerpt,
139
+            )
140
+        );
141
+
142
+        $this->read_object_data( $discount, $discount_object );
143
+        $discount->read_meta_data();
144
+        $discount->set_object_read( true );
145
+        do_action( 'getpaid_read_discount', $discount );
146
+
147
+    }
148
+
149
+    /**
150
+     * Method to update a discount in the database.
151
+     *
152
+     * @param WPInv_Discount $discount Discount object.
153
+     */
154
+    public function update( &$discount ) {
155
+        $discount->save_meta_data();
156
+        $discount->set_version( WPINV_VERSION );
157
+
158
+        if ( null === $discount->get_date_created( 'edit' ) ) {
159
+            $discount->set_date_created(  current_time('mysql') );
160
+        }
161
+
162
+        // Grab the current status so we can compare.
163
+        $previous_status = get_post_status( $discount->get_id() );
164
+
165
+        $changes = $discount->get_changes();
166
+
167
+        // Only update the post when the post data changes.
168
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
169
+            $post_data = array(
170
+                'post_date'         => $discount->get_date_created( 'edit' ),
171
+                'post_status'       => $discount->get_status( 'edit' ),
172
+                'post_title'        => $discount->get_name( 'edit' ),
173
+                'post_author'       => $discount->get_author( 'edit' ),
174
+                'post_modified'     => $discount->get_date_modified( 'edit' ),
175
+                'post_excerpt'      => $discount->get_description( 'edit' ),
176
+            );
177
+
178
+            /**
179
+             * When updating this object, to prevent infinite loops, use $wpdb
180
+             * to update data, since wp_update_post spawns more calls to the
181
+             * save_post action.
182
+             *
183
+             * This ensures hooks are fired by either WP itself (admin screen save),
184
+             * or an update purely from CRUD.
185
+             */
186
+            if ( doing_action( 'save_post' ) ) {
187
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
188
+                clean_post_cache( $discount->get_id() );
189
+            } else {
190
+                wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
191
+            }
192
+            $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
193
+        }
194
+        $this->update_post_meta( $discount );
195
+        $discount->apply_changes();
196
+        $this->clear_caches( $discount );
197
+
198
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
199
+        $new_status = $discount->get_status( 'edit' );
200
+
201
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
202
+            do_action( 'getpaid_new_discount', $discount );
203
+        } else {
204
+            do_action( 'getpaid_update_discount', $discount );
205
+        }
206
+
207
+    }
208
+
209
+    /*
210 210
 	|--------------------------------------------------------------------------
211 211
 	| Additional Methods
212 212
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-helper.php 1 patch
Indentation   +392 added lines, -392 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,395 +11,395 @@  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 !== null && $text !== false ) {
78
-			$output = ' value="' . esc_attr( wp_unslash( $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
-	 * Navigates through an array, object, or scalar, and removes slashes from the values.
262
-	 *
263
-	 * @since 0.1.41
264
-	 *
265
-	 * @param mixed $value The value to be stripped.
266
-	 * @param array $input Input Field.
267
-	 *
268
-	 * @return mixed Stripped value.
269
-	 */
270
-	public static function sanitize_html_field( $value, $input = array() ) {
271
-		$original = $value;
272
-
273
-		if ( is_array( $value ) ) {
274
-			foreach ( $value as $index => $item ) {
275
-				$value[ $index ] = self::_sanitize_html_field( $value, $input );
276
-			}
277
-		} elseif ( is_object( $value ) ) {
278
-			$object_vars = get_object_vars( $value );
279
-
280
-			foreach ( $object_vars as $property_name => $property_value ) {
281
-				$value->$property_name = self::_sanitize_html_field( $property_value, $input );
282
-			}
283
-		} else {
284
-			$value = self::_sanitize_html_field( $value, $input );
285
-		}
286
-
287
-		/**
288
-		 * Filters content and keeps only allowable HTML elements.
289
-		 *
290
-		 * @since 0.1.41
291
-		 *
292
-		 * @param string|array $value Content to filter through kses.
293
-		 * @param string|array $value Original content without filter.
294
-		 * @param array $input Input Field.
295
-		 */
296
-		return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
297
-	}
298
-
299
-	/**
300
-	 * Filters content and keeps only allowable HTML elements.
301
-	 *
302
-	 * This function makes sure that only the allowed HTML element names, attribute
303
-	 * names and attribute values plus only sane HTML entities will occur in
304
-	 * $string. You have to remove any slashes from PHP's magic quotes before you
305
-	 * call this function.
306
-	 *
307
-	 * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
308
-	 * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
309
-	 * covers all common link protocols, except for 'javascript' which should not
310
-	 * be allowed for untrusted users.
311
-	 *
312
-	 * @since 0.1.41
313
-	 *
314
-	 * @param string|array $value Content to filter through kses.
315
-	 * @param array $input Input Field.
316
-	 *
317
-	 * @return string Filtered content with only allowed HTML elements.
318
-	 */
319
-	public static function _sanitize_html_field( $value, $input = array() ) {
320
-		if ( $value === '' ) {
321
-			return $value;
322
-		}
323
-
324
-		$allowed_html = self::kses_allowed_html( 'post', $input );
325
-
326
-		if ( ! is_array( $allowed_html ) ) {
327
-			$allowed_html = wp_kses_allowed_html( 'post' );
328
-		}
329
-
330
-		$filtered = trim( wp_unslash( $value ) );
331
-		$filtered = wp_kses( $filtered, $allowed_html );
332
-		$filtered = balanceTags( $filtered ); // Balances tags
333
-
334
-		return $filtered;
335
-	}
336
-
337
-	/**
338
-	 * Returns an array of allowed HTML tags and attributes for a given context.
339
-	 *
340
-	 * @since 0.1.41
341
-	 *
342
-	 * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
343
-	 *                              'strip', 'data', 'entities', or the name of a field filter such as
344
-	 *                              'pre_user_description'.
345
-	 * @param array $input Input.
346
-	 *
347
-	 * @return array Array of allowed HTML tags and their allowed attributes.
348
-	 */
349
-	public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
-		$allowed_html = wp_kses_allowed_html( $context );
351
-
352
-		if ( is_array( $allowed_html ) ) {
353
-			// <iframe>
354
-			if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
355
-				$allowed_html['iframe'] = array(
356
-					'class'           => true,
357
-					'id'              => true,
358
-					'src'             => true,
359
-					'width'           => true,
360
-					'height'          => true,
361
-					'frameborder'     => true,
362
-					'marginwidth'     => true,
363
-					'marginheight'    => true,
364
-					'scrolling'       => true,
365
-					'style'           => true,
366
-					'title'           => true,
367
-					'allow'           => true,
368
-					'allowfullscreen' => true,
369
-					'data-*'          => true,
370
-				);
371
-			}
372
-		}
373
-
374
-		/**
375
-		 * Filters the allowed html tags.
376
-		 *
377
-		 * @since 0.1.41
378
-		 *
379
-		 * @param array[]|string $allowed_html Allowed html tags.
380
-		 * @param @param string|array $context The context for which to retrieve tags.
381
-		 * @param array $input Input field.
382
-		 */
383
-		return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
384
-	}
385
-
386
-	public static function get_column_class( $label_number = 2, $type = 'label' ) {
387
-
388
-		$class = '';
389
-
390
-		// set default if empty
391
-		if( $label_number === '' ){
392
-			$label_number = 2;
393
-		}
394
-
395
-		if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
-			if ( $type == 'label' ) {
397
-				$class = 'col-sm-' . absint( $label_number );
398
-			} elseif ( $type == 'input' ) {
399
-				$class = 'col-sm-' . ( 12 - absint( $label_number ) );
400
-			}
401
-		}
402
-
403
-		return $class;
404
-	}
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 !== null && $text !== false ) {
78
+            $output = ' value="' . esc_attr( wp_unslash( $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
+     * Navigates through an array, object, or scalar, and removes slashes from the values.
262
+     *
263
+     * @since 0.1.41
264
+     *
265
+     * @param mixed $value The value to be stripped.
266
+     * @param array $input Input Field.
267
+     *
268
+     * @return mixed Stripped value.
269
+     */
270
+    public static function sanitize_html_field( $value, $input = array() ) {
271
+        $original = $value;
272
+
273
+        if ( is_array( $value ) ) {
274
+            foreach ( $value as $index => $item ) {
275
+                $value[ $index ] = self::_sanitize_html_field( $value, $input );
276
+            }
277
+        } elseif ( is_object( $value ) ) {
278
+            $object_vars = get_object_vars( $value );
279
+
280
+            foreach ( $object_vars as $property_name => $property_value ) {
281
+                $value->$property_name = self::_sanitize_html_field( $property_value, $input );
282
+            }
283
+        } else {
284
+            $value = self::_sanitize_html_field( $value, $input );
285
+        }
286
+
287
+        /**
288
+         * Filters content and keeps only allowable HTML elements.
289
+         *
290
+         * @since 0.1.41
291
+         *
292
+         * @param string|array $value Content to filter through kses.
293
+         * @param string|array $value Original content without filter.
294
+         * @param array $input Input Field.
295
+         */
296
+        return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
297
+    }
298
+
299
+    /**
300
+     * Filters content and keeps only allowable HTML elements.
301
+     *
302
+     * This function makes sure that only the allowed HTML element names, attribute
303
+     * names and attribute values plus only sane HTML entities will occur in
304
+     * $string. You have to remove any slashes from PHP's magic quotes before you
305
+     * call this function.
306
+     *
307
+     * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
308
+     * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
309
+     * covers all common link protocols, except for 'javascript' which should not
310
+     * be allowed for untrusted users.
311
+     *
312
+     * @since 0.1.41
313
+     *
314
+     * @param string|array $value Content to filter through kses.
315
+     * @param array $input Input Field.
316
+     *
317
+     * @return string Filtered content with only allowed HTML elements.
318
+     */
319
+    public static function _sanitize_html_field( $value, $input = array() ) {
320
+        if ( $value === '' ) {
321
+            return $value;
322
+        }
323
+
324
+        $allowed_html = self::kses_allowed_html( 'post', $input );
325
+
326
+        if ( ! is_array( $allowed_html ) ) {
327
+            $allowed_html = wp_kses_allowed_html( 'post' );
328
+        }
329
+
330
+        $filtered = trim( wp_unslash( $value ) );
331
+        $filtered = wp_kses( $filtered, $allowed_html );
332
+        $filtered = balanceTags( $filtered ); // Balances tags
333
+
334
+        return $filtered;
335
+    }
336
+
337
+    /**
338
+     * Returns an array of allowed HTML tags and attributes for a given context.
339
+     *
340
+     * @since 0.1.41
341
+     *
342
+     * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
343
+     *                              'strip', 'data', 'entities', or the name of a field filter such as
344
+     *                              'pre_user_description'.
345
+     * @param array $input Input.
346
+     *
347
+     * @return array Array of allowed HTML tags and their allowed attributes.
348
+     */
349
+    public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
+        $allowed_html = wp_kses_allowed_html( $context );
351
+
352
+        if ( is_array( $allowed_html ) ) {
353
+            // <iframe>
354
+            if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
355
+                $allowed_html['iframe'] = array(
356
+                    'class'           => true,
357
+                    'id'              => true,
358
+                    'src'             => true,
359
+                    'width'           => true,
360
+                    'height'          => true,
361
+                    'frameborder'     => true,
362
+                    'marginwidth'     => true,
363
+                    'marginheight'    => true,
364
+                    'scrolling'       => true,
365
+                    'style'           => true,
366
+                    'title'           => true,
367
+                    'allow'           => true,
368
+                    'allowfullscreen' => true,
369
+                    'data-*'          => true,
370
+                );
371
+            }
372
+        }
373
+
374
+        /**
375
+         * Filters the allowed html tags.
376
+         *
377
+         * @since 0.1.41
378
+         *
379
+         * @param array[]|string $allowed_html Allowed html tags.
380
+         * @param @param string|array $context The context for which to retrieve tags.
381
+         * @param array $input Input field.
382
+         */
383
+        return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
384
+    }
385
+
386
+    public static function get_column_class( $label_number = 2, $type = 'label' ) {
387
+
388
+        $class = '';
389
+
390
+        // set default if empty
391
+        if( $label_number === '' ){
392
+            $label_number = 2;
393
+        }
394
+
395
+        if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
+            if ( $type == 'label' ) {
397
+                $class = 'col-sm-' . absint( $label_number );
398
+            } elseif ( $type == 'input' ) {
399
+                $class = 'col-sm-' . ( 12 - absint( $label_number ) );
400
+            }
401
+        }
402
+
403
+        return $class;
404
+    }
405 405
 }
406 406
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +451 added lines, -451 removed lines patch added patch discarded remove patch
@@ -12,492 +12,492 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
166
-
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
-			return;
186
-		}
187
-
188
-		$mailer     = new GetPaid_Notification_Email_Sender();
189
-		$merge_tags = $email->get_merge_tags();
190
-
191
-		$result = $mailer->send(
192
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
-			$email->get_content( $merge_tags, $extra_args ),
195
-			$email->get_attachments()
196
-		);
197
-
198
-		// Maybe send a copy to the admin.
199
-		if ( $email->include_admin_bcc() ) {
200
-			$mailer->send(
201
-				wpinv_get_admin_email(),
202
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
-				$email->get_content( $merge_tags ),
204
-				$email->get_attachments()
205
-			);
206
-		}
207
-
208
-		if ( $result ) {
209
-			$invoice->add_system_note(
210
-				sprintf(
211
-					__( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
-				)
215
-			);
216
-		} else {
217
-			$invoice->add_system_note(
218
-				sprintf(
219
-					__( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
-				)
223
-			);	
224
-		}
225
-
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
-
228
-		return $result;
229
-	}
230
-
231
-	/**
232
-	 * Also send emails to any cc users.
233
-	 *
234
-	 * @param array $recipients
235
-	 * @param GetPaid_Notification_Email $email
236
-	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
238
-
239
-		if ( ! $email->is_admin_email() ) {
240
-			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
-
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
-			}
247
-
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
-			}
252
-
253
-		}
254
-
255
-		return $recipients;
256
-
257
-	}
258
-
259
-	/**
260
-	 * Sends a new invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function new_invoice( $invoice ) {
265
-
266
-		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
-			return;
269
-		}
270
-
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = wpinv_get_admin_email();
273
-
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
-
276
-	}
277
-
278
-	/**
279
-	 * Sends a cancelled invoice notification.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function cancelled_invoice( $invoice ) {
284
-
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = wpinv_get_admin_email();
287
-
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
-
290
-	}
291
-
292
-	/**
293
-	 * Sends a failed invoice notification.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice
296
-	 */
297
-	public function failed_invoice( $invoice ) {
298
-
299
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
300
-		$recipient = wpinv_get_admin_email();
301
-
302
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
303
-
304
-	}
305
-
306
-	/**
307
-	 * Sends a notification whenever an invoice is put on hold.
308
-	 *
309
-	 * @param WPInv_Invoice $invoice
310
-	 */
311
-	public function onhold_invoice( $invoice ) {
312
-
313
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
314
-		$recipient = $invoice->get_email();
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166
+
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
+            return;
186
+        }
187
+
188
+        $mailer     = new GetPaid_Notification_Email_Sender();
189
+        $merge_tags = $email->get_merge_tags();
190
+
191
+        $result = $mailer->send(
192
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
+            $email->get_content( $merge_tags, $extra_args ),
195
+            $email->get_attachments()
196
+        );
197
+
198
+        // Maybe send a copy to the admin.
199
+        if ( $email->include_admin_bcc() ) {
200
+            $mailer->send(
201
+                wpinv_get_admin_email(),
202
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
+                $email->get_content( $merge_tags ),
204
+                $email->get_attachments()
205
+            );
206
+        }
207
+
208
+        if ( $result ) {
209
+            $invoice->add_system_note(
210
+                sprintf(
211
+                    __( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
+                    sanitize_key( $type ),
213
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
+                )
215
+            );
216
+        } else {
217
+            $invoice->add_system_note(
218
+                sprintf(
219
+                    __( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
+                )
223
+            );	
224
+        }
225
+
226
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+
228
+        return $result;
229
+    }
230
+
231
+    /**
232
+     * Also send emails to any cc users.
233
+     *
234
+     * @param array $recipients
235
+     * @param GetPaid_Notification_Email $email
236
+     */
237
+    public function filter_email_recipients( $recipients, $email ) {
238
+
239
+        if ( ! $email->is_admin_email() ) {
240
+            $cc   = $email->object->get_email_cc();
241
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+
243
+            if ( ! empty( $cc ) ) {
244
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
+            }
247
+
248
+            if ( ! empty( $cc_2 ) ) {
249
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
+            }
252
+
253
+        }
254
+
255
+        return $recipients;
256
+
257
+    }
258
+
259
+    /**
260
+     * Sends a new invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function new_invoice( $invoice ) {
265
+
266
+        // Only send this email for invoices created via the admin page.
267
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
+            return;
269
+        }
270
+
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = wpinv_get_admin_email();
273
+
274
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
+
276
+    }
277
+
278
+    /**
279
+     * Sends a cancelled invoice notification.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function cancelled_invoice( $invoice ) {
284
+
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
+        $recipient = wpinv_get_admin_email();
287
+
288
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
+
290
+    }
291
+
292
+    /**
293
+     * Sends a failed invoice notification.
294
+     *
295
+     * @param WPInv_Invoice $invoice
296
+     */
297
+    public function failed_invoice( $invoice ) {
298
+
299
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
300
+        $recipient = wpinv_get_admin_email();
301
+
302
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
303
+
304
+    }
305
+
306
+    /**
307
+     * Sends a notification whenever an invoice is put on hold.
308
+     *
309
+     * @param WPInv_Invoice $invoice
310
+     */
311
+    public function onhold_invoice( $invoice ) {
312
+
313
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
314
+        $recipient = $invoice->get_email();
315 315
 
316
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
316
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
317 317
 
318
-	}
318
+    }
319 319
 
320
-	/**
321
-	 * Sends a notification whenever an invoice is marked as processing payment.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 */
325
-	public function processing_invoice( $invoice ) {
320
+    /**
321
+     * Sends a notification whenever an invoice is marked as processing payment.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     */
325
+    public function processing_invoice( $invoice ) {
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
-		$recipient = $invoice->get_email();
327
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
+        $recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331
-
332
-	}
333
-
334
-	/**
335
-	 * Sends a notification whenever an invoice is paid.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice
338
-	 */
339
-	public function completed_invoice( $invoice ) {
330
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331
+
332
+    }
333
+
334
+    /**
335
+     * Sends a notification whenever an invoice is paid.
336
+     *
337
+     * @param WPInv_Invoice $invoice
338
+     */
339
+    public function completed_invoice( $invoice ) {
340 340
 
341
-		// (Maybe) abort if it is a renewal invoice.
342
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
343
-			return;
344
-		}
341
+        // (Maybe) abort if it is a renewal invoice.
342
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
343
+            return;
344
+        }
345 345
 
346
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
347
-		$recipient = $invoice->get_email();
346
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
347
+        $recipient = $invoice->get_email();
348 348
 
349
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
349
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
350 350
 
351
-	}
351
+    }
352 352
 
353
-	/**
354
-	 * Sends a notification whenever an invoice is refunded.
355
-	 *
356
-	 * @param WPInv_Invoice $invoice
357
-	 */
358
-	public function refunded_invoice( $invoice ) {
353
+    /**
354
+     * Sends a notification whenever an invoice is refunded.
355
+     *
356
+     * @param WPInv_Invoice $invoice
357
+     */
358
+    public function refunded_invoice( $invoice ) {
359 359
 
360
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
-		$recipient = $invoice->get_email();
360
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
+        $recipient = $invoice->get_email();
362 362
 
363
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
363
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
364 364
 
365
-	}
365
+    }
366 366
 
367
-	/**
368
-	 * Notifies a user about new invoices
369
-	 *
370
-	 * @param WPInv_Invoice $invoice
371
-	 * @param bool $force
372
-	 */
373
-	public function user_invoice( $invoice, $force = false ) {
367
+    /**
368
+     * Notifies a user about new invoices
369
+     *
370
+     * @param WPInv_Invoice $invoice
371
+     * @param bool $force
372
+     */
373
+    public function user_invoice( $invoice, $force = false ) {
374 374
 
375
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
376
-			return;
377
-		}
378
-
379
-		// Only send this email for invoices created via the admin page.
380
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
381
-			return;
382
-		}
375
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
376
+            return;
377
+        }
378
+
379
+        // Only send this email for invoices created via the admin page.
380
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
381
+            return;
382
+        }
383 383
 
384
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
385
-		$recipient = $invoice->get_email();
384
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
385
+        $recipient = $invoice->get_email();
386 386
 
387
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
387
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
388 388
 
389
-	}
390
-
391
-	/**
392
-	 * Checks if an invoice is a payment form invoice.
393
-	 *
394
-	 * @param int $invoice
395
-	 * @return bool
396
-	 */
397
-	public function is_payment_form_invoice( $invoice ) {
398
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
399
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
-	}
389
+    }
390
+
391
+    /**
392
+     * Checks if an invoice is a payment form invoice.
393
+     *
394
+     * @param int $invoice
395
+     * @return bool
396
+     */
397
+    public function is_payment_form_invoice( $invoice ) {
398
+        $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
399
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
+    }
401 401
 
402
-	/**
403
-	 * Notifies admin about new invoice notes
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 * @param string $note
407
-	 */
408
-	public function user_note( $invoice, $note ) {
409
-
410
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
-		$recipient = $invoice->get_email();
402
+    /**
403
+     * Notifies admin about new invoice notes
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     * @param string $note
407
+     */
408
+    public function user_note( $invoice, $note ) {
409
+
410
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
+        $recipient = $invoice->get_email();
412 412
 
413
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
-
415
-	}
416
-
417
-	/**
418
-	 * (Force) Sends overdue notices.
419
-	 *
420
-	 * @param WPInv_Invoice $invoice
421
-	 */
422
-	public function force_send_overdue_notice( $invoice ) {
423
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
-	}
426
-
427
-	/**
428
-	 * Sends overdue notices.
429
-	 *
430
-	 * @TODO: Create an invoices query class.
431
-	 */
432
-	public function overdue() {
433
-		global $wpdb;
434
-
435
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
436
-
437
-		// Fetch reminder days.
438
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
-
440
-		// Abort if non is set.
441
-		if ( empty( $reminder_days ) ) {
442
-			return;
443
-		}
444
-
445
-		// Retrieve date query.
446
-		$date_query = $this->get_date_query( $reminder_days );
447
-
448
-		// Invoices table.
449
-		$table = $wpdb->prefix . 'getpaid_invoices';
450
-
451
-		// Fetch invoices.
452
-		$invoices  = $wpdb->get_col(
453
-			"SELECT posts.ID FROM $wpdb->posts as posts
413
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
+
415
+    }
416
+
417
+    /**
418
+     * (Force) Sends overdue notices.
419
+     *
420
+     * @param WPInv_Invoice $invoice
421
+     */
422
+    public function force_send_overdue_notice( $invoice ) {
423
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
+    }
426
+
427
+    /**
428
+     * Sends overdue notices.
429
+     *
430
+     * @TODO: Create an invoices query class.
431
+     */
432
+    public function overdue() {
433
+        global $wpdb;
434
+
435
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
436
+
437
+        // Fetch reminder days.
438
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
+
440
+        // Abort if non is set.
441
+        if ( empty( $reminder_days ) ) {
442
+            return;
443
+        }
444
+
445
+        // Retrieve date query.
446
+        $date_query = $this->get_date_query( $reminder_days );
447
+
448
+        // Invoices table.
449
+        $table = $wpdb->prefix . 'getpaid_invoices';
450
+
451
+        // Fetch invoices.
452
+        $invoices  = $wpdb->get_col(
453
+            "SELECT posts.ID FROM $wpdb->posts as posts
454 454
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
455 455
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
456 456
 
457
-		foreach ( $invoices as $invoice ) {
457
+        foreach ( $invoices as $invoice ) {
458 458
 
459
-			// Only send this email for invoices created via the admin page.
460
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
461
-				$invoice       = new WPInv_Invoice( $invoice );
462
-				$email->object = $invoice;
459
+            // Only send this email for invoices created via the admin page.
460
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
461
+                $invoice       = new WPInv_Invoice( $invoice );
462
+                $email->object = $invoice;
463 463
 
464
-				if ( $invoice->needs_payment() ) {
465
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
-				}
464
+                if ( $invoice->needs_payment() ) {
465
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
+                }
467 467
 
468
-			}
468
+            }
469 469
 
470
-		}
470
+        }
471 471
 
472
-	}
472
+    }
473 473
 
474
-	/**
475
-	 * Calculates the date query for an invoices query
476
-	 *
477
-	 * @param array $reminder_days
478
-	 * @return string
479
-	 */
480
-	public function get_date_query( $reminder_days ) {
474
+    /**
475
+     * Calculates the date query for an invoices query
476
+     *
477
+     * @param array $reminder_days
478
+     * @return string
479
+     */
480
+    public function get_date_query( $reminder_days ) {
481 481
 
482
-		$date_query = array(
483
-			'relation'  => 'OR'
484
-		);
482
+        $date_query = array(
483
+            'relation'  => 'OR'
484
+        );
485 485
 
486
-		foreach ( $reminder_days as $days ) {
487
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
486
+        foreach ( $reminder_days as $days ) {
487
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
488 488
 
489
-			$date_query[] = array(
490
-				'year'  => $date['year'],
491
-				'month' => $date['month'],
492
-				'day'   => $date['day'],
493
-			);
489
+            $date_query[] = array(
490
+                'year'  => $date['year'],
491
+                'month' => $date['month'],
492
+                'day'   => $date['day'],
493
+            );
494 494
 
495
-		}
495
+        }
496 496
 
497
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
498 498
 
499
-		return $date_query->get_sql();
499
+        return $date_query->get_sql();
500 500
 
501
-	}
501
+    }
502 502
 
503 503
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/wp-super-duper.php 1 patch
Indentation   +2049 added lines, -2049 removed lines patch added patch discarded remove patch
@@ -1,268 +1,268 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 if ( ! class_exists( 'WP_Super_Duper' ) ) {
7 7
 
8 8
 
9
-	/**
10
-	 * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
11
-	 *
12
-	 * Should not be called direct but extended instead.
13
-	 *
14
-	 * Class WP_Super_Duper
15
-	 * @since 1.0.16 change log moved to file change-log.txt - CHANGED
16
-	 * @ver 1.0.19
17
-	 */
18
-	class WP_Super_Duper extends WP_Widget {
19
-
20
-		public $version = "1.0.29";
21
-		public $font_awesome_icon_version = "5.11.2";
22
-		public $block_code;
23
-		public $options;
24
-		public $base_id;
25
-		public $settings_hash;
26
-		public $arguments = array();
27
-		public $instance = array();
28
-		private $class_name;
29
-
30
-		/**
31
-		 * The relative url to the current folder.
32
-		 *
33
-		 * @var string
34
-		 */
35
-		public $url = '';
36
-
37
-		/**
38
-		 * Take the array options and use them to build.
39
-		 */
40
-		public function __construct( $options ) {
41
-			global $sd_widgets;
42
-
43
-			$sd_widgets[ $options['base_id'] ] = array(
44
-				'name'       => $options['name'],
45
-				'class_name' => $options['class_name']
46
-			);
47
-			$this->base_id                     = $options['base_id'];
48
-			// lets filter the options before we do anything
49
-			$options       = apply_filters( "wp_super_duper_options", $options );
50
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
51
-			$options       = $this->add_name_from_key( $options );
52
-			$this->options = $options;
53
-
54
-			$this->base_id   = $options['base_id'];
55
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
56
-
57
-			// init parent
58
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
59
-
60
-			if ( isset( $options['class_name'] ) ) {
61
-				// register widget
62
-				$this->class_name = $options['class_name'];
63
-
64
-				// register shortcode
65
-				$this->register_shortcode();
66
-
67
-				// Fusion Builder (avada) support
68
-				if ( function_exists( 'fusion_builder_map' ) ) {
69
-					add_action( 'init', array( $this, 'register_fusion_element' ) );
70
-				}
71
-
72
-				// register block
73
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
74
-			}
75
-
76
-			// add the CSS and JS we need ONCE
77
-			global $sd_widget_scripts;
78
-
79
-			if ( ! $sd_widget_scripts ) {
80
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
81
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
82
-				wp_add_inline_style( 'widgets', $this->widget_css() );
83
-
84
-				// maybe add elementor editor styles
85
-				add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) );
86
-
87
-				$sd_widget_scripts = true;
88
-
89
-				// add shortcode insert button once
90
-				add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
91
-				// generatepress theme sections compatibility
92
-				if ( function_exists( 'generate_sections_sections_metabox' ) ) {
93
-					add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) );
94
-				}
95
-				/* Load script on Divi theme builder page */
96
-				if ( function_exists( 'et_builder_is_tb_admin_screen' ) && et_builder_is_tb_admin_screen() ) {
97
-					add_thickbox();
98
-					add_action( 'admin_footer', array( $this, 'shortcode_insert_button_script' ) );
99
-				}
100
-
101
-				if ( $this->is_preview() ) {
102
-					add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
103
-					// this makes the insert button work for elementor
104
-					add_action( 'elementor/editor/after_enqueue_scripts', array(
105
-						$this,
106
-						'shortcode_insert_button_script'
107
-					) ); // for elementor
108
-				}
109
-				// this makes the insert button work for cornerstone
110
-				add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) );
111
-
112
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
113
-				add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
114
-
115
-				// add generator text to admin head
116
-				add_action( 'admin_head', array( $this, 'generator' ) );
117
-			}
118
-
119
-			do_action( 'wp_super_duper_widget_init', $options, $this );
120
-		}
121
-
122
-		/**
123
-		 * Add our widget CSS to elementor editor.
124
-		 */
125
-		public function elementor_editor_styles() {
126
-			wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) );
127
-		}
128
-
129
-		public function register_fusion_element() {
130
-
131
-			$options = $this->options;
132
-
133
-			if ( $this->base_id ) {
134
-
135
-				$params = $this->get_fusion_params();
136
-
137
-				$args = array(
138
-					'name'            => $options['name'],
139
-					'shortcode'       => $this->base_id,
140
-					'icon'            => $options['block-icon'] ? $options['block-icon'] : 'far fa-square',
141
-					'allow_generator' => true,
142
-				);
143
-
144
-				if ( ! empty( $params ) ) {
145
-					$args['params'] = $params;
146
-				}
147
-
148
-				fusion_builder_map( $args );
149
-			}
150
-
151
-		}
152
-
153
-		public function get_fusion_params() {
154
-			$params    = array();
155
-			$arguments = $this->get_arguments();
156
-
157
-			if ( ! empty( $arguments ) ) {
158
-				foreach ( $arguments as $key => $val ) {
159
-					$param = array();
160
-					// type
161
-					$param['type'] = str_replace(
162
-						array(
163
-							"text",
164
-							"number",
165
-							"email",
166
-							"color",
167
-							"checkbox"
168
-						),
169
-						array(
170
-							"textfield",
171
-							"textfield",
172
-							"textfield",
173
-							"colorpicker",
174
-							"select",
175
-
176
-						),
177
-						$val['type'] );
178
-
179
-					// multiselect
180
-					if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) {
181
-						$param['type']     = 'multiple_select';
182
-						$param['multiple'] = true;
183
-					}
184
-
185
-					// heading
186
-					$param['heading'] = $val['title'];
187
-
188
-					// description
189
-					$param['description'] = isset( $val['desc'] ) ? $val['desc'] : '';
190
-
191
-					// param_name
192
-					$param['param_name'] = $key;
193
-
194
-					// Default
195
-					$param['default'] = isset( $val['default'] ) ? $val['default'] : '';
196
-
197
-					// Group
198
-					if ( isset( $val['group'] ) ) {
199
-						$param['group'] = $val['group'];
200
-					}
201
-
202
-					// value
203
-					if ( $val['type'] == 'checkbox' ) {
204
-						if ( isset( $val['default'] ) && $val['default'] == '0' ) {
205
-							unset( $param['default'] );
206
-						}
207
-						$param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) );
208
-					} elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) {
209
-						$param['value'] = isset( $val['options'] ) ? $val['options'] : array();
210
-					} else {
211
-						$param['value'] = isset( $val['default'] ) ? $val['default'] : '';
212
-					}
213
-
214
-					// setup the param
215
-					$params[] = $param;
216
-
217
-				}
218
-			}
219
-
220
-
221
-			return $params;
222
-		}
223
-
224
-		/**
225
-		 * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder
226
-		 */
227
-		public static function maybe_cornerstone_builder() {
228
-			if ( did_action( 'cornerstone_before_boot_app' ) ) {
229
-				self::shortcode_insert_button_script();
230
-			}
231
-		}
232
-
233
-		/**
234
-		 * A function to ge the shortcode builder picker html.
235
-		 *
236
-		 * @param string $editor_id
237
-		 *
238
-		 * @return string
239
-		 */
240
-		public static function get_picker( $editor_id = '' ) {
241
-
242
-			ob_start();
243
-			if ( isset( $_POST['editor_id'] ) ) {
244
-				$editor_id = esc_attr( $_POST['editor_id'] );
245
-			} elseif ( isset( $_REQUEST['et_fb'] ) ) {
246
-				$editor_id = 'main_content_content_vb_tiny_mce';
247
-			}
248
-
249
-			global $sd_widgets;
250
-			?>
9
+    /**
10
+     * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
11
+     *
12
+     * Should not be called direct but extended instead.
13
+     *
14
+     * Class WP_Super_Duper
15
+     * @since 1.0.16 change log moved to file change-log.txt - CHANGED
16
+     * @ver 1.0.19
17
+     */
18
+    class WP_Super_Duper extends WP_Widget {
19
+
20
+        public $version = "1.0.29";
21
+        public $font_awesome_icon_version = "5.11.2";
22
+        public $block_code;
23
+        public $options;
24
+        public $base_id;
25
+        public $settings_hash;
26
+        public $arguments = array();
27
+        public $instance = array();
28
+        private $class_name;
29
+
30
+        /**
31
+         * The relative url to the current folder.
32
+         *
33
+         * @var string
34
+         */
35
+        public $url = '';
36
+
37
+        /**
38
+         * Take the array options and use them to build.
39
+         */
40
+        public function __construct( $options ) {
41
+            global $sd_widgets;
42
+
43
+            $sd_widgets[ $options['base_id'] ] = array(
44
+                'name'       => $options['name'],
45
+                'class_name' => $options['class_name']
46
+            );
47
+            $this->base_id                     = $options['base_id'];
48
+            // lets filter the options before we do anything
49
+            $options       = apply_filters( "wp_super_duper_options", $options );
50
+            $options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
51
+            $options       = $this->add_name_from_key( $options );
52
+            $this->options = $options;
53
+
54
+            $this->base_id   = $options['base_id'];
55
+            $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
56
+
57
+            // init parent
58
+            parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
59
+
60
+            if ( isset( $options['class_name'] ) ) {
61
+                // register widget
62
+                $this->class_name = $options['class_name'];
63
+
64
+                // register shortcode
65
+                $this->register_shortcode();
66
+
67
+                // Fusion Builder (avada) support
68
+                if ( function_exists( 'fusion_builder_map' ) ) {
69
+                    add_action( 'init', array( $this, 'register_fusion_element' ) );
70
+                }
71
+
72
+                // register block
73
+                add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
74
+            }
75
+
76
+            // add the CSS and JS we need ONCE
77
+            global $sd_widget_scripts;
78
+
79
+            if ( ! $sd_widget_scripts ) {
80
+                wp_add_inline_script( 'admin-widgets', $this->widget_js() );
81
+                wp_add_inline_script( 'customize-controls', $this->widget_js() );
82
+                wp_add_inline_style( 'widgets', $this->widget_css() );
83
+
84
+                // maybe add elementor editor styles
85
+                add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) );
86
+
87
+                $sd_widget_scripts = true;
88
+
89
+                // add shortcode insert button once
90
+                add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
91
+                // generatepress theme sections compatibility
92
+                if ( function_exists( 'generate_sections_sections_metabox' ) ) {
93
+                    add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) );
94
+                }
95
+                /* Load script on Divi theme builder page */
96
+                if ( function_exists( 'et_builder_is_tb_admin_screen' ) && et_builder_is_tb_admin_screen() ) {
97
+                    add_thickbox();
98
+                    add_action( 'admin_footer', array( $this, 'shortcode_insert_button_script' ) );
99
+                }
100
+
101
+                if ( $this->is_preview() ) {
102
+                    add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
103
+                    // this makes the insert button work for elementor
104
+                    add_action( 'elementor/editor/after_enqueue_scripts', array(
105
+                        $this,
106
+                        'shortcode_insert_button_script'
107
+                    ) ); // for elementor
108
+                }
109
+                // this makes the insert button work for cornerstone
110
+                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) );
111
+
112
+                add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
113
+                add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
114
+
115
+                // add generator text to admin head
116
+                add_action( 'admin_head', array( $this, 'generator' ) );
117
+            }
118
+
119
+            do_action( 'wp_super_duper_widget_init', $options, $this );
120
+        }
121
+
122
+        /**
123
+         * Add our widget CSS to elementor editor.
124
+         */
125
+        public function elementor_editor_styles() {
126
+            wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) );
127
+        }
128
+
129
+        public function register_fusion_element() {
130
+
131
+            $options = $this->options;
132
+
133
+            if ( $this->base_id ) {
134
+
135
+                $params = $this->get_fusion_params();
136
+
137
+                $args = array(
138
+                    'name'            => $options['name'],
139
+                    'shortcode'       => $this->base_id,
140
+                    'icon'            => $options['block-icon'] ? $options['block-icon'] : 'far fa-square',
141
+                    'allow_generator' => true,
142
+                );
143
+
144
+                if ( ! empty( $params ) ) {
145
+                    $args['params'] = $params;
146
+                }
147
+
148
+                fusion_builder_map( $args );
149
+            }
150
+
151
+        }
152
+
153
+        public function get_fusion_params() {
154
+            $params    = array();
155
+            $arguments = $this->get_arguments();
156
+
157
+            if ( ! empty( $arguments ) ) {
158
+                foreach ( $arguments as $key => $val ) {
159
+                    $param = array();
160
+                    // type
161
+                    $param['type'] = str_replace(
162
+                        array(
163
+                            "text",
164
+                            "number",
165
+                            "email",
166
+                            "color",
167
+                            "checkbox"
168
+                        ),
169
+                        array(
170
+                            "textfield",
171
+                            "textfield",
172
+                            "textfield",
173
+                            "colorpicker",
174
+                            "select",
175
+
176
+                        ),
177
+                        $val['type'] );
178
+
179
+                    // multiselect
180
+                    if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) {
181
+                        $param['type']     = 'multiple_select';
182
+                        $param['multiple'] = true;
183
+                    }
184
+
185
+                    // heading
186
+                    $param['heading'] = $val['title'];
187
+
188
+                    // description
189
+                    $param['description'] = isset( $val['desc'] ) ? $val['desc'] : '';
190
+
191
+                    // param_name
192
+                    $param['param_name'] = $key;
193
+
194
+                    // Default
195
+                    $param['default'] = isset( $val['default'] ) ? $val['default'] : '';
196
+
197
+                    // Group
198
+                    if ( isset( $val['group'] ) ) {
199
+                        $param['group'] = $val['group'];
200
+                    }
201
+
202
+                    // value
203
+                    if ( $val['type'] == 'checkbox' ) {
204
+                        if ( isset( $val['default'] ) && $val['default'] == '0' ) {
205
+                            unset( $param['default'] );
206
+                        }
207
+                        $param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) );
208
+                    } elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) {
209
+                        $param['value'] = isset( $val['options'] ) ? $val['options'] : array();
210
+                    } else {
211
+                        $param['value'] = isset( $val['default'] ) ? $val['default'] : '';
212
+                    }
213
+
214
+                    // setup the param
215
+                    $params[] = $param;
216
+
217
+                }
218
+            }
219
+
220
+
221
+            return $params;
222
+        }
223
+
224
+        /**
225
+         * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder
226
+         */
227
+        public static function maybe_cornerstone_builder() {
228
+            if ( did_action( 'cornerstone_before_boot_app' ) ) {
229
+                self::shortcode_insert_button_script();
230
+            }
231
+        }
232
+
233
+        /**
234
+         * A function to ge the shortcode builder picker html.
235
+         *
236
+         * @param string $editor_id
237
+         *
238
+         * @return string
239
+         */
240
+        public static function get_picker( $editor_id = '' ) {
241
+
242
+            ob_start();
243
+            if ( isset( $_POST['editor_id'] ) ) {
244
+                $editor_id = esc_attr( $_POST['editor_id'] );
245
+            } elseif ( isset( $_REQUEST['et_fb'] ) ) {
246
+                $editor_id = 'main_content_content_vb_tiny_mce';
247
+            }
248
+
249
+            global $sd_widgets;
250
+            ?>
251 251
 
252 252
 			<div class="sd-shortcode-left-wrap">
253 253
 				<?php
254
-				ksort( $sd_widgets );
255
-				//				print_r($sd_widgets);exit;
256
-				if ( ! empty( $sd_widgets ) ) {
257
-					echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
258
-					echo "<option>" . __( 'Select shortcode' ) . "</option>";
259
-					foreach ( $sd_widgets as $shortcode => $class ) {
260
-						echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
261
-					}
262
-					echo "</select>";
263
-
264
-				}
265
-				?>
254
+                ksort( $sd_widgets );
255
+                //				print_r($sd_widgets);exit;
256
+                if ( ! empty( $sd_widgets ) ) {
257
+                    echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
258
+                    echo "<option>" . __( 'Select shortcode' ) . "</option>";
259
+                    foreach ( $sd_widgets as $shortcode => $class ) {
260
+                        echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
261
+                    }
262
+                    echo "</select>";
263
+
264
+                }
265
+                ?>
266 266
 				<div class="sd-shortcode-settings"></div>
267 267
 
268 268
 			</div>
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 					<?php if ( $editor_id != '' ) { ?>
274 274
 						<button class="button sd-insert-shortcode-button"
275 275
 						        onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) {
276
-							        echo "'" . $editor_id . "'";
277
-						        } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
276
+                                    echo "'" . $editor_id . "'";
277
+                                } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
278 278
 					<?php } ?>
279 279
 					<button class="button"
280 280
 					        onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button>
@@ -282,134 +282,134 @@  discard block
 block discarded – undo
282 282
 			</div>
283 283
 			<?php
284 284
 
285
-			$html = ob_get_clean();
286
-
287
-			if ( wp_doing_ajax() ) {
288
-				echo $html;
289
-				$should_die = true;
290
-
291
-				// some builder get the editor via ajax so we should not die on those occasions
292
-				$dont_die = array(
293
-					'parent_tag',// WP Bakery
294
-					'avia_request' // enfold
295
-				);
296
-
297
-				foreach ( $dont_die as $request ) {
298
-					if ( isset( $_REQUEST[ $request ] ) ) {
299
-						$should_die = false;
300
-					}
301
-				}
302
-
303
-				if ( $should_die ) {
304
-					wp_die();
305
-				}
306
-
307
-			} else {
308
-				return $html;
309
-			}
310
-
311
-			return '';
312
-
313
-		}
314
-
315
-		/**
316
-		 * Output the version in the admin header.
317
-		 */
318
-		public function generator() {
319
-			echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />';
320
-		}
321
-
322
-		/**
323
-		 * Get widget settings.
324
-		 *
325
-		 * @since 1.0.0
326
-		 */
327
-		public static function get_widget_settings() {
328
-			global $sd_widgets;
329
-
330
-			$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
331
-			if ( ! $shortcode ) {
332
-				wp_die();
333
-			}
334
-			$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
335
-			if ( ! $widget_args ) {
336
-				wp_die();
337
-			}
338
-			$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
339
-			if ( ! $class_name ) {
340
-				wp_die();
341
-			}
342
-
343
-			// invoke an instance method
344
-			$widget = new $class_name;
345
-
346
-			ob_start();
347
-			$widget->form( array() );
348
-			$form = ob_get_clean();
349
-			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
350
-			echo "<style>" . $widget->widget_css() . "</style>";
351
-			echo "<script>" . $widget->widget_js() . "</script>";
352
-			?>
285
+            $html = ob_get_clean();
286
+
287
+            if ( wp_doing_ajax() ) {
288
+                echo $html;
289
+                $should_die = true;
290
+
291
+                // some builder get the editor via ajax so we should not die on those occasions
292
+                $dont_die = array(
293
+                    'parent_tag',// WP Bakery
294
+                    'avia_request' // enfold
295
+                );
296
+
297
+                foreach ( $dont_die as $request ) {
298
+                    if ( isset( $_REQUEST[ $request ] ) ) {
299
+                        $should_die = false;
300
+                    }
301
+                }
302
+
303
+                if ( $should_die ) {
304
+                    wp_die();
305
+                }
306
+
307
+            } else {
308
+                return $html;
309
+            }
310
+
311
+            return '';
312
+
313
+        }
314
+
315
+        /**
316
+         * Output the version in the admin header.
317
+         */
318
+        public function generator() {
319
+            echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />';
320
+        }
321
+
322
+        /**
323
+         * Get widget settings.
324
+         *
325
+         * @since 1.0.0
326
+         */
327
+        public static function get_widget_settings() {
328
+            global $sd_widgets;
329
+
330
+            $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
331
+            if ( ! $shortcode ) {
332
+                wp_die();
333
+            }
334
+            $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
335
+            if ( ! $widget_args ) {
336
+                wp_die();
337
+            }
338
+            $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
339
+            if ( ! $class_name ) {
340
+                wp_die();
341
+            }
342
+
343
+            // invoke an instance method
344
+            $widget = new $class_name;
345
+
346
+            ob_start();
347
+            $widget->form( array() );
348
+            $form = ob_get_clean();
349
+            echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
350
+            echo "<style>" . $widget->widget_css() . "</style>";
351
+            echo "<script>" . $widget->widget_js() . "</script>";
352
+            ?>
353 353
 			<?php
354
-			wp_die();
355
-		}
356
-
357
-		/**
358
-		 * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
359
-		 *
360
-		 * @since 1.0.0
361
-		 *
362
-		 * @param string $editor_id Optional. Shortcode editor id. Default null.
363
-		 * @param string $insert_shortcode_function Optional. Insert shortcode function. Default null.
364
-		 */
365
-		public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
366
-			global $sd_widgets, $shortcode_insert_button_once;
367
-			if ( $shortcode_insert_button_once ) {
368
-				return;
369
-			}
370
-			add_thickbox();
371
-
372
-
373
-			/**
374
-			 * Cornerstone makes us play dirty tricks :/
375
-			 * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed.
376
-			 */
377
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
378
-				echo '<span id="insert-media-button">';
379
-			}
380
-
381
-			echo self::shortcode_button( 'this', 'true' );
382
-
383
-			// see opening note
384
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
385
-				echo '</span>'; // end #insert-media-button
386
-			}
387
-
388
-			// Add separate script for generatepress theme sections
389
-			if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) {
390
-			} else {
391
-				self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
392
-			}
393
-
394
-			$shortcode_insert_button_once = true;
395
-		}
396
-
397
-		/**
398
-		 * Gets the shortcode insert button html.
399
-		 *
400
-		 * @param string $id
401
-		 * @param string $search_for_id
402
-		 *
403
-		 * @return mixed
404
-		 */
405
-		public static function shortcode_button( $id = '', $search_for_id = '' ) {
406
-			ob_start();
407
-			?>
354
+            wp_die();
355
+        }
356
+
357
+        /**
358
+         * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
359
+         *
360
+         * @since 1.0.0
361
+         *
362
+         * @param string $editor_id Optional. Shortcode editor id. Default null.
363
+         * @param string $insert_shortcode_function Optional. Insert shortcode function. Default null.
364
+         */
365
+        public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
366
+            global $sd_widgets, $shortcode_insert_button_once;
367
+            if ( $shortcode_insert_button_once ) {
368
+                return;
369
+            }
370
+            add_thickbox();
371
+
372
+
373
+            /**
374
+             * Cornerstone makes us play dirty tricks :/
375
+             * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed.
376
+             */
377
+            if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
378
+                echo '<span id="insert-media-button">';
379
+            }
380
+
381
+            echo self::shortcode_button( 'this', 'true' );
382
+
383
+            // see opening note
384
+            if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
385
+                echo '</span>'; // end #insert-media-button
386
+            }
387
+
388
+            // Add separate script for generatepress theme sections
389
+            if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) {
390
+            } else {
391
+                self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
392
+            }
393
+
394
+            $shortcode_insert_button_once = true;
395
+        }
396
+
397
+        /**
398
+         * Gets the shortcode insert button html.
399
+         *
400
+         * @param string $id
401
+         * @param string $search_for_id
402
+         *
403
+         * @return mixed
404
+         */
405
+        public static function shortcode_button( $id = '', $search_for_id = '' ) {
406
+            ob_start();
407
+            ?>
408 408
 			<span class="sd-lable-shortcode-inserter">
409 409
 				<a onclick="sd_ajax_get_picker(<?php echo $id;
410
-				if ( $search_for_id ) {
411
-					echo "," . $search_for_id;
412
-				} ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
410
+                if ( $search_for_id ) {
411
+                    echo "," . $search_for_id;
412
+                } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
413 413
 				   class="thickbox button super-duper-content-open" title="Add Shortcode">
414 414
 					<span style="vertical-align: middle;line-height: 18px;font-size: 20px;"
415 415
 					      class="dashicons dashicons-screenoptions"></span>
@@ -420,21 +420,21 @@  discard block
 block discarded – undo
420 420
 			</span>
421 421
 
422 422
 			<?php
423
-			$html = ob_get_clean();
424
-
425
-			// remove line breaks so we can use it in js
426
-			return preg_replace( "/\r|\n/", "", trim( $html ) );
427
-		}
428
-
429
-		/**
430
-		 * Makes SD work with the siteOrigin page builder.
431
-		 *
432
-		 * @since 1.0.6
433
-		 * @return mixed
434
-		 */
435
-		public static function siteorigin_js() {
436
-			ob_start();
437
-			?>
423
+            $html = ob_get_clean();
424
+
425
+            // remove line breaks so we can use it in js
426
+            return preg_replace( "/\r|\n/", "", trim( $html ) );
427
+        }
428
+
429
+        /**
430
+         * Makes SD work with the siteOrigin page builder.
431
+         *
432
+         * @since 1.0.6
433
+         * @return mixed
434
+         */
435
+        public static function siteorigin_js() {
436
+            ob_start();
437
+            ?>
438 438
 			<script>
439 439
 				/**
440 440
 				 * Check a form to see what items should be shown or hidden.
@@ -512,28 +512,28 @@  discard block
 block discarded – undo
512 512
 				});
513 513
 			</script>
514 514
 			<?php
515
-			$output = ob_get_clean();
515
+            $output = ob_get_clean();
516 516
 
517
-			/*
517
+            /*
518 518
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
519 519
 			 */
520 520
 
521
-			return str_replace( array(
522
-				'<script>',
523
-				'</script>'
524
-			), '', $output );
525
-		}
526
-
527
-		/**
528
-		 * Output the JS and CSS for the shortcode insert button.
529
-		 *
530
-		 * @since 1.0.6
531
-		 *
532
-		 * @param string $editor_id
533
-		 * @param string $insert_shortcode_function
534
-		 */
535
-		public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
536
-			?>
521
+            return str_replace( array(
522
+                '<script>',
523
+                '</script>'
524
+            ), '', $output );
525
+        }
526
+
527
+        /**
528
+         * Output the JS and CSS for the shortcode insert button.
529
+         *
530
+         * @since 1.0.6
531
+         *
532
+         * @param string $editor_id
533
+         * @param string $insert_shortcode_function
534
+         */
535
+        public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
536
+            ?>
537 537
 			<style>
538 538
 				.sd-shortcode-left-wrap {
539 539
 					float: left;
@@ -661,35 +661,35 @@  discard block
 block discarded – undo
661 661
 				<?php } ?>
662 662
 			</style>
663 663
 			<?php
664
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
665
-				echo "<script>" . self::siteorigin_js() . "</script>";
666
-			}
667
-			?>
664
+            if ( class_exists( 'SiteOrigin_Panels' ) ) {
665
+                echo "<script>" . self::siteorigin_js() . "</script>";
666
+            }
667
+            ?>
668 668
 			<script>
669 669
 				<?php
670
-				if(! empty( $insert_shortcode_function )){
671
-					echo $insert_shortcode_function;
672
-				}else{
673
-
674
-				/**
675
-				 * Function for super duper insert shortcode.
676
-				 *
677
-				 * @since 1.0.0
678
-				 */
679
-				?>
670
+                if(! empty( $insert_shortcode_function )){
671
+                    echo $insert_shortcode_function;
672
+                }else{
673
+
674
+                /**
675
+                 * Function for super duper insert shortcode.
676
+                 *
677
+                 * @since 1.0.0
678
+                 */
679
+                ?>
680 680
 				function sd_insert_shortcode($editor_id) {
681 681
 					$shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val();
682 682
 					if ($shortcode) {
683 683
 						if (!$editor_id) {
684 684
 							<?php
685
-							if ( isset( $_REQUEST['et_fb'] ) ) {
686
-								echo '$editor_id = "#main_content_content_vb_tiny_mce";';
687
-							} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
688
-								echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
689
-							} else {
690
-								echo '$editor_id = "#wp-content-editor-container textarea";';
691
-							}
692
-							?>
685
+                            if ( isset( $_REQUEST['et_fb'] ) ) {
686
+                                echo '$editor_id = "#main_content_content_vb_tiny_mce";';
687
+                            } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
688
+                                echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
689
+                            } else {
690
+                                echo '$editor_id = "#wp-content-editor-container textarea";';
691
+                            }
692
+                            ?>
693 693
 						} else {
694 694
 							$editor_id = '#' + $editor_id;
695 695
 						}
@@ -1016,18 +1016,18 @@  discard block
 block discarded – undo
1016 1016
 
1017 1017
 			</script>
1018 1018
 			<?php
1019
-		}
1020
-
1021
-		/**
1022
-		 * Gets some CSS for the widgets screen.
1023
-		 *
1024
-		 * @param bool $advanced If we should include advanced CSS.
1025
-		 *
1026
-		 * @return mixed
1027
-		 */
1028
-		public function widget_css( $advanced = true ) {
1029
-			ob_start();
1030
-			?>
1019
+        }
1020
+
1021
+        /**
1022
+         * Gets some CSS for the widgets screen.
1023
+         *
1024
+         * @param bool $advanced If we should include advanced CSS.
1025
+         *
1026
+         * @return mixed
1027
+         */
1028
+        public function widget_css( $advanced = true ) {
1029
+            ob_start();
1030
+            ?>
1031 1031
 			<style>
1032 1032
 				<?php if( $advanced ){ ?>
1033 1033
 				.sd-advanced-setting {
@@ -1065,26 +1065,26 @@  discard block
 block discarded – undo
1065 1065
 				}
1066 1066
 			</style>
1067 1067
 			<?php
1068
-			$output = ob_get_clean();
1068
+            $output = ob_get_clean();
1069 1069
 
1070
-			/*
1070
+            /*
1071 1071
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1072 1072
 			 */
1073 1073
 
1074
-			return str_replace( array(
1075
-				'<style>',
1076
-				'</style>'
1077
-			), '', $output );
1078
-		}
1079
-
1080
-		/**
1081
-		 * Gets some JS for the widgets screen.
1082
-		 *
1083
-		 * @return mixed
1084
-		 */
1085
-		public function widget_js() {
1086
-			ob_start();
1087
-			?>
1074
+            return str_replace( array(
1075
+                '<style>',
1076
+                '</style>'
1077
+            ), '', $output );
1078
+        }
1079
+
1080
+        /**
1081
+         * Gets some JS for the widgets screen.
1082
+         *
1083
+         * @return mixed
1084
+         */
1085
+        public function widget_js() {
1086
+            ob_start();
1087
+            ?>
1088 1088
 			<script>
1089 1089
 
1090 1090
 				/**
@@ -1242,435 +1242,435 @@  discard block
 block discarded – undo
1242 1242
 				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
1243 1243
 			</script>
1244 1244
 			<?php
1245
-			$output = ob_get_clean();
1245
+            $output = ob_get_clean();
1246 1246
 
1247
-			/*
1247
+            /*
1248 1248
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1249 1249
 			 */
1250 1250
 
1251
-			return str_replace( array(
1252
-				'<script>',
1253
-				'</script>'
1254
-			), '', $output );
1255
-		}
1256
-
1257
-
1258
-		/**
1259
-		 * Set the name from the argument key.
1260
-		 *
1261
-		 * @param $options
1262
-		 *
1263
-		 * @return mixed
1264
-		 */
1265
-		private function add_name_from_key( $options, $arguments = false ) {
1266
-			if ( ! empty( $options['arguments'] ) ) {
1267
-				foreach ( $options['arguments'] as $key => $val ) {
1268
-					$options['arguments'][ $key ]['name'] = $key;
1269
-				}
1270
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1271
-				foreach ( $options as $key => $val ) {
1272
-					$options[ $key ]['name'] = $key;
1273
-				}
1274
-			}
1275
-
1276
-			return $options;
1277
-		}
1278
-
1279
-		/**
1280
-		 * Register the parent shortcode.
1281
-		 *
1282
-		 * @since 1.0.0
1283
-		 */
1284
-		public function register_shortcode() {
1285
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1286
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( $this, 'render_shortcode' ) );
1287
-		}
1288
-
1289
-		/**
1290
-		 * Render the shortcode via ajax so we can return it to Gutenberg.
1291
-		 *
1292
-		 * @since 1.0.0
1293
-		 */
1294
-		public function render_shortcode() {
1295
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1296
-			if ( ! current_user_can( 'manage_options' ) ) {
1297
-				wp_die();
1298
-			}
1299
-
1300
-			// we might need the $post value here so lets set it.
1301
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1302
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
1303
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
1304
-					global $post;
1305
-					$post = $post_obj;
1306
-				}
1307
-			}
1308
-
1309
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1310
-				$is_preview = $this->is_preview();
1311
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1312
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1313
-				$attributes       = '';
1314
-				if ( ! empty( $attributes_array ) ) {
1315
-					foreach ( $attributes_array as $key => $value ) {
1316
-						if ( is_array( $value ) ) {
1317
-							$value = implode( ",", $value );
1318
-						}
1319
-
1320
-						if ( ! empty( $value ) ) {
1321
-							$value = wp_unslash( $value );
1322
-
1323
-							// Encode [ and ].
1324
-							if ( $is_preview ) {
1325
-								$value = $this->encode_shortcodes( $value );
1326
-							}
1327
-						}
1328
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . esc_attr( $value ) . "' ";
1329
-					}
1330
-				}
1331
-
1332
-				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1333
-
1334
-				$content = do_shortcode( $shortcode );
1335
-
1336
-				// Decode [ and ].
1337
-				if ( ! empty( $content ) && $is_preview ) {
1338
-					$content = $this->decode_shortcodes( $content );
1339
-				}
1340
-
1341
-				echo $content;
1342
-			}
1343
-			wp_die();
1344
-		}
1345
-
1346
-		/**
1347
-		 * Output the shortcode.
1348
-		 *
1349
-		 * @param array $args
1350
-		 * @param string $content
1351
-		 *
1352
-		 * @return string
1353
-		 */
1354
-		public function shortcode_output( $args = array(), $content = '' ) {
1355
-			$_instance = $args;
1356
-
1357
-			$args = $this->argument_values( $args );
1358
-
1359
-			// add extra argument so we know its a output to gutenberg
1360
-			//$args
1361
-			$args = $this->string_to_bool( $args );
1362
-
1363
-			// if we have a enclosed shortcode we add it to the special `html` argument
1364
-			if ( ! empty( $content ) ) {
1365
-				$args['html'] = $content;
1366
-			}
1367
-
1368
-			if ( ! $this->is_preview() ) {
1369
-				/**
1370
-				 * Filters the settings for a particular widget args.
1371
-				 *
1372
-				 * @since 1.0.28
1373
-				 *
1374
-				 * @param array          $args      The current widget instance's settings.
1375
-				 * @param WP_Super_Duper $widget    The current widget settings.
1376
-				 * @param array          $_instance An array of default widget arguments.
1377
-				 */
1378
-				$args = apply_filters( 'wp_super_duper_widget_display_callback', $args, $this, $_instance );
1379
-
1380
-				if ( ! is_array( $args ) ) {
1381
-					return $args;
1382
-				}
1383
-			}
1384
-
1385
-			$class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1386
-			$class .= " sdel-".$this->get_instance_hash();
1387
-
1388
-			$class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
1389
-			$class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
1390
-
1391
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1392
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1393
-
1394
-			$shortcode_args = array();
1395
-			$output         = '';
1396
-			$no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1397
-			if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) {
1398
-				$no_wrap = true;
1399
-			}
1400
-			$main_content = $this->output( $args, $shortcode_args, $content );
1401
-			if ( $main_content && ! $no_wrap ) {
1402
-				// wrap the shortcode in a div with the same class as the widget
1403
-				$output .= '<div class="' . $class . '" ' . $attrs . '>';
1404
-				if ( ! empty( $args['title'] ) ) {
1405
-					// if its a shortcode and there is a title try to grab the title wrappers
1406
-					$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1407
-					if ( empty( $instance ) ) {
1408
-						global $wp_registered_sidebars;
1409
-						if ( ! empty( $wp_registered_sidebars ) ) {
1410
-							foreach ( $wp_registered_sidebars as $sidebar ) {
1411
-								if ( ! empty( $sidebar['before_title'] ) ) {
1412
-									$shortcode_args['before_title'] = $sidebar['before_title'];
1413
-									$shortcode_args['after_title']  = $sidebar['after_title'];
1414
-									break;
1415
-								}
1416
-							}
1417
-						}
1418
-					}
1419
-					$output .= $this->output_title( $shortcode_args, $args );
1420
-				}
1421
-				$output .= $main_content;
1422
-				$output .= '</div>';
1423
-			} elseif ( $main_content && $no_wrap ) {
1424
-				$output .= $main_content;
1425
-			}
1426
-
1427
-			// if preview show a placeholder if empty
1428
-			if ( $this->is_preview() && $output == '' ) {
1429
-				$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1430
-			}
1431
-
1432
-			return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this );
1433
-		}
1434
-
1435
-		/**
1436
-		 * Placeholder text to show if output is empty and we are on a preview/builder page.
1437
-		 *
1438
-		 * @param string $name
1439
-		 *
1440
-		 * @return string
1441
-		 */
1442
-		public function preview_placeholder_text( $name = '' ) {
1443
-			return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1444
-		}
1445
-
1446
-		/**
1447
-		 * Sometimes booleans values can be turned to strings, so we fix that.
1448
-		 *
1449
-		 * @param $options
1450
-		 *
1451
-		 * @return mixed
1452
-		 */
1453
-		public function string_to_bool( $options ) {
1454
-			// convert bool strings to booleans
1455
-			foreach ( $options as $key => $val ) {
1456
-				if ( $val == 'false' ) {
1457
-					$options[ $key ] = false;
1458
-				} elseif ( $val == 'true' ) {
1459
-					$options[ $key ] = true;
1460
-				}
1461
-			}
1462
-
1463
-			return $options;
1464
-		}
1465
-
1466
-		/**
1467
-		 * Get the argument values that are also filterable.
1468
-		 *
1469
-		 * @param $instance
1470
-		 *
1471
-		 * @since 1.0.12 Don't set checkbox default value if the value is empty.
1472
-		 *
1473
-		 * @return array
1474
-		 */
1475
-		public function argument_values( $instance ) {
1476
-			$argument_values = array();
1477
-
1478
-			// set widget instance
1479
-			$this->instance = $instance;
1480
-
1481
-			if ( empty( $this->arguments ) ) {
1482
-				$this->arguments = $this->get_arguments();
1483
-			}
1484
-
1485
-			if ( ! empty( $this->arguments ) ) {
1486
-				foreach ( $this->arguments as $key => $args ) {
1487
-					// set the input name from the key
1488
-					$args['name'] = $key;
1489
-					//
1490
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1491
-					if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) {
1492
-						// don't set default for an empty checkbox
1493
-					} elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1494
-						$argument_values[ $key ] = $args['default'];
1495
-					}
1496
-				}
1497
-			}
1498
-
1499
-			return $argument_values;
1500
-		}
1501
-
1502
-		/**
1503
-		 * Set arguments in super duper.
1504
-		 *
1505
-		 * @since 1.0.0
1506
-		 *
1507
-		 * @return array Set arguments.
1508
-		 */
1509
-		public function set_arguments() {
1510
-			return $this->arguments;
1511
-		}
1512
-
1513
-		/**
1514
-		 * Get arguments in super duper.
1515
-		 *
1516
-		 * @since 1.0.0
1517
-		 *
1518
-		 * @return array Get arguments.
1519
-		 */
1520
-		public function get_arguments() {
1521
-			if ( empty( $this->arguments ) ) {
1522
-				$this->arguments = $this->set_arguments();
1523
-			}
1524
-
1525
-			$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1526
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
1527
-
1528
-			return $this->arguments;
1529
-		}
1530
-
1531
-		/**
1532
-		 * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
1533
-		 *
1534
-		 * @param array $args
1535
-		 * @param array $widget_args
1536
-		 * @param string $content
1537
-		 */
1538
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
1539
-
1540
-		}
1541
-
1542
-		/**
1543
-		 * Add the dynamic block code inline when the wp-block in enqueued.
1544
-		 */
1545
-		public function register_block() {
1546
-			wp_add_inline_script( 'wp-blocks', $this->block() );
1547
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
1548
-				wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1549
-			}
1550
-		}
1551
-
1552
-		/**
1553
-		 * Check if we need to show advanced options.
1554
-		 *
1555
-		 * @return bool
1556
-		 */
1557
-		public function block_show_advanced() {
1558
-
1559
-			$show      = false;
1560
-			$arguments = $this->get_arguments();
1251
+            return str_replace( array(
1252
+                '<script>',
1253
+                '</script>'
1254
+            ), '', $output );
1255
+        }
1256
+
1257
+
1258
+        /**
1259
+         * Set the name from the argument key.
1260
+         *
1261
+         * @param $options
1262
+         *
1263
+         * @return mixed
1264
+         */
1265
+        private function add_name_from_key( $options, $arguments = false ) {
1266
+            if ( ! empty( $options['arguments'] ) ) {
1267
+                foreach ( $options['arguments'] as $key => $val ) {
1268
+                    $options['arguments'][ $key ]['name'] = $key;
1269
+                }
1270
+            } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1271
+                foreach ( $options as $key => $val ) {
1272
+                    $options[ $key ]['name'] = $key;
1273
+                }
1274
+            }
1275
+
1276
+            return $options;
1277
+        }
1278
+
1279
+        /**
1280
+         * Register the parent shortcode.
1281
+         *
1282
+         * @since 1.0.0
1283
+         */
1284
+        public function register_shortcode() {
1285
+            add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1286
+            add_action( 'wp_ajax_super_duper_output_shortcode', array( $this, 'render_shortcode' ) );
1287
+        }
1288
+
1289
+        /**
1290
+         * Render the shortcode via ajax so we can return it to Gutenberg.
1291
+         *
1292
+         * @since 1.0.0
1293
+         */
1294
+        public function render_shortcode() {
1295
+            check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1296
+            if ( ! current_user_can( 'manage_options' ) ) {
1297
+                wp_die();
1298
+            }
1299
+
1300
+            // we might need the $post value here so lets set it.
1301
+            if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1302
+                $post_obj = get_post( absint( $_POST['post_id'] ) );
1303
+                if ( ! empty( $post_obj ) && empty( $post ) ) {
1304
+                    global $post;
1305
+                    $post = $post_obj;
1306
+                }
1307
+            }
1308
+
1309
+            if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1310
+                $is_preview = $this->is_preview();
1311
+                $shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1312
+                $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1313
+                $attributes       = '';
1314
+                if ( ! empty( $attributes_array ) ) {
1315
+                    foreach ( $attributes_array as $key => $value ) {
1316
+                        if ( is_array( $value ) ) {
1317
+                            $value = implode( ",", $value );
1318
+                        }
1319
+
1320
+                        if ( ! empty( $value ) ) {
1321
+                            $value = wp_unslash( $value );
1322
+
1323
+                            // Encode [ and ].
1324
+                            if ( $is_preview ) {
1325
+                                $value = $this->encode_shortcodes( $value );
1326
+                            }
1327
+                        }
1328
+                        $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . esc_attr( $value ) . "' ";
1329
+                    }
1330
+                }
1331
+
1332
+                $shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1333
+
1334
+                $content = do_shortcode( $shortcode );
1335
+
1336
+                // Decode [ and ].
1337
+                if ( ! empty( $content ) && $is_preview ) {
1338
+                    $content = $this->decode_shortcodes( $content );
1339
+                }
1340
+
1341
+                echo $content;
1342
+            }
1343
+            wp_die();
1344
+        }
1345
+
1346
+        /**
1347
+         * Output the shortcode.
1348
+         *
1349
+         * @param array $args
1350
+         * @param string $content
1351
+         *
1352
+         * @return string
1353
+         */
1354
+        public function shortcode_output( $args = array(), $content = '' ) {
1355
+            $_instance = $args;
1356
+
1357
+            $args = $this->argument_values( $args );
1358
+
1359
+            // add extra argument so we know its a output to gutenberg
1360
+            //$args
1361
+            $args = $this->string_to_bool( $args );
1362
+
1363
+            // if we have a enclosed shortcode we add it to the special `html` argument
1364
+            if ( ! empty( $content ) ) {
1365
+                $args['html'] = $content;
1366
+            }
1367
+
1368
+            if ( ! $this->is_preview() ) {
1369
+                /**
1370
+                 * Filters the settings for a particular widget args.
1371
+                 *
1372
+                 * @since 1.0.28
1373
+                 *
1374
+                 * @param array          $args      The current widget instance's settings.
1375
+                 * @param WP_Super_Duper $widget    The current widget settings.
1376
+                 * @param array          $_instance An array of default widget arguments.
1377
+                 */
1378
+                $args = apply_filters( 'wp_super_duper_widget_display_callback', $args, $this, $_instance );
1379
+
1380
+                if ( ! is_array( $args ) ) {
1381
+                    return $args;
1382
+                }
1383
+            }
1384
+
1385
+            $class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1386
+            $class .= " sdel-".$this->get_instance_hash();
1387
+
1388
+            $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
1389
+            $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
1390
+
1391
+            $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1392
+            $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1393
+
1394
+            $shortcode_args = array();
1395
+            $output         = '';
1396
+            $no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1397
+            if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) {
1398
+                $no_wrap = true;
1399
+            }
1400
+            $main_content = $this->output( $args, $shortcode_args, $content );
1401
+            if ( $main_content && ! $no_wrap ) {
1402
+                // wrap the shortcode in a div with the same class as the widget
1403
+                $output .= '<div class="' . $class . '" ' . $attrs . '>';
1404
+                if ( ! empty( $args['title'] ) ) {
1405
+                    // if its a shortcode and there is a title try to grab the title wrappers
1406
+                    $shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1407
+                    if ( empty( $instance ) ) {
1408
+                        global $wp_registered_sidebars;
1409
+                        if ( ! empty( $wp_registered_sidebars ) ) {
1410
+                            foreach ( $wp_registered_sidebars as $sidebar ) {
1411
+                                if ( ! empty( $sidebar['before_title'] ) ) {
1412
+                                    $shortcode_args['before_title'] = $sidebar['before_title'];
1413
+                                    $shortcode_args['after_title']  = $sidebar['after_title'];
1414
+                                    break;
1415
+                                }
1416
+                            }
1417
+                        }
1418
+                    }
1419
+                    $output .= $this->output_title( $shortcode_args, $args );
1420
+                }
1421
+                $output .= $main_content;
1422
+                $output .= '</div>';
1423
+            } elseif ( $main_content && $no_wrap ) {
1424
+                $output .= $main_content;
1425
+            }
1426
+
1427
+            // if preview show a placeholder if empty
1428
+            if ( $this->is_preview() && $output == '' ) {
1429
+                $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1430
+            }
1431
+
1432
+            return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this );
1433
+        }
1434
+
1435
+        /**
1436
+         * Placeholder text to show if output is empty and we are on a preview/builder page.
1437
+         *
1438
+         * @param string $name
1439
+         *
1440
+         * @return string
1441
+         */
1442
+        public function preview_placeholder_text( $name = '' ) {
1443
+            return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1444
+        }
1445
+
1446
+        /**
1447
+         * Sometimes booleans values can be turned to strings, so we fix that.
1448
+         *
1449
+         * @param $options
1450
+         *
1451
+         * @return mixed
1452
+         */
1453
+        public function string_to_bool( $options ) {
1454
+            // convert bool strings to booleans
1455
+            foreach ( $options as $key => $val ) {
1456
+                if ( $val == 'false' ) {
1457
+                    $options[ $key ] = false;
1458
+                } elseif ( $val == 'true' ) {
1459
+                    $options[ $key ] = true;
1460
+                }
1461
+            }
1462
+
1463
+            return $options;
1464
+        }
1465
+
1466
+        /**
1467
+         * Get the argument values that are also filterable.
1468
+         *
1469
+         * @param $instance
1470
+         *
1471
+         * @since 1.0.12 Don't set checkbox default value if the value is empty.
1472
+         *
1473
+         * @return array
1474
+         */
1475
+        public function argument_values( $instance ) {
1476
+            $argument_values = array();
1477
+
1478
+            // set widget instance
1479
+            $this->instance = $instance;
1480
+
1481
+            if ( empty( $this->arguments ) ) {
1482
+                $this->arguments = $this->get_arguments();
1483
+            }
1484
+
1485
+            if ( ! empty( $this->arguments ) ) {
1486
+                foreach ( $this->arguments as $key => $args ) {
1487
+                    // set the input name from the key
1488
+                    $args['name'] = $key;
1489
+                    //
1490
+                    $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1491
+                    if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) {
1492
+                        // don't set default for an empty checkbox
1493
+                    } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1494
+                        $argument_values[ $key ] = $args['default'];
1495
+                    }
1496
+                }
1497
+            }
1498
+
1499
+            return $argument_values;
1500
+        }
1501
+
1502
+        /**
1503
+         * Set arguments in super duper.
1504
+         *
1505
+         * @since 1.0.0
1506
+         *
1507
+         * @return array Set arguments.
1508
+         */
1509
+        public function set_arguments() {
1510
+            return $this->arguments;
1511
+        }
1512
+
1513
+        /**
1514
+         * Get arguments in super duper.
1515
+         *
1516
+         * @since 1.0.0
1517
+         *
1518
+         * @return array Get arguments.
1519
+         */
1520
+        public function get_arguments() {
1521
+            if ( empty( $this->arguments ) ) {
1522
+                $this->arguments = $this->set_arguments();
1523
+            }
1524
+
1525
+            $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1526
+            $this->arguments = $this->add_name_from_key( $this->arguments, true );
1527
+
1528
+            return $this->arguments;
1529
+        }
1530
+
1531
+        /**
1532
+         * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
1533
+         *
1534
+         * @param array $args
1535
+         * @param array $widget_args
1536
+         * @param string $content
1537
+         */
1538
+        public function output( $args = array(), $widget_args = array(), $content = '' ) {
1539
+
1540
+        }
1541
+
1542
+        /**
1543
+         * Add the dynamic block code inline when the wp-block in enqueued.
1544
+         */
1545
+        public function register_block() {
1546
+            wp_add_inline_script( 'wp-blocks', $this->block() );
1547
+            if ( class_exists( 'SiteOrigin_Panels' ) ) {
1548
+                wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1549
+            }
1550
+        }
1551
+
1552
+        /**
1553
+         * Check if we need to show advanced options.
1554
+         *
1555
+         * @return bool
1556
+         */
1557
+        public function block_show_advanced() {
1558
+
1559
+            $show      = false;
1560
+            $arguments = $this->get_arguments();
1561 1561
 			
1562
-			if ( ! empty( $arguments ) ) {
1563
-				foreach ( $arguments as $argument ) {
1564
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1565
-						$show = true;
1566
-						break; // no need to continue if we know we have it
1567
-					}
1568
-				}
1569
-			}
1570
-
1571
-			return $show;
1572
-		}
1573
-
1574
-		/**
1575
-		 * Get the url path to the current folder.
1576
-		 *
1577
-		 * @return string
1578
-		 */
1579
-		public function get_url() {
1580
-
1581
-			$url = $this->url;
1582
-
1583
-			if ( ! $url ) {
1584
-				// check if we are inside a plugin
1585
-				$file_dir = str_replace( "/includes", "", dirname( __FILE__ ) );
1586
-
1587
-				$dir_parts = explode( "/wp-content/", $file_dir );
1588
-				$url_parts = explode( "/wp-content/", plugins_url() );
1589
-
1590
-				if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) {
1591
-					$url       = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] );
1592
-					$this->url = $url;
1593
-				}
1594
-			}
1595
-
1596
-
1597
-			return $url;
1598
-		}
1599
-
1600
-		/**
1601
-		 * Generate the block icon.
1602
-		 *
1603
-		 * Enables the use of Font Awesome icons.
1604
-		 *
1605
-		 * @note xlink:href is actually deprecated but href is not supported by all so we use both.
1606
-		 *
1607
-		 * @param $icon
1608
-		 *
1609
-		 * @since 1.1.0
1610
-		 * @return string
1611
-		 */
1612
-		public function get_block_icon( $icon ) {
1613
-
1614
-			// check if we have a Font Awesome icon
1615
-			$fa_type = '';
1616
-			if ( substr( $icon, 0, 7 ) === "fas fa-" ) {
1617
-				$fa_type = 'solid';
1618
-			} elseif ( substr( $icon, 0, 7 ) === "far fa-" ) {
1619
-				$fa_type = 'regular';
1620
-			} elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) {
1621
-				$fa_type = 'brands';
1622
-			} else {
1623
-				$icon = "'" . $icon . "'";
1624
-			}
1625
-
1626
-			// set the icon if we found one
1627
-			if ( $fa_type ) {
1628
-				$fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon );
1629
-				$icon    = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))";
1630
-			}
1631
-
1632
-			return $icon;
1633
-		}
1634
-
1635
-		public function group_arguments( $arguments ) {
1562
+            if ( ! empty( $arguments ) ) {
1563
+                foreach ( $arguments as $argument ) {
1564
+                    if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1565
+                        $show = true;
1566
+                        break; // no need to continue if we know we have it
1567
+                    }
1568
+                }
1569
+            }
1570
+
1571
+            return $show;
1572
+        }
1573
+
1574
+        /**
1575
+         * Get the url path to the current folder.
1576
+         *
1577
+         * @return string
1578
+         */
1579
+        public function get_url() {
1580
+
1581
+            $url = $this->url;
1582
+
1583
+            if ( ! $url ) {
1584
+                // check if we are inside a plugin
1585
+                $file_dir = str_replace( "/includes", "", dirname( __FILE__ ) );
1586
+
1587
+                $dir_parts = explode( "/wp-content/", $file_dir );
1588
+                $url_parts = explode( "/wp-content/", plugins_url() );
1589
+
1590
+                if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) {
1591
+                    $url       = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] );
1592
+                    $this->url = $url;
1593
+                }
1594
+            }
1595
+
1596
+
1597
+            return $url;
1598
+        }
1599
+
1600
+        /**
1601
+         * Generate the block icon.
1602
+         *
1603
+         * Enables the use of Font Awesome icons.
1604
+         *
1605
+         * @note xlink:href is actually deprecated but href is not supported by all so we use both.
1606
+         *
1607
+         * @param $icon
1608
+         *
1609
+         * @since 1.1.0
1610
+         * @return string
1611
+         */
1612
+        public function get_block_icon( $icon ) {
1613
+
1614
+            // check if we have a Font Awesome icon
1615
+            $fa_type = '';
1616
+            if ( substr( $icon, 0, 7 ) === "fas fa-" ) {
1617
+                $fa_type = 'solid';
1618
+            } elseif ( substr( $icon, 0, 7 ) === "far fa-" ) {
1619
+                $fa_type = 'regular';
1620
+            } elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) {
1621
+                $fa_type = 'brands';
1622
+            } else {
1623
+                $icon = "'" . $icon . "'";
1624
+            }
1625
+
1626
+            // set the icon if we found one
1627
+            if ( $fa_type ) {
1628
+                $fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon );
1629
+                $icon    = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))";
1630
+            }
1631
+
1632
+            return $icon;
1633
+        }
1634
+
1635
+        public function group_arguments( $arguments ) {
1636 1636
 //			echo '###';print_r($arguments);
1637
-			if ( ! empty( $arguments ) ) {
1638
-				$temp_arguments = array();
1639
-				$general        = __( "General" );
1640
-				$add_sections   = false;
1641
-				foreach ( $arguments as $key => $args ) {
1642
-					if ( isset( $args['group'] ) ) {
1643
-						$temp_arguments[ $args['group'] ][ $key ] = $args;
1644
-						$add_sections                             = true;
1645
-					} else {
1646
-						$temp_arguments[ $general ][ $key ] = $args;
1647
-					}
1648
-				}
1649
-
1650
-				// only add sections if more than one
1651
-				if ( $add_sections ) {
1652
-					$arguments = $temp_arguments;
1653
-				}
1654
-			}
1637
+            if ( ! empty( $arguments ) ) {
1638
+                $temp_arguments = array();
1639
+                $general        = __( "General" );
1640
+                $add_sections   = false;
1641
+                foreach ( $arguments as $key => $args ) {
1642
+                    if ( isset( $args['group'] ) ) {
1643
+                        $temp_arguments[ $args['group'] ][ $key ] = $args;
1644
+                        $add_sections                             = true;
1645
+                    } else {
1646
+                        $temp_arguments[ $general ][ $key ] = $args;
1647
+                    }
1648
+                }
1649
+
1650
+                // only add sections if more than one
1651
+                if ( $add_sections ) {
1652
+                    $arguments = $temp_arguments;
1653
+                }
1654
+            }
1655 1655
 
1656 1656
 //			echo '###';print_r($arguments);
1657
-			return $arguments;
1658
-		}
1659
-
1660
-
1661
-		/**
1662
-		 * Output the JS for building the dynamic Guntenberg block.
1663
-		 *
1664
-		 * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap.
1665
-		 * @since 1.0.9 Save numbers as numbers and not strings.
1666
-		 * @since 1.1.0 Font Awesome classes can be used for icons.
1667
-		 * @return mixed
1668
-		 */
1669
-		public function block() {
1670
-			ob_start();
1671
-
1672
-			$show_advanced = $this->block_show_advanced();
1673
-			?>
1657
+            return $arguments;
1658
+        }
1659
+
1660
+
1661
+        /**
1662
+         * Output the JS for building the dynamic Guntenberg block.
1663
+         *
1664
+         * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap.
1665
+         * @since 1.0.9 Save numbers as numbers and not strings.
1666
+         * @since 1.1.0 Font Awesome classes can be used for icons.
1667
+         * @return mixed
1668
+         */
1669
+        public function block() {
1670
+            ob_start();
1671
+
1672
+            $show_advanced = $this->block_show_advanced();
1673
+            ?>
1674 1674
 			<script>
1675 1675
 				/**
1676 1676
 				 * BLOCK: Basic
@@ -1714,97 +1714,97 @@  discard block
 block discarded – undo
1714 1714
 						icon: <?php echo $this->get_block_icon( $this->options['block-icon'] );?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
1715 1715
 						supports: {
1716 1716
 							<?php
1717
-							if ( isset( $this->options['block-supports'] ) ) {
1718
-								echo $this->array_to_attributes( $this->options['block-supports'] );
1719
-							}
1720
-							?>
1717
+                            if ( isset( $this->options['block-supports'] ) ) {
1718
+                                echo $this->array_to_attributes( $this->options['block-supports'] );
1719
+                            }
1720
+                            ?>
1721 1721
 						},
1722 1722
 						category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
1723 1723
 						<?php if ( isset( $this->options['block-keywords'] ) ) {
1724
-						echo "keywords : " . $this->options['block-keywords'] . ",";
1725
-					}?>
1724
+                        echo "keywords : " . $this->options['block-keywords'] . ",";
1725
+                    }?>
1726 1726
 
1727 1727
 						<?php
1728 1728
 
1729
-						// maybe set no_wrap
1730
-						$no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1731
-						if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) {
1732
-							$no_wrap = true;
1733
-						}
1734
-						if ( $no_wrap ) {
1735
-							$this->options['block-wrap'] = '';
1736
-						}
1729
+                        // maybe set no_wrap
1730
+                        $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1731
+                        if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) {
1732
+                            $no_wrap = true;
1733
+                        }
1734
+                        if ( $no_wrap ) {
1735
+                            $this->options['block-wrap'] = '';
1736
+                        }
1737 1737
 
1738 1738
 
1739 1739
 
1740
-						$show_alignment = false;
1741
-						// align feature
1742
-						/*echo "supports: {";
1740
+                        $show_alignment = false;
1741
+                        // align feature
1742
+                        /*echo "supports: {";
1743 1743
 						echo "	align: true,";
1744 1744
 						echo "  html: false";
1745 1745
 						echo "},";*/
1746 1746
 
1747
-						if ( ! empty( $this->arguments ) ) {
1748
-							echo "attributes : {";
1749
-
1750
-							if ( $show_advanced ) {
1751
-								echo "show_advanced: {";
1752
-								echo "	type: 'boolean',";
1753
-								echo "  default: false,";
1754
-								echo "},";
1755
-							}
1756
-
1757
-							// block wrap element
1758
-							if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this?
1759
-								echo "block_wrap: {";
1760
-								echo "	type: 'string',";
1761
-								echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
1762
-								echo "},";
1763
-							}
1764
-
1765
-							foreach ( $this->arguments as $key => $args ) {
1766
-
1767
-								// set if we should show alignment
1768
-								if ( $key == 'alignment' ) {
1769
-									$show_alignment = true;
1770
-								}
1771
-
1772
-								$extra = '';
1773
-
1774
-								if ( $args['type'] == 'checkbox' ) {
1775
-									$type    = 'boolean';
1776
-									$default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
1777
-								} elseif ( $args['type'] == 'number' ) {
1778
-									$type    = 'number';
1779
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1780
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
1781
-									$type = 'array';
1782
-									if ( isset( $args['default'] ) && is_array( $args['default'] ) ) {
1783
-										$default = ! empty( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
1784
-									} else {
1785
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1786
-									}
1787
-								} elseif ( $args['type'] == 'multiselect' ) {
1788
-									$type    = 'array';
1789
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1790
-								} else {
1791
-									$type    = 'string';
1792
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1793
-								}
1794
-								echo $key . " : {";
1795
-								echo "type : '$type',";
1796
-								echo "default : $default,";
1797
-								echo "},";
1798
-							}
1799
-
1800
-							echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
1801
-							echo "className: { type: 'string', default: '' },";
1802
-
1803
-							echo "},";
1804
-
1805
-						}
1806
-
1807
-						?>
1747
+                        if ( ! empty( $this->arguments ) ) {
1748
+                            echo "attributes : {";
1749
+
1750
+                            if ( $show_advanced ) {
1751
+                                echo "show_advanced: {";
1752
+                                echo "	type: 'boolean',";
1753
+                                echo "  default: false,";
1754
+                                echo "},";
1755
+                            }
1756
+
1757
+                            // block wrap element
1758
+                            if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this?
1759
+                                echo "block_wrap: {";
1760
+                                echo "	type: 'string',";
1761
+                                echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
1762
+                                echo "},";
1763
+                            }
1764
+
1765
+                            foreach ( $this->arguments as $key => $args ) {
1766
+
1767
+                                // set if we should show alignment
1768
+                                if ( $key == 'alignment' ) {
1769
+                                    $show_alignment = true;
1770
+                                }
1771
+
1772
+                                $extra = '';
1773
+
1774
+                                if ( $args['type'] == 'checkbox' ) {
1775
+                                    $type    = 'boolean';
1776
+                                    $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
1777
+                                } elseif ( $args['type'] == 'number' ) {
1778
+                                    $type    = 'number';
1779
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1780
+                                } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
1781
+                                    $type = 'array';
1782
+                                    if ( isset( $args['default'] ) && is_array( $args['default'] ) ) {
1783
+                                        $default = ! empty( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
1784
+                                    } else {
1785
+                                        $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1786
+                                    }
1787
+                                } elseif ( $args['type'] == 'multiselect' ) {
1788
+                                    $type    = 'array';
1789
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1790
+                                } else {
1791
+                                    $type    = 'string';
1792
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1793
+                                }
1794
+                                echo $key . " : {";
1795
+                                echo "type : '$type',";
1796
+                                echo "default : $default,";
1797
+                                echo "},";
1798
+                            }
1799
+
1800
+                            echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
1801
+                            echo "className: { type: 'string', default: '' },";
1802
+
1803
+                            echo "},";
1804
+
1805
+                        }
1806
+
1807
+                        ?>
1808 1808
 
1809 1809
 						// The "edit" property must be a valid function.
1810 1810
 						edit: function (props) {
@@ -1812,9 +1812,9 @@  discard block
 block discarded – undo
1812 1812
 
1813 1813
 							var $value = '';
1814 1814
 							<?php
1815
-							// if we have a post_type and a category then link them
1816
-							if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){
1817
-							?>
1815
+                            // if we have a post_type and a category then link them
1816
+                            if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){
1817
+                            ?>
1818 1818
 							if(typeof(prev_attributes[props.id]) != 'undefined' ){
1819 1819
 								$pt = props.attributes.post_type;
1820 1820
 								if(post_type_rest_slugs.length){
@@ -1898,8 +1898,8 @@  discard block
 block discarded – undo
1898 1898
 										'shortcode': '<?php echo $this->options['base_id'];?>',
1899 1899
 										'attributes': props.attributes,
1900 1900
 										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
1901
-										echo $post->ID;
1902
-									}else{echo '0';}?>,
1901
+                                        echo $post->ID;
1902
+                                    }else{echo '0';}?>,
1903 1903
 										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
1904 1904
 									};
1905 1905
 
@@ -1951,10 +1951,10 @@  discard block
 block discarded – undo
1951 1951
 
1952 1952
 									<?php
1953 1953
 
1954
-									if(! empty( $this->arguments )){
1954
+                                    if(! empty( $this->arguments )){
1955 1955
 
1956
-									if ( $show_advanced ) {
1957
-									?>
1956
+                                    if ( $show_advanced ) {
1957
+                                    ?>
1958 1958
 									el('div', {
1959 1959
 											style: {'padding-left': '16px','padding-right': '16px'}
1960 1960
 										},
@@ -1972,79 +1972,79 @@  discard block
 block discarded – undo
1972 1972
 									,
1973 1973
 									<?php
1974 1974
 
1975
-									}
1975
+                                    }
1976 1976
 
1977
-									$arguments = $this->group_arguments( $this->arguments );
1977
+                                    $arguments = $this->group_arguments( $this->arguments );
1978 1978
 
1979
-									// Do we have sections?
1980
-									$has_sections = $arguments == $this->arguments ? false : true;
1979
+                                    // Do we have sections?
1980
+                                    $has_sections = $arguments == $this->arguments ? false : true;
1981 1981
 
1982 1982
 
1983
-									if($has_sections){
1984
-									$panel_count = 0;
1985
-									foreach($arguments as $key => $args){
1986
-									?>
1983
+                                    if($has_sections){
1984
+                                    $panel_count = 0;
1985
+                                    foreach($arguments as $key => $args){
1986
+                                    ?>
1987 1987
 									el(wp.components.PanelBody, {
1988 1988
 											title: '<?php esc_attr_e( $key ); ?>',
1989 1989
 											initialOpen: <?php if ( $panel_count ) {
1990
-											echo "false";
1991
-										} else {
1992
-											echo "true";
1993
-										}?>
1990
+                                            echo "false";
1991
+                                        } else {
1992
+                                            echo "true";
1993
+                                        }?>
1994 1994
 										},
1995 1995
 										<?php
1996 1996
 
1997 1997
 
1998 1998
 
1999
-										foreach ( $args as $k => $a ) {
1999
+                                        foreach ( $args as $k => $a ) {
2000 2000
 
2001
-											$this->block_row_start( $k, $a );
2002
-											$this->build_block_arguments( $k, $a );
2003
-											$this->block_row_end( $k, $a );
2004
-										}
2005
-										?>
2001
+                                            $this->block_row_start( $k, $a );
2002
+                                            $this->build_block_arguments( $k, $a );
2003
+                                            $this->block_row_end( $k, $a );
2004
+                                        }
2005
+                                        ?>
2006 2006
 									),
2007 2007
 									<?php
2008
-									$panel_count ++;
2008
+                                    $panel_count ++;
2009 2009
 
2010
-									}
2011
-									}else {
2012
-									?>
2010
+                                    }
2011
+                                    }else {
2012
+                                    ?>
2013 2013
 									el(wp.components.PanelBody, {
2014 2014
 											title: '<?php esc_attr_e( "Settings" ); ?>',
2015 2015
 											initialOpen: true
2016 2016
 										},
2017 2017
 										<?php
2018
-										foreach ( $this->arguments as $key => $args ) {
2019
-											$this->block_row_start( $key, $args );
2020
-											$this->build_block_arguments( $key, $args );
2021
-											$this->block_row_end( $key, $args );
2022
-										}
2023
-										?>
2018
+                                        foreach ( $this->arguments as $key => $args ) {
2019
+                                            $this->block_row_start( $key, $args );
2020
+                                            $this->build_block_arguments( $key, $args );
2021
+                                            $this->block_row_end( $key, $args );
2022
+                                        }
2023
+                                        ?>
2024 2024
 									),
2025 2025
 									<?php
2026
-									}
2026
+                                    }
2027 2027
 
2028
-									}
2029
-									?>
2028
+                                    }
2029
+                                    ?>
2030 2030
 
2031 2031
 								),
2032 2032
 
2033 2033
 								<?php
2034
-								// If the user sets block-output array then build it
2035
-								if ( ! empty( $this->options['block-output'] ) ) {
2036
-								$this->block_element( $this->options['block-output'] );
2037
-							}else{
2038
-								// if no block-output is set then we try and get the shortcode html output via ajax.
2039
-								?>
2034
+                                // If the user sets block-output array then build it
2035
+                                if ( ! empty( $this->options['block-output'] ) ) {
2036
+                                $this->block_element( $this->options['block-output'] );
2037
+                            }else{
2038
+                                // if no block-output is set then we try and get the shortcode html output via ajax.
2039
+                                ?>
2040 2040
 								el('div', {
2041 2041
 									dangerouslySetInnerHTML: {__html: onChangeContent()},
2042 2042
 									className: props.className,
2043 2043
 									style: {'minHeight': '30px'}
2044 2044
 								})
2045 2045
 								<?php
2046
-								}
2047
-								?>
2046
+                                }
2047
+                                ?>
2048 2048
 							]; // end return
2049 2049
 						},
2050 2050
 
@@ -2062,10 +2062,10 @@  discard block
 block discarded – undo
2062 2062
 							$html = '';
2063 2063
 							<?php
2064 2064
 
2065
-							if(! empty( $this->arguments )){
2065
+                            if(! empty( $this->arguments )){
2066 2066
 
2067
-							foreach($this->arguments as $key => $args){
2068
-							?>
2067
+                            foreach($this->arguments as $key => $args){
2068
+                            ?>
2069 2069
 							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
2070 2070
 								if ('<?php echo esc_attr( $key );?>' == 'html') {
2071 2071
 									$html = attr.<?php echo esc_attr( $key );?>;
@@ -2074,10 +2074,10 @@  discard block
 block discarded – undo
2074 2074
 								}
2075 2075
 							}
2076 2076
 							<?php
2077
-							}
2078
-							}
2077
+                            }
2078
+                            }
2079 2079
 
2080
-							?>
2080
+                            ?>
2081 2081
 							content += "]";
2082 2082
 
2083 2083
 							// if has html element
@@ -2100,20 +2100,20 @@  discard block
 block discarded – undo
2100 2100
 							}
2101 2101
 
2102 2102
 							<?php
2103
-							if(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){
2104
-							?>
2103
+                            if(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){
2104
+                            ?>
2105 2105
 							return content;
2106 2106
 							<?php
2107
-							}else{
2108
-							?>
2107
+                            }else{
2108
+                            ?>
2109 2109
 							var block_wrap = 'div';
2110 2110
 							if (attr.hasOwnProperty("block_wrap")) {
2111 2111
 								block_wrap = attr.block_wrap;
2112 2112
 							}
2113 2113
 							return el(block_wrap, {dangerouslySetInnerHTML: {__html: content}, className: align});
2114 2114
 							<?php
2115
-							}
2116
-							?>
2115
+                            }
2116
+                            ?>
2117 2117
 
2118 2118
 
2119 2119
 						}
@@ -2121,30 +2121,30 @@  discard block
 block discarded – undo
2121 2121
 				})();
2122 2122
 			</script>
2123 2123
 			<?php
2124
-			$output = ob_get_clean();
2124
+            $output = ob_get_clean();
2125 2125
 
2126
-			/*
2126
+            /*
2127 2127
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
2128 2128
 			 */
2129 2129
 
2130
-			return str_replace( array(
2131
-				'<script>',
2132
-				'</script>'
2133
-			), '', $output );
2134
-		}
2130
+            return str_replace( array(
2131
+                '<script>',
2132
+                '</script>'
2133
+            ), '', $output );
2134
+        }
2135 2135
 
2136
-		public function block_row_start($key, $args){
2136
+        public function block_row_start($key, $args){
2137 2137
 
2138
-			// check for row
2139
-			if(!empty($args['row'])){
2138
+            // check for row
2139
+            if(!empty($args['row'])){
2140 2140
 
2141
-				if(!empty($args['row']['open'])){
2141
+                if(!empty($args['row']['open'])){
2142 2142
 
2143
-				// element require
2144
-				$element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
2145
-				echo $element_require;
2143
+                // element require
2144
+                $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
2145
+                echo $element_require;
2146 2146
 
2147
-					if(false){?><script><?php }?>
2147
+                    if(false){?><script><?php }?>
2148 2148
 						el('div', {
2149 2149
 								className: 'bsui components-base-control',
2150 2150
 							},
@@ -2174,87 +2174,87 @@  discard block
 block discarded – undo
2174 2174
 									},
2175 2175
 
2176 2176
 					<?php
2177
-					if(false){?></script><?php }
2178
-				}elseif(!empty($args['row']['close'])){
2179
-					if(false){?><script><?php }?>
2177
+                    if(false){?></script><?php }
2178
+                }elseif(!empty($args['row']['close'])){
2179
+                    if(false){?><script><?php }?>
2180 2180
 						el(
2181 2181
 							'div',
2182 2182
 							{
2183 2183
 								className: 'col pl-0',
2184 2184
 							},
2185 2185
 					<?php
2186
-					if(false){?></script><?php }
2187
-				}else{
2188
-					if(false){?><script><?php }?>
2186
+                    if(false){?></script><?php }
2187
+                }else{
2188
+                    if(false){?><script><?php }?>
2189 2189
 						el(
2190 2190
 							'div',
2191 2191
 							{
2192 2192
 								className: 'col pl-0 pr-2',
2193 2193
 							},
2194 2194
 					<?php
2195
-					if(false){?></script><?php }
2196
-				}
2197
-
2198
-			}
2199
-
2200
-		}
2201
-
2202
-		public function block_row_end($key, $args){
2203
-
2204
-			if(!empty($args['row'])){
2205
-				// maybe close
2206
-				if(!empty($args['row']['close'])){
2207
-					echo "))";
2208
-				}
2209
-
2210
-				echo "),";
2211
-			}
2212
-		}
2213
-
2214
-		public function build_block_arguments( $key, $args ) {
2215
-			$custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
2216
-			$options           = '';
2217
-			$extra             = '';
2218
-			$require           = '';
2219
-
2220
-			// `content` is a protected and special argument
2221
-			if ( $key == 'content' ) {
2222
-				return;
2223
-			}
2224
-
2225
-
2226
-			// icon
2227
-			$icon = '';
2228
-			if( !empty( $args['icon'] ) ){
2229
-				$icon .= "el('div', {";
2230
-									$icon .= "dangerouslySetInnerHTML: {__html: '".self::get_widget_icon( esc_attr($args['icon']))."'},";
2231
-									$icon .= "className: 'text-center',";
2232
-									$icon .= "title: '".addslashes( $args['title'] )."',";
2233
-								$icon .= "}),";
2234
-
2235
-				// blank title as its added to the icon.
2236
-				$args['title'] = '';
2237
-			}
2238
-
2239
-			// require advanced
2240
-			$require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : "";
2241
-
2242
-			// element require
2243
-			$element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
2244
-
2245
-
2246
-			$onchange  = "props.setAttributes({ $key: $key } )";
2247
-			$onchangecomplete  = "";
2248
-			$value     = "props.attributes.$key";
2249
-			$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx' );
2250
-			if ( in_array( $args['type'], $text_type ) ) {
2251
-				$type = 'TextControl';
2252
-				// Save numbers as numbers and not strings
2253
-				if ( $args['type'] == 'number' ) {
2254
-					$onchange = "props.setAttributes({ $key: Number($key) } )";
2255
-				}
2256
-			}
2257
-			/*
2195
+                    if(false){?></script><?php }
2196
+                }
2197
+
2198
+            }
2199
+
2200
+        }
2201
+
2202
+        public function block_row_end($key, $args){
2203
+
2204
+            if(!empty($args['row'])){
2205
+                // maybe close
2206
+                if(!empty($args['row']['close'])){
2207
+                    echo "))";
2208
+                }
2209
+
2210
+                echo "),";
2211
+            }
2212
+        }
2213
+
2214
+        public function build_block_arguments( $key, $args ) {
2215
+            $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
2216
+            $options           = '';
2217
+            $extra             = '';
2218
+            $require           = '';
2219
+
2220
+            // `content` is a protected and special argument
2221
+            if ( $key == 'content' ) {
2222
+                return;
2223
+            }
2224
+
2225
+
2226
+            // icon
2227
+            $icon = '';
2228
+            if( !empty( $args['icon'] ) ){
2229
+                $icon .= "el('div', {";
2230
+                                    $icon .= "dangerouslySetInnerHTML: {__html: '".self::get_widget_icon( esc_attr($args['icon']))."'},";
2231
+                                    $icon .= "className: 'text-center',";
2232
+                                    $icon .= "title: '".addslashes( $args['title'] )."',";
2233
+                                $icon .= "}),";
2234
+
2235
+                // blank title as its added to the icon.
2236
+                $args['title'] = '';
2237
+            }
2238
+
2239
+            // require advanced
2240
+            $require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : "";
2241
+
2242
+            // element require
2243
+            $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
2244
+
2245
+
2246
+            $onchange  = "props.setAttributes({ $key: $key } )";
2247
+            $onchangecomplete  = "";
2248
+            $value     = "props.attributes.$key";
2249
+            $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx' );
2250
+            if ( in_array( $args['type'], $text_type ) ) {
2251
+                $type = 'TextControl';
2252
+                // Save numbers as numbers and not strings
2253
+                if ( $args['type'] == 'number' ) {
2254
+                    $onchange = "props.setAttributes({ $key: Number($key) } )";
2255
+                }
2256
+            }
2257
+            /*
2258 2258
 			 * https://www.wptricks.com/question/set-current-tab-on-a-gutenberg-tabpanel-component-from-outside-that-component/ es5 layout
2259 2259
 						elseif($args['type']=='tabs'){
2260 2260
 							?>
@@ -2288,85 +2288,85 @@  discard block
 block discarded – undo
2288 2288
 							return;
2289 2289
 						}
2290 2290
 			*/
2291
-			elseif ( $args['type'] == 'color' ) {
2292
-				$type = 'ColorPicker';
2293
-				$onchange = "";
2294
-				$extra = "color: $value,";
2295
-				if(!empty($args['disable_alpha'])){
2296
-					$extra .= "disableAlpha: true,";
2297
-				}
2298
-				$onchangecomplete = "onChangeComplete: function($key) {
2291
+            elseif ( $args['type'] == 'color' ) {
2292
+                $type = 'ColorPicker';
2293
+                $onchange = "";
2294
+                $extra = "color: $value,";
2295
+                if(!empty($args['disable_alpha'])){
2296
+                    $extra .= "disableAlpha: true,";
2297
+                }
2298
+                $onchangecomplete = "onChangeComplete: function($key) {
2299 2299
 				value =  $key.rgb.a && $key.rgb.a < 1 ? \"rgba(\"+$key.rgb.r+\",\"+$key.rgb.g+\",\"+$key.rgb.b+\",\"+$key.rgb.a+\")\" : $key.hex;
2300 2300
                         props.setAttributes({
2301 2301
                             $key: value
2302 2302
                         });
2303 2303
                     },";
2304
-			}
2305
-			elseif ( $args['type'] == 'checkbox' ) {
2306
-				$type = 'CheckboxControl';
2307
-				$extra .= "checked: props.attributes.$key,";
2308
-				$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
2309
-			} elseif ( $args['type'] == 'textarea' ) {
2310
-				$type = 'TextareaControl';
2311
-			} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
2312
-				$type = 'SelectControl';
2313
-
2314
-				if($args['name'] == 'category' && !empty($args['post_type_linked'])){
2315
-					$options .= "options: taxonomies_".str_replace("-","_", $this->id).",";
2316
-				}elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){
2317
-					$options .= "options: sort_by_".str_replace("-","_", $this->id).",";
2318
-				}else {
2319
-
2320
-					if ( ! empty( $args['options'] ) ) {
2321
-						$options .= "options: [";
2322
-						foreach ( $args['options'] as $option_val => $option_label ) {
2323
-							$options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },";
2324
-						}
2325
-						$options .= "],";
2326
-					}
2327
-				}
2328
-				if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
2329
-					$extra .= ' multiple:true,style:{height:"auto",paddingRight:"8px"}, ';
2330
-				}
2331
-			} elseif ( $args['type'] == 'alignment' ) {
2332
-				$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
2333
-			}elseif ( $args['type'] == 'margins' ) {
2334
-
2335
-			} else {
2336
-				return;// if we have not implemented the control then don't break the JS.
2337
-			}
2338
-
2339
-
2340
-
2341
-			// color input does not show the labels so we add them
2342
-			if($args['type']=='color'){
2343
-				// add show only if advanced
2344
-				echo $require_advanced;
2345
-				// add setting require if defined
2346
-				echo $element_require;
2347
-				echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),";
2348
-			}
2349
-
2350
-			// add show only if advanced
2351
-			echo $require_advanced;
2352
-			// add setting require if defined
2353
-			echo $element_require;
2354
-
2355
-			// icon
2356
-			echo $icon;
2357
-			?>
2304
+            }
2305
+            elseif ( $args['type'] == 'checkbox' ) {
2306
+                $type = 'CheckboxControl';
2307
+                $extra .= "checked: props.attributes.$key,";
2308
+                $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
2309
+            } elseif ( $args['type'] == 'textarea' ) {
2310
+                $type = 'TextareaControl';
2311
+            } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
2312
+                $type = 'SelectControl';
2313
+
2314
+                if($args['name'] == 'category' && !empty($args['post_type_linked'])){
2315
+                    $options .= "options: taxonomies_".str_replace("-","_", $this->id).",";
2316
+                }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){
2317
+                    $options .= "options: sort_by_".str_replace("-","_", $this->id).",";
2318
+                }else {
2319
+
2320
+                    if ( ! empty( $args['options'] ) ) {
2321
+                        $options .= "options: [";
2322
+                        foreach ( $args['options'] as $option_val => $option_label ) {
2323
+                            $options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },";
2324
+                        }
2325
+                        $options .= "],";
2326
+                    }
2327
+                }
2328
+                if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
2329
+                    $extra .= ' multiple:true,style:{height:"auto",paddingRight:"8px"}, ';
2330
+                }
2331
+            } elseif ( $args['type'] == 'alignment' ) {
2332
+                $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
2333
+            }elseif ( $args['type'] == 'margins' ) {
2334
+
2335
+            } else {
2336
+                return;// if we have not implemented the control then don't break the JS.
2337
+            }
2338
+
2339
+
2340
+
2341
+            // color input does not show the labels so we add them
2342
+            if($args['type']=='color'){
2343
+                // add show only if advanced
2344
+                echo $require_advanced;
2345
+                // add setting require if defined
2346
+                echo $element_require;
2347
+                echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),";
2348
+            }
2349
+
2350
+            // add show only if advanced
2351
+            echo $require_advanced;
2352
+            // add setting require if defined
2353
+            echo $element_require;
2354
+
2355
+            // icon
2356
+            echo $icon;
2357
+            ?>
2358 2358
 			el( wp.components.<?php echo $type; ?>, {
2359 2359
 			label: '<?php echo addslashes( $args['title'] ); ?>',
2360 2360
 			help: '<?php if ( isset( $args['desc'] ) ) {
2361
-				echo addslashes( $args['desc'] );
2362
-			} ?>',
2361
+                echo addslashes( $args['desc'] );
2362
+            } ?>',
2363 2363
 			value: <?php echo $value; ?>,
2364 2364
 			<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
2365
-				echo "type: '" . addslashes( $args['type'] ) . "',";
2366
-			} ?>
2365
+                echo "type: '" . addslashes( $args['type'] ) . "',";
2366
+            } ?>
2367 2367
 			<?php if ( ! empty( $args['placeholder'] ) ) {
2368
-				echo "placeholder: '" . addslashes( $args['placeholder'] ) . "',";
2369
-			} ?>
2368
+                echo "placeholder: '" . addslashes( $args['placeholder'] ) . "',";
2369
+            } ?>
2370 2370
 			<?php echo $options; ?>
2371 2371
 			<?php echo $extra; ?>
2372 2372
 			<?php echo $custom_attributes; ?>
@@ -2378,608 +2378,608 @@  discard block
 block discarded – undo
2378 2378
 			<?php
2379 2379
 
2380 2380
 
2381
-		}
2382
-
2383
-		/**
2384
-		 * Convert an array of attributes to block string.
2385
-		 *
2386
-		 * @todo there is prob a faster way to do this, also we could add some validation here.
2387
-		 *
2388
-		 * @param $custom_attributes
2389
-		 *
2390
-		 * @return string
2391
-		 */
2392
-		public function array_to_attributes( $custom_attributes, $html = false ) {
2393
-			$attributes = '';
2394
-			if ( ! empty( $custom_attributes ) ) {
2395
-
2396
-				if ( $html ) {
2397
-					foreach ( $custom_attributes as $key => $val ) {
2398
-						$attributes .= " $key='$val' ";
2399
-					}
2400
-				} else {
2401
-					foreach ( $custom_attributes as $key => $val ) {
2402
-						$attributes .= "'$key': '$val',";
2403
-					}
2404
-				}
2405
-			}
2406
-
2407
-			return $attributes;
2408
-		}
2409
-
2410
-		/**
2411
-		 * A self looping function to create the output for JS block elements.
2412
-		 *
2413
-		 * This is what is output in the WP Editor visual view.
2414
-		 *
2415
-		 * @param $args
2416
-		 */
2417
-		public function block_element( $args ) {
2418
-
2419
-
2420
-			if ( ! empty( $args ) ) {
2421
-				foreach ( $args as $element => $new_args ) {
2422
-
2423
-					if ( is_array( $new_args ) ) { // its an element
2424
-
2425
-
2426
-						if ( isset( $new_args['element'] ) ) {
2427
-
2428
-							if ( isset( $new_args['element_require'] ) ) {
2429
-								echo str_replace( array(
2430
-										"'+",
2431
-										"+'"
2432
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
2433
-								unset( $new_args['element_require'] );
2434
-							}
2435
-
2436
-							echo "\n el( '" . $new_args['element'] . "', {";
2437
-
2438
-							// get the attributes
2439
-							foreach ( $new_args as $new_key => $new_value ) {
2440
-
2441
-
2442
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
2443
-									// do nothing
2444
-								} else {
2445
-									echo $this->block_element( array( $new_key => $new_value ) );
2446
-								}
2447
-							}
2448
-
2449
-							echo "},";// end attributes
2450
-
2451
-							// get the content
2452
-							$first_item = 0;
2453
-							foreach ( $new_args as $new_key => $new_value ) {
2454
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
2455
-
2456
-									if ( $new_key === 'content' ) {
2457
-										echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'";
2458
-									}
2459
-
2460
-									if ( is_array( $new_value ) ) {
2461
-
2462
-										if ( isset( $new_value['element_require'] ) ) {
2463
-											echo str_replace( array(
2464
-													"'+",
2465
-													"+'"
2466
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
2467
-											unset( $new_value['element_require'] );
2468
-										}
2469
-
2470
-										if ( isset( $new_value['element_repeat'] ) ) {
2471
-											$x = 1;
2472
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
2473
-												$this->block_element( array( '' => $new_value ) );
2474
-												$x ++;
2475
-											}
2476
-										} else {
2477
-											$this->block_element( array( '' => $new_value ) );
2478
-										}
2479
-									}
2480
-									$first_item ++;
2481
-								}
2482
-							}
2483
-
2484
-							echo ")";// end content
2485
-
2486
-							echo ", \n";
2487
-
2488
-						}
2489
-					} else {
2490
-
2491
-						if ( substr( $element, 0, 3 ) === "if_" ) {
2492
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
2493
-						} elseif ( $element == 'style' ) {
2494
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
2495
-						} else {
2496
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
2497
-						}
2498
-
2499
-					}
2500
-				}
2501
-			}
2502
-		}
2503
-
2504
-		/**
2505
-		 * Replace block attributes placeholders with the proper naming.
2506
-		 *
2507
-		 * @param $string
2508
-		 *
2509
-		 * @return mixed
2510
-		 */
2511
-		public function block_props_replace( $string, $no_wrap = false ) {
2512
-
2513
-			if ( $no_wrap ) {
2514
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
2515
-			} else {
2516
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
2517
-			}
2518
-
2519
-			return $string;
2520
-		}
2521
-
2522
-		/**
2523
-		 * Outputs the content of the widget
2524
-		 *
2525
-		 * @param array $args
2526
-		 * @param array $instance
2527
-		 */
2528
-		public function widget( $args, $instance ) {
2529
-
2530
-			// get the filtered values
2531
-			$argument_values = $this->argument_values( $instance );
2532
-			$argument_values = $this->string_to_bool( $argument_values );
2533
-			$output          = $this->output( $argument_values, $args );
2534
-
2535
-			$no_wrap = false;
2536
-			if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) {
2537
-				$no_wrap = true;
2538
-			}
2539
-
2540
-			ob_start();
2541
-			if ( $output && ! $no_wrap ) {
2542
-
2543
-				$class_original = $this->options['widget_ops']['classname'];
2544
-				$class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash();
2545
-
2546
-				// Before widget
2547
-				$before_widget = $args['before_widget'];
2548
-				$before_widget = str_replace($class_original,$class,$before_widget);
2549
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
2550
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
2551
-
2552
-				// After widget
2553
-				$after_widget = $args['after_widget'];
2554
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
2555
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
2556
-
2557
-				echo $before_widget;
2558
-				// elementor strips the widget wrapping div so we check for and add it back if needed
2559
-				if ( $this->is_elementor_widget_output() ) {
2560
-					// Filter class & attrs for elementor widget output.
2561
-					$class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
2562
-					$class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
2563
-
2564
-					$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
2565
-					$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
2566
-
2567
-					echo "<span class='" . esc_attr( $class  ) . "' " . $attrs . ">";
2568
-				}
2569
-				echo $this->output_title( $args, $instance );
2570
-				echo $output;
2571
-				if ( $this->is_elementor_widget_output() ) {
2572
-					echo "</span>";
2573
-				}
2574
-				echo $after_widget;
2575
-			} elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
2576
-				$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
2577
-				echo $output;
2578
-			} elseif ( $output && $no_wrap ) {
2579
-				echo $output;
2580
-			}
2581
-			$output = ob_get_clean();
2582
-
2583
-			$output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this );
2584
-
2585
-			echo $output;
2586
-		}
2587
-
2588
-		/**
2589
-		 * Tests if the current output is inside a elementor container.
2590
-		 *
2591
-		 * @since 1.0.4
2592
-		 * @return bool
2593
-		 */
2594
-		public function is_elementor_widget_output() {
2595
-			$result = false;
2596
-			if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
2597
-				$result = true;
2598
-			}
2599
-
2600
-			return $result;
2601
-		}
2602
-
2603
-		/**
2604
-		 * Tests if the current output is inside a elementor preview.
2605
-		 *
2606
-		 * @since 1.0.4
2607
-		 * @return bool
2608
-		 */
2609
-		public function is_elementor_preview() {
2610
-			$result = false;
2611
-			if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
2612
-				$result = true;
2613
-			}
2614
-
2615
-			return $result;
2616
-		}
2617
-
2618
-		/**
2619
-		 * Tests if the current output is inside a Divi preview.
2620
-		 *
2621
-		 * @since 1.0.6
2622
-		 * @return bool
2623
-		 */
2624
-		public function is_divi_preview() {
2625
-			$result = false;
2626
-			if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
2627
-				$result = true;
2628
-			}
2629
-
2630
-			return $result;
2631
-		}
2632
-
2633
-		/**
2634
-		 * Tests if the current output is inside a Beaver builder preview.
2635
-		 *
2636
-		 * @since 1.0.6
2637
-		 * @return bool
2638
-		 */
2639
-		public function is_beaver_preview() {
2640
-			$result = false;
2641
-			if ( isset( $_REQUEST['fl_builder'] ) ) {
2642
-				$result = true;
2643
-			}
2644
-
2645
-			return $result;
2646
-		}
2647
-
2648
-		/**
2649
-		 * Tests if the current output is inside a siteorigin builder preview.
2650
-		 *
2651
-		 * @since 1.0.6
2652
-		 * @return bool
2653
-		 */
2654
-		public function is_siteorigin_preview() {
2655
-			$result = false;
2656
-			if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
2657
-				$result = true;
2658
-			}
2659
-
2660
-			return $result;
2661
-		}
2662
-
2663
-		/**
2664
-		 * Tests if the current output is inside a cornerstone builder preview.
2665
-		 *
2666
-		 * @since 1.0.8
2667
-		 * @return bool
2668
-		 */
2669
-		public function is_cornerstone_preview() {
2670
-			$result = false;
2671
-			if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
2672
-				$result = true;
2673
-			}
2674
-
2675
-			return $result;
2676
-		}
2677
-
2678
-		/**
2679
-		 * Tests if the current output is inside a fusion builder preview.
2680
-		 *
2681
-		 * @since 1.1.0
2682
-		 * @return bool
2683
-		 */
2684
-		public function is_fusion_preview() {
2685
-			$result = false;
2686
-			if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) {
2687
-				$result = true;
2688
-			}
2689
-
2690
-			return $result;
2691
-		}
2692
-
2693
-		/**
2694
-		 * Tests if the current output is inside a Oxygen builder preview.
2695
-		 *
2696
-		 * @since 1.0.18
2697
-		 * @return bool
2698
-		 */
2699
-		public function is_oxygen_preview() {
2700
-			$result = false;
2701
-			if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) {
2702
-				$result = true;
2703
-			}
2704
-
2705
-			return $result;
2706
-		}
2707
-
2708
-		/**
2709
-		 * General function to check if we are in a preview situation.
2710
-		 *
2711
-		 * @since 1.0.6
2712
-		 * @return bool
2713
-		 */
2714
-		public function is_preview() {
2715
-			$preview = false;
2716
-			if ( $this->is_divi_preview() ) {
2717
-				$preview = true;
2718
-			} elseif ( $this->is_elementor_preview() ) {
2719
-				$preview = true;
2720
-			} elseif ( $this->is_beaver_preview() ) {
2721
-				$preview = true;
2722
-			} elseif ( $this->is_siteorigin_preview() ) {
2723
-				$preview = true;
2724
-			} elseif ( $this->is_cornerstone_preview() ) {
2725
-				$preview = true;
2726
-			} elseif ( $this->is_fusion_preview() ) {
2727
-				$preview = true;
2728
-			} elseif ( $this->is_oxygen_preview() ) {
2729
-				$preview = true;
2730
-			} elseif( $this->is_block_content_call() ) {
2731
-				$preview = true;
2732
-			}
2733
-
2734
-			return $preview;
2735
-		}
2736
-
2737
-		/**
2738
-		 * Output the super title.
2739
-		 *
2740
-		 * @param $args
2741
-		 * @param array $instance
2742
-		 *
2743
-		 * @return string
2744
-		 */
2745
-		public function output_title( $args, $instance = array() ) {
2746
-			$output = '';
2747
-			if ( ! empty( $instance['title'] ) ) {
2748
-				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
2749
-				$title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2750
-
2751
-				if(empty($instance['widget_title_tag'])){
2752
-					$output = $args['before_title'] . $title . $args['after_title'];
2753
-				}else{
2754
-					$title_tag = esc_attr( $instance['widget_title_tag'] );
2755
-
2756
-					// classes
2757
-					$title_classes = array();
2758
-					$title_classes[] = !empty( $instance['widget_title_size_class'] ) ? sanitize_html_class( $instance['widget_title_size_class'] ) : '';
2759
-					$title_classes[] = !empty( $instance['widget_title_align_class'] ) ? sanitize_html_class( $instance['widget_title_align_class'] ) : '';
2760
-					$title_classes[] = !empty( $instance['widget_title_color_class'] ) ? "text-".sanitize_html_class( $instance['widget_title_color_class'] ) : '';
2761
-					$title_classes[] = !empty( $instance['widget_title_border_class'] ) ? sanitize_html_class( $instance['widget_title_border_class'] ) : '';
2762
-					$title_classes[] = !empty( $instance['widget_title_border_color_class'] ) ? "border-".sanitize_html_class( $instance['widget_title_border_color_class'] ) : '';
2763
-					$title_classes[] = !empty( $instance['widget_title_mt_class'] ) ? "mt-".absint( $instance['widget_title_mt_class'] ) : '';
2764
-					$title_classes[] = !empty( $instance['widget_title_mr_class'] ) ? "mr-".absint( $instance['widget_title_mr_class'] ) : '';
2765
-					$title_classes[] = !empty( $instance['widget_title_mb_class'] ) ? "mb-".absint( $instance['widget_title_mb_class'] ) : '';
2766
-					$title_classes[] = !empty( $instance['widget_title_ml_class'] ) ? "ml-".absint( $instance['widget_title_ml_class'] ) : '';
2767
-					$title_classes[] = !empty( $instance['widget_title_pt_class'] ) ? "pt-".absint( $instance['widget_title_pt_class'] ) : '';
2768
-					$title_classes[] = !empty( $instance['widget_title_pr_class'] ) ? "pr-".absint( $instance['widget_title_pr_class'] ) : '';
2769
-					$title_classes[] = !empty( $instance['widget_title_pb_class'] ) ? "pb-".absint( $instance['widget_title_pb_class'] ) : '';
2770
-					$title_classes[] = !empty( $instance['widget_title_pl_class'] ) ? "pl-".absint( $instance['widget_title_pl_class'] ) : '';
2771
-
2772
-					$class = !empty( $title_classes ) ? implode(" ",$title_classes) : '';
2773
-					$output = "<$title_tag class='$class' >$title</$title_tag>";
2774
-				}
2775
-
2776
-			}
2777
-
2778
-			return $output;
2779
-		}
2780
-
2781
-		/**
2782
-		 * Outputs the options form inputs for the widget.
2783
-		 *
2784
-		 * @param array $instance The widget options.
2785
-		 */
2786
-		public function form( $instance ) {
2787
-
2788
-			// set widget instance
2789
-			$this->instance = $instance;
2790
-
2791
-			// set it as a SD widget
2792
-			echo $this->widget_advanced_toggle();
2793
-
2794
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
2795
-			$arguments_raw = $this->get_arguments();
2796
-
2797
-			if ( is_array( $arguments_raw ) ) {
2798
-
2799
-				$arguments = $this->group_arguments( $arguments_raw );
2800
-
2801
-				// Do we have sections?
2802
-				$has_sections = $arguments == $arguments_raw ? false : true;
2803
-
2804
-
2805
-				if ( $has_sections ) {
2806
-					$panel_count = 0;
2807
-					foreach ( $arguments as $key => $args ) {
2808
-
2809
-						?>
2381
+        }
2382
+
2383
+        /**
2384
+         * Convert an array of attributes to block string.
2385
+         *
2386
+         * @todo there is prob a faster way to do this, also we could add some validation here.
2387
+         *
2388
+         * @param $custom_attributes
2389
+         *
2390
+         * @return string
2391
+         */
2392
+        public function array_to_attributes( $custom_attributes, $html = false ) {
2393
+            $attributes = '';
2394
+            if ( ! empty( $custom_attributes ) ) {
2395
+
2396
+                if ( $html ) {
2397
+                    foreach ( $custom_attributes as $key => $val ) {
2398
+                        $attributes .= " $key='$val' ";
2399
+                    }
2400
+                } else {
2401
+                    foreach ( $custom_attributes as $key => $val ) {
2402
+                        $attributes .= "'$key': '$val',";
2403
+                    }
2404
+                }
2405
+            }
2406
+
2407
+            return $attributes;
2408
+        }
2409
+
2410
+        /**
2411
+         * A self looping function to create the output for JS block elements.
2412
+         *
2413
+         * This is what is output in the WP Editor visual view.
2414
+         *
2415
+         * @param $args
2416
+         */
2417
+        public function block_element( $args ) {
2418
+
2419
+
2420
+            if ( ! empty( $args ) ) {
2421
+                foreach ( $args as $element => $new_args ) {
2422
+
2423
+                    if ( is_array( $new_args ) ) { // its an element
2424
+
2425
+
2426
+                        if ( isset( $new_args['element'] ) ) {
2427
+
2428
+                            if ( isset( $new_args['element_require'] ) ) {
2429
+                                echo str_replace( array(
2430
+                                        "'+",
2431
+                                        "+'"
2432
+                                    ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
2433
+                                unset( $new_args['element_require'] );
2434
+                            }
2435
+
2436
+                            echo "\n el( '" . $new_args['element'] . "', {";
2437
+
2438
+                            // get the attributes
2439
+                            foreach ( $new_args as $new_key => $new_value ) {
2440
+
2441
+
2442
+                                if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
2443
+                                    // do nothing
2444
+                                } else {
2445
+                                    echo $this->block_element( array( $new_key => $new_value ) );
2446
+                                }
2447
+                            }
2448
+
2449
+                            echo "},";// end attributes
2450
+
2451
+                            // get the content
2452
+                            $first_item = 0;
2453
+                            foreach ( $new_args as $new_key => $new_value ) {
2454
+                                if ( $new_key === 'content' || is_array( $new_value ) ) {
2455
+
2456
+                                    if ( $new_key === 'content' ) {
2457
+                                        echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'";
2458
+                                    }
2459
+
2460
+                                    if ( is_array( $new_value ) ) {
2461
+
2462
+                                        if ( isset( $new_value['element_require'] ) ) {
2463
+                                            echo str_replace( array(
2464
+                                                    "'+",
2465
+                                                    "+'"
2466
+                                                ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
2467
+                                            unset( $new_value['element_require'] );
2468
+                                        }
2469
+
2470
+                                        if ( isset( $new_value['element_repeat'] ) ) {
2471
+                                            $x = 1;
2472
+                                            while ( $x <= absint( $new_value['element_repeat'] ) ) {
2473
+                                                $this->block_element( array( '' => $new_value ) );
2474
+                                                $x ++;
2475
+                                            }
2476
+                                        } else {
2477
+                                            $this->block_element( array( '' => $new_value ) );
2478
+                                        }
2479
+                                    }
2480
+                                    $first_item ++;
2481
+                                }
2482
+                            }
2483
+
2484
+                            echo ")";// end content
2485
+
2486
+                            echo ", \n";
2487
+
2488
+                        }
2489
+                    } else {
2490
+
2491
+                        if ( substr( $element, 0, 3 ) === "if_" ) {
2492
+                            echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
2493
+                        } elseif ( $element == 'style' ) {
2494
+                            echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
2495
+                        } else {
2496
+                            echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
2497
+                        }
2498
+
2499
+                    }
2500
+                }
2501
+            }
2502
+        }
2503
+
2504
+        /**
2505
+         * Replace block attributes placeholders with the proper naming.
2506
+         *
2507
+         * @param $string
2508
+         *
2509
+         * @return mixed
2510
+         */
2511
+        public function block_props_replace( $string, $no_wrap = false ) {
2512
+
2513
+            if ( $no_wrap ) {
2514
+                $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
2515
+            } else {
2516
+                $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
2517
+            }
2518
+
2519
+            return $string;
2520
+        }
2521
+
2522
+        /**
2523
+         * Outputs the content of the widget
2524
+         *
2525
+         * @param array $args
2526
+         * @param array $instance
2527
+         */
2528
+        public function widget( $args, $instance ) {
2529
+
2530
+            // get the filtered values
2531
+            $argument_values = $this->argument_values( $instance );
2532
+            $argument_values = $this->string_to_bool( $argument_values );
2533
+            $output          = $this->output( $argument_values, $args );
2534
+
2535
+            $no_wrap = false;
2536
+            if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) {
2537
+                $no_wrap = true;
2538
+            }
2539
+
2540
+            ob_start();
2541
+            if ( $output && ! $no_wrap ) {
2542
+
2543
+                $class_original = $this->options['widget_ops']['classname'];
2544
+                $class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash();
2545
+
2546
+                // Before widget
2547
+                $before_widget = $args['before_widget'];
2548
+                $before_widget = str_replace($class_original,$class,$before_widget);
2549
+                $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
2550
+                $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
2551
+
2552
+                // After widget
2553
+                $after_widget = $args['after_widget'];
2554
+                $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
2555
+                $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
2556
+
2557
+                echo $before_widget;
2558
+                // elementor strips the widget wrapping div so we check for and add it back if needed
2559
+                if ( $this->is_elementor_widget_output() ) {
2560
+                    // Filter class & attrs for elementor widget output.
2561
+                    $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
2562
+                    $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
2563
+
2564
+                    $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
2565
+                    $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
2566
+
2567
+                    echo "<span class='" . esc_attr( $class  ) . "' " . $attrs . ">";
2568
+                }
2569
+                echo $this->output_title( $args, $instance );
2570
+                echo $output;
2571
+                if ( $this->is_elementor_widget_output() ) {
2572
+                    echo "</span>";
2573
+                }
2574
+                echo $after_widget;
2575
+            } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
2576
+                $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
2577
+                echo $output;
2578
+            } elseif ( $output && $no_wrap ) {
2579
+                echo $output;
2580
+            }
2581
+            $output = ob_get_clean();
2582
+
2583
+            $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this );
2584
+
2585
+            echo $output;
2586
+        }
2587
+
2588
+        /**
2589
+         * Tests if the current output is inside a elementor container.
2590
+         *
2591
+         * @since 1.0.4
2592
+         * @return bool
2593
+         */
2594
+        public function is_elementor_widget_output() {
2595
+            $result = false;
2596
+            if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
2597
+                $result = true;
2598
+            }
2599
+
2600
+            return $result;
2601
+        }
2602
+
2603
+        /**
2604
+         * Tests if the current output is inside a elementor preview.
2605
+         *
2606
+         * @since 1.0.4
2607
+         * @return bool
2608
+         */
2609
+        public function is_elementor_preview() {
2610
+            $result = false;
2611
+            if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
2612
+                $result = true;
2613
+            }
2614
+
2615
+            return $result;
2616
+        }
2617
+
2618
+        /**
2619
+         * Tests if the current output is inside a Divi preview.
2620
+         *
2621
+         * @since 1.0.6
2622
+         * @return bool
2623
+         */
2624
+        public function is_divi_preview() {
2625
+            $result = false;
2626
+            if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
2627
+                $result = true;
2628
+            }
2629
+
2630
+            return $result;
2631
+        }
2632
+
2633
+        /**
2634
+         * Tests if the current output is inside a Beaver builder preview.
2635
+         *
2636
+         * @since 1.0.6
2637
+         * @return bool
2638
+         */
2639
+        public function is_beaver_preview() {
2640
+            $result = false;
2641
+            if ( isset( $_REQUEST['fl_builder'] ) ) {
2642
+                $result = true;
2643
+            }
2644
+
2645
+            return $result;
2646
+        }
2647
+
2648
+        /**
2649
+         * Tests if the current output is inside a siteorigin builder preview.
2650
+         *
2651
+         * @since 1.0.6
2652
+         * @return bool
2653
+         */
2654
+        public function is_siteorigin_preview() {
2655
+            $result = false;
2656
+            if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
2657
+                $result = true;
2658
+            }
2659
+
2660
+            return $result;
2661
+        }
2662
+
2663
+        /**
2664
+         * Tests if the current output is inside a cornerstone builder preview.
2665
+         *
2666
+         * @since 1.0.8
2667
+         * @return bool
2668
+         */
2669
+        public function is_cornerstone_preview() {
2670
+            $result = false;
2671
+            if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
2672
+                $result = true;
2673
+            }
2674
+
2675
+            return $result;
2676
+        }
2677
+
2678
+        /**
2679
+         * Tests if the current output is inside a fusion builder preview.
2680
+         *
2681
+         * @since 1.1.0
2682
+         * @return bool
2683
+         */
2684
+        public function is_fusion_preview() {
2685
+            $result = false;
2686
+            if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) {
2687
+                $result = true;
2688
+            }
2689
+
2690
+            return $result;
2691
+        }
2692
+
2693
+        /**
2694
+         * Tests if the current output is inside a Oxygen builder preview.
2695
+         *
2696
+         * @since 1.0.18
2697
+         * @return bool
2698
+         */
2699
+        public function is_oxygen_preview() {
2700
+            $result = false;
2701
+            if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) {
2702
+                $result = true;
2703
+            }
2704
+
2705
+            return $result;
2706
+        }
2707
+
2708
+        /**
2709
+         * General function to check if we are in a preview situation.
2710
+         *
2711
+         * @since 1.0.6
2712
+         * @return bool
2713
+         */
2714
+        public function is_preview() {
2715
+            $preview = false;
2716
+            if ( $this->is_divi_preview() ) {
2717
+                $preview = true;
2718
+            } elseif ( $this->is_elementor_preview() ) {
2719
+                $preview = true;
2720
+            } elseif ( $this->is_beaver_preview() ) {
2721
+                $preview = true;
2722
+            } elseif ( $this->is_siteorigin_preview() ) {
2723
+                $preview = true;
2724
+            } elseif ( $this->is_cornerstone_preview() ) {
2725
+                $preview = true;
2726
+            } elseif ( $this->is_fusion_preview() ) {
2727
+                $preview = true;
2728
+            } elseif ( $this->is_oxygen_preview() ) {
2729
+                $preview = true;
2730
+            } elseif( $this->is_block_content_call() ) {
2731
+                $preview = true;
2732
+            }
2733
+
2734
+            return $preview;
2735
+        }
2736
+
2737
+        /**
2738
+         * Output the super title.
2739
+         *
2740
+         * @param $args
2741
+         * @param array $instance
2742
+         *
2743
+         * @return string
2744
+         */
2745
+        public function output_title( $args, $instance = array() ) {
2746
+            $output = '';
2747
+            if ( ! empty( $instance['title'] ) ) {
2748
+                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
2749
+                $title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2750
+
2751
+                if(empty($instance['widget_title_tag'])){
2752
+                    $output = $args['before_title'] . $title . $args['after_title'];
2753
+                }else{
2754
+                    $title_tag = esc_attr( $instance['widget_title_tag'] );
2755
+
2756
+                    // classes
2757
+                    $title_classes = array();
2758
+                    $title_classes[] = !empty( $instance['widget_title_size_class'] ) ? sanitize_html_class( $instance['widget_title_size_class'] ) : '';
2759
+                    $title_classes[] = !empty( $instance['widget_title_align_class'] ) ? sanitize_html_class( $instance['widget_title_align_class'] ) : '';
2760
+                    $title_classes[] = !empty( $instance['widget_title_color_class'] ) ? "text-".sanitize_html_class( $instance['widget_title_color_class'] ) : '';
2761
+                    $title_classes[] = !empty( $instance['widget_title_border_class'] ) ? sanitize_html_class( $instance['widget_title_border_class'] ) : '';
2762
+                    $title_classes[] = !empty( $instance['widget_title_border_color_class'] ) ? "border-".sanitize_html_class( $instance['widget_title_border_color_class'] ) : '';
2763
+                    $title_classes[] = !empty( $instance['widget_title_mt_class'] ) ? "mt-".absint( $instance['widget_title_mt_class'] ) : '';
2764
+                    $title_classes[] = !empty( $instance['widget_title_mr_class'] ) ? "mr-".absint( $instance['widget_title_mr_class'] ) : '';
2765
+                    $title_classes[] = !empty( $instance['widget_title_mb_class'] ) ? "mb-".absint( $instance['widget_title_mb_class'] ) : '';
2766
+                    $title_classes[] = !empty( $instance['widget_title_ml_class'] ) ? "ml-".absint( $instance['widget_title_ml_class'] ) : '';
2767
+                    $title_classes[] = !empty( $instance['widget_title_pt_class'] ) ? "pt-".absint( $instance['widget_title_pt_class'] ) : '';
2768
+                    $title_classes[] = !empty( $instance['widget_title_pr_class'] ) ? "pr-".absint( $instance['widget_title_pr_class'] ) : '';
2769
+                    $title_classes[] = !empty( $instance['widget_title_pb_class'] ) ? "pb-".absint( $instance['widget_title_pb_class'] ) : '';
2770
+                    $title_classes[] = !empty( $instance['widget_title_pl_class'] ) ? "pl-".absint( $instance['widget_title_pl_class'] ) : '';
2771
+
2772
+                    $class = !empty( $title_classes ) ? implode(" ",$title_classes) : '';
2773
+                    $output = "<$title_tag class='$class' >$title</$title_tag>";
2774
+                }
2775
+
2776
+            }
2777
+
2778
+            return $output;
2779
+        }
2780
+
2781
+        /**
2782
+         * Outputs the options form inputs for the widget.
2783
+         *
2784
+         * @param array $instance The widget options.
2785
+         */
2786
+        public function form( $instance ) {
2787
+
2788
+            // set widget instance
2789
+            $this->instance = $instance;
2790
+
2791
+            // set it as a SD widget
2792
+            echo $this->widget_advanced_toggle();
2793
+
2794
+            echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
2795
+            $arguments_raw = $this->get_arguments();
2796
+
2797
+            if ( is_array( $arguments_raw ) ) {
2798
+
2799
+                $arguments = $this->group_arguments( $arguments_raw );
2800
+
2801
+                // Do we have sections?
2802
+                $has_sections = $arguments == $arguments_raw ? false : true;
2803
+
2804
+
2805
+                if ( $has_sections ) {
2806
+                    $panel_count = 0;
2807
+                    foreach ( $arguments as $key => $args ) {
2808
+
2809
+                        ?>
2810 2810
 						<script>
2811 2811
 							//							jQuery(this).find("i").toggleClass("fas fa-chevron-up fas fa-chevron-down");jQuery(this).next().toggle();
2812 2812
 						</script>
2813 2813
 						<?php
2814 2814
 
2815
-						$hide       = $panel_count ? ' style="display:none;" ' : '';
2816
-						$icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down';
2817
-						echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes( $key ) . "'>" . esc_attr( $key ) . " <i style='float:right;' class='" . $icon_class . "'></i></button>";
2818
-						echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>";
2815
+                        $hide       = $panel_count ? ' style="display:none;" ' : '';
2816
+                        $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down';
2817
+                        echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes( $key ) . "'>" . esc_attr( $key ) . " <i style='float:right;' class='" . $icon_class . "'></i></button>";
2818
+                        echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>";
2819 2819
 
2820
-						foreach ( $args as $k => $a ) {
2820
+                        foreach ( $args as $k => $a ) {
2821 2821
 
2822
-							$this->widget_inputs_row_start($k, $a);
2823
-							$this->widget_inputs( $a, $instance );
2824
-							$this->widget_inputs_row_end($k, $a);
2822
+                            $this->widget_inputs_row_start($k, $a);
2823
+                            $this->widget_inputs( $a, $instance );
2824
+                            $this->widget_inputs_row_end($k, $a);
2825 2825
 
2826
-						}
2826
+                        }
2827 2827
 
2828
-						echo "</div>";
2828
+                        echo "</div>";
2829 2829
 
2830
-						$panel_count ++;
2830
+                        $panel_count ++;
2831 2831
 
2832
-					}
2833
-				} else {
2834
-					foreach ( $arguments as $key => $args ) {
2835
-						$this->widget_inputs_row_start($key, $args);
2836
-						$this->widget_inputs( $args, $instance );
2837
-						$this->widget_inputs_row_end($key, $args);
2838
-					}
2839
-				}
2832
+                    }
2833
+                } else {
2834
+                    foreach ( $arguments as $key => $args ) {
2835
+                        $this->widget_inputs_row_start($key, $args);
2836
+                        $this->widget_inputs( $args, $instance );
2837
+                        $this->widget_inputs_row_end($key, $args);
2838
+                    }
2839
+                }
2840 2840
 
2841
-			}
2842
-		}
2841
+            }
2842
+        }
2843 2843
 
2844
-		public function widget_inputs_row_start($key, $args){
2845
-			if(!empty($args['row'])){
2846
-				// maybe open
2847
-				if(!empty($args['row']['open'])){
2848
-					?>
2844
+        public function widget_inputs_row_start($key, $args){
2845
+            if(!empty($args['row'])){
2846
+                // maybe open
2847
+                if(!empty($args['row']['open'])){
2848
+                    ?>
2849 2849
 					<div class='bsui sd-argument ' data-argument='<?php echo esc_attr( $args['row']['key'] ); ?>' data-element_require='<?php if ( !empty($args['row']['element_require'])) {
2850
-						echo $this->convert_element_require( $args['row']['element_require'] );
2851
-					} ?>'>
2850
+                        echo $this->convert_element_require( $args['row']['element_require'] );
2851
+                    } ?>'>
2852 2852
 					<?php if(!empty($args['row']['title'])){ ?>
2853 2853
 					<label class="mb-0 "><?php echo esc_attr( $args['row']['title'] ); ?><?php echo $this->widget_field_desc( $args['row'] ); ?></label>
2854 2854
 					<?php }?>
2855 2855
 					<div class='row <?php if(!empty($args['row']['class'])){ echo esc_attr($args['row']['class']);} ?>'>
2856 2856
 					<div class='col pr-2'>
2857 2857
 					<?php
2858
-				}elseif(!empty($args['row']['close'])){
2859
-					echo "<div class='col pl-0'>";
2860
-				}else{
2861
-					echo "<div class='col pl-0 pr-2'>";
2862
-				}
2863
-			}
2864
-		}
2865
-
2866
-		public function widget_inputs_row_end($key, $args){
2867
-
2868
-			if(!empty($args['row'])){
2869
-				// maybe close
2870
-				if(!empty($args['row']['close'])){
2871
-					echo "</div></div>";
2872
-				}
2873
-
2874
-				echo "</div>";
2875
-			}
2876
-		}
2877
-
2878
-		/**
2879
-		 * Get the hidden input that when added makes the advanced button show on widget settings.
2880
-		 *
2881
-		 * @return string
2882
-		 */
2883
-		public function widget_advanced_toggle() {
2884
-
2885
-			$output = '';
2886
-			if ( $this->block_show_advanced() ) {
2887
-				$val = 1;
2888
-			} else {
2889
-				$val = 0;
2890
-			}
2891
-
2892
-			$output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
2893
-
2894
-			return $output;
2895
-		}
2896
-
2897
-		/**
2898
-		 * Convert require element.
2899
-		 *
2900
-		 * @since 1.0.0
2901
-		 *
2902
-		 * @param string $input Input element.
2903
-		 *
2904
-		 * @return string $output
2905
-		 */
2906
-		public function convert_element_require( $input ) {
2907
-
2908
-			$input = str_replace( "'", '"', $input );// we only want double quotes
2909
-
2910
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
2911
-				"jQuery(form).find('[data-argument=\"",
2912
-				"\"]').find('input,select,textarea').val()"
2913
-			), $input ) );
2914
-
2915
-			return $output;
2916
-		}
2917
-
2918
-		/**
2919
-		 * Builds the inputs for the widget options.
2920
-		 *
2921
-		 * @param $args
2922
-		 * @param $instance
2923
-		 */
2924
-		public function widget_inputs( $args, $instance ) {
2925
-
2926
-			$class             = "";
2927
-			$element_require   = "";
2928
-			$custom_attributes = "";
2929
-
2930
-			// get value
2931
-			if ( isset( $instance[ $args['name'] ] ) ) {
2932
-				$value = $instance[ $args['name'] ];
2933
-			} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
2934
-				$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
2935
-			} else {
2936
-				$value = '';
2937
-			}
2938
-
2939
-			// get placeholder
2940
-			if ( ! empty( $args['placeholder'] ) ) {
2941
-				$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
2942
-			} else {
2943
-				$placeholder = '';
2944
-			}
2945
-
2946
-			// get if advanced
2947
-			if ( isset( $args['advanced'] ) && $args['advanced'] ) {
2948
-				$class .= " sd-advanced-setting ";
2949
-			}
2950
-
2951
-			// element_require
2952
-			if ( isset( $args['element_require'] ) && $args['element_require'] ) {
2953
-				$element_require = $args['element_require'];
2954
-			}
2955
-
2956
-			// custom_attributes
2957
-			if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
2958
-				$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
2959
-			}
2960
-
2961
-
2962
-			// before wrapper
2963
-			?>
2858
+                }elseif(!empty($args['row']['close'])){
2859
+                    echo "<div class='col pl-0'>";
2860
+                }else{
2861
+                    echo "<div class='col pl-0 pr-2'>";
2862
+                }
2863
+            }
2864
+        }
2865
+
2866
+        public function widget_inputs_row_end($key, $args){
2867
+
2868
+            if(!empty($args['row'])){
2869
+                // maybe close
2870
+                if(!empty($args['row']['close'])){
2871
+                    echo "</div></div>";
2872
+                }
2873
+
2874
+                echo "</div>";
2875
+            }
2876
+        }
2877
+
2878
+        /**
2879
+         * Get the hidden input that when added makes the advanced button show on widget settings.
2880
+         *
2881
+         * @return string
2882
+         */
2883
+        public function widget_advanced_toggle() {
2884
+
2885
+            $output = '';
2886
+            if ( $this->block_show_advanced() ) {
2887
+                $val = 1;
2888
+            } else {
2889
+                $val = 0;
2890
+            }
2891
+
2892
+            $output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
2893
+
2894
+            return $output;
2895
+        }
2896
+
2897
+        /**
2898
+         * Convert require element.
2899
+         *
2900
+         * @since 1.0.0
2901
+         *
2902
+         * @param string $input Input element.
2903
+         *
2904
+         * @return string $output
2905
+         */
2906
+        public function convert_element_require( $input ) {
2907
+
2908
+            $input = str_replace( "'", '"', $input );// we only want double quotes
2909
+
2910
+            $output = esc_attr( str_replace( array( "[%", "%]" ), array(
2911
+                "jQuery(form).find('[data-argument=\"",
2912
+                "\"]').find('input,select,textarea').val()"
2913
+            ), $input ) );
2914
+
2915
+            return $output;
2916
+        }
2917
+
2918
+        /**
2919
+         * Builds the inputs for the widget options.
2920
+         *
2921
+         * @param $args
2922
+         * @param $instance
2923
+         */
2924
+        public function widget_inputs( $args, $instance ) {
2925
+
2926
+            $class             = "";
2927
+            $element_require   = "";
2928
+            $custom_attributes = "";
2929
+
2930
+            // get value
2931
+            if ( isset( $instance[ $args['name'] ] ) ) {
2932
+                $value = $instance[ $args['name'] ];
2933
+            } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
2934
+                $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
2935
+            } else {
2936
+                $value = '';
2937
+            }
2938
+
2939
+            // get placeholder
2940
+            if ( ! empty( $args['placeholder'] ) ) {
2941
+                $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
2942
+            } else {
2943
+                $placeholder = '';
2944
+            }
2945
+
2946
+            // get if advanced
2947
+            if ( isset( $args['advanced'] ) && $args['advanced'] ) {
2948
+                $class .= " sd-advanced-setting ";
2949
+            }
2950
+
2951
+            // element_require
2952
+            if ( isset( $args['element_require'] ) && $args['element_require'] ) {
2953
+                $element_require = $args['element_require'];
2954
+            }
2955
+
2956
+            // custom_attributes
2957
+            if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
2958
+                $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
2959
+            }
2960
+
2961
+
2962
+            // before wrapper
2963
+            ?>
2964 2964
 			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
2965 2965
 			data-argument='<?php echo esc_attr( $args['name'] ); ?>'
2966 2966
 			data-element_require='<?php if ( $element_require ) {
2967
-				echo $this->convert_element_require( $element_require );
2968
-			} ?>'
2967
+                echo $this->convert_element_require( $element_require );
2968
+            } ?>'
2969 2969
 			>
2970 2970
 			<?php
2971 2971
 
2972 2972
 
2973
-			switch ( $args['type'] ) {
2974
-				//array('text','password','number','email','tel','url','color')
2975
-				case "text":
2976
-				case "password":
2977
-				case "number":
2978
-				case "email":
2979
-				case "tel":
2980
-				case "url":
2981
-				case "color":
2982
-					?>
2973
+            switch ( $args['type'] ) {
2974
+                //array('text','password','number','email','tel','url','color')
2975
+                case "text":
2976
+                case "password":
2977
+                case "number":
2978
+                case "email":
2979
+                case "tel":
2980
+                case "url":
2981
+                case "color":
2982
+                    ?>
2983 2983
 					<label
2984 2984
 						for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args );?><?php echo $this->widget_field_desc( $args ); ?></label>
2985 2985
 					<input <?php echo $placeholder; ?> class="widefat"
@@ -2990,47 +2990,47 @@  discard block
 block discarded – undo
2990 2990
 						                               value="<?php echo esc_attr( $value ); ?>">
2991 2991
 					<?php
2992 2992
 
2993
-					break;
2994
-				case "select":
2995
-					$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
2996
-					if ( $multiple ) {
2997
-						if ( empty( $value ) ) {
2998
-							$value = array();
2999
-						}
3000
-					}
3001
-					?>
2993
+                    break;
2994
+                case "select":
2995
+                    $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
2996
+                    if ( $multiple ) {
2997
+                        if ( empty( $value ) ) {
2998
+                            $value = array();
2999
+                        }
3000
+                    }
3001
+                    ?>
3002 3002
 					<label
3003 3003
 						for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args ); ?><?php echo $this->widget_field_desc( $args ); ?></label>
3004 3004
 					<select <?php echo $placeholder; ?> class="widefat"
3005 3005
 						<?php echo $custom_attributes; ?>
3006 3006
 						                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
3007 3007
 						                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) );
3008
-						                                if ( $multiple ) {
3009
-							                                echo "[]";
3010
-						                                } ?>"
3008
+                                                        if ( $multiple ) {
3009
+                                                            echo "[]";
3010
+                                                        } ?>"
3011 3011
 						<?php if ( $multiple ) {
3012
-							echo "multiple";
3013
-						} //@todo not implemented yet due to gutenberg not supporting it
3014
-						?>
3012
+                            echo "multiple";
3013
+                        } //@todo not implemented yet due to gutenberg not supporting it
3014
+                        ?>
3015 3015
 					>
3016 3016
 						<?php
3017 3017
 
3018
-						if ( ! empty( $args['options'] ) ) {
3019
-							foreach ( $args['options'] as $val => $label ) {
3020
-								if ( $multiple ) {
3021
-									$selected = in_array( $val, $value ) ? 'selected="selected"' : '';
3022
-								} else {
3023
-									$selected = selected( $value, $val, false );
3024
-								}
3025
-								echo "<option value='$val' " . $selected . ">$label</option>";
3026
-							}
3027
-						}
3028
-						?>
3018
+                        if ( ! empty( $args['options'] ) ) {
3019
+                            foreach ( $args['options'] as $val => $label ) {
3020
+                                if ( $multiple ) {
3021
+                                    $selected = in_array( $val, $value ) ? 'selected="selected"' : '';
3022
+                                } else {
3023
+                                    $selected = selected( $value, $val, false );
3024
+                                }
3025
+                                echo "<option value='$val' " . $selected . ">$label</option>";
3026
+                            }
3027
+                        }
3028
+                        ?>
3029 3029
 					</select>
3030 3030
 					<?php
3031
-					break;
3032
-				case "checkbox":
3033
-					?>
3031
+                    break;
3032
+                case "checkbox":
3033
+                    ?>
3034 3034
 					<input <?php echo $placeholder; ?>
3035 3035
 						<?php checked( 1, $value, true ) ?>
3036 3036
 						<?php echo $custom_attributes; ?>
@@ -3040,9 +3040,9 @@  discard block
 block discarded – undo
3040 3040
 					<label
3041 3041
 						for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args );?><?php echo $this->widget_field_desc( $args ); ?></label>
3042 3042
 					<?php
3043
-					break;
3044
-				case "textarea":
3045
-					?>
3043
+                    break;
3044
+                case "textarea":
3045
+                    ?>
3046 3046
 					<label
3047 3047
 						for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo $this->widget_field_title( $args ); ?><?php echo $this->widget_field_desc( $args ); ?></label>
3048 3048
 					<textarea <?php echo $placeholder; ?> class="widefat"
@@ -3052,280 +3052,280 @@  discard block
 block discarded – undo
3052 3052
 					><?php echo esc_attr( $value ); ?></textarea>
3053 3053
 					<?php
3054 3054
 
3055
-					break;
3056
-				case "hidden":
3057
-					?>
3055
+                    break;
3056
+                case "hidden":
3057
+                    ?>
3058 3058
 					<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
3059 3059
 					       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
3060 3060
 					       value="<?php echo esc_attr( $value ); ?>">
3061 3061
 					<?php
3062
-					break;
3063
-				default:
3064
-					echo "No input type found!"; // @todo we need to add more input types.
3065
-			}
3062
+                    break;
3063
+                default:
3064
+                    echo "No input type found!"; // @todo we need to add more input types.
3065
+            }
3066 3066
 
3067
-			// after wrapper
3068
-			?>
3067
+            // after wrapper
3068
+            ?>
3069 3069
 			</p>
3070 3070
 			<?php
3071 3071
 
3072 3072
 
3073
-		}
3074
-
3075
-		public function get_widget_icon($icon = 'box-top', $title = ''){
3076
-			if($icon=='box-top'){
3077
-				return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1.048" height="9.017" fill="#555D66"></rect><rect x="16.265" y="5.498" width="1.023" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.186" width="8.964" height="2.482" fill="#272B2F"></rect><rect x="5.487" y="16.261" width="9.026" height="1.037" fill="#555D66"></rect></svg>';
3078
-			}elseif($icon=='box-right'){
3079
-				return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1.046" height="9.017" fill="#555D66"></rect><rect x="15.244" y="5.498" width="2.518" height="9.003" fill="#272B2F"></rect><rect x="5.518" y="2.719" width="8.964" height="0.954" fill="#555D66"></rect><rect x="5.487" y="16.308" width="9.026" height="0.99" fill="#555D66"></rect></svg>';
3080
-			}elseif($icon=='box-bottom'){
3081
-				return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1" height="9.017" fill="#555D66"></rect><rect x="16.261" y="5.498" width="1.027" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.719" width="8.964" height="0.968" fill="#555D66"></rect><rect x="5.487" y="15.28" width="9.026" height="2.499" fill="#272B2F"></rect></svg>';
3082
-			}elseif($icon=='box-left'){
3083
-				return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.202" y="5.492" width="2.503" height="9.017" fill="#272B2F"></rect><rect x="16.276" y="5.498" width="1.012" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.719" width="8.964" height="0.966" fill="#555D66"></rect><rect x="5.487" y="16.303" width="9.026" height="0.995" fill="#555D66"></rect></svg>';
3084
-			}
3085
-		}
3086
-
3087
-		/**
3088
-		 * Get the widget input description html.
3089
-		 *
3090
-		 * @param $args
3091
-		 *
3092
-		 * @return string
3093
-		 * @todo, need to make its own tooltip script
3094
-		 */
3095
-		public function widget_field_desc( $args ) {
3096
-
3097
-			$description = '';
3098
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
3099
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
3100
-					$description = $this->desc_tip( $args['desc'] );
3101
-				} else {
3102
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
3103
-				}
3104
-			}
3105
-
3106
-			return $description;
3107
-		}
3108
-
3109
-		/**
3110
-		 * Get the widget input title html.
3111
-		 *
3112
-		 * @param $args
3113
-		 *
3114
-		 * @return string
3115
-		 */
3116
-		public function widget_field_title( $args ) {
3117
-
3118
-			$title = '';
3119
-			if ( isset( $args['title'] ) && $args['title'] ) {
3120
-				if ( isset( $args['icon'] ) && $args['icon'] ) {
3121
-					$title = self::get_widget_icon( $args['icon'], $args['title']  );
3122
-				} else {
3123
-					$title = esc_attr($args['title']);
3124
-				}
3125
-			}
3126
-
3127
-			return $title;
3128
-		}
3129
-
3130
-		/**
3131
-		 * Get the tool tip html.
3132
-		 *
3133
-		 * @param $tip
3134
-		 * @param bool $allow_html
3135
-		 *
3136
-		 * @return string
3137
-		 */
3138
-		function desc_tip( $tip, $allow_html = false ) {
3139
-			if ( $allow_html ) {
3140
-				$tip = $this->sanitize_tooltip( $tip );
3141
-			} else {
3142
-				$tip = esc_attr( $tip );
3143
-			}
3144
-
3145
-			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
3146
-		}
3147
-
3148
-		/**
3149
-		 * Sanitize a string destined to be a tooltip.
3150
-		 *
3151
-		 * @param string $var
3152
-		 *
3153
-		 * @return string
3154
-		 */
3155
-		public function sanitize_tooltip( $var ) {
3156
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
3157
-				'br'     => array(),
3158
-				'em'     => array(),
3159
-				'strong' => array(),
3160
-				'small'  => array(),
3161
-				'span'   => array(),
3162
-				'ul'     => array(),
3163
-				'li'     => array(),
3164
-				'ol'     => array(),
3165
-				'p'      => array(),
3166
-			) ) );
3167
-		}
3168
-
3169
-		/**
3170
-		 * Processing widget options on save
3171
-		 *
3172
-		 * @param array $new_instance The new options
3173
-		 * @param array $old_instance The previous options
3174
-		 *
3175
-		 * @return array
3176
-		 * @todo we should add some sanitation here.
3177
-		 */
3178
-		public function update( $new_instance, $old_instance ) {
3179
-
3180
-			//save the widget
3181
-			$instance = array_merge( (array) $old_instance, (array) $new_instance );
3182
-
3183
-			// set widget instance
3184
-			$this->instance = $instance;
3185
-
3186
-			if ( empty( $this->arguments ) ) {
3187
-				$this->get_arguments();
3188
-			}
3189
-
3190
-			// check for checkboxes
3191
-			if ( ! empty( $this->arguments ) ) {
3192
-				foreach ( $this->arguments as $argument ) {
3193
-					if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
3194
-						$instance[ $argument['name'] ] = '0';
3195
-					}
3196
-				}
3197
-			}
3198
-
3199
-			return $instance;
3200
-		}
3201
-
3202
-		/**
3203
-		 * Checks if the current call is a ajax call to get the block content.
3204
-		 *
3205
-		 * This can be used in your widget to return different content as the block content.
3206
-		 *
3207
-		 * @since 1.0.3
3208
-		 * @return bool
3209
-		 */
3210
-		public function is_block_content_call() {
3211
-			$result = false;
3212
-			if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
3213
-				$result = true;
3214
-			}
3215
-
3216
-			return $result;
3217
-		}
3218
-
3219
-		/**
3220
-		 * Get an instance hash that will be unique to the type and settings.
3221
-		 *
3222
-		 * @since 1.0.20
3223
-		 * @return string
3224
-		 */
3225
-		public function get_instance_hash(){
3226
-			$instance_string = $this->base_id.serialize($this->instance);
3227
-			return hash('crc32b',$instance_string);
3228
-		}
3229
-
3230
-		/**
3231
-		 * Generate and return inline styles from CSS rules that will match the unique class of the instance.
3232
-		 *
3233
-		 * @param array $rules
3234
-		 *
3235
-		 * @since 1.0.20
3236
-		 * @return string
3237
-		 */
3238
-		public function get_instance_style($rules = array()){
3239
-			$css = '';
3240
-
3241
-			if(!empty($rules)){
3242
-				$rules = array_unique($rules);
3243
-				$instance_hash = $this->get_instance_hash();
3244
-				$css .= "<style>";
3245
-				foreach($rules as $rule){
3246
-					$css .= ".sdel-$instance_hash $rule";
3247
-				}
3248
-				$css .= "</style>";
3249
-			}
3250
-
3251
-			return $css;
3252
-		}
3253
-
3254
-		/**
3255
-		 * Encode shortcodes tags.
3256
-		 *
3257
-		 * @since 1.0.28
3258
-		 *
3259
-		 * @param string $content Content to search for shortcode tags.
3260
-		 * @return string Content with shortcode tags removed.
3261
-		 */
3262
-		public function encode_shortcodes( $content ) {
3263
-			// Avoids existing encoded tags.
3264
-			$trans   = array(
3265
-				'&#91;' => '&#091;',
3266
-				'&#93;' => '&#093;',
3267
-				'&amp;#91;' => '&#091;',
3268
-				'&amp;#93;' => '&#093;',
3269
-				'&lt;' => '&0lt;',
3270
-				'&gt;' => '&0gt;',
3271
-				'&amp;lt;' => '&0lt;',
3272
-				'&amp;gt;' => '&0gt;',
3273
-			);
3274
-
3275
-			$content = strtr( $content, $trans );
3276
-
3277
-			$trans   = array(
3278
-				'[' => '&#91;',
3279
-				']' => '&#93;',
3280
-				'<' => '&lt;',
3281
-				'>' => '&gt;',
3282
-				'"' => '&quot;',
3283
-				"'" => '&apos;',
3284
-			);
3285
-
3286
-			$content = strtr( $content, $trans );
3287
-
3288
-			return $content;
3289
-		}
3290
-
3291
-		/**
3292
-		 * Remove encoded shortcod tags.
3293
-		 *
3294
-		 * @since 1.0.28
3295
-		 *
3296
-		 * @param string $content Content to search for shortcode tags.
3297
-		 * @return string Content with decoded shortcode tags.
3298
-		 */
3299
-		public function decode_shortcodes( $content ) {
3300
-			$trans   = array(
3301
-				'&#91;' => '[',
3302
-				'&#93;' => ']',
3303
-				'&amp;#91;' => '[',
3304
-				'&amp;#93;' => ']',
3305
-				'&lt;' => '<',
3306
-				'&gt;' => '>',
3307
-				'&amp;lt;' => '<',
3308
-				'&amp;gt;' => '>',
3309
-				'&quot;' => '"',
3310
-				'&apos;' => "'",
3311
-			);
3312
-
3313
-			$content = strtr( $content, $trans );
3314
-
3315
-			$trans   = array(
3316
-				'&#091;' => '&#91;',
3317
-				'&#093;' => '&#93;',
3318
-				'&amp;#091;' => '&#91;',
3319
-				'&amp;#093;' => '&#93;',
3320
-				'&0lt;' => '&lt;',
3321
-				'&0gt;' => '&gt;',
3322
-				'&amp;0lt;' => '&lt;',
3323
-				'&amp;0gt;' => '&gt;',
3324
-			);
3325
-
3326
-			$content = strtr( $content, $trans );
3327
-
3328
-			return $content;
3329
-		}
3330
-	}
3073
+        }
3074
+
3075
+        public function get_widget_icon($icon = 'box-top', $title = ''){
3076
+            if($icon=='box-top'){
3077
+                return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1.048" height="9.017" fill="#555D66"></rect><rect x="16.265" y="5.498" width="1.023" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.186" width="8.964" height="2.482" fill="#272B2F"></rect><rect x="5.487" y="16.261" width="9.026" height="1.037" fill="#555D66"></rect></svg>';
3078
+            }elseif($icon=='box-right'){
3079
+                return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1.046" height="9.017" fill="#555D66"></rect><rect x="15.244" y="5.498" width="2.518" height="9.003" fill="#272B2F"></rect><rect x="5.518" y="2.719" width="8.964" height="0.954" fill="#555D66"></rect><rect x="5.487" y="16.308" width="9.026" height="0.99" fill="#555D66"></rect></svg>';
3080
+            }elseif($icon=='box-bottom'){
3081
+                return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.714" y="5.492" width="1" height="9.017" fill="#555D66"></rect><rect x="16.261" y="5.498" width="1.027" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.719" width="8.964" height="0.968" fill="#555D66"></rect><rect x="5.487" y="15.28" width="9.026" height="2.499" fill="#272B2F"></rect></svg>';
3082
+            }elseif($icon=='box-left'){
3083
+                return '<svg title="'.esc_attr($title).'" width="20px" height="20px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414" role="img" aria-hidden="true" focusable="false"><rect x="2.202" y="5.492" width="2.503" height="9.017" fill="#272B2F"></rect><rect x="16.276" y="5.498" width="1.012" height="9.003" fill="#555D66"></rect><rect x="5.518" y="2.719" width="8.964" height="0.966" fill="#555D66"></rect><rect x="5.487" y="16.303" width="9.026" height="0.995" fill="#555D66"></rect></svg>';
3084
+            }
3085
+        }
3086
+
3087
+        /**
3088
+         * Get the widget input description html.
3089
+         *
3090
+         * @param $args
3091
+         *
3092
+         * @return string
3093
+         * @todo, need to make its own tooltip script
3094
+         */
3095
+        public function widget_field_desc( $args ) {
3096
+
3097
+            $description = '';
3098
+            if ( isset( $args['desc'] ) && $args['desc'] ) {
3099
+                if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
3100
+                    $description = $this->desc_tip( $args['desc'] );
3101
+                } else {
3102
+                    $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
3103
+                }
3104
+            }
3105
+
3106
+            return $description;
3107
+        }
3108
+
3109
+        /**
3110
+         * Get the widget input title html.
3111
+         *
3112
+         * @param $args
3113
+         *
3114
+         * @return string
3115
+         */
3116
+        public function widget_field_title( $args ) {
3117
+
3118
+            $title = '';
3119
+            if ( isset( $args['title'] ) && $args['title'] ) {
3120
+                if ( isset( $args['icon'] ) && $args['icon'] ) {
3121
+                    $title = self::get_widget_icon( $args['icon'], $args['title']  );
3122
+                } else {
3123
+                    $title = esc_attr($args['title']);
3124
+                }
3125
+            }
3126
+
3127
+            return $title;
3128
+        }
3129
+
3130
+        /**
3131
+         * Get the tool tip html.
3132
+         *
3133
+         * @param $tip
3134
+         * @param bool $allow_html
3135
+         *
3136
+         * @return string
3137
+         */
3138
+        function desc_tip( $tip, $allow_html = false ) {
3139
+            if ( $allow_html ) {
3140
+                $tip = $this->sanitize_tooltip( $tip );
3141
+            } else {
3142
+                $tip = esc_attr( $tip );
3143
+            }
3144
+
3145
+            return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
3146
+        }
3147
+
3148
+        /**
3149
+         * Sanitize a string destined to be a tooltip.
3150
+         *
3151
+         * @param string $var
3152
+         *
3153
+         * @return string
3154
+         */
3155
+        public function sanitize_tooltip( $var ) {
3156
+            return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
3157
+                'br'     => array(),
3158
+                'em'     => array(),
3159
+                'strong' => array(),
3160
+                'small'  => array(),
3161
+                'span'   => array(),
3162
+                'ul'     => array(),
3163
+                'li'     => array(),
3164
+                'ol'     => array(),
3165
+                'p'      => array(),
3166
+            ) ) );
3167
+        }
3168
+
3169
+        /**
3170
+         * Processing widget options on save
3171
+         *
3172
+         * @param array $new_instance The new options
3173
+         * @param array $old_instance The previous options
3174
+         *
3175
+         * @return array
3176
+         * @todo we should add some sanitation here.
3177
+         */
3178
+        public function update( $new_instance, $old_instance ) {
3179
+
3180
+            //save the widget
3181
+            $instance = array_merge( (array) $old_instance, (array) $new_instance );
3182
+
3183
+            // set widget instance
3184
+            $this->instance = $instance;
3185
+
3186
+            if ( empty( $this->arguments ) ) {
3187
+                $this->get_arguments();
3188
+            }
3189
+
3190
+            // check for checkboxes
3191
+            if ( ! empty( $this->arguments ) ) {
3192
+                foreach ( $this->arguments as $argument ) {
3193
+                    if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
3194
+                        $instance[ $argument['name'] ] = '0';
3195
+                    }
3196
+                }
3197
+            }
3198
+
3199
+            return $instance;
3200
+        }
3201
+
3202
+        /**
3203
+         * Checks if the current call is a ajax call to get the block content.
3204
+         *
3205
+         * This can be used in your widget to return different content as the block content.
3206
+         *
3207
+         * @since 1.0.3
3208
+         * @return bool
3209
+         */
3210
+        public function is_block_content_call() {
3211
+            $result = false;
3212
+            if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
3213
+                $result = true;
3214
+            }
3215
+
3216
+            return $result;
3217
+        }
3218
+
3219
+        /**
3220
+         * Get an instance hash that will be unique to the type and settings.
3221
+         *
3222
+         * @since 1.0.20
3223
+         * @return string
3224
+         */
3225
+        public function get_instance_hash(){
3226
+            $instance_string = $this->base_id.serialize($this->instance);
3227
+            return hash('crc32b',$instance_string);
3228
+        }
3229
+
3230
+        /**
3231
+         * Generate and return inline styles from CSS rules that will match the unique class of the instance.
3232
+         *
3233
+         * @param array $rules
3234
+         *
3235
+         * @since 1.0.20
3236
+         * @return string
3237
+         */
3238
+        public function get_instance_style($rules = array()){
3239
+            $css = '';
3240
+
3241
+            if(!empty($rules)){
3242
+                $rules = array_unique($rules);
3243
+                $instance_hash = $this->get_instance_hash();
3244
+                $css .= "<style>";
3245
+                foreach($rules as $rule){
3246
+                    $css .= ".sdel-$instance_hash $rule";
3247
+                }
3248
+                $css .= "</style>";
3249
+            }
3250
+
3251
+            return $css;
3252
+        }
3253
+
3254
+        /**
3255
+         * Encode shortcodes tags.
3256
+         *
3257
+         * @since 1.0.28
3258
+         *
3259
+         * @param string $content Content to search for shortcode tags.
3260
+         * @return string Content with shortcode tags removed.
3261
+         */
3262
+        public function encode_shortcodes( $content ) {
3263
+            // Avoids existing encoded tags.
3264
+            $trans   = array(
3265
+                '&#91;' => '&#091;',
3266
+                '&#93;' => '&#093;',
3267
+                '&amp;#91;' => '&#091;',
3268
+                '&amp;#93;' => '&#093;',
3269
+                '&lt;' => '&0lt;',
3270
+                '&gt;' => '&0gt;',
3271
+                '&amp;lt;' => '&0lt;',
3272
+                '&amp;gt;' => '&0gt;',
3273
+            );
3274
+
3275
+            $content = strtr( $content, $trans );
3276
+
3277
+            $trans   = array(
3278
+                '[' => '&#91;',
3279
+                ']' => '&#93;',
3280
+                '<' => '&lt;',
3281
+                '>' => '&gt;',
3282
+                '"' => '&quot;',
3283
+                "'" => '&apos;',
3284
+            );
3285
+
3286
+            $content = strtr( $content, $trans );
3287
+
3288
+            return $content;
3289
+        }
3290
+
3291
+        /**
3292
+         * Remove encoded shortcod tags.
3293
+         *
3294
+         * @since 1.0.28
3295
+         *
3296
+         * @param string $content Content to search for shortcode tags.
3297
+         * @return string Content with decoded shortcode tags.
3298
+         */
3299
+        public function decode_shortcodes( $content ) {
3300
+            $trans   = array(
3301
+                '&#91;' => '[',
3302
+                '&#93;' => ']',
3303
+                '&amp;#91;' => '[',
3304
+                '&amp;#93;' => ']',
3305
+                '&lt;' => '<',
3306
+                '&gt;' => '>',
3307
+                '&amp;lt;' => '<',
3308
+                '&amp;gt;' => '>',
3309
+                '&quot;' => '"',
3310
+                '&apos;' => "'",
3311
+            );
3312
+
3313
+            $content = strtr( $content, $trans );
3314
+
3315
+            $trans   = array(
3316
+                '&#091;' => '&#91;',
3317
+                '&#093;' => '&#93;',
3318
+                '&amp;#091;' => '&#91;',
3319
+                '&amp;#093;' => '&#93;',
3320
+                '&0lt;' => '&lt;',
3321
+                '&0gt;' => '&gt;',
3322
+                '&amp;0lt;' => '&lt;',
3323
+                '&amp;0gt;' => '&gt;',
3324
+            );
3325
+
3326
+            $content = strtr( $content, $trans );
3327
+
3328
+            return $content;
3329
+        }
3330
+    }
3331 3331
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-item-details.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Item_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the item.
@@ -270,35 +270,35 @@  discard block
 block discarded – undo
270 270
     }
271 271
 
272 272
     /**
273
-	 * Save meta box data.
274
-	 *
275
-	 * @param int $post_id
276
-	 */
277
-	public static function save( $post_id ) {
273
+     * Save meta box data.
274
+     *
275
+     * @param int $post_id
276
+     */
277
+    public static function save( $post_id ) {
278 278
 
279 279
         // Prepare the item.
280 280
         $item = new WPInv_Item( $post_id );
281 281
 
282 282
         // Load new data.
283 283
         $item->set_props(
284
-			array(
285
-				'price'                => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
-				'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
-				'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
-				'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
-				'is_dynamic_pricing'   => ! empty( $_POST['wpinv_name_your_price'] ),
284
+            array(
285
+                'price'                => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
+                'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
+                'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
+                'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
+                'is_dynamic_pricing'   => ! empty( $_POST['wpinv_name_your_price'] ),
290 290
                 'minimum_price'        => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null,
291
-				'is_recurring'         => ! empty( $_POST['wpinv_is_recurring'] ),
292
-				'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
-				'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
-				'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
-				'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
-				'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
-				'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
-			)
291
+                'is_recurring'         => ! empty( $_POST['wpinv_is_recurring'] ),
292
+                'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
+                'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
+                'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
+                'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
+                'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
+                'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
+            )
299 299
         );
300 300
 
301
-		$item->save();
302
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
-	}
301
+        $item->save();
302
+        do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
+    }
304 304
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-discount-details.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Discount_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the discount.
@@ -396,35 +396,35 @@  discard block
 block discarded – undo
396 396
     }
397 397
 
398 398
     /**
399
-	 * Save meta box data.
400
-	 *
401
-	 * @param int $post_id
402
-	 */
403
-	public static function save( $post_id ) {
399
+     * Save meta box data.
400
+     *
401
+     * @param int $post_id
402
+     */
403
+    public static function save( $post_id ) {
404 404
 
405 405
         // Prepare the discount.
406 406
         $discount = new WPInv_Discount( $post_id );
407 407
 
408 408
         // Load new data.
409 409
         $discount->set_props(
410
-			array(
411
-				'code'                 => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null,
412
-				'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null,
413
-				'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
414
-				'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
415
-				'is_single_use'        => ! empty( $_POST['wpinv_discount_single_use'] ),
410
+            array(
411
+                'code'                 => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null,
412
+                'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null,
413
+                'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
414
+                'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
415
+                'is_single_use'        => ! empty( $_POST['wpinv_discount_single_use'] ),
416 416
                 'type'                 => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null,
417
-				'is_recurring'         => ! empty( $_POST['wpinv_discount_recurring'] ),
418
-				'items'                => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(),
419
-				'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(),
417
+                'is_recurring'         => ! empty( $_POST['wpinv_discount_recurring'] ),
418
+                'items'                => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(),
419
+                'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(),
420 420
                 'required_items'       => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(),
421
-				'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null,
422
-				'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null,
423
-				'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null,
424
-			)
421
+                'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null,
422
+                'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null,
423
+                'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null,
424
+            )
425 425
         );
426 426
 
427
-		$discount->save();
428
-		do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
429
-	}
427
+        $discount->save();
428
+        do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
429
+    }
430 430
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-profile.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -5,110 +5,110 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit; // Exit if accessed directly
8
+    exit; // Exit if accessed directly
9 9
 }
10 10
 
11 11
 if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) :
12 12
 
13
-	/**
14
-	 * GetPaid_Admin_Profile Class.
15
-	 */
16
-	class GetPaid_Admin_Profile {
17
-
18
-		/**
19
-		 * Hook in tabs.
20
-		 */
21
-		public function __construct() {
22
-			add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
-			add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
-
25
-			add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
-			add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
-		}
28
-
29
-		/**
30
-		 * Get Address Fields for the edit user pages.
31
-		 *
32
-		 * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
-		 */
34
-		public function get_customer_meta_fields() {
35
-
36
-			$show_fields = apply_filters(
37
-				'getpaid_customer_meta_fields',
38
-				array(
39
-					'billing'  => array(
40
-						'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
-						'fields' => array(
42
-							'_wpinv_first_name' => array(
43
-								'label'       => __( 'First name', 'invoicing' ),
44
-								'description' => '',
45
-							),
46
-							'_wpinv_last_name'  => array(
47
-								'label'       => __( 'Last name', 'invoicing' ),
48
-								'description' => '',
49
-							),
50
-							'_wpinv_company'    => array(
51
-								'label'       => __( 'Company', 'invoicing' ),
52
-								'description' => '',
53
-							),
54
-							'_wpinv_company_id'    => array(
55
-								'label'       => __( 'Company ID', 'invoicing' ),
56
-								'description' => '',
57
-							),
58
-							'_wpinv_address'  => array(
59
-								'label'       => __( 'Address', 'invoicing' ),
60
-								'description' => '',
61
-							),
62
-							'_wpinv_city'       => array(
63
-								'label'       => __( 'City', 'invoicing' ),
64
-								'description' => '',
65
-							),
66
-							'_wpinv_zip'   => array(
67
-								'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
-								'description' => '',
69
-							),
70
-							'_wpinv_country'    => array(
71
-								'label'       => __( 'Country / Region', 'invoicing' ),
72
-								'description' => '',
73
-								'class'       => 'getpaid_js_field-country',
74
-								'type'        => 'select',
75
-								'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
-							),
77
-							'_wpinv_state'      => array(
78
-								'label'       => __( 'State / County', 'invoicing' ),
79
-								'description' => __( 'State / County or state code', 'invoicing' ),
80
-								'class'       => 'getpaid_js_field-state regular-text',
81
-							),
82
-							'_wpinv_phone'      => array(
83
-								'label'       => __( 'Phone', 'invoicing' ),
84
-								'description' => '',
85
-							),
86
-							'_wpinv_vat_number'      => array(
87
-								'label'       => __( 'VAT Number', 'invoicing' ),
88
-								'description' => '',
89
-							),
90
-						),
91
-					),
92
-				)
93
-			);
94
-			return $show_fields;
95
-		}
96
-
97
-		/**
98
-		 * Show Address Fields on edit user pages.
99
-		 *
100
-		 * @param WP_User $user
101
-		 */
102
-		public function add_customer_meta_fields( $user ) {
103
-
104
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
-				return;
106
-			}
107
-
108
-			$show_fields = $this->get_customer_meta_fields();
109
-
110
-			foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
-				?>
13
+    /**
14
+     * GetPaid_Admin_Profile Class.
15
+     */
16
+    class GetPaid_Admin_Profile {
17
+
18
+        /**
19
+         * Hook in tabs.
20
+         */
21
+        public function __construct() {
22
+            add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
+            add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
+
25
+            add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
+            add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
+        }
28
+
29
+        /**
30
+         * Get Address Fields for the edit user pages.
31
+         *
32
+         * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
+         */
34
+        public function get_customer_meta_fields() {
35
+
36
+            $show_fields = apply_filters(
37
+                'getpaid_customer_meta_fields',
38
+                array(
39
+                    'billing'  => array(
40
+                        'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
+                        'fields' => array(
42
+                            '_wpinv_first_name' => array(
43
+                                'label'       => __( 'First name', 'invoicing' ),
44
+                                'description' => '',
45
+                            ),
46
+                            '_wpinv_last_name'  => array(
47
+                                'label'       => __( 'Last name', 'invoicing' ),
48
+                                'description' => '',
49
+                            ),
50
+                            '_wpinv_company'    => array(
51
+                                'label'       => __( 'Company', 'invoicing' ),
52
+                                'description' => '',
53
+                            ),
54
+                            '_wpinv_company_id'    => array(
55
+                                'label'       => __( 'Company ID', 'invoicing' ),
56
+                                'description' => '',
57
+                            ),
58
+                            '_wpinv_address'  => array(
59
+                                'label'       => __( 'Address', 'invoicing' ),
60
+                                'description' => '',
61
+                            ),
62
+                            '_wpinv_city'       => array(
63
+                                'label'       => __( 'City', 'invoicing' ),
64
+                                'description' => '',
65
+                            ),
66
+                            '_wpinv_zip'   => array(
67
+                                'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
+                                'description' => '',
69
+                            ),
70
+                            '_wpinv_country'    => array(
71
+                                'label'       => __( 'Country / Region', 'invoicing' ),
72
+                                'description' => '',
73
+                                'class'       => 'getpaid_js_field-country',
74
+                                'type'        => 'select',
75
+                                'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
+                            ),
77
+                            '_wpinv_state'      => array(
78
+                                'label'       => __( 'State / County', 'invoicing' ),
79
+                                'description' => __( 'State / County or state code', 'invoicing' ),
80
+                                'class'       => 'getpaid_js_field-state regular-text',
81
+                            ),
82
+                            '_wpinv_phone'      => array(
83
+                                'label'       => __( 'Phone', 'invoicing' ),
84
+                                'description' => '',
85
+                            ),
86
+                            '_wpinv_vat_number'      => array(
87
+                                'label'       => __( 'VAT Number', 'invoicing' ),
88
+                                'description' => '',
89
+                            ),
90
+                        ),
91
+                    ),
92
+                )
93
+            );
94
+            return $show_fields;
95
+        }
96
+
97
+        /**
98
+         * Show Address Fields on edit user pages.
99
+         *
100
+         * @param WP_User $user
101
+         */
102
+        public function add_customer_meta_fields( $user ) {
103
+
104
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
+                return;
106
+            }
107
+
108
+            $show_fields = $this->get_customer_meta_fields();
109
+
110
+            foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
+                ?>
112 112
 				<h2><?php echo $fieldset['title']; ?></h2>
113 113
 				<table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>">
114 114
 					<?php foreach ( $fieldset['fields'] as $key => $field ) : ?>
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 								<?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?>
121 121
 									<select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;">
122 122
 										<?php
123
-											$selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
-										foreach ( $field['options'] as $option_key => $option_value ) :
125
-											?>
123
+                                            $selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
+                                        foreach ( $field['options'] as $option_key => $option_value ) :
125
+                                            ?>
126 126
 											<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option>
127 127
 										<?php endforeach; ?>
128 128
 									</select>
@@ -137,52 +137,52 @@  discard block
 block discarded – undo
137 137
 					<?php endforeach; ?>
138 138
 				</table>
139 139
 				<?php
140
-			endforeach;
141
-		}
142
-
143
-		/**
144
-		 * Save Address Fields on edit user pages.
145
-		 *
146
-		 * @param int $user_id User ID of the user being saved
147
-		 */
148
-		public function save_customer_meta_fields( $user_id ) {
149
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
-				return;
151
-			}
152
-
153
-			$save_fields = $this->get_customer_meta_fields();
154
-
155
-			foreach ( $save_fields as $fieldset ) {
156
-
157
-				foreach ( $fieldset['fields'] as $key => $field ) {
158
-
159
-					if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
160
-						update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) );
161
-					} elseif ( isset( $_POST[ $key ] ) ) {
162
-						update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) );
163
-					}
164
-				}
165
-			}
166
-		}
167
-
168
-		/**
169
-		 * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
170
-		 *
171
-		 * @since 3.1.0
172
-		 * @param int    $user_id User ID of the user being edited
173
-		 * @param string $key     Key for user meta field
174
-		 * @return string
175
-		 */
176
-		protected function get_user_meta( $user_id, $key ) {
177
-			$value           = get_user_meta( $user_id, $key, true );
178
-			$existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
179
-			if ( ! $value && in_array( $key, $existing_fields ) ) {
180
-				$value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
181
-			}
182
-
183
-			return $value;
184
-		}
185
-	}
140
+            endforeach;
141
+        }
142
+
143
+        /**
144
+         * Save Address Fields on edit user pages.
145
+         *
146
+         * @param int $user_id User ID of the user being saved
147
+         */
148
+        public function save_customer_meta_fields( $user_id ) {
149
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
+                return;
151
+            }
152
+
153
+            $save_fields = $this->get_customer_meta_fields();
154
+
155
+            foreach ( $save_fields as $fieldset ) {
156
+
157
+                foreach ( $fieldset['fields'] as $key => $field ) {
158
+
159
+                    if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
160
+                        update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) );
161
+                    } elseif ( isset( $_POST[ $key ] ) ) {
162
+                        update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) );
163
+                    }
164
+                }
165
+            }
166
+        }
167
+
168
+        /**
169
+         * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
170
+         *
171
+         * @since 3.1.0
172
+         * @param int    $user_id User ID of the user being edited
173
+         * @param string $key     Key for user meta field
174
+         * @return string
175
+         */
176
+        protected function get_user_meta( $user_id, $key ) {
177
+            $value           = get_user_meta( $user_id, $key, true );
178
+            $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
179
+            if ( ! $value && in_array( $key, $existing_fields ) ) {
180
+                $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
181
+            }
182
+
183
+            return $value;
184
+        }
185
+    }
186 186
 
187 187
 endif;
188 188
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-address.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Invoice_Address {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the invoice.
@@ -366,18 +366,18 @@  discard block
 block discarded – undo
366 366
     }
367 367
 
368 368
     /**
369
-	 * Save meta box data.
370
-	 *
371
-	 * @param int $post_id
372
-	 */
373
-	public static function save( $post_id ) {
369
+     * Save meta box data.
370
+     *
371
+     * @param int $post_id
372
+     */
373
+    public static function save( $post_id ) {
374 374
 
375 375
         // Prepare the invoice.
376 376
         $invoice = new WPInv_Invoice( $post_id );
377 377
 
378 378
         // Load new data.
379 379
         $invoice->set_props(
380
-			array(
380
+            array(
381 381
                 'template'             => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null,
382 382
                 'email_cc'             => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null,
383 383
                 'disable_taxes'        => ! empty( $_POST['disable_taxes'] ),
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
                 'due_date'             => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null,
401 401
                 'number'               => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null,
402 402
                 'status'               => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null,
403
-			)
403
+            )
404 404
         );
405 405
 
406 406
         // Discount code.
@@ -465,6 +465,6 @@  discard block
 block discarded – undo
465 465
         }
466 466
 
467 467
         // Fires after an invoice is saved.
468
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
469
-	}
468
+        do_action( 'wpinv_invoice_metabox_saved', $invoice );
469
+    }
470 470
 }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +2609 added lines, -2609 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 class WPInv_Invoice extends GetPaid_Data {
15 15
 
16 16
     /**
17
-	 * Which data store to load.
18
-	 *
19
-	 * @var string
20
-	 */
17
+     * Which data store to load.
18
+     *
19
+     * @var string
20
+     */
21 21
     protected $data_store_name = 'invoice';
22 22
 
23 23
     /**
24
-	 * This is the name of this object type.
25
-	 *
26
-	 * @var string
27
-	 */
24
+     * This is the name of this object type.
25
+     *
26
+     * @var string
27
+     */
28 28
     protected $object_type = 'invoice';
29 29
 
30 30
     /**
31
-	 * Item Data array. This is the core item data exposed in APIs.
32
-	 *
33
-	 * @since 1.0.19
34
-	 * @var array
35
-	 */
36
-	protected $data = array(
37
-		'parent_id'            => 0,
38
-		'status'               => 'wpi-pending',
39
-		'version'              => '',
40
-		'date_created'         => null,
31
+     * Item Data array. This is the core item data exposed in APIs.
32
+     *
33
+     * @since 1.0.19
34
+     * @var array
35
+     */
36
+    protected $data = array(
37
+        'parent_id'            => 0,
38
+        'status'               => 'wpi-pending',
39
+        'version'              => '',
40
+        'date_created'         => null,
41 41
         'date_modified'        => null,
42 42
         'due_date'             => null,
43 43
         'completed_date'       => null,
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
         'state'                => null,
61 61
         'zip'                  => null,
62 62
         'company'              => null,
63
-		'company_id'           => null,
63
+        'company_id'           => null,
64 64
         'vat_number'           => null,
65 65
         'vat_rate'             => null,
66 66
         'address'              => null,
67 67
         'address_confirmed'    => false,
68 68
         'shipping'             => null,
69
-		'subtotal'             => 0,
69
+        'subtotal'             => 0,
70 70
         'total_discount'       => 0,
71 71
         'total_tax'            => 0,
72
-		'total_fees'           => 0,
73
-		'total'                => 0,
72
+        'total_fees'           => 0,
73
+        'total'                => 0,
74 74
         'fees'                 => array(),
75 75
         'discounts'            => array(),
76 76
         'taxes'                => array(),
@@ -82,22 +82,22 @@  discard block
 block discarded – undo
82 82
         'transaction_id'       => '',
83 83
         'currency'             => '',
84 84
         'disable_taxes'        => false,
85
-		'subscription_id'      => null,
86
-		'remote_subscription_id' => null,
87
-		'is_viewed'            => false,
88
-		'email_cc'             => '',
89
-		'template'             => 'quantity', // hours, amount only
90
-		'created_via'          => null,
85
+        'subscription_id'      => null,
86
+        'remote_subscription_id' => null,
87
+        'is_viewed'            => false,
88
+        'email_cc'             => '',
89
+        'template'             => 'quantity', // hours, amount only
90
+        'created_via'          => null,
91 91
     );
92 92
 
93 93
     /**
94
-	 * Stores meta in cache for future reads.
95
-	 *
96
-	 * A group must be set to to enable caching.
97
-	 *
98
-	 * @var string
99
-	 */
100
-	protected $cache_group = 'getpaid_invoices';
94
+     * Stores meta in cache for future reads.
95
+     *
96
+     * A group must be set to to enable caching.
97
+     *
98
+     * @var string
99
+     */
100
+    protected $cache_group = 'getpaid_invoices';
101 101
 
102 102
     /**
103 103
      * Stores a reference to the original WP_Post object
@@ -111,111 +111,111 @@  discard block
 block discarded – undo
111 111
      *
112 112
      * @var int
113 113
      */
114
-	protected $recurring_item = null;
114
+    protected $recurring_item = null;
115 115
 
116
-	/**
116
+    /**
117 117
      * Stores an array of item totals.
118
-	 *
119
-	 * e.g $totals['discount'] = array(
120
-	 * 		'initial'   => 10,
121
-	 * 		'recurring' => 10,
122
-	 * )
118
+     *
119
+     * e.g $totals['discount'] = array(
120
+     * 		'initial'   => 10,
121
+     * 		'recurring' => 10,
122
+     * )
123 123
      *
124 124
      * @var array
125 125
      */
126
-	protected $totals = array();
126
+    protected $totals = array();
127 127
 
128
-	/**
128
+    /**
129 129
      * Tax rate.
130
-	 *
130
+     *
131 131
      * @var float
132 132
      */
133
-	protected $tax_rate = 0;
133
+    protected $tax_rate = 0;
134 134
 
135
-	/**
136
-	 * Stores the status transition information.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @var bool|array
140
-	 */
141
-	protected $status_transition = false;
135
+    /**
136
+     * Stores the status transition information.
137
+     *
138
+     * @since 1.0.19
139
+     * @var bool|array
140
+     */
141
+    protected $status_transition = false;
142 142
 
143 143
     /**
144
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
145
-	 *
146
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
147
-	 */
144
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
145
+     *
146
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
147
+     */
148 148
     public function __construct( $invoice = 0 ) {
149 149
 
150 150
         parent::__construct( $invoice );
151 151
 
152
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) {
153
-			$this->set_id( (int) $invoice );
154
-		} elseif ( $invoice instanceof self ) {
155
-			$this->set_id( $invoice->get_id() );
156
-		} elseif ( ! empty( $invoice->ID ) ) {
157
-			$this->set_id( $invoice->ID );
158
-		} elseif ( is_array( $invoice ) ) {
159
-			$this->set_props( $invoice );
160
-
161
-			if ( isset( $invoice['ID'] ) ) {
162
-				$this->set_id( $invoice['ID'] );
163
-			}
164
-
165
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
166
-			$this->set_id( $invoice_id );
167
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
168
-			$this->set_id( $invoice_id );
169
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
170
-			$this->set_id( $invoice_id );
171
-		} else {
172
-			$this->set_object_read( true );
173
-		}
152
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) {
153
+            $this->set_id( (int) $invoice );
154
+        } elseif ( $invoice instanceof self ) {
155
+            $this->set_id( $invoice->get_id() );
156
+        } elseif ( ! empty( $invoice->ID ) ) {
157
+            $this->set_id( $invoice->ID );
158
+        } elseif ( is_array( $invoice ) ) {
159
+            $this->set_props( $invoice );
160
+
161
+            if ( isset( $invoice['ID'] ) ) {
162
+                $this->set_id( $invoice['ID'] );
163
+            }
164
+
165
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
166
+            $this->set_id( $invoice_id );
167
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
168
+            $this->set_id( $invoice_id );
169
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
170
+            $this->set_id( $invoice_id );
171
+        } else {
172
+            $this->set_object_read( true );
173
+        }
174 174
 
175 175
         // Load the datastore.
176
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
176
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
177 177
 
178
-		if ( $this->get_id() > 0 ) {
178
+        if ( $this->get_id() > 0 ) {
179 179
             $this->post = get_post( $this->get_id() );
180 180
             $this->ID   = $this->get_id();
181
-			$this->data_store->read( $this );
181
+            $this->data_store->read( $this );
182 182
         }
183 183
 
184 184
     }
185 185
 
186 186
     /**
187
-	 * Given an invoice key/number, it returns its id.
188
-	 *
189
-	 *
190
-	 * @static
191
-	 * @param string $value The invoice key or number
192
-	 * @param string $field Either key, transaction_id or number.
193
-	 * @since 1.0.15
194
-	 * @return int
195
-	 */
196
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
187
+     * Given an invoice key/number, it returns its id.
188
+     *
189
+     *
190
+     * @static
191
+     * @param string $value The invoice key or number
192
+     * @param string $field Either key, transaction_id or number.
193
+     * @since 1.0.15
194
+     * @return int
195
+     */
196
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
197 197
         global $wpdb;
198 198
 
199
-		// Trim the value.
200
-		$value = trim( $value );
199
+        // Trim the value.
200
+        $value = trim( $value );
201 201
 
202
-		if ( empty( $value ) ) {
203
-			return 0;
204
-		}
202
+        if ( empty( $value ) ) {
203
+            return 0;
204
+        }
205 205
 
206 206
         // Valid fields.
207 207
         $fields = array( 'key', 'number', 'transaction_id' );
208 208
 
209
-		// Ensure a field has been passed.
210
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
211
-			return 0;
212
-		}
209
+        // Ensure a field has been passed.
210
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
211
+            return 0;
212
+        }
213 213
 
214
-		// Maybe retrieve from the cache.
215
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
216
-		if ( false !== $invoice_id ) {
217
-			return $invoice_id;
218
-		}
214
+        // Maybe retrieve from the cache.
215
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
216
+        if ( false !== $invoice_id ) {
217
+            return $invoice_id;
218
+        }
219 219
 
220 220
         // Fetch from the db.
221 221
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
224 224
         );
225 225
 
226
-		// Update the cache with our data
227
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
226
+        // Update the cache with our data
227
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
228 228
 
229
-		return $invoice_id;
229
+        return $invoice_id;
230 230
     }
231 231
 
232 232
     /**
@@ -252,83 +252,83 @@  discard block
 block discarded – undo
252 252
     */
253 253
 
254 254
     /**
255
-	 * Get parent invoice ID.
256
-	 *
257
-	 * @since 1.0.19
258
-	 * @param  string $context View or edit context.
259
-	 * @return int
260
-	 */
261
-	public function get_parent_id( $context = 'view' ) {
262
-		return (int) $this->get_prop( 'parent_id', $context );
255
+     * Get parent invoice ID.
256
+     *
257
+     * @since 1.0.19
258
+     * @param  string $context View or edit context.
259
+     * @return int
260
+     */
261
+    public function get_parent_id( $context = 'view' ) {
262
+        return (int) $this->get_prop( 'parent_id', $context );
263 263
     }
264 264
 
265 265
     /**
266
-	 * Get parent invoice.
267
-	 *
268
-	 * @since 1.0.19
269
-	 * @return WPInv_Invoice
270
-	 */
266
+     * Get parent invoice.
267
+     *
268
+     * @since 1.0.19
269
+     * @return WPInv_Invoice
270
+     */
271 271
     public function get_parent_payment() {
272 272
         return new WPInv_Invoice( $this->get_parent_id() );
273 273
     }
274 274
 
275 275
     /**
276
-	 * Alias for self::get_parent_payment().
277
-	 *
278
-	 * @since 1.0.19
279
-	 * @return WPInv_Invoice
280
-	 */
276
+     * Alias for self::get_parent_payment().
277
+     *
278
+     * @since 1.0.19
279
+     * @return WPInv_Invoice
280
+     */
281 281
     public function get_parent() {
282 282
         return $this->get_parent_payment();
283 283
     }
284 284
 
285 285
     /**
286
-	 * Get invoice status.
287
-	 *
288
-	 * @since 1.0.19
289
-	 * @param  string $context View or edit context.
290
-	 * @return string
291
-	 */
292
-	public function get_status( $context = 'view' ) {
293
-		return $this->get_prop( 'status', $context );
294
-	}
286
+     * Get invoice status.
287
+     *
288
+     * @since 1.0.19
289
+     * @param  string $context View or edit context.
290
+     * @return string
291
+     */
292
+    public function get_status( $context = 'view' ) {
293
+        return $this->get_prop( 'status', $context );
294
+    }
295 295
 	
296
-	/**
297
-	 * Retrieves an array of possible invoice statuses.
298
-	 *
299
-	 * @since 1.0.19
300
-	 * @return array
301
-	 */
302
-	public function get_all_statuses() {
303
-		return wpinv_get_invoice_statuses( true, true, $this );
304
-    }
305
-
306
-    /**
307
-	 * Get invoice status nice name.
308
-	 *
309
-	 * @since 1.0.19
310
-	 * @return string
311
-	 */
296
+    /**
297
+     * Retrieves an array of possible invoice statuses.
298
+     *
299
+     * @since 1.0.19
300
+     * @return array
301
+     */
302
+    public function get_all_statuses() {
303
+        return wpinv_get_invoice_statuses( true, true, $this );
304
+    }
305
+
306
+    /**
307
+     * Get invoice status nice name.
308
+     *
309
+     * @since 1.0.19
310
+     * @return string
311
+     */
312 312
     public function get_status_nicename() {
313
-		$statuses = $this->get_all_statuses();
313
+        $statuses = $this->get_all_statuses();
314 314
 
315 315
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
316 316
 
317 317
         return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this );
318 318
     }
319 319
 
320
-	/**
321
-	 * Retrieves the invoice status class
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @return string
325
-	 */
326
-	public function get_status_class() {
327
-		$statuses = getpaid_get_invoice_status_classes();
328
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
329
-	}
320
+    /**
321
+     * Retrieves the invoice status class
322
+     *
323
+     * @since  1.0.19
324
+     * @return string
325
+     */
326
+    public function get_status_class() {
327
+        $statuses = getpaid_get_invoice_status_classes();
328
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
329
+    }
330 330
 
331
-	/**
331
+    /**
332 332
      * Retrieves the invoice status label html
333 333
      *
334 334
      * @since  1.0.0
@@ -336,263 +336,263 @@  discard block
 block discarded – undo
336 336
      */
337 337
     public function get_status_label_html() {
338 338
 
339
-		$status_label = sanitize_text_field( $this->get_status_nicename() );
340
-		$status       = sanitize_html_class( $this->get_status() );
341
-		$class        = esc_attr( $this->get_status_class() );
339
+        $status_label = sanitize_text_field( $this->get_status_nicename() );
340
+        $status       = sanitize_html_class( $this->get_status() );
341
+        $class        = esc_attr( $this->get_status_class() );
342 342
 
343
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
344
-	}
343
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
344
+    }
345 345
 
346 346
     /**
347
-	 * Get plugin version when the invoice was created.
348
-	 *
349
-	 * @since 1.0.19
350
-	 * @param  string $context View or edit context.
351
-	 * @return string
352
-	 */
353
-	public function get_version( $context = 'view' ) {
354
-		return $this->get_prop( 'version', $context );
355
-	}
347
+     * Get plugin version when the invoice was created.
348
+     *
349
+     * @since 1.0.19
350
+     * @param  string $context View or edit context.
351
+     * @return string
352
+     */
353
+    public function get_version( $context = 'view' ) {
354
+        return $this->get_prop( 'version', $context );
355
+    }
356 356
 
357
-	/**
358
-	 * @deprecated
359
-	 */
360
-	public function get_invoice_date( $format = true ) {
361
-		$date      = getpaid_format_date( $this->get_date_completed() );
362
-		$date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
363
-		$formatted = getpaid_format_date( $date );
357
+    /**
358
+     * @deprecated
359
+     */
360
+    public function get_invoice_date( $format = true ) {
361
+        $date      = getpaid_format_date( $this->get_date_completed() );
362
+        $date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
363
+        $formatted = getpaid_format_date( $date );
364 364
 
365
-		if ( $format ) {
366
-			return $formatted;
367
-		}
365
+        if ( $format ) {
366
+            return $formatted;
367
+        }
368 368
 
369
-		return empty( $formatted ) ? '' : $date;
369
+        return empty( $formatted ) ? '' : $date;
370 370
 
371 371
     }
372 372
 
373 373
     /**
374
-	 * Get date when the invoice was created.
375
-	 *
376
-	 * @since 1.0.19
377
-	 * @param  string $context View or edit context.
378
-	 * @return string
379
-	 */
380
-	public function get_date_created( $context = 'view' ) {
381
-		return $this->get_prop( 'date_created', $context );
382
-	}
374
+     * Get date when the invoice was created.
375
+     *
376
+     * @since 1.0.19
377
+     * @param  string $context View or edit context.
378
+     * @return string
379
+     */
380
+    public function get_date_created( $context = 'view' ) {
381
+        return $this->get_prop( 'date_created', $context );
382
+    }
383 383
 	
384
-	/**
385
-	 * Alias for self::get_date_created().
386
-	 *
387
-	 * @since 1.0.19
388
-	 * @param  string $context View or edit context.
389
-	 * @return string
390
-	 */
391
-	public function get_created_date( $context = 'view' ) {
392
-		return $this->get_date_created( $context );
393
-    }
394
-
395
-    /**
396
-	 * Get GMT date when the invoice was created.
397
-	 *
398
-	 * @since 1.0.19
399
-	 * @param  string $context View or edit context.
400
-	 * @return string
401
-	 */
402
-	public function get_date_created_gmt( $context = 'view' ) {
384
+    /**
385
+     * Alias for self::get_date_created().
386
+     *
387
+     * @since 1.0.19
388
+     * @param  string $context View or edit context.
389
+     * @return string
390
+     */
391
+    public function get_created_date( $context = 'view' ) {
392
+        return $this->get_date_created( $context );
393
+    }
394
+
395
+    /**
396
+     * Get GMT date when the invoice was created.
397
+     *
398
+     * @since 1.0.19
399
+     * @param  string $context View or edit context.
400
+     * @return string
401
+     */
402
+    public function get_date_created_gmt( $context = 'view' ) {
403 403
         $date = $this->get_date_created( $context );
404 404
 
405 405
         if ( $date ) {
406 406
             $date = get_gmt_from_date( $date );
407 407
         }
408
-		return $date;
408
+        return $date;
409 409
     }
410 410
 
411 411
     /**
412
-	 * Get date when the invoice was last modified.
413
-	 *
414
-	 * @since 1.0.19
415
-	 * @param  string $context View or edit context.
416
-	 * @return string
417
-	 */
418
-	public function get_date_modified( $context = 'view' ) {
419
-		return $this->get_prop( 'date_modified', $context );
420
-	}
412
+     * Get date when the invoice was last modified.
413
+     *
414
+     * @since 1.0.19
415
+     * @param  string $context View or edit context.
416
+     * @return string
417
+     */
418
+    public function get_date_modified( $context = 'view' ) {
419
+        return $this->get_prop( 'date_modified', $context );
420
+    }
421 421
 
422
-	/**
423
-	 * Alias for self::get_date_modified().
424
-	 *
425
-	 * @since 1.0.19
426
-	 * @param  string $context View or edit context.
427
-	 * @return string
428
-	 */
429
-	public function get_modified_date( $context = 'view' ) {
430
-		return $this->get_date_modified( $context );
422
+    /**
423
+     * Alias for self::get_date_modified().
424
+     *
425
+     * @since 1.0.19
426
+     * @param  string $context View or edit context.
427
+     * @return string
428
+     */
429
+    public function get_modified_date( $context = 'view' ) {
430
+        return $this->get_date_modified( $context );
431 431
     }
432 432
 
433 433
     /**
434
-	 * Get GMT date when the invoice was last modified.
435
-	 *
436
-	 * @since 1.0.19
437
-	 * @param  string $context View or edit context.
438
-	 * @return string
439
-	 */
440
-	public function get_date_modified_gmt( $context = 'view' ) {
434
+     * Get GMT date when the invoice was last modified.
435
+     *
436
+     * @since 1.0.19
437
+     * @param  string $context View or edit context.
438
+     * @return string
439
+     */
440
+    public function get_date_modified_gmt( $context = 'view' ) {
441 441
         $date = $this->get_date_modified( $context );
442 442
 
443 443
         if ( $date ) {
444 444
             $date = get_gmt_from_date( $date );
445 445
         }
446
-		return $date;
446
+        return $date;
447 447
     }
448 448
 
449 449
     /**
450
-	 * Get the invoice due date.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return string
455
-	 */
456
-	public function get_due_date( $context = 'view' ) {
457
-		return $this->get_prop( 'due_date', $context );
450
+     * Get the invoice due date.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return string
455
+     */
456
+    public function get_due_date( $context = 'view' ) {
457
+        return $this->get_prop( 'due_date', $context );
458 458
     }
459 459
 
460 460
     /**
461
-	 * Alias for self::get_due_date().
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return string
466
-	 */
467
-	public function get_date_due( $context = 'view' ) {
468
-		return $this->get_due_date( $context );
461
+     * Alias for self::get_due_date().
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return string
466
+     */
467
+    public function get_date_due( $context = 'view' ) {
468
+        return $this->get_due_date( $context );
469 469
     }
470 470
 
471 471
     /**
472
-	 * Get the invoice GMT due date.
473
-	 *
474
-	 * @since 1.0.19
475
-	 * @param  string $context View or edit context.
476
-	 * @return string
477
-	 */
478
-	public function get_due_date_gmt( $context = 'view' ) {
472
+     * Get the invoice GMT due date.
473
+     *
474
+     * @since 1.0.19
475
+     * @param  string $context View or edit context.
476
+     * @return string
477
+     */
478
+    public function get_due_date_gmt( $context = 'view' ) {
479 479
         $date = $this->get_due_date( $context );
480 480
 
481 481
         if ( $date ) {
482 482
             $date = get_gmt_from_date( $date );
483 483
         }
484
-		return $date;
484
+        return $date;
485 485
     }
486 486
 
487 487
     /**
488
-	 * Alias for self::get_due_date_gmt().
489
-	 *
490
-	 * @since 1.0.19
491
-	 * @param  string $context View or edit context.
492
-	 * @return string
493
-	 */
494
-	public function get_gmt_date_due( $context = 'view' ) {
495
-		return $this->get_due_date_gmt( $context );
488
+     * Alias for self::get_due_date_gmt().
489
+     *
490
+     * @since 1.0.19
491
+     * @param  string $context View or edit context.
492
+     * @return string
493
+     */
494
+    public function get_gmt_date_due( $context = 'view' ) {
495
+        return $this->get_due_date_gmt( $context );
496 496
     }
497 497
 
498 498
     /**
499
-	 * Get date when the invoice was completed.
500
-	 *
501
-	 * @since 1.0.19
502
-	 * @param  string $context View or edit context.
503
-	 * @return string
504
-	 */
505
-	public function get_completed_date( $context = 'view' ) {
506
-		return $this->get_prop( 'completed_date', $context );
499
+     * Get date when the invoice was completed.
500
+     *
501
+     * @since 1.0.19
502
+     * @param  string $context View or edit context.
503
+     * @return string
504
+     */
505
+    public function get_completed_date( $context = 'view' ) {
506
+        return $this->get_prop( 'completed_date', $context );
507 507
     }
508 508
 
509 509
     /**
510
-	 * Alias for self::get_completed_date().
511
-	 *
512
-	 * @since 1.0.19
513
-	 * @param  string $context View or edit context.
514
-	 * @return string
515
-	 */
516
-	public function get_date_completed( $context = 'view' ) {
517
-		return $this->get_completed_date( $context );
510
+     * Alias for self::get_completed_date().
511
+     *
512
+     * @since 1.0.19
513
+     * @param  string $context View or edit context.
514
+     * @return string
515
+     */
516
+    public function get_date_completed( $context = 'view' ) {
517
+        return $this->get_completed_date( $context );
518 518
     }
519 519
 
520 520
     /**
521
-	 * Get GMT date when the invoice was was completed.
522
-	 *
523
-	 * @since 1.0.19
524
-	 * @param  string $context View or edit context.
525
-	 * @return string
526
-	 */
527
-	public function get_completed_date_gmt( $context = 'view' ) {
521
+     * Get GMT date when the invoice was was completed.
522
+     *
523
+     * @since 1.0.19
524
+     * @param  string $context View or edit context.
525
+     * @return string
526
+     */
527
+    public function get_completed_date_gmt( $context = 'view' ) {
528 528
         $date = $this->get_completed_date( $context );
529 529
 
530 530
         if ( $date ) {
531 531
             $date = get_gmt_from_date( $date );
532 532
         }
533
-		return $date;
533
+        return $date;
534 534
     }
535 535
 
536 536
     /**
537
-	 * Alias for self::get_completed_date_gmt().
538
-	 *
539
-	 * @since 1.0.19
540
-	 * @param  string $context View or edit context.
541
-	 * @return string
542
-	 */
543
-	public function get_gmt_completed_date( $context = 'view' ) {
544
-		return $this->get_completed_date_gmt( $context );
537
+     * Alias for self::get_completed_date_gmt().
538
+     *
539
+     * @since 1.0.19
540
+     * @param  string $context View or edit context.
541
+     * @return string
542
+     */
543
+    public function get_gmt_completed_date( $context = 'view' ) {
544
+        return $this->get_completed_date_gmt( $context );
545 545
     }
546 546
 
547 547
     /**
548
-	 * Get the invoice number.
549
-	 *
550
-	 * @since 1.0.19
551
-	 * @param  string $context View or edit context.
552
-	 * @return string
553
-	 */
554
-	public function get_number( $context = 'view' ) {
555
-		$number = $this->get_prop( 'number', $context );
548
+     * Get the invoice number.
549
+     *
550
+     * @since 1.0.19
551
+     * @param  string $context View or edit context.
552
+     * @return string
553
+     */
554
+    public function get_number( $context = 'view' ) {
555
+        $number = $this->get_prop( 'number', $context );
556 556
 
557
-		if ( empty( $number ) ) {
558
-			$number = $this->generate_number();
559
-			$this->set_number( $this->generate_number() );
560
-		}
557
+        if ( empty( $number ) ) {
558
+            $number = $this->generate_number();
559
+            $this->set_number( $this->generate_number() );
560
+        }
561 561
 
562
-		return $number;
562
+        return $number;
563 563
     }
564 564
 
565
-	/**
566
-	 * Set the invoice number.
567
-	 *
568
-	 * @since 1.0.19
569
-	 */
570
-	public function maybe_set_number() {
565
+    /**
566
+     * Set the invoice number.
567
+     *
568
+     * @since 1.0.19
569
+     */
570
+    public function maybe_set_number() {
571 571
         $number = $this->get_number();
572 572
 
573 573
         if ( empty( $number ) || $this->get_id() == $number ) {
574
-			$this->set_number( $this->generate_number() );
574
+            $this->set_number( $this->generate_number() );
575 575
         }
576 576
 
577
-	}
577
+    }
578 578
 
579 579
     /**
580
-	 * Get the invoice key.
581
-	 *
582
-	 * @since 1.0.19
583
-	 * @param  string $context View or edit context.
584
-	 * @return string
585
-	 */
586
-	public function get_key( $context = 'view' ) {
580
+     * Get the invoice key.
581
+     *
582
+     * @since 1.0.19
583
+     * @param  string $context View or edit context.
584
+     * @return string
585
+     */
586
+    public function get_key( $context = 'view' ) {
587 587
         return $this->get_prop( 'key', $context );
588
-	}
589
-
590
-	/**
591
-	 * Set the invoice key.
592
-	 *
593
-	 * @since 1.0.19
594
-	 */
595
-	public function maybe_set_key() {
588
+    }
589
+
590
+    /**
591
+     * Set the invoice key.
592
+     *
593
+     * @since 1.0.19
594
+     */
595
+    public function maybe_set_key() {
596 596
         $key = $this->get_key();
597 597
 
598 598
         if ( empty( $key ) ) {
@@ -603,140 +603,140 @@  discard block
 block discarded – undo
603 603
     }
604 604
 
605 605
     /**
606
-	 * Get the invoice type.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  string $context View or edit context.
610
-	 * @return string
611
-	 */
612
-	public function get_type( $context = 'view' ) {
606
+     * Get the invoice type.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  string $context View or edit context.
610
+     * @return string
611
+     */
612
+    public function get_type( $context = 'view' ) {
613 613
         return $this->get_prop( 'type', $context );
614
-	}
615
-
616
-	/**
617
-	 * Returns the post type name.
618
-	 *
619
-	 * @since 1.0.19
620
-	 * @return string
621
-	 */
622
-	public function get_invoice_quote_type() {
614
+    }
615
+
616
+    /**
617
+     * Returns the post type name.
618
+     *
619
+     * @since 1.0.19
620
+     * @return string
621
+     */
622
+    public function get_invoice_quote_type() {
623 623
         return getpaid_get_post_type_label( $this->get_post_type(), false );
624 624
     }
625 625
 
626 626
     /**
627
-	 * Get the invoice post type label.
628
-	 *
629
-	 * @since 1.0.19
630
-	 * @param  string $context View or edit context.
631
-	 * @return string
632
-	 */
633
-	public function get_label( $context = 'view' ) {
627
+     * Get the invoice post type label.
628
+     *
629
+     * @since 1.0.19
630
+     * @param  string $context View or edit context.
631
+     * @return string
632
+     */
633
+    public function get_label( $context = 'view' ) {
634 634
         return getpaid_get_post_type_label( $this->get_post_type( $context ), false );
635
-	}
636
-
637
-	/**
638
-	 * Get the invoice post type.
639
-	 *
640
-	 * @since 1.0.19
641
-	 * @param  string $context View or edit context.
642
-	 * @return string
643
-	 */
644
-	public function get_post_type( $context = 'view' ) {
635
+    }
636
+
637
+    /**
638
+     * Get the invoice post type.
639
+     *
640
+     * @since 1.0.19
641
+     * @param  string $context View or edit context.
642
+     * @return string
643
+     */
644
+    public function get_post_type( $context = 'view' ) {
645 645
         return $this->get_prop( 'post_type', $context );
646 646
     }
647 647
 
648 648
     /**
649
-	 * Get the invoice mode.
650
-	 *
651
-	 * @since 1.0.19
652
-	 * @param  string $context View or edit context.
653
-	 * @return string
654
-	 */
655
-	public function get_mode( $context = 'view' ) {
649
+     * Get the invoice mode.
650
+     *
651
+     * @since 1.0.19
652
+     * @param  string $context View or edit context.
653
+     * @return string
654
+     */
655
+    public function get_mode( $context = 'view' ) {
656 656
         return $this->get_prop( 'mode', $context );
657 657
     }
658 658
 
659 659
     /**
660
-	 * Get the invoice path.
661
-	 *
662
-	 * @since 1.0.19
663
-	 * @param  string $context View or edit context.
664
-	 * @return string
665
-	 */
666
-	public function get_path( $context = 'view' ) {
660
+     * Get the invoice path.
661
+     *
662
+     * @since 1.0.19
663
+     * @param  string $context View or edit context.
664
+     * @return string
665
+     */
666
+    public function get_path( $context = 'view' ) {
667 667
         $path   = $this->get_prop( 'path', $context );
668
-		$prefix = $this->get_type();
668
+        $prefix = $this->get_type();
669 669
 
670
-		if ( 0 !== strpos( $path, $prefix ) ) {
671
-			$path = sanitize_title(  $prefix . '-' . $this->get_id()  );
672
-			$this->set_path( $path );
673
-		}
670
+        if ( 0 !== strpos( $path, $prefix ) ) {
671
+            $path = sanitize_title(  $prefix . '-' . $this->get_id()  );
672
+            $this->set_path( $path );
673
+        }
674 674
 
675
-		return $path;
675
+        return $path;
676 676
     }
677 677
 
678 678
     /**
679
-	 * Get the invoice name/title.
680
-	 *
681
-	 * @since 1.0.19
682
-	 * @param  string $context View or edit context.
683
-	 * @return string
684
-	 */
685
-	public function get_name( $context = 'view' ) {
679
+     * Get the invoice name/title.
680
+     *
681
+     * @since 1.0.19
682
+     * @param  string $context View or edit context.
683
+     * @return string
684
+     */
685
+    public function get_name( $context = 'view' ) {
686 686
         return $this->get_prop( 'title', $context );
687 687
     }
688 688
 
689 689
     /**
690
-	 * Alias of self::get_name().
691
-	 *
692
-	 * @since 1.0.19
693
-	 * @param  string $context View or edit context.
694
-	 * @return string
695
-	 */
696
-	public function get_title( $context = 'view' ) {
697
-		return $this->get_name( $context );
690
+     * Alias of self::get_name().
691
+     *
692
+     * @since 1.0.19
693
+     * @param  string $context View or edit context.
694
+     * @return string
695
+     */
696
+    public function get_title( $context = 'view' ) {
697
+        return $this->get_name( $context );
698 698
     }
699 699
 
700 700
     /**
701
-	 * Get the invoice description.
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @param  string $context View or edit context.
705
-	 * @return string
706
-	 */
707
-	public function get_description( $context = 'view' ) {
708
-		return $this->get_prop( 'description', $context );
701
+     * Get the invoice description.
702
+     *
703
+     * @since 1.0.19
704
+     * @param  string $context View or edit context.
705
+     * @return string
706
+     */
707
+    public function get_description( $context = 'view' ) {
708
+        return $this->get_prop( 'description', $context );
709 709
     }
710 710
 
711 711
     /**
712
-	 * Alias of self::get_description().
713
-	 *
714
-	 * @since 1.0.19
715
-	 * @param  string $context View or edit context.
716
-	 * @return string
717
-	 */
718
-	public function get_excerpt( $context = 'view' ) {
719
-		return $this->get_description( $context );
712
+     * Alias of self::get_description().
713
+     *
714
+     * @since 1.0.19
715
+     * @param  string $context View or edit context.
716
+     * @return string
717
+     */
718
+    public function get_excerpt( $context = 'view' ) {
719
+        return $this->get_description( $context );
720 720
     }
721 721
 
722 722
     /**
723
-	 * Alias of self::get_description().
724
-	 *
725
-	 * @since 1.0.19
726
-	 * @param  string $context View or edit context.
727
-	 * @return string
728
-	 */
729
-	public function get_summary( $context = 'view' ) {
730
-		return $this->get_description( $context );
723
+     * Alias of self::get_description().
724
+     *
725
+     * @since 1.0.19
726
+     * @param  string $context View or edit context.
727
+     * @return string
728
+     */
729
+    public function get_summary( $context = 'view' ) {
730
+        return $this->get_description( $context );
731 731
     }
732 732
 
733 733
     /**
734
-	 * Returns the user info.
735
-	 *
736
-	 * @since 1.0.19
734
+     * Returns the user info.
735
+     *
736
+     * @since 1.0.19
737 737
      * @param  string $context View or edit context.
738
-	 * @return array
739
-	 */
738
+     * @return array
739
+     */
740 740
     public function get_user_info( $context = 'view' ) {
741 741
 
742 742
         $user_info = array(
@@ -751,669 +751,669 @@  discard block
 block discarded – undo
751 751
             'state'      => $this->get_state( $context ),
752 752
             'zip'        => $this->get_zip( $context ),
753 753
             'company'    => $this->get_company( $context ),
754
-			'company_id' => $this->get_company_id( $context ),
754
+            'company_id' => $this->get_company_id( $context ),
755 755
             'vat_number' => $this->get_vat_number( $context ),
756 756
             'discount'   => $this->get_discount_code( $context ),
757
-		);
757
+        );
758 758
 
759
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
759
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
760 760
 
761 761
     }
762 762
 
763 763
     /**
764
-	 * Get the customer id.
765
-	 *
766
-	 * @since 1.0.19
767
-	 * @param  string $context View or edit context.
768
-	 * @return int
769
-	 */
770
-	public function get_author( $context = 'view' ) {
771
-		return (int) $this->get_prop( 'author', $context );
764
+     * Get the customer id.
765
+     *
766
+     * @since 1.0.19
767
+     * @param  string $context View or edit context.
768
+     * @return int
769
+     */
770
+    public function get_author( $context = 'view' ) {
771
+        return (int) $this->get_prop( 'author', $context );
772 772
     }
773 773
 
774 774
     /**
775
-	 * Alias of self::get_author().
776
-	 *
777
-	 * @since 1.0.19
778
-	 * @param  string $context View or edit context.
779
-	 * @return int
780
-	 */
781
-	public function get_user_id( $context = 'view' ) {
782
-		return $this->get_author( $context );
775
+     * Alias of self::get_author().
776
+     *
777
+     * @since 1.0.19
778
+     * @param  string $context View or edit context.
779
+     * @return int
780
+     */
781
+    public function get_user_id( $context = 'view' ) {
782
+        return $this->get_author( $context );
783 783
     }
784 784
 
785
-     /**
786
-	 * Alias of self::get_author().
787
-	 *
788
-	 * @since 1.0.19
789
-	 * @param  string $context View or edit context.
790
-	 * @return int
791
-	 */
792
-	public function get_customer_id( $context = 'view' ) {
793
-		return $this->get_author( $context );
785
+        /**
786
+         * Alias of self::get_author().
787
+         *
788
+         * @since 1.0.19
789
+         * @param  string $context View or edit context.
790
+         * @return int
791
+         */
792
+    public function get_customer_id( $context = 'view' ) {
793
+        return $this->get_author( $context );
794 794
     }
795 795
 
796 796
     /**
797
-	 * Get the customer's ip.
798
-	 *
799
-	 * @since 1.0.19
800
-	 * @param  string $context View or edit context.
801
-	 * @return string
802
-	 */
803
-	public function get_ip( $context = 'view' ) {
804
-		return $this->get_prop( 'user_ip', $context );
797
+     * Get the customer's ip.
798
+     *
799
+     * @since 1.0.19
800
+     * @param  string $context View or edit context.
801
+     * @return string
802
+     */
803
+    public function get_ip( $context = 'view' ) {
804
+        return $this->get_prop( 'user_ip', $context );
805 805
     }
806 806
 
807 807
     /**
808
-	 * Alias of self::get_ip().
809
-	 *
810
-	 * @since 1.0.19
811
-	 * @param  string $context View or edit context.
812
-	 * @return string
813
-	 */
814
-	public function get_user_ip( $context = 'view' ) {
815
-		return $this->get_ip( $context );
808
+     * Alias of self::get_ip().
809
+     *
810
+     * @since 1.0.19
811
+     * @param  string $context View or edit context.
812
+     * @return string
813
+     */
814
+    public function get_user_ip( $context = 'view' ) {
815
+        return $this->get_ip( $context );
816 816
     }
817 817
 
818
-     /**
819
-	 * Alias of self::get_ip().
820
-	 *
821
-	 * @since 1.0.19
822
-	 * @param  string $context View or edit context.
823
-	 * @return string
824
-	 */
825
-	public function get_customer_ip( $context = 'view' ) {
826
-		return $this->get_ip( $context );
818
+        /**
819
+         * Alias of self::get_ip().
820
+         *
821
+         * @since 1.0.19
822
+         * @param  string $context View or edit context.
823
+         * @return string
824
+         */
825
+    public function get_customer_ip( $context = 'view' ) {
826
+        return $this->get_ip( $context );
827 827
     }
828 828
 
829 829
     /**
830
-	 * Get the customer's first name.
831
-	 *
832
-	 * @since 1.0.19
833
-	 * @param  string $context View or edit context.
834
-	 * @return string
835
-	 */
836
-	public function get_first_name( $context = 'view' ) {
837
-		return $this->get_prop( 'first_name', $context );
830
+     * Get the customer's first name.
831
+     *
832
+     * @since 1.0.19
833
+     * @param  string $context View or edit context.
834
+     * @return string
835
+     */
836
+    public function get_first_name( $context = 'view' ) {
837
+        return $this->get_prop( 'first_name', $context );
838 838
     }
839 839
 
840 840
     /**
841
-	 * Alias of self::get_first_name().
842
-	 *
843
-	 * @since 1.0.19
844
-	 * @param  string $context View or edit context.
845
-	 * @return string
846
-	 */
847
-	public function get_user_first_name( $context = 'view' ) {
848
-		return $this->get_first_name( $context );
841
+     * Alias of self::get_first_name().
842
+     *
843
+     * @since 1.0.19
844
+     * @param  string $context View or edit context.
845
+     * @return string
846
+     */
847
+    public function get_user_first_name( $context = 'view' ) {
848
+        return $this->get_first_name( $context );
849 849
     }
850 850
 
851
-     /**
852
-	 * Alias of self::get_first_name().
853
-	 *
854
-	 * @since 1.0.19
855
-	 * @param  string $context View or edit context.
856
-	 * @return string
857
-	 */
858
-	public function get_customer_first_name( $context = 'view' ) {
859
-		return $this->get_first_name( $context );
851
+        /**
852
+         * Alias of self::get_first_name().
853
+         *
854
+         * @since 1.0.19
855
+         * @param  string $context View or edit context.
856
+         * @return string
857
+         */
858
+    public function get_customer_first_name( $context = 'view' ) {
859
+        return $this->get_first_name( $context );
860 860
     }
861 861
 
862 862
     /**
863
-	 * Get the customer's last name.
864
-	 *
865
-	 * @since 1.0.19
866
-	 * @param  string $context View or edit context.
867
-	 * @return string
868
-	 */
869
-	public function get_last_name( $context = 'view' ) {
870
-		return $this->get_prop( 'last_name', $context );
863
+     * Get the customer's last name.
864
+     *
865
+     * @since 1.0.19
866
+     * @param  string $context View or edit context.
867
+     * @return string
868
+     */
869
+    public function get_last_name( $context = 'view' ) {
870
+        return $this->get_prop( 'last_name', $context );
871 871
     }
872 872
 
873 873
     /**
874
-	 * Alias of self::get_last_name().
875
-	 *
876
-	 * @since 1.0.19
877
-	 * @param  string $context View or edit context.
878
-	 * @return string
879
-	 */
880
-	public function get_user_last_name( $context = 'view' ) {
881
-		return $this->get_last_name( $context );
874
+     * Alias of self::get_last_name().
875
+     *
876
+     * @since 1.0.19
877
+     * @param  string $context View or edit context.
878
+     * @return string
879
+     */
880
+    public function get_user_last_name( $context = 'view' ) {
881
+        return $this->get_last_name( $context );
882 882
     }
883 883
 
884 884
     /**
885
-	 * Alias of self::get_last_name().
886
-	 *
887
-	 * @since 1.0.19
888
-	 * @param  string $context View or edit context.
889
-	 * @return string
890
-	 */
891
-	public function get_customer_last_name( $context = 'view' ) {
892
-		return $this->get_last_name( $context );
885
+     * Alias of self::get_last_name().
886
+     *
887
+     * @since 1.0.19
888
+     * @param  string $context View or edit context.
889
+     * @return string
890
+     */
891
+    public function get_customer_last_name( $context = 'view' ) {
892
+        return $this->get_last_name( $context );
893 893
     }
894 894
 
895 895
     /**
896
-	 * Get the customer's full name.
897
-	 *
898
-	 * @since 1.0.19
899
-	 * @param  string $context View or edit context.
900
-	 * @return string
901
-	 */
902
-	public function get_full_name( $context = 'view' ) {
903
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
896
+     * Get the customer's full name.
897
+     *
898
+     * @since 1.0.19
899
+     * @param  string $context View or edit context.
900
+     * @return string
901
+     */
902
+    public function get_full_name( $context = 'view' ) {
903
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
904 904
     }
905 905
 
906 906
     /**
907
-	 * Alias of self::get_full_name().
908
-	 *
909
-	 * @since 1.0.19
910
-	 * @param  string $context View or edit context.
911
-	 * @return string
912
-	 */
913
-	public function get_user_full_name( $context = 'view' ) {
914
-		return $this->get_full_name( $context );
907
+     * Alias of self::get_full_name().
908
+     *
909
+     * @since 1.0.19
910
+     * @param  string $context View or edit context.
911
+     * @return string
912
+     */
913
+    public function get_user_full_name( $context = 'view' ) {
914
+        return $this->get_full_name( $context );
915 915
     }
916 916
 
917 917
     /**
918
-	 * Alias of self::get_full_name().
919
-	 *
920
-	 * @since 1.0.19
921
-	 * @param  string $context View or edit context.
922
-	 * @return string
923
-	 */
924
-	public function get_customer_full_name( $context = 'view' ) {
925
-		return $this->get_full_name( $context );
918
+     * Alias of self::get_full_name().
919
+     *
920
+     * @since 1.0.19
921
+     * @param  string $context View or edit context.
922
+     * @return string
923
+     */
924
+    public function get_customer_full_name( $context = 'view' ) {
925
+        return $this->get_full_name( $context );
926 926
     }
927 927
 
928 928
     /**
929
-	 * Get the customer's phone number.
930
-	 *
931
-	 * @since 1.0.19
932
-	 * @param  string $context View or edit context.
933
-	 * @return string
934
-	 */
935
-	public function get_phone( $context = 'view' ) {
936
-		return $this->get_prop( 'phone', $context );
929
+     * Get the customer's phone number.
930
+     *
931
+     * @since 1.0.19
932
+     * @param  string $context View or edit context.
933
+     * @return string
934
+     */
935
+    public function get_phone( $context = 'view' ) {
936
+        return $this->get_prop( 'phone', $context );
937 937
     }
938 938
 
939 939
     /**
940
-	 * Alias of self::get_phone().
941
-	 *
942
-	 * @since 1.0.19
943
-	 * @param  string $context View or edit context.
944
-	 * @return string
945
-	 */
946
-	public function get_phone_number( $context = 'view' ) {
947
-		return $this->get_phone( $context );
940
+     * Alias of self::get_phone().
941
+     *
942
+     * @since 1.0.19
943
+     * @param  string $context View or edit context.
944
+     * @return string
945
+     */
946
+    public function get_phone_number( $context = 'view' ) {
947
+        return $this->get_phone( $context );
948 948
     }
949 949
 
950 950
     /**
951
-	 * Alias of self::get_phone().
952
-	 *
953
-	 * @since 1.0.19
954
-	 * @param  string $context View or edit context.
955
-	 * @return string
956
-	 */
957
-	public function get_user_phone( $context = 'view' ) {
958
-		return $this->get_phone( $context );
959
-    }
960
-
951
+     * Alias of self::get_phone().
952
+     *
953
+     * @since 1.0.19
954
+     * @param  string $context View or edit context.
955
+     * @return string
956
+     */
957
+    public function get_user_phone( $context = 'view' ) {
958
+        return $this->get_phone( $context );
959
+    }
960
+
961 961
     /**
962
-	 * Alias of self::get_phone().
963
-	 *
964
-	 * @since 1.0.19
965
-	 * @param  string $context View or edit context.
966
-	 * @return string
967
-	 */
968
-	public function get_customer_phone( $context = 'view' ) {
969
-		return $this->get_phone( $context );
962
+     * Alias of self::get_phone().
963
+     *
964
+     * @since 1.0.19
965
+     * @param  string $context View or edit context.
966
+     * @return string
967
+     */
968
+    public function get_customer_phone( $context = 'view' ) {
969
+        return $this->get_phone( $context );
970 970
     }
971 971
 
972 972
     /**
973
-	 * Get the customer's email address.
974
-	 *
975
-	 * @since 1.0.19
976
-	 * @param  string $context View or edit context.
977
-	 * @return string
978
-	 */
979
-	public function get_email( $context = 'view' ) {
980
-		return $this->get_prop( 'email', $context );
973
+     * Get the customer's email address.
974
+     *
975
+     * @since 1.0.19
976
+     * @param  string $context View or edit context.
977
+     * @return string
978
+     */
979
+    public function get_email( $context = 'view' ) {
980
+        return $this->get_prop( 'email', $context );
981 981
     }
982 982
 
983 983
     /**
984
-	 * Alias of self::get_email().
985
-	 *
986
-	 * @since 1.0.19
987
-	 * @param  string $context View or edit context.
988
-	 * @return string
989
-	 */
990
-	public function get_email_address( $context = 'view' ) {
991
-		return $this->get_email( $context );
984
+     * Alias of self::get_email().
985
+     *
986
+     * @since 1.0.19
987
+     * @param  string $context View or edit context.
988
+     * @return string
989
+     */
990
+    public function get_email_address( $context = 'view' ) {
991
+        return $this->get_email( $context );
992 992
     }
993 993
 
994 994
     /**
995
-	 * Alias of self::get_email().
996
-	 *
997
-	 * @since 1.0.19
998
-	 * @param  string $context View or edit context.
999
-	 * @return string
1000
-	 */
1001
-	public function get_user_email( $context = 'view' ) {
1002
-		return $this->get_email( $context );
995
+     * Alias of self::get_email().
996
+     *
997
+     * @since 1.0.19
998
+     * @param  string $context View or edit context.
999
+     * @return string
1000
+     */
1001
+    public function get_user_email( $context = 'view' ) {
1002
+        return $this->get_email( $context );
1003 1003
     }
1004 1004
 
1005 1005
     /**
1006
-	 * Alias of self::get_email().
1007
-	 *
1008
-	 * @since 1.0.19
1009
-	 * @param  string $context View or edit context.
1010
-	 * @return string
1011
-	 */
1012
-	public function get_customer_email( $context = 'view' ) {
1013
-		return $this->get_email( $context );
1006
+     * Alias of self::get_email().
1007
+     *
1008
+     * @since 1.0.19
1009
+     * @param  string $context View or edit context.
1010
+     * @return string
1011
+     */
1012
+    public function get_customer_email( $context = 'view' ) {
1013
+        return $this->get_email( $context );
1014 1014
     }
1015 1015
 
1016 1016
     /**
1017
-	 * Get the customer's country.
1018
-	 *
1019
-	 * @since 1.0.19
1020
-	 * @param  string $context View or edit context.
1021
-	 * @return string
1022
-	 */
1023
-	public function get_country( $context = 'view' ) {
1024
-		$country = $this->get_prop( 'country', $context );
1025
-		return empty( $country ) ? wpinv_get_default_country() : $country;
1017
+     * Get the customer's country.
1018
+     *
1019
+     * @since 1.0.19
1020
+     * @param  string $context View or edit context.
1021
+     * @return string
1022
+     */
1023
+    public function get_country( $context = 'view' ) {
1024
+        $country = $this->get_prop( 'country', $context );
1025
+        return empty( $country ) ? wpinv_get_default_country() : $country;
1026 1026
     }
1027 1027
 
1028 1028
     /**
1029
-	 * Alias of self::get_country().
1030
-	 *
1031
-	 * @since 1.0.19
1032
-	 * @param  string $context View or edit context.
1033
-	 * @return string
1034
-	 */
1035
-	public function get_user_country( $context = 'view' ) {
1036
-		return $this->get_country( $context );
1029
+     * Alias of self::get_country().
1030
+     *
1031
+     * @since 1.0.19
1032
+     * @param  string $context View or edit context.
1033
+     * @return string
1034
+     */
1035
+    public function get_user_country( $context = 'view' ) {
1036
+        return $this->get_country( $context );
1037 1037
     }
1038 1038
 
1039 1039
     /**
1040
-	 * Alias of self::get_country().
1041
-	 *
1042
-	 * @since 1.0.19
1043
-	 * @param  string $context View or edit context.
1044
-	 * @return string
1045
-	 */
1046
-	public function get_customer_country( $context = 'view' ) {
1047
-		return $this->get_country( $context );
1040
+     * Alias of self::get_country().
1041
+     *
1042
+     * @since 1.0.19
1043
+     * @param  string $context View or edit context.
1044
+     * @return string
1045
+     */
1046
+    public function get_customer_country( $context = 'view' ) {
1047
+        return $this->get_country( $context );
1048 1048
     }
1049 1049
 
1050 1050
     /**
1051
-	 * Get the customer's state.
1052
-	 *
1053
-	 * @since 1.0.19
1054
-	 * @param  string $context View or edit context.
1055
-	 * @return string
1056
-	 */
1057
-	public function get_state( $context = 'view' ) {
1058
-		$state = $this->get_prop( 'state', $context );
1059
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1051
+     * Get the customer's state.
1052
+     *
1053
+     * @since 1.0.19
1054
+     * @param  string $context View or edit context.
1055
+     * @return string
1056
+     */
1057
+    public function get_state( $context = 'view' ) {
1058
+        $state = $this->get_prop( 'state', $context );
1059
+        return empty( $state ) ? wpinv_get_default_state() : $state;
1060 1060
     }
1061 1061
 
1062 1062
     /**
1063
-	 * Alias of self::get_state().
1064
-	 *
1065
-	 * @since 1.0.19
1066
-	 * @param  string $context View or edit context.
1067
-	 * @return string
1068
-	 */
1069
-	public function get_user_state( $context = 'view' ) {
1070
-		return $this->get_state( $context );
1063
+     * Alias of self::get_state().
1064
+     *
1065
+     * @since 1.0.19
1066
+     * @param  string $context View or edit context.
1067
+     * @return string
1068
+     */
1069
+    public function get_user_state( $context = 'view' ) {
1070
+        return $this->get_state( $context );
1071 1071
     }
1072 1072
 
1073 1073
     /**
1074
-	 * Alias of self::get_state().
1075
-	 *
1076
-	 * @since 1.0.19
1077
-	 * @param  string $context View or edit context.
1078
-	 * @return string
1079
-	 */
1080
-	public function get_customer_state( $context = 'view' ) {
1081
-		return $this->get_state( $context );
1074
+     * Alias of self::get_state().
1075
+     *
1076
+     * @since 1.0.19
1077
+     * @param  string $context View or edit context.
1078
+     * @return string
1079
+     */
1080
+    public function get_customer_state( $context = 'view' ) {
1081
+        return $this->get_state( $context );
1082 1082
     }
1083 1083
 
1084 1084
     /**
1085
-	 * Get the customer's city.
1086
-	 *
1087
-	 * @since 1.0.19
1088
-	 * @param  string $context View or edit context.
1089
-	 * @return string
1090
-	 */
1091
-	public function get_city( $context = 'view' ) {
1092
-		return $this->get_prop( 'city', $context );
1085
+     * Get the customer's city.
1086
+     *
1087
+     * @since 1.0.19
1088
+     * @param  string $context View or edit context.
1089
+     * @return string
1090
+     */
1091
+    public function get_city( $context = 'view' ) {
1092
+        return $this->get_prop( 'city', $context );
1093 1093
     }
1094 1094
 
1095 1095
     /**
1096
-	 * Alias of self::get_city().
1097
-	 *
1098
-	 * @since 1.0.19
1099
-	 * @param  string $context View or edit context.
1100
-	 * @return string
1101
-	 */
1102
-	public function get_user_city( $context = 'view' ) {
1103
-		return $this->get_city( $context );
1096
+     * Alias of self::get_city().
1097
+     *
1098
+     * @since 1.0.19
1099
+     * @param  string $context View or edit context.
1100
+     * @return string
1101
+     */
1102
+    public function get_user_city( $context = 'view' ) {
1103
+        return $this->get_city( $context );
1104 1104
     }
1105 1105
 
1106 1106
     /**
1107
-	 * Alias of self::get_city().
1108
-	 *
1109
-	 * @since 1.0.19
1110
-	 * @param  string $context View or edit context.
1111
-	 * @return string
1112
-	 */
1113
-	public function get_customer_city( $context = 'view' ) {
1114
-		return $this->get_city( $context );
1107
+     * Alias of self::get_city().
1108
+     *
1109
+     * @since 1.0.19
1110
+     * @param  string $context View or edit context.
1111
+     * @return string
1112
+     */
1113
+    public function get_customer_city( $context = 'view' ) {
1114
+        return $this->get_city( $context );
1115 1115
     }
1116 1116
 
1117 1117
     /**
1118
-	 * Get the customer's zip.
1119
-	 *
1120
-	 * @since 1.0.19
1121
-	 * @param  string $context View or edit context.
1122
-	 * @return string
1123
-	 */
1124
-	public function get_zip( $context = 'view' ) {
1125
-		return $this->get_prop( 'zip', $context );
1118
+     * Get the customer's zip.
1119
+     *
1120
+     * @since 1.0.19
1121
+     * @param  string $context View or edit context.
1122
+     * @return string
1123
+     */
1124
+    public function get_zip( $context = 'view' ) {
1125
+        return $this->get_prop( 'zip', $context );
1126 1126
     }
1127 1127
 
1128 1128
     /**
1129
-	 * Alias of self::get_zip().
1130
-	 *
1131
-	 * @since 1.0.19
1132
-	 * @param  string $context View or edit context.
1133
-	 * @return string
1134
-	 */
1135
-	public function get_user_zip( $context = 'view' ) {
1136
-		return $this->get_zip( $context );
1129
+     * Alias of self::get_zip().
1130
+     *
1131
+     * @since 1.0.19
1132
+     * @param  string $context View or edit context.
1133
+     * @return string
1134
+     */
1135
+    public function get_user_zip( $context = 'view' ) {
1136
+        return $this->get_zip( $context );
1137 1137
     }
1138 1138
 
1139 1139
     /**
1140
-	 * Alias of self::get_zip().
1141
-	 *
1142
-	 * @since 1.0.19
1143
-	 * @param  string $context View or edit context.
1144
-	 * @return string
1145
-	 */
1146
-	public function get_customer_zip( $context = 'view' ) {
1147
-		return $this->get_zip( $context );
1140
+     * Alias of self::get_zip().
1141
+     *
1142
+     * @since 1.0.19
1143
+     * @param  string $context View or edit context.
1144
+     * @return string
1145
+     */
1146
+    public function get_customer_zip( $context = 'view' ) {
1147
+        return $this->get_zip( $context );
1148 1148
     }
1149 1149
 
1150 1150
     /**
1151
-	 * Get the customer's company.
1152
-	 *
1153
-	 * @since 1.0.19
1154
-	 * @param  string $context View or edit context.
1155
-	 * @return string
1156
-	 */
1157
-	public function get_company( $context = 'view' ) {
1158
-		return $this->get_prop( 'company', $context );
1151
+     * Get the customer's company.
1152
+     *
1153
+     * @since 1.0.19
1154
+     * @param  string $context View or edit context.
1155
+     * @return string
1156
+     */
1157
+    public function get_company( $context = 'view' ) {
1158
+        return $this->get_prop( 'company', $context );
1159 1159
     }
1160 1160
 
1161 1161
     /**
1162
-	 * Alias of self::get_company().
1163
-	 *
1164
-	 * @since 1.0.19
1165
-	 * @param  string $context View or edit context.
1166
-	 * @return string
1167
-	 */
1168
-	public function get_user_company( $context = 'view' ) {
1169
-		return $this->get_company( $context );
1162
+     * Alias of self::get_company().
1163
+     *
1164
+     * @since 1.0.19
1165
+     * @param  string $context View or edit context.
1166
+     * @return string
1167
+     */
1168
+    public function get_user_company( $context = 'view' ) {
1169
+        return $this->get_company( $context );
1170 1170
     }
1171 1171
 
1172 1172
     /**
1173
-	 * Alias of self::get_company().
1174
-	 *
1175
-	 * @since 1.0.19
1176
-	 * @param  string $context View or edit context.
1177
-	 * @return string
1178
-	 */
1179
-	public function get_customer_company( $context = 'view' ) {
1180
-		return $this->get_company( $context );
1173
+     * Alias of self::get_company().
1174
+     *
1175
+     * @since 1.0.19
1176
+     * @param  string $context View or edit context.
1177
+     * @return string
1178
+     */
1179
+    public function get_customer_company( $context = 'view' ) {
1180
+        return $this->get_company( $context );
1181 1181
     }
1182 1182
 
1183
-	/**
1184
-	 * Get the customer's company id.
1185
-	 *
1186
-	 * @since 1.0.19
1187
-	 * @param  string $context View or edit context.
1188
-	 * @return string
1189
-	 */
1190
-	public function get_company_id( $context = 'view' ) {
1191
-		return $this->get_prop( 'company_id', $context );
1183
+    /**
1184
+     * Get the customer's company id.
1185
+     *
1186
+     * @since 1.0.19
1187
+     * @param  string $context View or edit context.
1188
+     * @return string
1189
+     */
1190
+    public function get_company_id( $context = 'view' ) {
1191
+        return $this->get_prop( 'company_id', $context );
1192 1192
     }
1193 1193
 
1194 1194
     /**
1195
-	 * Get the customer's vat number.
1196
-	 *
1197
-	 * @since 1.0.19
1198
-	 * @param  string $context View or edit context.
1199
-	 * @return string
1200
-	 */
1201
-	public function get_vat_number( $context = 'view' ) {
1202
-		return $this->get_prop( 'vat_number', $context );
1195
+     * Get the customer's vat number.
1196
+     *
1197
+     * @since 1.0.19
1198
+     * @param  string $context View or edit context.
1199
+     * @return string
1200
+     */
1201
+    public function get_vat_number( $context = 'view' ) {
1202
+        return $this->get_prop( 'vat_number', $context );
1203
+    }
1204
+
1205
+    /**
1206
+     * Alias of self::get_vat_number().
1207
+     *
1208
+     * @since 1.0.19
1209
+     * @param  string $context View or edit context.
1210
+     * @return string
1211
+     */
1212
+    public function get_user_vat_number( $context = 'view' ) {
1213
+        return $this->get_vat_number( $context );
1203 1214
     }
1204 1215
 
1205 1216
     /**
1206
-	 * Alias of self::get_vat_number().
1207
-	 *
1208
-	 * @since 1.0.19
1209
-	 * @param  string $context View or edit context.
1210
-	 * @return string
1211
-	 */
1212
-	public function get_user_vat_number( $context = 'view' ) {
1213
-		return $this->get_vat_number( $context );
1217
+     * Alias of self::get_vat_number().
1218
+     *
1219
+     * @since 1.0.19
1220
+     * @param  string $context View or edit context.
1221
+     * @return string
1222
+     */
1223
+    public function get_customer_vat_number( $context = 'view' ) {
1224
+        return $this->get_vat_number( $context );
1214 1225
     }
1215 1226
 
1216 1227
     /**
1217
-	 * Alias of self::get_vat_number().
1218
-	 *
1219
-	 * @since 1.0.19
1220
-	 * @param  string $context View or edit context.
1221
-	 * @return string
1222
-	 */
1223
-	public function get_customer_vat_number( $context = 'view' ) {
1224
-		return $this->get_vat_number( $context );
1228
+     * Get the customer's vat rate.
1229
+     *
1230
+     * @since 1.0.19
1231
+     * @param  string $context View or edit context.
1232
+     * @return string
1233
+     */
1234
+    public function get_vat_rate( $context = 'view' ) {
1235
+        return $this->get_prop( 'vat_rate', $context );
1225 1236
     }
1226 1237
 
1227
-    /**
1228
-	 * Get the customer's vat rate.
1229
-	 *
1230
-	 * @since 1.0.19
1231
-	 * @param  string $context View or edit context.
1232
-	 * @return string
1233
-	 */
1234
-	public function get_vat_rate( $context = 'view' ) {
1235
-		return $this->get_prop( 'vat_rate', $context );
1236
-    }
1237
-
1238
-    /**
1239
-	 * Alias of self::get_vat_rate().
1240
-	 *
1241
-	 * @since 1.0.19
1242
-	 * @param  string $context View or edit context.
1243
-	 * @return string
1244
-	 */
1245
-	public function get_user_vat_rate( $context = 'view' ) {
1246
-		return $this->get_vat_rate( $context );
1247
-    }
1248
-
1249
-    /**
1250
-	 * Alias of self::get_vat_rate().
1251
-	 *
1252
-	 * @since 1.0.19
1253
-	 * @param  string $context View or edit context.
1254
-	 * @return string
1255
-	 */
1256
-	public function get_customer_vat_rate( $context = 'view' ) {
1257
-		return $this->get_vat_rate( $context );
1258
-    }
1259
-
1260
-    /**
1261
-	 * Get the customer's address.
1262
-	 *
1263
-	 * @since 1.0.19
1264
-	 * @param  string $context View or edit context.
1265
-	 * @return string
1266
-	 */
1267
-	public function get_address( $context = 'view' ) {
1268
-		return $this->get_prop( 'address', $context );
1269
-    }
1270
-
1271
-    /**
1272
-	 * Alias of self::get_address().
1273
-	 *
1274
-	 * @since 1.0.19
1275
-	 * @param  string $context View or edit context.
1276
-	 * @return string
1277
-	 */
1278
-	public function get_user_address( $context = 'view' ) {
1279
-		return $this->get_address( $context );
1280
-    }
1281
-
1282
-    /**
1283
-	 * Alias of self::get_address().
1284
-	 *
1285
-	 * @since 1.0.19
1286
-	 * @param  string $context View or edit context.
1287
-	 * @return string
1288
-	 */
1289
-	public function get_customer_address( $context = 'view' ) {
1290
-		return $this->get_address( $context );
1291
-    }
1292
-
1293
-    /**
1294
-	 * Get whether the customer has viewed the invoice or not.
1295
-	 *
1296
-	 * @since 1.0.19
1297
-	 * @param  string $context View or edit context.
1298
-	 * @return bool
1299
-	 */
1300
-	public function get_is_viewed( $context = 'view' ) {
1301
-		return (bool) $this->get_prop( 'is_viewed', $context );
1302
-	}
1303
-
1304
-	/**
1305
-	 * Get other recipients for invoice communications.
1306
-	 *
1307
-	 * @since 1.0.19
1308
-	 * @param  string $context View or edit context.
1309
-	 * @return bool
1310
-	 */
1311
-	public function get_email_cc( $context = 'view' ) {
1312
-		return $this->get_prop( 'email_cc', $context );
1313
-	}
1314
-
1315
-	/**
1316
-	 * Get invoice template.
1317
-	 *
1318
-	 * @since 1.0.19
1319
-	 * @param  string $context View or edit context.
1320
-	 * @return bool
1321
-	 */
1322
-	public function get_template( $context = 'view' ) {
1323
-		return $this->get_prop( 'template', $context );
1324
-	}
1325
-
1326
-	/**
1327
-	 * Get invoice source.
1328
-	 *
1329
-	 * @since 1.0.19
1330
-	 * @param  string $context View or edit context.
1331
-	 * @return bool
1332
-	 */
1333
-	public function get_created_via( $context = 'view' ) {
1334
-		return $this->get_prop( 'created_via', $context );
1335
-	}
1336
-
1337
-	/**
1338
-	 * Get whether the customer has confirmed their address.
1339
-	 *
1340
-	 * @since 1.0.19
1341
-	 * @param  string $context View or edit context.
1342
-	 * @return bool
1343
-	 */
1344
-	public function get_address_confirmed( $context = 'view' ) {
1345
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1346
-    }
1347
-
1348
-    /**
1349
-	 * Alias of self::get_address_confirmed().
1350
-	 *
1351
-	 * @since 1.0.19
1352
-	 * @param  string $context View or edit context.
1353
-	 * @return bool
1354
-	 */
1355
-	public function get_user_address_confirmed( $context = 'view' ) {
1356
-		return $this->get_address_confirmed( $context );
1357
-    }
1358
-
1359
-    /**
1360
-	 * Alias of self::get_address().
1361
-	 *
1362
-	 * @since 1.0.19
1363
-	 * @param  string $context View or edit context.
1364
-	 * @return bool
1365
-	 */
1366
-	public function get_customer_address_confirmed( $context = 'view' ) {
1367
-		return $this->get_address_confirmed( $context );
1368
-    }
1369
-
1370
-	/**
1371
-	 * Get the shipping address.
1372
-	 *
1373
-	 * @since 1.0.19
1374
-	 * @return array|false
1375
-	 */
1376
-	public function get_shipping_address() {
1377
-
1378
-		$shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true );
1379
-		return is_array( $shipping_address ) ? $shipping_address : false;
1380
-    }
1381
-
1382
-	/**
1383
-	 * Check if the invoice has a shipping address.
1384
-	 */
1385
-	public function has_shipping_address() {
1386
-		return false !== $this->get_shipping_address();
1387
-    }
1388
-
1389
-	/**
1390
-	 * Get the shipping amount.
1391
-	 *
1392
-	 * @since 1.0.19
1393
-	 * @param  string $context View or edit context.
1394
-	 * @return float
1395
-	 */
1396
-	public function get_shipping( $context = 'view' ) {
1397
-
1398
-		if ( $context = 'view' ) {
1399
-			return floatval( $this->get_prop( 'shipping', $context ) );
1400
-		}
1238
+    /**
1239
+     * Alias of self::get_vat_rate().
1240
+     *
1241
+     * @since 1.0.19
1242
+     * @param  string $context View or edit context.
1243
+     * @return string
1244
+     */
1245
+    public function get_user_vat_rate( $context = 'view' ) {
1246
+        return $this->get_vat_rate( $context );
1247
+    }
1248
+
1249
+    /**
1250
+     * Alias of self::get_vat_rate().
1251
+     *
1252
+     * @since 1.0.19
1253
+     * @param  string $context View or edit context.
1254
+     * @return string
1255
+     */
1256
+    public function get_customer_vat_rate( $context = 'view' ) {
1257
+        return $this->get_vat_rate( $context );
1258
+    }
1259
+
1260
+    /**
1261
+     * Get the customer's address.
1262
+     *
1263
+     * @since 1.0.19
1264
+     * @param  string $context View or edit context.
1265
+     * @return string
1266
+     */
1267
+    public function get_address( $context = 'view' ) {
1268
+        return $this->get_prop( 'address', $context );
1269
+    }
1270
+
1271
+    /**
1272
+     * Alias of self::get_address().
1273
+     *
1274
+     * @since 1.0.19
1275
+     * @param  string $context View or edit context.
1276
+     * @return string
1277
+     */
1278
+    public function get_user_address( $context = 'view' ) {
1279
+        return $this->get_address( $context );
1280
+    }
1281
+
1282
+    /**
1283
+     * Alias of self::get_address().
1284
+     *
1285
+     * @since 1.0.19
1286
+     * @param  string $context View or edit context.
1287
+     * @return string
1288
+     */
1289
+    public function get_customer_address( $context = 'view' ) {
1290
+        return $this->get_address( $context );
1291
+    }
1292
+
1293
+    /**
1294
+     * Get whether the customer has viewed the invoice or not.
1295
+     *
1296
+     * @since 1.0.19
1297
+     * @param  string $context View or edit context.
1298
+     * @return bool
1299
+     */
1300
+    public function get_is_viewed( $context = 'view' ) {
1301
+        return (bool) $this->get_prop( 'is_viewed', $context );
1302
+    }
1303
+
1304
+    /**
1305
+     * Get other recipients for invoice communications.
1306
+     *
1307
+     * @since 1.0.19
1308
+     * @param  string $context View or edit context.
1309
+     * @return bool
1310
+     */
1311
+    public function get_email_cc( $context = 'view' ) {
1312
+        return $this->get_prop( 'email_cc', $context );
1313
+    }
1314
+
1315
+    /**
1316
+     * Get invoice template.
1317
+     *
1318
+     * @since 1.0.19
1319
+     * @param  string $context View or edit context.
1320
+     * @return bool
1321
+     */
1322
+    public function get_template( $context = 'view' ) {
1323
+        return $this->get_prop( 'template', $context );
1324
+    }
1325
+
1326
+    /**
1327
+     * Get invoice source.
1328
+     *
1329
+     * @since 1.0.19
1330
+     * @param  string $context View or edit context.
1331
+     * @return bool
1332
+     */
1333
+    public function get_created_via( $context = 'view' ) {
1334
+        return $this->get_prop( 'created_via', $context );
1335
+    }
1336
+
1337
+    /**
1338
+     * Get whether the customer has confirmed their address.
1339
+     *
1340
+     * @since 1.0.19
1341
+     * @param  string $context View or edit context.
1342
+     * @return bool
1343
+     */
1344
+    public function get_address_confirmed( $context = 'view' ) {
1345
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1346
+    }
1347
+
1348
+    /**
1349
+     * Alias of self::get_address_confirmed().
1350
+     *
1351
+     * @since 1.0.19
1352
+     * @param  string $context View or edit context.
1353
+     * @return bool
1354
+     */
1355
+    public function get_user_address_confirmed( $context = 'view' ) {
1356
+        return $this->get_address_confirmed( $context );
1357
+    }
1358
+
1359
+    /**
1360
+     * Alias of self::get_address().
1361
+     *
1362
+     * @since 1.0.19
1363
+     * @param  string $context View or edit context.
1364
+     * @return bool
1365
+     */
1366
+    public function get_customer_address_confirmed( $context = 'view' ) {
1367
+        return $this->get_address_confirmed( $context );
1368
+    }
1369
+
1370
+    /**
1371
+     * Get the shipping address.
1372
+     *
1373
+     * @since 1.0.19
1374
+     * @return array|false
1375
+     */
1376
+    public function get_shipping_address() {
1377
+
1378
+        $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true );
1379
+        return is_array( $shipping_address ) ? $shipping_address : false;
1380
+    }
1381
+
1382
+    /**
1383
+     * Check if the invoice has a shipping address.
1384
+     */
1385
+    public function has_shipping_address() {
1386
+        return false !== $this->get_shipping_address();
1387
+    }
1388
+
1389
+    /**
1390
+     * Get the shipping amount.
1391
+     *
1392
+     * @since 1.0.19
1393
+     * @param  string $context View or edit context.
1394
+     * @return float
1395
+     */
1396
+    public function get_shipping( $context = 'view' ) {
1397
+
1398
+        if ( $context = 'view' ) {
1399
+            return floatval( $this->get_prop( 'shipping', $context ) );
1400
+        }
1401 1401
  
1402
-		return $this->get_prop( 'shipping', $context );
1402
+        return $this->get_prop( 'shipping', $context );
1403 1403
     }
1404 1404
 
1405
-	public function has_shipping() {
1406
-		return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' );
1405
+    public function has_shipping() {
1406
+        return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' );
1407 1407
     }
1408 1408
 
1409 1409
     /**
1410
-	 * Get the invoice subtotal.
1411
-	 *
1412
-	 * @since 1.0.19
1413
-	 * @param  string $context View or edit context.
1414
-	 * @return float
1415
-	 */
1416
-	public function get_subtotal( $context = 'view' ) {
1410
+     * Get the invoice subtotal.
1411
+     *
1412
+     * @since 1.0.19
1413
+     * @param  string $context View or edit context.
1414
+     * @return float
1415
+     */
1416
+    public function get_subtotal( $context = 'view' ) {
1417 1417
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1418 1418
 
1419 1419
         // Backwards compatibility.
@@ -1425,198 +1425,198 @@  discard block
 block discarded – undo
1425 1425
     }
1426 1426
 
1427 1427
     /**
1428
-	 * Get the invoice discount total.
1429
-	 *
1430
-	 * @since 1.0.19
1431
-	 * @param  string $context View or edit context.
1432
-	 * @return float
1433
-	 */
1434
-	public function get_total_discount( $context = 'view' ) {
1435
-		return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) );
1428
+     * Get the invoice discount total.
1429
+     *
1430
+     * @since 1.0.19
1431
+     * @param  string $context View or edit context.
1432
+     * @return float
1433
+     */
1434
+    public function get_total_discount( $context = 'view' ) {
1435
+        return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) );
1436 1436
     }
1437 1437
 
1438 1438
     /**
1439
-	 * Get the invoice tax total.
1440
-	 *
1441
-	 * @since 1.0.19
1442
-	 * @param  string $context View or edit context.
1443
-	 * @return float
1444
-	 */
1445
-	public function get_total_tax( $context = 'view' ) {
1446
-		return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) );
1447
-	}
1439
+     * Get the invoice tax total.
1440
+     *
1441
+     * @since 1.0.19
1442
+     * @param  string $context View or edit context.
1443
+     * @return float
1444
+     */
1445
+    public function get_total_tax( $context = 'view' ) {
1446
+        return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) );
1447
+    }
1448 1448
 
1449
-	/**
1450
-	 * @deprecated
1451
-	 */
1452
-	public function get_final_tax( $currency = false ) {
1453
-		$tax = $this->get_total_tax();
1449
+    /**
1450
+     * @deprecated
1451
+     */
1452
+    public function get_final_tax( $currency = false ) {
1453
+        $tax = $this->get_total_tax();
1454 1454
 
1455 1455
         if ( $currency ) {
1456
-			return wpinv_price( $tax, $this->get_currency() );
1456
+            return wpinv_price( $tax, $this->get_currency() );
1457 1457
         }
1458 1458
 
1459 1459
         return $tax;
1460 1460
     }
1461 1461
 
1462 1462
     /**
1463
-	 * Get the invoice fees total.
1464
-	 *
1465
-	 * @since 1.0.19
1466
-	 * @param  string $context View or edit context.
1467
-	 * @return float
1468
-	 */
1469
-	public function get_total_fees( $context = 'view' ) {
1470
-		return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) );
1463
+     * Get the invoice fees total.
1464
+     *
1465
+     * @since 1.0.19
1466
+     * @param  string $context View or edit context.
1467
+     * @return float
1468
+     */
1469
+    public function get_total_fees( $context = 'view' ) {
1470
+        return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) );
1471 1471
     }
1472 1472
 
1473 1473
     /**
1474
-	 * Alias for self::get_total_fees().
1475
-	 *
1476
-	 * @since 1.0.19
1477
-	 * @param  string $context View or edit context.
1478
-	 * @return float
1479
-	 */
1480
-	public function get_fees_total( $context = 'view' ) {
1481
-		return $this->get_total_fees( $context );
1474
+     * Alias for self::get_total_fees().
1475
+     *
1476
+     * @since 1.0.19
1477
+     * @param  string $context View or edit context.
1478
+     * @return float
1479
+     */
1480
+    public function get_fees_total( $context = 'view' ) {
1481
+        return $this->get_total_fees( $context );
1482 1482
     }
1483 1483
 
1484 1484
     /**
1485
-	 * Get the invoice total.
1486
-	 *
1487
-	 * @since 1.0.19
1485
+     * Get the invoice total.
1486
+     *
1487
+     * @since 1.0.19
1488 1488
      * @return float
1489
-	 */
1490
-	public function get_total( $context = 'view' ) {
1491
-		$total = $this->get_prop( 'total', $context );
1492
-
1493
-		if ( $this->has_shipping() && $context == 'view' ) {
1494
-			$total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context );
1495
-		}
1496
-
1497
-		return wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1498
-	}
1499
-
1500
-	/**
1501
-	 * Retrieves the non-recurring total of items.
1502
-	 *
1503
-	 * @since 2.3.0
1504
-	 * @return float
1505
-	 */
1506
-	public function get_non_recurring_total() {
1507
-
1508
-		$subtotal = 0;
1509
-		foreach ( $this->get_items() as $item ) {
1510
-			if ( ! $item->is_recurring() ) {
1511
-				$subtotal += $item->get_sub_total();
1512
-			}
1513
-		}
1514
-
1515
-		foreach ( $this->get_fees() as $fee ) {
1516
-			if ( empty( $fee['recurring_fee'] ) ) {
1517
-				$subtotal += wpinv_sanitize_amount( $fee['initial_fee'] );
1518
-			}
1519
-		}
1520
-
1521
-		$subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) );
1489
+     */
1490
+    public function get_total( $context = 'view' ) {
1491
+        $total = $this->get_prop( 'total', $context );
1492
+
1493
+        if ( $this->has_shipping() && $context == 'view' ) {
1494
+            $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context );
1495
+        }
1496
+
1497
+        return wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1498
+    }
1499
+
1500
+    /**
1501
+     * Retrieves the non-recurring total of items.
1502
+     *
1503
+     * @since 2.3.0
1504
+     * @return float
1505
+     */
1506
+    public function get_non_recurring_total() {
1507
+
1508
+        $subtotal = 0;
1509
+        foreach ( $this->get_items() as $item ) {
1510
+            if ( ! $item->is_recurring() ) {
1511
+                $subtotal += $item->get_sub_total();
1512
+            }
1513
+        }
1514
+
1515
+        foreach ( $this->get_fees() as $fee ) {
1516
+            if ( empty( $fee['recurring_fee'] ) ) {
1517
+                $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] );
1518
+            }
1519
+        }
1520
+
1521
+        $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) );
1522 1522
         return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this );
1523 1523
 
1524 1524
     }
1525 1525
 
1526
-	/**
1527
-	 * Get the invoice totals.
1528
-	 *
1529
-	 * @since 1.0.19
1526
+    /**
1527
+     * Get the invoice totals.
1528
+     *
1529
+     * @since 1.0.19
1530 1530
      * @return array
1531
-	 */
1532
-	public function get_totals() {
1533
-		return $this->totals;
1531
+     */
1532
+    public function get_totals() {
1533
+        return $this->totals;
1534 1534
     }
1535 1535
 
1536 1536
     /**
1537
-	 * Get the initial invoice total.
1538
-	 *
1539
-	 * @since 1.0.19
1537
+     * Get the initial invoice total.
1538
+     *
1539
+     * @since 1.0.19
1540 1540
      * @param  string $context View or edit context.
1541 1541
      * @return float
1542
-	 */
1542
+     */
1543 1543
     public function get_initial_total() {
1544 1544
 
1545
-		if ( empty( $this->totals ) ) {
1546
-			$this->recalculate_total();
1547
-		}
1545
+        if ( empty( $this->totals ) ) {
1546
+            $this->recalculate_total();
1547
+        }
1548 1548
 
1549
-		$tax      = $this->totals['tax']['initial'];
1550
-		$fee      = $this->totals['fee']['initial'];
1551
-		$discount = $this->totals['discount']['initial'];
1552
-		$subtotal = $this->totals['subtotal']['initial'];
1553
-		$total    = $tax + $fee - $discount + $subtotal;
1549
+        $tax      = $this->totals['tax']['initial'];
1550
+        $fee      = $this->totals['fee']['initial'];
1551
+        $discount = $this->totals['discount']['initial'];
1552
+        $subtotal = $this->totals['subtotal']['initial'];
1553
+        $total    = $tax + $fee - $discount + $subtotal;
1554 1554
 
1555
-		if ( 0 > $total ) {
1556
-			$total = 0;
1557
-		}
1555
+        if ( 0 > $total ) {
1556
+            $total = 0;
1557
+        }
1558 1558
 
1559
-		$total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1559
+        $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1560 1560
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1561
-	}
1561
+    }
1562 1562
 
1563
-	/**
1564
-	 * Get the recurring invoice total.
1565
-	 *
1566
-	 * @since 1.0.19
1563
+    /**
1564
+     * Get the recurring invoice total.
1565
+     *
1566
+     * @since 1.0.19
1567 1567
      * @param  string $context View or edit context.
1568 1568
      * @return float
1569
-	 */
1569
+     */
1570 1570
     public function get_recurring_total() {
1571 1571
 
1572
-		if ( empty( $this->totals ) ) {
1573
-			$this->recalculate_total();
1574
-		}
1572
+        if ( empty( $this->totals ) ) {
1573
+            $this->recalculate_total();
1574
+        }
1575 1575
 
1576
-		$tax      = $this->totals['tax']['recurring'];
1577
-		$fee      = $this->totals['fee']['recurring'];
1578
-		$discount = $this->totals['discount']['recurring'];
1579
-		$subtotal = $this->totals['subtotal']['recurring'];
1580
-		$total    = $tax + $fee - $discount + $subtotal;
1576
+        $tax      = $this->totals['tax']['recurring'];
1577
+        $fee      = $this->totals['fee']['recurring'];
1578
+        $discount = $this->totals['discount']['recurring'];
1579
+        $subtotal = $this->totals['subtotal']['recurring'];
1580
+        $total    = $tax + $fee - $discount + $subtotal;
1581 1581
 
1582
-		if ( 0 > $total ) {
1583
-			$total = 0;
1584
-		}
1582
+        if ( 0 > $total ) {
1583
+            $total = 0;
1584
+        }
1585 1585
 
1586
-		$total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1586
+        $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) );
1587 1587
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1588
-	}
1588
+    }
1589 1589
 
1590
-	/**
1591
-	 * Returns recurring payment details.
1592
-	 *
1593
-	 * @since 1.0.19
1590
+    /**
1591
+     * Returns recurring payment details.
1592
+     *
1593
+     * @since 1.0.19
1594 1594
      * @param  string $field Optionally provide a field to return.
1595
-	 * @param string $currency Whether to include the currency.
1595
+     * @param string $currency Whether to include the currency.
1596 1596
      * @return float|string
1597
-	 */
1597
+     */
1598 1598
     public function get_recurring_details( $field = '', $currency = false ) {
1599 1599
 
1600
-		// Maybe recalculate totals.
1601
-		if ( empty( $this->totals ) ) {
1602
-			$this->recalculate_total();
1603
-		}
1600
+        // Maybe recalculate totals.
1601
+        if ( empty( $this->totals ) ) {
1602
+            $this->recalculate_total();
1603
+        }
1604 1604
 
1605
-		// Prepare recurring totals.
1605
+        // Prepare recurring totals.
1606 1606
         $data = apply_filters(
1607
-			'wpinv_get_invoice_recurring_details',
1608
-			array(
1609
-				'cart_details' => $this->get_cart_details(),
1610
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1611
-				'discount'     => $this->totals['discount']['recurring'],
1612
-				'tax'          => $this->totals['tax']['recurring'],
1613
-				'fee'          => $this->totals['fee']['recurring'],
1614
-				'total'        => $this->get_recurring_total(),
1615
-			),
1616
-			$this,
1617
-			$field,
1618
-			$currency
1619
-		);
1607
+            'wpinv_get_invoice_recurring_details',
1608
+            array(
1609
+                'cart_details' => $this->get_cart_details(),
1610
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1611
+                'discount'     => $this->totals['discount']['recurring'],
1612
+                'tax'          => $this->totals['tax']['recurring'],
1613
+                'fee'          => $this->totals['fee']['recurring'],
1614
+                'total'        => $this->get_recurring_total(),
1615
+            ),
1616
+            $this,
1617
+            $field,
1618
+            $currency
1619
+        );
1620 1620
 
1621 1621
         if ( isset( $data[$field] ) ) {
1622 1622
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1626,166 +1626,166 @@  discard block
 block discarded – undo
1626 1626
     }
1627 1627
 
1628 1628
     /**
1629
-	 * Get the invoice fees.
1630
-	 *
1631
-	 * @since 1.0.19
1632
-	 * @param  string $context View or edit context.
1633
-	 * @return array
1634
-	 */
1635
-	public function get_fees( $context = 'view' ) {
1636
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1629
+     * Get the invoice fees.
1630
+     *
1631
+     * @since 1.0.19
1632
+     * @param  string $context View or edit context.
1633
+     * @return array
1634
+     */
1635
+    public function get_fees( $context = 'view' ) {
1636
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1637 1637
     }
1638 1638
 
1639 1639
     /**
1640
-	 * Get the invoice discounts.
1641
-	 *
1642
-	 * @since 1.0.19
1643
-	 * @param  string $context View or edit context.
1644
-	 * @return array
1645
-	 */
1646
-	public function get_discounts( $context = 'view' ) {
1647
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1640
+     * Get the invoice discounts.
1641
+     *
1642
+     * @since 1.0.19
1643
+     * @param  string $context View or edit context.
1644
+     * @return array
1645
+     */
1646
+    public function get_discounts( $context = 'view' ) {
1647
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1648 1648
     }
1649 1649
 
1650 1650
     /**
1651
-	 * Get the invoice taxes.
1652
-	 *
1653
-	 * @since 1.0.19
1654
-	 * @param  string $context View or edit context.
1655
-	 * @return array
1656
-	 */
1657
-	public function get_taxes( $context = 'view' ) {
1658
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1651
+     * Get the invoice taxes.
1652
+     *
1653
+     * @since 1.0.19
1654
+     * @param  string $context View or edit context.
1655
+     * @return array
1656
+     */
1657
+    public function get_taxes( $context = 'view' ) {
1658
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1659 1659
     }
1660 1660
 
1661 1661
     /**
1662
-	 * Get the invoice items.
1663
-	 *
1664
-	 * @since 1.0.19
1665
-	 * @param  string $context View or edit context.
1666
-	 * @return GetPaid_Form_Item[]
1667
-	 */
1668
-	public function get_items( $context = 'view' ) {
1662
+     * Get the invoice items.
1663
+     *
1664
+     * @since 1.0.19
1665
+     * @param  string $context View or edit context.
1666
+     * @return GetPaid_Form_Item[]
1667
+     */
1668
+    public function get_items( $context = 'view' ) {
1669 1669
         return $this->get_prop( 'items', $context );
1670
-	}
1670
+    }
1671 1671
 
1672
-	/**
1673
-	 * Get the invoice item ids.
1674
-	 *
1675
-	 * @since 1.0.19
1676
-	 * @return string
1677
-	 */
1678
-	public function get_item_ids() {
1679
-		return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) );
1672
+    /**
1673
+     * Get the invoice item ids.
1674
+     *
1675
+     * @since 1.0.19
1676
+     * @return string
1677
+     */
1678
+    public function get_item_ids() {
1679
+        return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) );
1680 1680
     }
1681 1681
 
1682 1682
     /**
1683
-	 * Get the invoice's payment form.
1684
-	 *
1685
-	 * @since 1.0.19
1686
-	 * @param  string $context View or edit context.
1687
-	 * @return int
1688
-	 */
1689
-	public function get_payment_form( $context = 'view' ) {
1690
-		return intval( $this->get_prop( 'payment_form', $context ) );
1683
+     * Get the invoice's payment form.
1684
+     *
1685
+     * @since 1.0.19
1686
+     * @param  string $context View or edit context.
1687
+     * @return int
1688
+     */
1689
+    public function get_payment_form( $context = 'view' ) {
1690
+        return intval( $this->get_prop( 'payment_form', $context ) );
1691 1691
     }
1692 1692
 
1693 1693
     /**
1694
-	 * Get the invoice's submission id.
1695
-	 *
1696
-	 * @since 1.0.19
1697
-	 * @param  string $context View or edit context.
1698
-	 * @return string
1699
-	 */
1700
-	public function get_submission_id( $context = 'view' ) {
1701
-		return $this->get_prop( 'submission_id', $context );
1694
+     * Get the invoice's submission id.
1695
+     *
1696
+     * @since 1.0.19
1697
+     * @param  string $context View or edit context.
1698
+     * @return string
1699
+     */
1700
+    public function get_submission_id( $context = 'view' ) {
1701
+        return $this->get_prop( 'submission_id', $context );
1702 1702
     }
1703 1703
 
1704 1704
     /**
1705
-	 * Get the invoice's discount code.
1706
-	 *
1707
-	 * @since 1.0.19
1708
-	 * @param  string $context View or edit context.
1709
-	 * @return string
1710
-	 */
1711
-	public function get_discount_code( $context = 'view' ) {
1712
-		return $this->get_prop( 'discount_code', $context );
1705
+     * Get the invoice's discount code.
1706
+     *
1707
+     * @since 1.0.19
1708
+     * @param  string $context View or edit context.
1709
+     * @return string
1710
+     */
1711
+    public function get_discount_code( $context = 'view' ) {
1712
+        return $this->get_prop( 'discount_code', $context );
1713 1713
     }
1714 1714
 
1715 1715
     /**
1716
-	 * Get the invoice's gateway.
1717
-	 *
1718
-	 * @since 1.0.19
1719
-	 * @param  string $context View or edit context.
1720
-	 * @return string
1721
-	 */
1722
-	public function get_gateway( $context = 'view' ) {
1723
-		return $this->get_prop( 'gateway', $context );
1716
+     * Get the invoice's gateway.
1717
+     *
1718
+     * @since 1.0.19
1719
+     * @param  string $context View or edit context.
1720
+     * @return string
1721
+     */
1722
+    public function get_gateway( $context = 'view' ) {
1723
+        return $this->get_prop( 'gateway', $context );
1724 1724
     }
1725 1725
 
1726 1726
     /**
1727
-	 * Get the invoice's gateway display title.
1728
-	 *
1729
-	 * @since 1.0.19
1730
-	 * @return string
1731
-	 */
1727
+     * Get the invoice's gateway display title.
1728
+     *
1729
+     * @since 1.0.19
1730
+     * @return string
1731
+     */
1732 1732
     public function get_gateway_title() {
1733 1733
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1734 1734
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1735 1735
     }
1736 1736
 
1737 1737
     /**
1738
-	 * Get the invoice's transaction id.
1739
-	 *
1740
-	 * @since 1.0.19
1741
-	 * @param  string $context View or edit context.
1742
-	 * @return string
1743
-	 */
1744
-	public function get_transaction_id( $context = 'view' ) {
1745
-		return $this->get_prop( 'transaction_id', $context );
1738
+     * Get the invoice's transaction id.
1739
+     *
1740
+     * @since 1.0.19
1741
+     * @param  string $context View or edit context.
1742
+     * @return string
1743
+     */
1744
+    public function get_transaction_id( $context = 'view' ) {
1745
+        return $this->get_prop( 'transaction_id', $context );
1746 1746
     }
1747 1747
 
1748 1748
     /**
1749
-	 * Get the invoice's currency.
1750
-	 *
1751
-	 * @since 1.0.19
1752
-	 * @param  string $context View or edit context.
1753
-	 * @return string
1754
-	 */
1755
-	public function get_currency( $context = 'view' ) {
1749
+     * Get the invoice's currency.
1750
+     *
1751
+     * @since 1.0.19
1752
+     * @param  string $context View or edit context.
1753
+     * @return string
1754
+     */
1755
+    public function get_currency( $context = 'view' ) {
1756 1756
         $currency = $this->get_prop( 'currency', $context );
1757 1757
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1758 1758
     }
1759 1759
 
1760 1760
     /**
1761
-	 * Checks if we are charging taxes for this invoice.
1762
-	 *
1763
-	 * @since 1.0.19
1764
-	 * @param  string $context View or edit context.
1765
-	 * @return bool
1766
-	 */
1767
-	public function get_disable_taxes( $context = 'view' ) {
1761
+     * Checks if we are charging taxes for this invoice.
1762
+     *
1763
+     * @since 1.0.19
1764
+     * @param  string $context View or edit context.
1765
+     * @return bool
1766
+     */
1767
+    public function get_disable_taxes( $context = 'view' ) {
1768 1768
         return (bool) $this->get_prop( 'disable_taxes', $context );
1769 1769
     }
1770 1770
 
1771 1771
     /**
1772
-	 * Retrieves the subscription id for an invoice.
1773
-	 *
1774
-	 * @since 1.0.19
1775
-	 * @param  string $context View or edit context.
1776
-	 * @return int
1777
-	 */
1772
+     * Retrieves the subscription id for an invoice.
1773
+     *
1774
+     * @since 1.0.19
1775
+     * @param  string $context View or edit context.
1776
+     * @return int
1777
+     */
1778 1778
     public function get_subscription_id( $context = 'view' ) {
1779
-		return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1780
-	}
1781
-
1782
-	/**
1783
-	 * Retrieves the remote subscription id for an invoice.
1784
-	 *
1785
-	 * @since 1.0.19
1786
-	 * @param  string $context View or edit context.
1787
-	 * @return int
1788
-	 */
1779
+        return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1780
+    }
1781
+
1782
+    /**
1783
+     * Retrieves the remote subscription id for an invoice.
1784
+     *
1785
+     * @since 1.0.19
1786
+     * @param  string $context View or edit context.
1787
+     * @return int
1788
+     */
1789 1789
     public function get_remote_subscription_id( $context = 'view' ) {
1790 1790
         $subscription_id = $this->get_prop( 'remote_subscription_id', $context );
1791 1791
 
@@ -1798,12 +1798,12 @@  discard block
 block discarded – undo
1798 1798
     }
1799 1799
 
1800 1800
     /**
1801
-	 * Retrieves the payment meta for an invoice.
1802
-	 *
1803
-	 * @since 1.0.19
1804
-	 * @param  string $context View or edit context.
1805
-	 * @return array
1806
-	 */
1801
+     * Retrieves the payment meta for an invoice.
1802
+     *
1803
+     * @since 1.0.19
1804
+     * @param  string $context View or edit context.
1805
+     * @return array
1806
+     */
1807 1807
     public function get_payment_meta( $context = 'view' ) {
1808 1808
 
1809 1809
         return array(
@@ -1823,31 +1823,31 @@  discard block
 block discarded – undo
1823 1823
     }
1824 1824
 
1825 1825
     /**
1826
-	 * Retrieves the cart details for an invoice.
1827
-	 *
1828
-	 * @since 1.0.19
1829
-	 * @return array
1830
-	 */
1826
+     * Retrieves the cart details for an invoice.
1827
+     *
1828
+     * @since 1.0.19
1829
+     * @return array
1830
+     */
1831 1831
     public function get_cart_details() {
1832 1832
         $items        = $this->get_items();
1833 1833
         $cart_details = array();
1834 1834
 
1835 1835
         foreach ( $items as $item ) {
1836
-			$item->invoice_id = $this->get_id();
1836
+            $item->invoice_id = $this->get_id();
1837 1837
             $cart_details[]   = $item->prepare_data_for_saving();
1838 1838
         }
1839 1839
 
1840 1840
         return $cart_details;
1841
-	}
1841
+    }
1842 1842
 
1843
-	/**
1844
-	 * Retrieves the recurring item.
1845
-	 *
1846
-	 * @return null|GetPaid_Form_Item|int
1847
-	 */
1848
-	public function get_recurring( $object = false ) {
1843
+    /**
1844
+     * Retrieves the recurring item.
1845
+     *
1846
+     * @return null|GetPaid_Form_Item|int
1847
+     */
1848
+    public function get_recurring( $object = false ) {
1849 1849
 
1850
-		// Are we returning an object?
1850
+        // Are we returning an object?
1851 1851
         if ( $object ) {
1852 1852
             return $this->get_item( $this->recurring_item );
1853 1853
         }
@@ -1855,124 +1855,124 @@  discard block
 block discarded – undo
1855 1855
         return $this->recurring_item;
1856 1856
     }
1857 1857
 
1858
-	/**
1859
-	 * Retrieves the subscription name.
1860
-	 *
1861
-	 * @since 1.0.19
1862
-	 * @return string
1863
-	 */
1864
-	public function get_subscription_name() {
1858
+    /**
1859
+     * Retrieves the subscription name.
1860
+     *
1861
+     * @since 1.0.19
1862
+     * @return string
1863
+     */
1864
+    public function get_subscription_name() {
1865 1865
 
1866
-		// Retrieve the recurring name
1866
+        // Retrieve the recurring name
1867 1867
         $item = $this->get_recurring( true );
1868 1868
 
1869
-		// Abort if it does not exist.
1869
+        // Abort if it does not exist.
1870 1870
         if ( empty( $item ) ) {
1871 1871
             return '';
1872 1872
         }
1873 1873
 
1874
-		// Return the item name.
1874
+        // Return the item name.
1875 1875
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1876
-	}
1877
-
1878
-	/**
1879
-	 * Retrieves the view url.
1880
-	 *
1881
-	 * @since 1.0.19
1882
-	 * @return string
1883
-	 */
1884
-	public function get_view_url() {
1876
+    }
1877
+
1878
+    /**
1879
+     * Retrieves the view url.
1880
+     *
1881
+     * @since 1.0.19
1882
+     * @return string
1883
+     */
1884
+    public function get_view_url() {
1885 1885
         $invoice_url = get_permalink( $this->get_id() );
1886
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1886
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1887 1887
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1888
-	}
1888
+    }
1889 1889
 
1890
-	/**
1891
-	 * Retrieves the payment url.
1892
-	 *
1893
-	 * @since 1.0.19
1894
-	 * @return string
1895
-	 */
1896
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1890
+    /**
1891
+     * Retrieves the payment url.
1892
+     *
1893
+     * @since 1.0.19
1894
+     * @return string
1895
+     */
1896
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1897 1897
 
1898
-		// Retrieve the checkout url.
1898
+        // Retrieve the checkout url.
1899 1899
         $pay_url = wpinv_get_checkout_uri();
1900 1900
 
1901
-		// Maybe force ssl.
1901
+        // Maybe force ssl.
1902 1902
         if ( is_ssl() ) {
1903 1903
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1904 1904
         }
1905 1905
 
1906
-		// Add the invoice key.
1907
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1906
+        // Add the invoice key.
1907
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1908 1908
 
1909
-		// (Maybe?) add a secret
1909
+        // (Maybe?) add a secret
1910 1910
         if ( $secret ) {
1911 1911
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1912 1912
         }
1913 1913
 
1914 1914
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1915
-	}
1915
+    }
1916 1916
 	
1917
-	/**
1918
-	 * Retrieves the receipt url.
1919
-	 *
1920
-	 * @since 1.0.19
1921
-	 * @return string
1922
-	 */
1923
-	public function get_receipt_url() {
1924
-
1925
-		// Retrieve the checkout url.
1917
+    /**
1918
+     * Retrieves the receipt url.
1919
+     *
1920
+     * @since 1.0.19
1921
+     * @return string
1922
+     */
1923
+    public function get_receipt_url() {
1924
+
1925
+        // Retrieve the checkout url.
1926 1926
         $receipt_url = wpinv_get_success_page_uri();
1927 1927
 
1928
-		// Maybe force ssl.
1928
+        // Maybe force ssl.
1929 1929
         if ( is_ssl() ) {
1930 1930
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1931 1931
         }
1932 1932
 
1933
-		// Add the invoice key.
1934
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1933
+        // Add the invoice key.
1934
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1935 1935
 
1936 1936
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1937
-	}
1938
-
1939
-	/**
1940
-	 * Retrieves the remote transaction url.
1941
-	 *
1942
-	 * @since 1.6.0
1943
-	 * @return string
1944
-	 */
1945
-	public function get_transaction_url() {
1946
-		return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this );
1947
-	}
1948
-
1949
-	/**
1950
-	 * Retrieves the default status.
1951
-	 *
1952
-	 * @since 1.0.19
1953
-	 * @return string
1954
-	 */
1955
-	public function get_default_status() {
1956
-
1957
-		$type   = $this->get_type();
1958
-		$status = "wpi-$type-pending";
1959
-		return str_replace( '-invoice', '', $status );
1960
-
1961
-	}
1962
-
1963
-    /**
1964
-	 * Magic method for accessing invoice properties.
1965
-	 *
1966
-	 * @since 1.0.15
1967
-	 * @access public
1968
-	 *
1969
-	 * @param string $key Discount data to retrieve
1970
-	 * @param  string $context View or edit context.
1971
-	 * @return mixed Value of the given invoice property (if set).
1972
-	 */
1973
-	public function get( $key, $context = 'view' ) {
1937
+    }
1938
+
1939
+    /**
1940
+     * Retrieves the remote transaction url.
1941
+     *
1942
+     * @since 1.6.0
1943
+     * @return string
1944
+     */
1945
+    public function get_transaction_url() {
1946
+        return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this );
1947
+    }
1948
+
1949
+    /**
1950
+     * Retrieves the default status.
1951
+     *
1952
+     * @since 1.0.19
1953
+     * @return string
1954
+     */
1955
+    public function get_default_status() {
1956
+
1957
+        $type   = $this->get_type();
1958
+        $status = "wpi-$type-pending";
1959
+        return str_replace( '-invoice', '', $status );
1960
+
1961
+    }
1962
+
1963
+    /**
1964
+     * Magic method for accessing invoice properties.
1965
+     *
1966
+     * @since 1.0.15
1967
+     * @access public
1968
+     *
1969
+     * @param string $key Discount data to retrieve
1970
+     * @param  string $context View or edit context.
1971
+     * @return mixed Value of the given invoice property (if set).
1972
+     */
1973
+    public function get( $key, $context = 'view' ) {
1974 1974
         return $this->get_prop( $key, $context );
1975
-	}
1975
+    }
1976 1976
 
1977 1977
     /*
1978 1978
 	|--------------------------------------------------------------------------
@@ -1985,130 +1985,130 @@  discard block
 block discarded – undo
1985 1985
     */
1986 1986
 
1987 1987
     /**
1988
-	 * Magic method for setting invoice properties.
1989
-	 *
1990
-	 * @since 1.0.19
1991
-	 * @access public
1992
-	 *
1993
-	 * @param string $key Discount data to retrieve
1994
-	 * @param  mixed $value new value.
1995
-	 * @return mixed Value of the given invoice property (if set).
1996
-	 */
1997
-	public function set( $key, $value ) {
1988
+     * Magic method for setting invoice properties.
1989
+     *
1990
+     * @since 1.0.19
1991
+     * @access public
1992
+     *
1993
+     * @param string $key Discount data to retrieve
1994
+     * @param  mixed $value new value.
1995
+     * @return mixed Value of the given invoice property (if set).
1996
+     */
1997
+    public function set( $key, $value ) {
1998 1998
 
1999 1999
         $setter = "set_$key";
2000 2000
         if ( is_callable( array( $this, $setter ) ) ) {
2001 2001
             $this->{$setter}( $value );
2002 2002
         }
2003 2003
 
2004
-	}
2004
+    }
2005 2005
 
2006
-	/**
2007
-	 * Sets item status.
2008
-	 *
2009
-	 * @since 1.0.19
2010
-	 * @param string $new_status    New status.
2011
-	 * @param string $note          Optional note to add.
2012
-	 * @param bool   $manual_update Is this a manual status change?.
2013
-	 * @return array details of change.
2014
-	 */
2015
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
2016
-		$old_status = $this->get_status();
2006
+    /**
2007
+     * Sets item status.
2008
+     *
2009
+     * @since 1.0.19
2010
+     * @param string $new_status    New status.
2011
+     * @param string $note          Optional note to add.
2012
+     * @param bool   $manual_update Is this a manual status change?.
2013
+     * @return array details of change.
2014
+     */
2015
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
2016
+        $old_status = $this->get_status();
2017 2017
 
2018
-		$statuses = $this->get_all_statuses();
2018
+        $statuses = $this->get_all_statuses();
2019 2019
 
2020
-		if ( isset( $statuses[ 'draft' ] ) ) {
2021
-			unset( $statuses[ 'draft' ] );
2022
-		}
2020
+        if ( isset( $statuses[ 'draft' ] ) ) {
2021
+            unset( $statuses[ 'draft' ] );
2022
+        }
2023 2023
 
2024
-		$this->set_prop( 'status', $new_status );
2024
+        $this->set_prop( 'status', $new_status );
2025 2025
 
2026
-		// If setting the status, ensure it's set to a valid status.
2027
-		if ( true === $this->object_read ) {
2026
+        // If setting the status, ensure it's set to a valid status.
2027
+        if ( true === $this->object_read ) {
2028 2028
 
2029
-			// Only allow valid new status.
2030
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
2031
-				$new_status = $this->get_default_status();
2032
-			}
2029
+            // Only allow valid new status.
2030
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
2031
+                $new_status = $this->get_default_status();
2032
+            }
2033 2033
 
2034
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
2035
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
2036
-				$old_status = $this->get_default_status();
2037
-			}
2034
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
2035
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
2036
+                $old_status = $this->get_default_status();
2037
+            }
2038 2038
 
2039
-			// Paid - Renewal (i.e when duplicating a parent invoice )
2040
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
2041
-				$old_status = 'wpi-pending';
2042
-			}
2039
+            // Paid - Renewal (i.e when duplicating a parent invoice )
2040
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
2041
+                $old_status = 'wpi-pending';
2042
+            }
2043 2043
 
2044
-			if ( $old_status !== $new_status ) {
2045
-				$this->status_transition = array(
2046
-					'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
2047
-					'to'     => $new_status,
2048
-					'note'   => $note,
2049
-					'manual' => (bool) $manual_update,
2050
-				);
2044
+            if ( $old_status !== $new_status ) {
2045
+                $this->status_transition = array(
2046
+                    'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
2047
+                    'to'     => $new_status,
2048
+                    'note'   => $note,
2049
+                    'manual' => (bool) $manual_update,
2050
+                );
2051 2051
 
2052
-				if ( $manual_update ) {
2053
-					do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
2054
-				}
2052
+                if ( $manual_update ) {
2053
+                    do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
2054
+                }
2055 2055
 
2056
-				$this->maybe_set_date_paid();
2056
+                $this->maybe_set_date_paid();
2057 2057
 
2058
-			}
2058
+            }
2059 2059
 
2060
-		}
2060
+        }
2061 2061
 
2062
-		return array(
2063
-			'from' => $old_status,
2064
-			'to'   => $new_status,
2065
-		);
2066
-	}
2062
+        return array(
2063
+            'from' => $old_status,
2064
+            'to'   => $new_status,
2065
+        );
2066
+    }
2067 2067
 
2068
-	/**
2069
-	 * Maybe set date paid.
2070
-	 *
2071
-	 * Sets the date paid variable when transitioning to the payment complete
2072
-	 * order status.
2073
-	 *
2074
-	 * @since 1.0.19
2075
-	 */
2076
-	public function maybe_set_date_paid() {
2068
+    /**
2069
+     * Maybe set date paid.
2070
+     *
2071
+     * Sets the date paid variable when transitioning to the payment complete
2072
+     * order status.
2073
+     *
2074
+     * @since 1.0.19
2075
+     */
2076
+    public function maybe_set_date_paid() {
2077 2077
 
2078
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
2079
-			$this->set_date_completed( current_time( 'mysql' ) );
2080
-		}
2081
-	}
2078
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
2079
+            $this->set_date_completed( current_time( 'mysql' ) );
2080
+        }
2081
+    }
2082 2082
 
2083 2083
     /**
2084
-	 * Set parent invoice ID.
2085
-	 *
2086
-	 * @since 1.0.19
2087
-	 */
2088
-	public function set_parent_id( $value ) {
2089
-		if ( $value && ( $value === $this->get_id() ) ) {
2090
-			return;
2091
-		}
2092
-		$this->set_prop( 'parent_id', absint( $value ) );
2084
+     * Set parent invoice ID.
2085
+     *
2086
+     * @since 1.0.19
2087
+     */
2088
+    public function set_parent_id( $value ) {
2089
+        if ( $value && ( $value === $this->get_id() ) ) {
2090
+            return;
2091
+        }
2092
+        $this->set_prop( 'parent_id', absint( $value ) );
2093 2093
     }
2094 2094
 
2095 2095
     /**
2096
-	 * Set plugin version when the invoice was created.
2097
-	 *
2098
-	 * @since 1.0.19
2099
-	 */
2100
-	public function set_version( $value ) {
2101
-		$this->set_prop( 'version', $value );
2096
+     * Set plugin version when the invoice was created.
2097
+     *
2098
+     * @since 1.0.19
2099
+     */
2100
+    public function set_version( $value ) {
2101
+        $this->set_prop( 'version', $value );
2102 2102
     }
2103
-
2104
-    /**
2105
-	 * Set date when the invoice was created.
2106
-	 *
2107
-	 * @since 1.0.19
2108
-	 * @param string $value Value to set.
2103
+
2104
+    /**
2105
+     * Set date when the invoice was created.
2106
+     *
2107
+     * @since 1.0.19
2108
+     * @param string $value Value to set.
2109 2109
      * @return bool Whether or not the date was set.
2110
-	 */
2111
-	public function set_date_created( $value ) {
2110
+     */
2111
+    public function set_date_created( $value ) {
2112 2112
         $date = strtotime( $value );
2113 2113
 
2114 2114
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2116,19 +2116,19 @@  discard block
 block discarded – undo
2116 2116
             return true;
2117 2117
         }
2118 2118
 
2119
-		$this->set_prop( 'date_created', '' );
2120
-		return false;
2119
+        $this->set_prop( 'date_created', '' );
2120
+        return false;
2121 2121
 
2122 2122
     }
2123 2123
 
2124 2124
     /**
2125
-	 * Set date invoice due date.
2126
-	 *
2127
-	 * @since 1.0.19
2128
-	 * @param string $value Value to set.
2125
+     * Set date invoice due date.
2126
+     *
2127
+     * @since 1.0.19
2128
+     * @param string $value Value to set.
2129 2129
      * @return bool Whether or not the date was set.
2130
-	 */
2131
-	public function set_due_date( $value ) {
2130
+     */
2131
+    public function set_due_date( $value ) {
2132 2132
         $date = strtotime( $value );
2133 2133
 
2134 2134
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2136,29 +2136,29 @@  discard block
 block discarded – undo
2136 2136
             return true;
2137 2137
         }
2138 2138
 
2139
-		$this->set_prop( 'due_date', '' );
2139
+        $this->set_prop( 'due_date', '' );
2140 2140
         return false;
2141 2141
 
2142 2142
     }
2143 2143
 
2144 2144
     /**
2145
-	 * Alias of self::set_due_date().
2146
-	 *
2147
-	 * @since 1.0.19
2148
-	 * @param  string $value New name.
2149
-	 */
2150
-	public function set_date_due( $value ) {
2151
-		$this->set_due_date( $value );
2145
+     * Alias of self::set_due_date().
2146
+     *
2147
+     * @since 1.0.19
2148
+     * @param  string $value New name.
2149
+     */
2150
+    public function set_date_due( $value ) {
2151
+        $this->set_due_date( $value );
2152 2152
     }
2153 2153
 
2154 2154
     /**
2155
-	 * Set date invoice was completed.
2156
-	 *
2157
-	 * @since 1.0.19
2158
-	 * @param string $value Value to set.
2155
+     * Set date invoice was completed.
2156
+     *
2157
+     * @since 1.0.19
2158
+     * @param string $value Value to set.
2159 2159
      * @return bool Whether or not the date was set.
2160
-	 */
2161
-	public function set_completed_date( $value ) {
2160
+     */
2161
+    public function set_completed_date( $value ) {
2162 2162
         $date = strtotime( $value );
2163 2163
 
2164 2164
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -2166,29 +2166,29 @@  discard block
 block discarded – undo
2166 2166
             return true;
2167 2167
         }
2168 2168
 
2169
-		$this->set_prop( 'completed_date', '' );
2169
+        $this->set_prop( 'completed_date', '' );
2170 2170
         return false;
2171 2171
 
2172 2172
     }
2173 2173
 
2174 2174
     /**
2175
-	 * Alias of self::set_completed_date().
2176
-	 *
2177
-	 * @since 1.0.19
2178
-	 * @param  string $value New name.
2179
-	 */
2180
-	public function set_date_completed( $value ) {
2181
-		$this->set_completed_date( $value );
2175
+     * Alias of self::set_completed_date().
2176
+     *
2177
+     * @since 1.0.19
2178
+     * @param  string $value New name.
2179
+     */
2180
+    public function set_date_completed( $value ) {
2181
+        $this->set_completed_date( $value );
2182 2182
     }
2183 2183
 
2184 2184
     /**
2185
-	 * Set date when the invoice was last modified.
2186
-	 *
2187
-	 * @since 1.0.19
2188
-	 * @param string $value Value to set.
2185
+     * Set date when the invoice was last modified.
2186
+     *
2187
+     * @since 1.0.19
2188
+     * @param string $value Value to set.
2189 2189
      * @return bool Whether or not the date was set.
2190
-	 */
2191
-	public function set_date_modified( $value ) {
2190
+     */
2191
+    public function set_date_modified( $value ) {
2192 2192
         $date = strtotime( $value );
2193 2193
 
2194 2194
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2196,813 +2196,813 @@  discard block
 block discarded – undo
2196 2196
             return true;
2197 2197
         }
2198 2198
 
2199
-		$this->set_prop( 'date_modified', '' );
2199
+        $this->set_prop( 'date_modified', '' );
2200 2200
         return false;
2201 2201
 
2202 2202
     }
2203 2203
 
2204 2204
     /**
2205
-	 * Set the invoice number.
2206
-	 *
2207
-	 * @since 1.0.19
2208
-	 * @param  string $value New number.
2209
-	 */
2210
-	public function set_number( $value ) {
2205
+     * Set the invoice number.
2206
+     *
2207
+     * @since 1.0.19
2208
+     * @param  string $value New number.
2209
+     */
2210
+    public function set_number( $value ) {
2211 2211
         $number = sanitize_text_field( $value );
2212
-		$this->set_prop( 'number', $number );
2212
+        $this->set_prop( 'number', $number );
2213 2213
     }
2214 2214
 
2215 2215
     /**
2216
-	 * Set the invoice type.
2217
-	 *
2218
-	 * @since 1.0.19
2219
-	 * @param  string $value Type.
2220
-	 */
2221
-	public function set_type( $value ) {
2216
+     * Set the invoice type.
2217
+     *
2218
+     * @since 1.0.19
2219
+     * @param  string $value Type.
2220
+     */
2221
+    public function set_type( $value ) {
2222 2222
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2223
-		$this->set_prop( 'type', $type );
2224
-	}
2223
+        $this->set_prop( 'type', $type );
2224
+    }
2225 2225
 
2226 2226
     /**
2227
-	 * Set the invoice post type.
2228
-	 *
2229
-	 * @since 1.0.19
2230
-	 * @param  string $value Post type.
2231
-	 */
2232
-	public function set_post_type( $value ) {
2227
+     * Set the invoice post type.
2228
+     *
2229
+     * @since 1.0.19
2230
+     * @param  string $value Post type.
2231
+     */
2232
+    public function set_post_type( $value ) {
2233 2233
         if ( getpaid_is_invoice_post_type( $value ) ) {
2234
-			$this->set_type( $value );
2234
+            $this->set_type( $value );
2235 2235
             $this->set_prop( 'post_type', $value );
2236 2236
         }
2237 2237
     }
2238 2238
 
2239 2239
     /**
2240
-	 * Set the invoice key.
2241
-	 *
2242
-	 * @since 1.0.19
2243
-	 * @param  string $value New key.
2244
-	 */
2245
-	public function set_key( $value ) {
2240
+     * Set the invoice key.
2241
+     *
2242
+     * @since 1.0.19
2243
+     * @param  string $value New key.
2244
+     */
2245
+    public function set_key( $value ) {
2246 2246
         $key = sanitize_text_field( $value );
2247
-		$this->set_prop( 'key', $key );
2247
+        $this->set_prop( 'key', $key );
2248 2248
     }
2249 2249
 
2250 2250
     /**
2251
-	 * Set the invoice mode.
2252
-	 *
2253
-	 * @since 1.0.19
2254
-	 * @param  string $value mode.
2255
-	 */
2256
-	public function set_mode( $value ) {
2251
+     * Set the invoice mode.
2252
+     *
2253
+     * @since 1.0.19
2254
+     * @param  string $value mode.
2255
+     */
2256
+    public function set_mode( $value ) {
2257 2257
         if ( in_array( $value, array( 'live', 'test' ) ) ) {
2258 2258
             $this->set_prop( 'mode', $value );
2259 2259
         }
2260 2260
     }
2261 2261
 
2262 2262
     /**
2263
-	 * Set the invoice path.
2264
-	 *
2265
-	 * @since 1.0.19
2266
-	 * @param  string $value path.
2267
-	 */
2268
-	public function set_path( $value ) {
2263
+     * Set the invoice path.
2264
+     *
2265
+     * @since 1.0.19
2266
+     * @param  string $value path.
2267
+     */
2268
+    public function set_path( $value ) {
2269 2269
         $this->set_prop( 'path', $value );
2270 2270
     }
2271 2271
 
2272 2272
     /**
2273
-	 * Set the invoice name.
2274
-	 *
2275
-	 * @since 1.0.19
2276
-	 * @param  string $value New name.
2277
-	 */
2278
-	public function set_name( $value ) {
2273
+     * Set the invoice name.
2274
+     *
2275
+     * @since 1.0.19
2276
+     * @param  string $value New name.
2277
+     */
2278
+    public function set_name( $value ) {
2279 2279
         $name = sanitize_text_field( $value );
2280
-		$this->set_prop( 'name', $name );
2280
+        $this->set_prop( 'name', $name );
2281 2281
     }
2282 2282
 
2283 2283
     /**
2284
-	 * Alias of self::set_name().
2285
-	 *
2286
-	 * @since 1.0.19
2287
-	 * @param  string $value New name.
2288
-	 */
2289
-	public function set_title( $value ) {
2290
-		$this->set_name( $value );
2284
+     * Alias of self::set_name().
2285
+     *
2286
+     * @since 1.0.19
2287
+     * @param  string $value New name.
2288
+     */
2289
+    public function set_title( $value ) {
2290
+        $this->set_name( $value );
2291 2291
     }
2292 2292
 
2293 2293
     /**
2294
-	 * Set the invoice description.
2295
-	 *
2296
-	 * @since 1.0.19
2297
-	 * @param  string $value New description.
2298
-	 */
2299
-	public function set_description( $value ) {
2294
+     * Set the invoice description.
2295
+     *
2296
+     * @since 1.0.19
2297
+     * @param  string $value New description.
2298
+     */
2299
+    public function set_description( $value ) {
2300 2300
         $description = wp_kses_post( $value );
2301
-		$this->set_prop( 'description', $description );
2301
+        $this->set_prop( 'description', $description );
2302
+    }
2303
+
2304
+    /**
2305
+     * Alias of self::set_description().
2306
+     *
2307
+     * @since 1.0.19
2308
+     * @param  string $value New description.
2309
+     */
2310
+    public function set_excerpt( $value ) {
2311
+        $this->set_description( $value );
2312
+    }
2313
+
2314
+    /**
2315
+     * Alias of self::set_description().
2316
+     *
2317
+     * @since 1.0.19
2318
+     * @param  string $value New description.
2319
+     */
2320
+    public function set_summary( $value ) {
2321
+        $this->set_description( $value );
2322
+    }
2323
+
2324
+    /**
2325
+     * Set the receiver of the invoice.
2326
+     *
2327
+     * @since 1.0.19
2328
+     * @param  int $value New author.
2329
+     */
2330
+    public function set_author( $value ) {
2331
+        $user = get_user_by( 'id', (int) $value );
2332
+
2333
+        if ( $user && $user->ID ) {
2334
+            $this->set_prop( 'author', $user->ID );
2335
+            $this->set_prop( 'email', $user->user_email );
2336
+        }
2337
+
2338
+    }
2339
+
2340
+    /**
2341
+     * Alias of self::set_author().
2342
+     *
2343
+     * @since 1.0.19
2344
+     * @param  int $value New user id.
2345
+     */
2346
+    public function set_user_id( $value ) {
2347
+        $this->set_author( $value );
2348
+    }
2349
+
2350
+    /**
2351
+     * Alias of self::set_author().
2352
+     *
2353
+     * @since 1.0.19
2354
+     * @param  int $value New user id.
2355
+     */
2356
+    public function set_customer_id( $value ) {
2357
+        $this->set_author( $value );
2358
+    }
2359
+
2360
+    /**
2361
+     * Set the customer's ip.
2362
+     *
2363
+     * @since 1.0.19
2364
+     * @param  string $value ip address.
2365
+     */
2366
+    public function set_ip( $value ) {
2367
+        $this->set_prop( 'ip', $value );
2368
+    }
2369
+
2370
+    /**
2371
+     * Alias of self::set_ip().
2372
+     *
2373
+     * @since 1.0.19
2374
+     * @param  string $value ip address.
2375
+     */
2376
+    public function set_user_ip( $value ) {
2377
+        $this->set_ip( $value );
2378
+    }
2379
+
2380
+    /**
2381
+     * Set the customer's first name.
2382
+     *
2383
+     * @since 1.0.19
2384
+     * @param  string $value first name.
2385
+     */
2386
+    public function set_first_name( $value ) {
2387
+        $this->set_prop( 'first_name', $value );
2388
+    }
2389
+
2390
+    /**
2391
+     * Alias of self::set_first_name().
2392
+     *
2393
+     * @since 1.0.19
2394
+     * @param  string $value first name.
2395
+     */
2396
+    public function set_user_first_name( $value ) {
2397
+        $this->set_first_name( $value );
2398
+    }
2399
+
2400
+    /**
2401
+     * Alias of self::set_first_name().
2402
+     *
2403
+     * @since 1.0.19
2404
+     * @param  string $value first name.
2405
+     */
2406
+    public function set_customer_first_name( $value ) {
2407
+        $this->set_first_name( $value );
2408
+    }
2409
+
2410
+    /**
2411
+     * Set the customer's last name.
2412
+     *
2413
+     * @since 1.0.19
2414
+     * @param  string $value last name.
2415
+     */
2416
+    public function set_last_name( $value ) {
2417
+        $this->set_prop( 'last_name', $value );
2418
+    }
2419
+
2420
+    /**
2421
+     * Alias of self::set_last_name().
2422
+     *
2423
+     * @since 1.0.19
2424
+     * @param  string $value last name.
2425
+     */
2426
+    public function set_user_last_name( $value ) {
2427
+        $this->set_last_name( $value );
2428
+    }
2429
+
2430
+    /**
2431
+     * Alias of self::set_last_name().
2432
+     *
2433
+     * @since 1.0.19
2434
+     * @param  string $value last name.
2435
+     */
2436
+    public function set_customer_last_name( $value ) {
2437
+        $this->set_last_name( $value );
2438
+    }
2439
+
2440
+    /**
2441
+     * Set the customer's phone number.
2442
+     *
2443
+     * @since 1.0.19
2444
+     * @param  string $value phone.
2445
+     */
2446
+    public function set_phone( $value ) {
2447
+        $this->set_prop( 'phone', $value );
2302 2448
     }
2303 2449
 
2304 2450
     /**
2305
-	 * Alias of self::set_description().
2306
-	 *
2307
-	 * @since 1.0.19
2308
-	 * @param  string $value New description.
2309
-	 */
2310
-	public function set_excerpt( $value ) {
2311
-		$this->set_description( $value );
2451
+     * Alias of self::set_phone().
2452
+     *
2453
+     * @since 1.0.19
2454
+     * @param  string $value phone.
2455
+     */
2456
+    public function set_user_phone( $value ) {
2457
+        $this->set_phone( $value );
2312 2458
     }
2313 2459
 
2314 2460
     /**
2315
-	 * Alias of self::set_description().
2316
-	 *
2317
-	 * @since 1.0.19
2318
-	 * @param  string $value New description.
2319
-	 */
2320
-	public function set_summary( $value ) {
2321
-		$this->set_description( $value );
2461
+     * Alias of self::set_phone().
2462
+     *
2463
+     * @since 1.0.19
2464
+     * @param  string $value phone.
2465
+     */
2466
+    public function set_customer_phone( $value ) {
2467
+        $this->set_phone( $value );
2322 2468
     }
2323 2469
 
2324 2470
     /**
2325
-	 * Set the receiver of the invoice.
2326
-	 *
2327
-	 * @since 1.0.19
2328
-	 * @param  int $value New author.
2329
-	 */
2330
-	public function set_author( $value ) {
2331
-		$user = get_user_by( 'id', (int) $value );
2471
+     * Alias of self::set_phone().
2472
+     *
2473
+     * @since 1.0.19
2474
+     * @param  string $value phone.
2475
+     */
2476
+    public function set_phone_number( $value ) {
2477
+        $this->set_phone( $value );
2478
+    }
2332 2479
 
2333
-		if ( $user && $user->ID ) {
2334
-			$this->set_prop( 'author', $user->ID );
2335
-			$this->set_prop( 'email', $user->user_email );
2336
-		}
2480
+    /**
2481
+     * Set the customer's email address.
2482
+     *
2483
+     * @since 1.0.19
2484
+     * @param  string $value email address.
2485
+     */
2486
+    public function set_email( $value ) {
2487
+        $this->set_prop( 'email', $value );
2488
+    }
2337 2489
 
2490
+    /**
2491
+     * Alias of self::set_email().
2492
+     *
2493
+     * @since 1.0.19
2494
+     * @param  string $value email address.
2495
+     */
2496
+    public function set_user_email( $value ) {
2497
+        $this->set_email( $value );
2338 2498
     }
2339 2499
 
2340 2500
     /**
2341
-	 * Alias of self::set_author().
2342
-	 *
2343
-	 * @since 1.0.19
2344
-	 * @param  int $value New user id.
2345
-	 */
2346
-	public function set_user_id( $value ) {
2347
-		$this->set_author( $value );
2501
+     * Alias of self::set_email().
2502
+     *
2503
+     * @since 1.0.19
2504
+     * @param  string $value email address.
2505
+     */
2506
+    public function set_email_address( $value ) {
2507
+        $this->set_email( $value );
2348 2508
     }
2349 2509
 
2350 2510
     /**
2351
-	 * Alias of self::set_author().
2352
-	 *
2353
-	 * @since 1.0.19
2354
-	 * @param  int $value New user id.
2355
-	 */
2356
-	public function set_customer_id( $value ) {
2357
-		$this->set_author( $value );
2511
+     * Alias of self::set_email().
2512
+     *
2513
+     * @since 1.0.19
2514
+     * @param  string $value email address.
2515
+     */
2516
+    public function set_customer_email( $value ) {
2517
+        $this->set_email( $value );
2358 2518
     }
2359 2519
 
2360 2520
     /**
2361
-	 * Set the customer's ip.
2362
-	 *
2363
-	 * @since 1.0.19
2364
-	 * @param  string $value ip address.
2365
-	 */
2366
-	public function set_ip( $value ) {
2367
-		$this->set_prop( 'ip', $value );
2521
+     * Set the customer's country.
2522
+     *
2523
+     * @since 1.0.19
2524
+     * @param  string $value country.
2525
+     */
2526
+    public function set_country( $value ) {
2527
+        $this->set_prop( 'country', $value );
2368 2528
     }
2369 2529
 
2370 2530
     /**
2371
-	 * Alias of self::set_ip().
2372
-	 *
2373
-	 * @since 1.0.19
2374
-	 * @param  string $value ip address.
2375
-	 */
2376
-	public function set_user_ip( $value ) {
2377
-		$this->set_ip( $value );
2531
+     * Alias of self::set_country().
2532
+     *
2533
+     * @since 1.0.19
2534
+     * @param  string $value country.
2535
+     */
2536
+    public function set_user_country( $value ) {
2537
+        $this->set_country( $value );
2378 2538
     }
2379 2539
 
2380 2540
     /**
2381
-	 * Set the customer's first name.
2382
-	 *
2383
-	 * @since 1.0.19
2384
-	 * @param  string $value first name.
2385
-	 */
2386
-	public function set_first_name( $value ) {
2387
-		$this->set_prop( 'first_name', $value );
2541
+     * Alias of self::set_country().
2542
+     *
2543
+     * @since 1.0.19
2544
+     * @param  string $value country.
2545
+     */
2546
+    public function set_customer_country( $value ) {
2547
+        $this->set_country( $value );
2388 2548
     }
2389 2549
 
2390 2550
     /**
2391
-	 * Alias of self::set_first_name().
2392
-	 *
2393
-	 * @since 1.0.19
2394
-	 * @param  string $value first name.
2395
-	 */
2396
-	public function set_user_first_name( $value ) {
2397
-		$this->set_first_name( $value );
2551
+     * Set the customer's state.
2552
+     *
2553
+     * @since 1.0.19
2554
+     * @param  string $value state.
2555
+     */
2556
+    public function set_state( $value ) {
2557
+        $this->set_prop( 'state', $value );
2398 2558
     }
2399 2559
 
2400 2560
     /**
2401
-	 * Alias of self::set_first_name().
2402
-	 *
2403
-	 * @since 1.0.19
2404
-	 * @param  string $value first name.
2405
-	 */
2406
-	public function set_customer_first_name( $value ) {
2407
-		$this->set_first_name( $value );
2561
+     * Alias of self::set_state().
2562
+     *
2563
+     * @since 1.0.19
2564
+     * @param  string $value state.
2565
+     */
2566
+    public function set_user_state( $value ) {
2567
+        $this->set_state( $value );
2408 2568
     }
2409 2569
 
2410 2570
     /**
2411
-	 * Set the customer's last name.
2412
-	 *
2413
-	 * @since 1.0.19
2414
-	 * @param  string $value last name.
2415
-	 */
2416
-	public function set_last_name( $value ) {
2417
-		$this->set_prop( 'last_name', $value );
2571
+     * Alias of self::set_state().
2572
+     *
2573
+     * @since 1.0.19
2574
+     * @param  string $value state.
2575
+     */
2576
+    public function set_customer_state( $value ) {
2577
+        $this->set_state( $value );
2418 2578
     }
2419 2579
 
2420 2580
     /**
2421
-	 * Alias of self::set_last_name().
2422
-	 *
2423
-	 * @since 1.0.19
2424
-	 * @param  string $value last name.
2425
-	 */
2426
-	public function set_user_last_name( $value ) {
2427
-		$this->set_last_name( $value );
2581
+     * Set the customer's city.
2582
+     *
2583
+     * @since 1.0.19
2584
+     * @param  string $value city.
2585
+     */
2586
+    public function set_city( $value ) {
2587
+        $this->set_prop( 'city', $value );
2428 2588
     }
2429 2589
 
2430 2590
     /**
2431
-	 * Alias of self::set_last_name().
2432
-	 *
2433
-	 * @since 1.0.19
2434
-	 * @param  string $value last name.
2435
-	 */
2436
-	public function set_customer_last_name( $value ) {
2437
-		$this->set_last_name( $value );
2591
+     * Alias of self::set_city().
2592
+     *
2593
+     * @since 1.0.19
2594
+     * @param  string $value city.
2595
+     */
2596
+    public function set_user_city( $value ) {
2597
+        $this->set_city( $value );
2438 2598
     }
2439 2599
 
2440 2600
     /**
2441
-	 * Set the customer's phone number.
2442
-	 *
2443
-	 * @since 1.0.19
2444
-	 * @param  string $value phone.
2445
-	 */
2446
-	public function set_phone( $value ) {
2447
-		$this->set_prop( 'phone', $value );
2601
+     * Alias of self::set_city().
2602
+     *
2603
+     * @since 1.0.19
2604
+     * @param  string $value city.
2605
+     */
2606
+    public function set_customer_city( $value ) {
2607
+        $this->set_city( $value );
2448 2608
     }
2449 2609
 
2450 2610
     /**
2451
-	 * Alias of self::set_phone().
2452
-	 *
2453
-	 * @since 1.0.19
2454
-	 * @param  string $value phone.
2455
-	 */
2456
-	public function set_user_phone( $value ) {
2457
-		$this->set_phone( $value );
2611
+     * Set the customer's zip code.
2612
+     *
2613
+     * @since 1.0.19
2614
+     * @param  string $value zip.
2615
+     */
2616
+    public function set_zip( $value ) {
2617
+        $this->set_prop( 'zip', $value );
2458 2618
     }
2459 2619
 
2460 2620
     /**
2461
-	 * Alias of self::set_phone().
2462
-	 *
2463
-	 * @since 1.0.19
2464
-	 * @param  string $value phone.
2465
-	 */
2466
-	public function set_customer_phone( $value ) {
2467
-		$this->set_phone( $value );
2621
+     * Alias of self::set_zip().
2622
+     *
2623
+     * @since 1.0.19
2624
+     * @param  string $value zip.
2625
+     */
2626
+    public function set_user_zip( $value ) {
2627
+        $this->set_zip( $value );
2468 2628
     }
2469 2629
 
2470 2630
     /**
2471
-	 * Alias of self::set_phone().
2472
-	 *
2473
-	 * @since 1.0.19
2474
-	 * @param  string $value phone.
2475
-	 */
2476
-	public function set_phone_number( $value ) {
2477
-		$this->set_phone( $value );
2631
+     * Alias of self::set_zip().
2632
+     *
2633
+     * @since 1.0.19
2634
+     * @param  string $value zip.
2635
+     */
2636
+    public function set_customer_zip( $value ) {
2637
+        $this->set_zip( $value );
2478 2638
     }
2479 2639
 
2480 2640
     /**
2481
-	 * Set the customer's email address.
2482
-	 *
2483
-	 * @since 1.0.19
2484
-	 * @param  string $value email address.
2485
-	 */
2486
-	public function set_email( $value ) {
2487
-		$this->set_prop( 'email', $value );
2641
+     * Set the customer's company.
2642
+     *
2643
+     * @since 1.0.19
2644
+     * @param  string $value company.
2645
+     */
2646
+    public function set_company( $value ) {
2647
+        $this->set_prop( 'company', $value );
2488 2648
     }
2489 2649
 
2490 2650
     /**
2491
-	 * Alias of self::set_email().
2492
-	 *
2493
-	 * @since 1.0.19
2494
-	 * @param  string $value email address.
2495
-	 */
2496
-	public function set_user_email( $value ) {
2497
-		$this->set_email( $value );
2651
+     * Alias of self::set_company().
2652
+     *
2653
+     * @since 1.0.19
2654
+     * @param  string $value company.
2655
+     */
2656
+    public function set_user_company( $value ) {
2657
+        $this->set_company( $value );
2498 2658
     }
2499 2659
 
2500 2660
     /**
2501
-	 * Alias of self::set_email().
2502
-	 *
2503
-	 * @since 1.0.19
2504
-	 * @param  string $value email address.
2505
-	 */
2506
-	public function set_email_address( $value ) {
2507
-		$this->set_email( $value );
2661
+     * Alias of self::set_company().
2662
+     *
2663
+     * @since 1.0.19
2664
+     * @param  string $value company.
2665
+     */
2666
+    public function set_customer_company( $value ) {
2667
+        $this->set_company( $value );
2508 2668
     }
2509 2669
 
2510 2670
     /**
2511
-	 * Alias of self::set_email().
2512
-	 *
2513
-	 * @since 1.0.19
2514
-	 * @param  string $value email address.
2515
-	 */
2516
-	public function set_customer_email( $value ) {
2517
-		$this->set_email( $value );
2671
+     * Set the customer's company id.
2672
+     *
2673
+     * @since 1.0.19
2674
+     * @param  string $value company id.
2675
+     */
2676
+    public function set_company_id( $value ) {
2677
+        $this->set_prop( 'company_id', $value );
2518 2678
     }
2519 2679
 
2520 2680
     /**
2521
-	 * Set the customer's country.
2522
-	 *
2523
-	 * @since 1.0.19
2524
-	 * @param  string $value country.
2525
-	 */
2526
-	public function set_country( $value ) {
2527
-		$this->set_prop( 'country', $value );
2681
+     * Set the customer's var number.
2682
+     *
2683
+     * @since 1.0.19
2684
+     * @param  string $value var number.
2685
+     */
2686
+    public function set_vat_number( $value ) {
2687
+        $this->set_prop( 'vat_number', $value );
2528 2688
     }
2529 2689
 
2530 2690
     /**
2531
-	 * Alias of self::set_country().
2532
-	 *
2533
-	 * @since 1.0.19
2534
-	 * @param  string $value country.
2535
-	 */
2536
-	public function set_user_country( $value ) {
2537
-		$this->set_country( $value );
2691
+     * Alias of self::set_vat_number().
2692
+     *
2693
+     * @since 1.0.19
2694
+     * @param  string $value var number.
2695
+     */
2696
+    public function set_user_vat_number( $value ) {
2697
+        $this->set_vat_number( $value );
2538 2698
     }
2539 2699
 
2540 2700
     /**
2541
-	 * Alias of self::set_country().
2542
-	 *
2543
-	 * @since 1.0.19
2544
-	 * @param  string $value country.
2545
-	 */
2546
-	public function set_customer_country( $value ) {
2547
-		$this->set_country( $value );
2701
+     * Alias of self::set_vat_number().
2702
+     *
2703
+     * @since 1.0.19
2704
+     * @param  string $value var number.
2705
+     */
2706
+    public function set_customer_vat_number( $value ) {
2707
+        $this->set_vat_number( $value );
2548 2708
     }
2549 2709
 
2550 2710
     /**
2551
-	 * Set the customer's state.
2552
-	 *
2553
-	 * @since 1.0.19
2554
-	 * @param  string $value state.
2555
-	 */
2556
-	public function set_state( $value ) {
2557
-		$this->set_prop( 'state', $value );
2711
+     * Set the customer's vat rate.
2712
+     *
2713
+     * @since 1.0.19
2714
+     * @param  string $value var rate.
2715
+     */
2716
+    public function set_vat_rate( $value ) {
2717
+        $this->set_prop( 'vat_rate', $value );
2558 2718
     }
2559 2719
 
2560 2720
     /**
2561
-	 * Alias of self::set_state().
2562
-	 *
2563
-	 * @since 1.0.19
2564
-	 * @param  string $value state.
2565
-	 */
2566
-	public function set_user_state( $value ) {
2567
-		$this->set_state( $value );
2721
+     * Alias of self::set_vat_rate().
2722
+     *
2723
+     * @since 1.0.19
2724
+     * @param  string $value var number.
2725
+     */
2726
+    public function set_user_vat_rate( $value ) {
2727
+        $this->set_vat_rate( $value );
2568 2728
     }
2569 2729
 
2570 2730
     /**
2571
-	 * Alias of self::set_state().
2572
-	 *
2573
-	 * @since 1.0.19
2574
-	 * @param  string $value state.
2575
-	 */
2576
-	public function set_customer_state( $value ) {
2577
-		$this->set_state( $value );
2731
+     * Alias of self::set_vat_rate().
2732
+     *
2733
+     * @since 1.0.19
2734
+     * @param  string $value var number.
2735
+     */
2736
+    public function set_customer_vat_rate( $value ) {
2737
+        $this->set_vat_rate( $value );
2578 2738
     }
2579 2739
 
2580 2740
     /**
2581
-	 * Set the customer's city.
2582
-	 *
2583
-	 * @since 1.0.19
2584
-	 * @param  string $value city.
2585
-	 */
2586
-	public function set_city( $value ) {
2587
-		$this->set_prop( 'city', $value );
2741
+     * Set the customer's address.
2742
+     *
2743
+     * @since 1.0.19
2744
+     * @param  string $value address.
2745
+     */
2746
+    public function set_address( $value ) {
2747
+        $this->set_prop( 'address', $value );
2588 2748
     }
2589 2749
 
2590 2750
     /**
2591
-	 * Alias of self::set_city().
2592
-	 *
2593
-	 * @since 1.0.19
2594
-	 * @param  string $value city.
2595
-	 */
2596
-	public function set_user_city( $value ) {
2597
-		$this->set_city( $value );
2751
+     * Alias of self::set_address().
2752
+     *
2753
+     * @since 1.0.19
2754
+     * @param  string $value address.
2755
+     */
2756
+    public function set_user_address( $value ) {
2757
+        $this->set_address( $value );
2598 2758
     }
2599 2759
 
2600 2760
     /**
2601
-	 * Alias of self::set_city().
2602
-	 *
2603
-	 * @since 1.0.19
2604
-	 * @param  string $value city.
2605
-	 */
2606
-	public function set_customer_city( $value ) {
2607
-		$this->set_city( $value );
2761
+     * Alias of self::set_address().
2762
+     *
2763
+     * @since 1.0.19
2764
+     * @param  string $value address.
2765
+     */
2766
+    public function set_customer_address( $value ) {
2767
+        $this->set_address( $value );
2608 2768
     }
2609 2769
 
2610 2770
     /**
2611
-	 * Set the customer's zip code.
2612
-	 *
2613
-	 * @since 1.0.19
2614
-	 * @param  string $value zip.
2615
-	 */
2616
-	public function set_zip( $value ) {
2617
-		$this->set_prop( 'zip', $value );
2771
+     * Set whether the customer has viewed the invoice or not.
2772
+     *
2773
+     * @since 1.0.19
2774
+     * @param  int|bool $value confirmed.
2775
+     */
2776
+    public function set_is_viewed( $value ) {
2777
+        $this->set_prop( 'is_viewed', $value );
2618 2778
     }
2619 2779
 
2620 2780
     /**
2621
-	 * Alias of self::set_zip().
2622
-	 *
2623
-	 * @since 1.0.19
2624
-	 * @param  string $value zip.
2625
-	 */
2626
-	public function set_user_zip( $value ) {
2627
-		$this->set_zip( $value );
2781
+     * Set extra email recipients.
2782
+     *
2783
+     * @since 1.0.19
2784
+     * @param  string $value email recipients.
2785
+     */
2786
+    public function set_email_cc( $value ) {
2787
+        $this->set_prop( 'email_cc', $value );
2628 2788
     }
2629 2789
 
2630 2790
     /**
2631
-	 * Alias of self::set_zip().
2632
-	 *
2633
-	 * @since 1.0.19
2634
-	 * @param  string $value zip.
2635
-	 */
2636
-	public function set_customer_zip( $value ) {
2637
-		$this->set_zip( $value );
2791
+     * Set the invoice template.
2792
+     *
2793
+     * @since 1.0.19
2794
+     * @param  string $value template.
2795
+     */
2796
+    public function set_template( $value ) {
2797
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2798
+            $this->set_prop( 'template', $value );
2799
+        }
2638 2800
     }
2639 2801
 
2640 2802
     /**
2641
-	 * Set the customer's company.
2642
-	 *
2643
-	 * @since 1.0.19
2644
-	 * @param  string $value company.
2645
-	 */
2646
-	public function set_company( $value ) {
2647
-		$this->set_prop( 'company', $value );
2803
+     * Set the invoice source.
2804
+     *
2805
+     * @since 1.0.19
2806
+     * @param  string $value source.
2807
+     * @deprecated
2808
+     */
2809
+    public function created_via( $value ) {
2810
+        $this->set_created_via( sanitize_text_field( $value ) );
2648 2811
     }
2649 2812
 
2650 2813
     /**
2651
-	 * Alias of self::set_company().
2652
-	 *
2653
-	 * @since 1.0.19
2654
-	 * @param  string $value company.
2655
-	 */
2656
-	public function set_user_company( $value ) {
2657
-		$this->set_company( $value );
2814
+     * Set the invoice source.
2815
+     *
2816
+     * @since 1.0.19
2817
+     * @param  string $value source.
2818
+     */
2819
+    public function set_created_via( $value ) {
2820
+        $this->set_prop( 'created_via', sanitize_text_field( $value ) );
2658 2821
     }
2659 2822
 
2660 2823
     /**
2661
-	 * Alias of self::set_company().
2662
-	 *
2663
-	 * @since 1.0.19
2664
-	 * @param  string $value company.
2665
-	 */
2666
-	public function set_customer_company( $value ) {
2667
-		$this->set_company( $value );
2668
-    }
2669
-
2670
-	/**
2671
-	 * Set the customer's company id.
2672
-	 *
2673
-	 * @since 1.0.19
2674
-	 * @param  string $value company id.
2675
-	 */
2676
-	public function set_company_id( $value ) {
2677
-		$this->set_prop( 'company_id', $value );
2824
+     * Set the customer's address confirmed status.
2825
+     *
2826
+     * @since 1.0.19
2827
+     * @param  int|bool $value confirmed.
2828
+     */
2829
+    public function set_address_confirmed( $value ) {
2830
+        $this->set_prop( 'address_confirmed', $value );
2678 2831
     }
2679 2832
 
2680 2833
     /**
2681
-	 * Set the customer's var number.
2682
-	 *
2683
-	 * @since 1.0.19
2684
-	 * @param  string $value var number.
2685
-	 */
2686
-	public function set_vat_number( $value ) {
2687
-		$this->set_prop( 'vat_number', $value );
2834
+     * Alias of self::set_address_confirmed().
2835
+     *
2836
+     * @since 1.0.19
2837
+     * @param  int|bool $value confirmed.
2838
+     */
2839
+    public function set_user_address_confirmed( $value ) {
2840
+        $this->set_address_confirmed( $value );
2688 2841
     }
2689 2842
 
2690 2843
     /**
2691
-	 * Alias of self::set_vat_number().
2692
-	 *
2693
-	 * @since 1.0.19
2694
-	 * @param  string $value var number.
2695
-	 */
2696
-	public function set_user_vat_number( $value ) {
2697
-		$this->set_vat_number( $value );
2844
+     * Alias of self::set_address_confirmed().
2845
+     *
2846
+     * @since 1.0.19
2847
+     * @param  int|bool $value confirmed.
2848
+     */
2849
+    public function set_customer_address_confirmed( $value ) {
2850
+        $this->set_address_confirmed( $value );
2698 2851
     }
2699 2852
 
2700 2853
     /**
2701
-	 * Alias of self::set_vat_number().
2702
-	 *
2703
-	 * @since 1.0.19
2704
-	 * @param  string $value var number.
2705
-	 */
2706
-	public function set_customer_vat_number( $value ) {
2707
-		$this->set_vat_number( $value );
2854
+     * Set the shipping fee
2855
+     *
2856
+     * @since 1.0.19
2857
+     * @param  float $value shipping amount.
2858
+     */
2859
+    public function set_shipping( $value ) {
2860
+
2861
+        if ( ! is_numeric( $value ) ) {
2862
+            return $this->set_prop( 'shipping', null );
2863
+        }
2864
+
2865
+        $this->set_prop( 'shipping', max( 0, floatval( $value ) ) );
2708 2866
     }
2709 2867
 
2710 2868
     /**
2711
-	 * Set the customer's vat rate.
2712
-	 *
2713
-	 * @since 1.0.19
2714
-	 * @param  string $value var rate.
2715
-	 */
2716
-	public function set_vat_rate( $value ) {
2717
-		$this->set_prop( 'vat_rate', $value );
2869
+     * Set the invoice sub total.
2870
+     *
2871
+     * @since 1.0.19
2872
+     * @param  float $value sub total.
2873
+     */
2874
+    public function set_subtotal( $value ) {
2875
+        $this->set_prop( 'subtotal', max( 0, $value ) );
2718 2876
     }
2719 2877
 
2720
-    /**
2721
-	 * Alias of self::set_vat_rate().
2722
-	 *
2723
-	 * @since 1.0.19
2724
-	 * @param  string $value var number.
2725
-	 */
2726
-	public function set_user_vat_rate( $value ) {
2727
-		$this->set_vat_rate( $value );
2728
-    }
2729
-
2730
-    /**
2731
-	 * Alias of self::set_vat_rate().
2732
-	 *
2733
-	 * @since 1.0.19
2734
-	 * @param  string $value var number.
2735
-	 */
2736
-	public function set_customer_vat_rate( $value ) {
2737
-		$this->set_vat_rate( $value );
2738
-    }
2739
-
2740
-    /**
2741
-	 * Set the customer's address.
2742
-	 *
2743
-	 * @since 1.0.19
2744
-	 * @param  string $value address.
2745
-	 */
2746
-	public function set_address( $value ) {
2747
-		$this->set_prop( 'address', $value );
2748
-    }
2749
-
2750
-    /**
2751
-	 * Alias of self::set_address().
2752
-	 *
2753
-	 * @since 1.0.19
2754
-	 * @param  string $value address.
2755
-	 */
2756
-	public function set_user_address( $value ) {
2757
-		$this->set_address( $value );
2758
-    }
2759
-
2760
-    /**
2761
-	 * Alias of self::set_address().
2762
-	 *
2763
-	 * @since 1.0.19
2764
-	 * @param  string $value address.
2765
-	 */
2766
-	public function set_customer_address( $value ) {
2767
-		$this->set_address( $value );
2768
-    }
2769
-
2770
-    /**
2771
-	 * Set whether the customer has viewed the invoice or not.
2772
-	 *
2773
-	 * @since 1.0.19
2774
-	 * @param  int|bool $value confirmed.
2775
-	 */
2776
-	public function set_is_viewed( $value ) {
2777
-		$this->set_prop( 'is_viewed', $value );
2778
-	}
2779
-
2780
-	/**
2781
-	 * Set extra email recipients.
2782
-	 *
2783
-	 * @since 1.0.19
2784
-	 * @param  string $value email recipients.
2785
-	 */
2786
-	public function set_email_cc( $value ) {
2787
-		$this->set_prop( 'email_cc', $value );
2788
-	}
2789
-
2790
-	/**
2791
-	 * Set the invoice template.
2792
-	 *
2793
-	 * @since 1.0.19
2794
-	 * @param  string $value template.
2795
-	 */
2796
-	public function set_template( $value ) {
2797
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2798
-			$this->set_prop( 'template', $value );
2799
-		}
2800
-	}
2801
-
2802
-	/**
2803
-	 * Set the invoice source.
2804
-	 *
2805
-	 * @since 1.0.19
2806
-	 * @param  string $value source.
2807
-	 * @deprecated
2808
-	 */
2809
-	public function created_via( $value ) {
2810
-		$this->set_created_via( sanitize_text_field( $value ) );
2811
-	}
2812
-
2813
-	/**
2814
-	 * Set the invoice source.
2815
-	 *
2816
-	 * @since 1.0.19
2817
-	 * @param  string $value source.
2818
-	 */
2819
-	public function set_created_via( $value ) {
2820
-		$this->set_prop( 'created_via', sanitize_text_field( $value ) );
2821
-	}
2822
-
2823
-	/**
2824
-	 * Set the customer's address confirmed status.
2825
-	 *
2826
-	 * @since 1.0.19
2827
-	 * @param  int|bool $value confirmed.
2828
-	 */
2829
-	public function set_address_confirmed( $value ) {
2830
-		$this->set_prop( 'address_confirmed', $value );
2831
-    }
2832
-
2833
-    /**
2834
-	 * Alias of self::set_address_confirmed().
2835
-	 *
2836
-	 * @since 1.0.19
2837
-	 * @param  int|bool $value confirmed.
2838
-	 */
2839
-	public function set_user_address_confirmed( $value ) {
2840
-		$this->set_address_confirmed( $value );
2841
-    }
2842
-
2843
-    /**
2844
-	 * Alias of self::set_address_confirmed().
2845
-	 *
2846
-	 * @since 1.0.19
2847
-	 * @param  int|bool $value confirmed.
2848
-	 */
2849
-	public function set_customer_address_confirmed( $value ) {
2850
-		$this->set_address_confirmed( $value );
2851
-    }
2852
-
2853
-    /**
2854
-	 * Set the shipping fee
2855
-	 *
2856
-	 * @since 1.0.19
2857
-	 * @param  float $value shipping amount.
2858
-	 */
2859
-	public function set_shipping( $value ) {
2860
-
2861
-		if ( ! is_numeric( $value ) ) {
2862
-			return $this->set_prop( 'shipping', null );
2863
-		}
2864
-
2865
-		$this->set_prop( 'shipping', max( 0, floatval( $value ) ) );
2866
-	}
2867
-
2868
-	/**
2869
-	 * Set the invoice sub total.
2870
-	 *
2871
-	 * @since 1.0.19
2872
-	 * @param  float $value sub total.
2873
-	 */
2874
-	public function set_subtotal( $value ) {
2875
-		$this->set_prop( 'subtotal', max( 0, $value ) );
2876
-	}
2877
-
2878
-	/**
2879
-	 * Set the invoice total.
2880
-	 *
2881
-	 * @since 1.0.19
2882
-	 * @param  float $value sub total.
2883
-	 */
2884
-	public function set_total( $value ) {
2885
-		$this->set_prop( 'total', max( 0, $value ) );
2878
+    /**
2879
+     * Set the invoice total.
2880
+     *
2881
+     * @since 1.0.19
2882
+     * @param  float $value sub total.
2883
+     */
2884
+    public function set_total( $value ) {
2885
+        $this->set_prop( 'total', max( 0, $value ) );
2886 2886
     }
2887 2887
 
2888 2888
     /**
2889
-	 * Set the invoice discount amount.
2890
-	 *
2891
-	 * @since 1.0.19
2892
-	 * @param  float $value discount total.
2893
-	 */
2894
-	public function set_total_discount( $value ) {
2895
-		$this->set_prop( 'total_discount', max( 0, $value ) );
2889
+     * Set the invoice discount amount.
2890
+     *
2891
+     * @since 1.0.19
2892
+     * @param  float $value discount total.
2893
+     */
2894
+    public function set_total_discount( $value ) {
2895
+        $this->set_prop( 'total_discount', max( 0, $value ) );
2896 2896
     }
2897 2897
 
2898 2898
     /**
2899
-	 * Alias of self::set_total_discount().
2900
-	 *
2901
-	 * @since 1.0.19
2902
-	 * @param  float $value discount total.
2903
-	 */
2904
-	public function set_discount( $value ) {
2905
-		$this->set_total_discount( $value );
2899
+     * Alias of self::set_total_discount().
2900
+     *
2901
+     * @since 1.0.19
2902
+     * @param  float $value discount total.
2903
+     */
2904
+    public function set_discount( $value ) {
2905
+        $this->set_total_discount( $value );
2906 2906
     }
2907 2907
 
2908 2908
     /**
2909
-	 * Set the invoice tax amount.
2910
-	 *
2911
-	 * @since 1.0.19
2912
-	 * @param  float $value tax total.
2913
-	 */
2914
-	public function set_total_tax( $value ) {
2915
-		$this->set_prop( 'total_tax', max( 0, $value ) );
2909
+     * Set the invoice tax amount.
2910
+     *
2911
+     * @since 1.0.19
2912
+     * @param  float $value tax total.
2913
+     */
2914
+    public function set_total_tax( $value ) {
2915
+        $this->set_prop( 'total_tax', max( 0, $value ) );
2916 2916
     }
2917 2917
 
2918 2918
     /**
2919
-	 * Alias of self::set_total_tax().
2920
-	 *
2921
-	 * @since 1.0.19
2922
-	 * @param  float $value tax total.
2923
-	 */
2924
-	public function set_tax_total( $value ) {
2925
-		$this->set_total_tax( $value );
2919
+     * Alias of self::set_total_tax().
2920
+     *
2921
+     * @since 1.0.19
2922
+     * @param  float $value tax total.
2923
+     */
2924
+    public function set_tax_total( $value ) {
2925
+        $this->set_total_tax( $value );
2926 2926
     }
2927 2927
 
2928 2928
     /**
2929
-	 * Set the invoice fees amount.
2930
-	 *
2931
-	 * @since 1.0.19
2932
-	 * @param  float $value fees total.
2933
-	 */
2934
-	public function set_total_fees( $value ) {
2935
-		$this->set_prop( 'total_fees', max( 0, $value ) );
2929
+     * Set the invoice fees amount.
2930
+     *
2931
+     * @since 1.0.19
2932
+     * @param  float $value fees total.
2933
+     */
2934
+    public function set_total_fees( $value ) {
2935
+        $this->set_prop( 'total_fees', max( 0, $value ) );
2936 2936
     }
2937 2937
 
2938 2938
     /**
2939
-	 * Alias of self::set_total_fees().
2940
-	 *
2941
-	 * @since 1.0.19
2942
-	 * @param  float $value fees total.
2943
-	 */
2944
-	public function set_fees_total( $value ) {
2945
-		$this->set_total_fees( $value );
2939
+     * Alias of self::set_total_fees().
2940
+     *
2941
+     * @since 1.0.19
2942
+     * @param  float $value fees total.
2943
+     */
2944
+    public function set_fees_total( $value ) {
2945
+        $this->set_total_fees( $value );
2946 2946
     }
2947 2947
 
2948 2948
     /**
2949
-	 * Set the invoice fees.
2950
-	 *
2951
-	 * @since 1.0.19
2952
-	 * @param  array $value fees.
2953
-	 */
2954
-	public function set_fees( $value ) {
2949
+     * Set the invoice fees.
2950
+     *
2951
+     * @since 1.0.19
2952
+     * @param  array $value fees.
2953
+     */
2954
+    public function set_fees( $value ) {
2955 2955
 
2956
-		if ( ! is_array( $value ) ) {
2957
-			$value = array();
2958
-		}
2956
+        if ( ! is_array( $value ) ) {
2957
+            $value = array();
2958
+        }
2959 2959
 
2960
-		$this->set_prop( 'fees', $value );
2960
+        $this->set_prop( 'fees', $value );
2961 2961
 
2962 2962
     }
2963 2963
 
2964 2964
     /**
2965
-	 * Set the invoice taxes.
2966
-	 *
2967
-	 * @since 1.0.19
2968
-	 * @param  array $value taxes.
2969
-	 */
2970
-	public function set_taxes( $value ) {
2965
+     * Set the invoice taxes.
2966
+     *
2967
+     * @since 1.0.19
2968
+     * @param  array $value taxes.
2969
+     */
2970
+    public function set_taxes( $value ) {
2971 2971
 
2972
-		if ( ! is_array( $value ) ) {
2973
-			$value = array();
2974
-		}
2972
+        if ( ! is_array( $value ) ) {
2973
+            $value = array();
2974
+        }
2975 2975
 
2976
-		$this->set_prop( 'taxes', $value );
2976
+        $this->set_prop( 'taxes', $value );
2977 2977
 
2978 2978
     }
2979 2979
 
2980 2980
     /**
2981
-	 * Set the invoice discounts.
2982
-	 *
2983
-	 * @since 1.0.19
2984
-	 * @param  array $value discounts.
2985
-	 */
2986
-	public function set_discounts( $value ) {
2981
+     * Set the invoice discounts.
2982
+     *
2983
+     * @since 1.0.19
2984
+     * @param  array $value discounts.
2985
+     */
2986
+    public function set_discounts( $value ) {
2987 2987
 
2988
-		if ( ! is_array( $value ) ) {
2989
-			$value = array();
2990
-		}
2988
+        if ( ! is_array( $value ) ) {
2989
+            $value = array();
2990
+        }
2991 2991
 
2992
-		$this->set_prop( 'discounts', $value );
2992
+        $this->set_prop( 'discounts', $value );
2993 2993
     }
2994 2994
 
2995 2995
     /**
2996
-	 * Set the invoice items.
2997
-	 *
2998
-	 * @since 1.0.19
2999
-	 * @param  GetPaid_Form_Item[] $value items.
3000
-	 */
3001
-	public function set_items( $value ) {
2996
+     * Set the invoice items.
2997
+     *
2998
+     * @since 1.0.19
2999
+     * @param  GetPaid_Form_Item[] $value items.
3000
+     */
3001
+    public function set_items( $value ) {
3002 3002
 
3003 3003
         // Remove existing items.
3004 3004
         $this->set_prop( 'items', array() );
3005
-		$this->recurring_item = null;
3005
+        $this->recurring_item = null;
3006 3006
 
3007 3007
         // Ensure that we have an array.
3008 3008
         if ( ! is_array( $value ) ) {
@@ -3016,95 +3016,95 @@  discard block
 block discarded – undo
3016 3016
     }
3017 3017
 
3018 3018
     /**
3019
-	 * Set the payment form.
3020
-	 *
3021
-	 * @since 1.0.19
3022
-	 * @param  int $value payment form.
3023
-	 */
3024
-	public function set_payment_form( $value ) {
3025
-		$this->set_prop( 'payment_form', $value );
3019
+     * Set the payment form.
3020
+     *
3021
+     * @since 1.0.19
3022
+     * @param  int $value payment form.
3023
+     */
3024
+    public function set_payment_form( $value ) {
3025
+        $this->set_prop( 'payment_form', $value );
3026 3026
     }
3027 3027
 
3028 3028
     /**
3029
-	 * Set the submission id.
3030
-	 *
3031
-	 * @since 1.0.19
3032
-	 * @param  string $value submission id.
3033
-	 */
3034
-	public function set_submission_id( $value ) {
3035
-		$this->set_prop( 'submission_id', $value );
3029
+     * Set the submission id.
3030
+     *
3031
+     * @since 1.0.19
3032
+     * @param  string $value submission id.
3033
+     */
3034
+    public function set_submission_id( $value ) {
3035
+        $this->set_prop( 'submission_id', $value );
3036 3036
     }
3037 3037
 
3038 3038
     /**
3039
-	 * Set the discount code.
3040
-	 *
3041
-	 * @since 1.0.19
3042
-	 * @param  string $value discount code.
3043
-	 */
3044
-	public function set_discount_code( $value ) {
3045
-		$this->set_prop( 'discount_code', sanitize_text_field( $value ) );
3039
+     * Set the discount code.
3040
+     *
3041
+     * @since 1.0.19
3042
+     * @param  string $value discount code.
3043
+     */
3044
+    public function set_discount_code( $value ) {
3045
+        $this->set_prop( 'discount_code', sanitize_text_field( $value ) );
3046 3046
     }
3047 3047
 
3048 3048
     /**
3049
-	 * Set the gateway.
3050
-	 *
3051
-	 * @since 1.0.19
3052
-	 * @param  string $value gateway.
3053
-	 */
3054
-	public function set_gateway( $value ) {
3055
-		$this->set_prop( 'gateway', $value );
3049
+     * Set the gateway.
3050
+     *
3051
+     * @since 1.0.19
3052
+     * @param  string $value gateway.
3053
+     */
3054
+    public function set_gateway( $value ) {
3055
+        $this->set_prop( 'gateway', $value );
3056 3056
     }
3057 3057
 
3058 3058
     /**
3059
-	 * Set the transaction id.
3060
-	 *
3061
-	 * @since 1.0.19
3062
-	 * @param  string $value transaction id.
3063
-	 */
3064
-	public function set_transaction_id( $value ) {
3065
-		if ( ! empty( $value ) ) {
3066
-			$this->set_prop( 'transaction_id', $value );
3067
-		}
3059
+     * Set the transaction id.
3060
+     *
3061
+     * @since 1.0.19
3062
+     * @param  string $value transaction id.
3063
+     */
3064
+    public function set_transaction_id( $value ) {
3065
+        if ( ! empty( $value ) ) {
3066
+            $this->set_prop( 'transaction_id', $value );
3067
+        }
3068 3068
     }
3069 3069
 
3070 3070
     /**
3071
-	 * Set the currency id.
3072
-	 *
3073
-	 * @since 1.0.19
3074
-	 * @param  string $value currency id.
3075
-	 */
3076
-	public function set_currency( $value ) {
3077
-		$this->set_prop( 'currency', $value );
3071
+     * Set the currency id.
3072
+     *
3073
+     * @since 1.0.19
3074
+     * @param  string $value currency id.
3075
+     */
3076
+    public function set_currency( $value ) {
3077
+        $this->set_prop( 'currency', $value );
3078 3078
     }
3079 3079
 
3080
-	/**
3081
-	 * Set whether to disable taxes.
3082
-	 *
3083
-	 * @since 1.0.19
3084
-	 * @param  bool $value value.
3085
-	 */
3086
-	public function set_disable_taxes( $value ) {
3087
-		$this->set_prop( 'disable_taxes', (bool) $value );
3088
-	}
3080
+    /**
3081
+     * Set whether to disable taxes.
3082
+     *
3083
+     * @since 1.0.19
3084
+     * @param  bool $value value.
3085
+     */
3086
+    public function set_disable_taxes( $value ) {
3087
+        $this->set_prop( 'disable_taxes', (bool) $value );
3088
+    }
3089 3089
 
3090 3090
     /**
3091
-	 * Set the subscription id.
3092
-	 *
3093
-	 * @since 1.0.19
3094
-	 * @param  string $value subscription id.
3095
-	 */
3096
-	public function set_subscription_id( $value ) {
3097
-		$this->set_prop( 'subscription_id', $value );
3098
-	}
3091
+     * Set the subscription id.
3092
+     *
3093
+     * @since 1.0.19
3094
+     * @param  string $value subscription id.
3095
+     */
3096
+    public function set_subscription_id( $value ) {
3097
+        $this->set_prop( 'subscription_id', $value );
3098
+    }
3099 3099
 	
3100
-	/**
3101
-	 * Set the remote subscription id.
3102
-	 *
3103
-	 * @since 1.0.19
3104
-	 * @param  string $value subscription id.
3105
-	 */
3106
-	public function set_remote_subscription_id( $value ) {
3107
-		$this->set_prop( 'remote_subscription_id', $value );
3100
+    /**
3101
+     * Set the remote subscription id.
3102
+     *
3103
+     * @since 1.0.19
3104
+     * @param  string $value subscription id.
3105
+     */
3106
+    public function set_remote_subscription_id( $value ) {
3107
+        $this->set_prop( 'remote_subscription_id', $value );
3108 3108
     }
3109 3109
 
3110 3110
     /*
@@ -3143,24 +3143,24 @@  discard block
 block discarded – undo
3143 3143
      */
3144 3144
     public function is_taxable() {
3145 3145
         return ! $this->get_disable_taxes();
3146
-	}
3146
+    }
3147 3147
 
3148
-	/**
3149
-	 * @deprecated
3150
-	 */
3151
-	public function has_vat() {
3148
+    /**
3149
+     * @deprecated
3150
+     */
3151
+    public function has_vat() {
3152 3152
         return $this->is_taxable();
3153
-	}
3153
+    }
3154 3154
 
3155
-	/**
3156
-	 * Checks to see if the invoice requires payment.
3157
-	 */
3158
-	public function is_free() {
3155
+    /**
3156
+     * Checks to see if the invoice requires payment.
3157
+     */
3158
+    public function is_free() {
3159 3159
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
3160 3160
 
3161
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
3162
-			$is_free = false;
3163
-		}
3161
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
3162
+            $is_free = false;
3163
+        }
3164 3164
 
3165 3165
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
3166 3166
     }
@@ -3171,46 +3171,46 @@  discard block
 block discarded – undo
3171 3171
     public function is_paid() {
3172 3172
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
3173 3173
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
3174
-	}
3174
+    }
3175 3175
 
3176
-	/**
3176
+    /**
3177 3177
      * Checks if the invoice needs payment.
3178 3178
      */
3179
-	public function needs_payment() {
3180
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
3179
+    public function needs_payment() {
3180
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
3181 3181
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
3182 3182
     }
3183 3183
   
3184
-	/**
3184
+    /**
3185 3185
      * Checks if the invoice is refunded.
3186 3186
      */
3187
-	public function is_refunded() {
3187
+    public function is_refunded() {
3188 3188
         $is_refunded = $this->has_status( 'wpi-refunded' );
3189 3189
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
3190
-	}
3190
+    }
3191 3191
 
3192
-	/**
3192
+    /**
3193 3193
      * Checks if the invoice is held.
3194 3194
      */
3195
-	public function is_held() {
3195
+    public function is_held() {
3196 3196
         $is_held = $this->has_status( 'wpi-onhold' );
3197 3197
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
3198
-	}
3198
+    }
3199 3199
 
3200
-	/**
3200
+    /**
3201 3201
      * Checks if the invoice is due.
3202 3202
      */
3203
-	public function is_due() {
3204
-		$due_date = $this->get_due_date();
3205
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3206
-	}
3203
+    public function is_due() {
3204
+        $due_date = $this->get_due_date();
3205
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3206
+    }
3207 3207
 
3208
-	/**
3208
+    /**
3209 3209
      * Checks if the invoice is draft.
3210 3210
      */
3211
-	public function is_draft() {
3211
+    public function is_draft() {
3212 3212
         return $this->has_status( 'draft, auto-draft' );
3213
-	}
3213
+    }
3214 3214
 
3215 3215
     /**
3216 3216
      * Checks if the invoice has a given status.
@@ -3218,9 +3218,9 @@  discard block
 block discarded – undo
3218 3218
     public function has_status( $status ) {
3219 3219
         $status = wpinv_parse_list( $status );
3220 3220
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
3221
-	}
3221
+    }
3222 3222
 
3223
-	/**
3223
+    /**
3224 3224
      * Checks if the invoice is of a given type.
3225 3225
      */
3226 3226
     public function is_type( $type ) {
@@ -3243,25 +3243,25 @@  discard block
 block discarded – undo
3243 3243
      */
3244 3244
     public function has_free_trial() {
3245 3245
         return $this->is_recurring() && 0 == $this->get_initial_total();
3246
-	}
3246
+    }
3247 3247
 
3248
-	/**
3248
+    /**
3249 3249
      * @deprecated
3250 3250
      */
3251 3251
     public function is_free_trial() {
3252 3252
         $this->has_free_trial();
3253 3253
     }
3254 3254
 
3255
-	/**
3255
+    /**
3256 3256
      * Check if the initial payment if 0.
3257 3257
      *
3258 3258
      */
3259
-	public function is_initial_free() {
3259
+    public function is_initial_free() {
3260 3260
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3261 3261
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3262 3262
     }
3263 3263
 	
3264
-	/**
3264
+    /**
3265 3265
      * Check if the recurring item has a free trial.
3266 3266
      *
3267 3267
      */
@@ -3274,21 +3274,21 @@  discard block
 block discarded – undo
3274 3274
 
3275 3275
         $item = $this->get_recurring( true );
3276 3276
         return $item->has_free_trial();
3277
-	}
3277
+    }
3278 3278
 
3279
-	/**
3279
+    /**
3280 3280
      * Check if the free trial is a result of a discount.
3281 3281
      */
3282 3282
     public function is_free_trial_from_discount() {
3283
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3284
-	}
3283
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3284
+    }
3285 3285
 	
3286
-	/**
3286
+    /**
3287 3287
      * @deprecated
3288 3288
      */
3289 3289
     public function discount_first_payment_only() {
3290 3290
 
3291
-		$discount = wpinv_get_discount_obj( $this->get_discount_code() );
3291
+        $discount = wpinv_get_discount_obj( $this->get_discount_code() );
3292 3292
         if ( ! $discount->exists() || ! $this->is_recurring() ) {
3293 3293
             return true;
3294 3294
         }
@@ -3313,147 +3313,147 @@  discard block
 block discarded – undo
3313 3313
      */
3314 3314
     public function add_item( $item ) {
3315 3315
 
3316
-		if ( is_array( $item ) ) {
3317
-			$item = $this->process_array_item( $item );
3318
-		}
3316
+        if ( is_array( $item ) ) {
3317
+            $item = $this->process_array_item( $item );
3318
+        }
3319 3319
 
3320
-		if ( is_numeric( $item ) ) {
3321
-			$item = new GetPaid_Form_Item( $item );
3322
-		}
3320
+        if ( is_numeric( $item ) ) {
3321
+            $item = new GetPaid_Form_Item( $item );
3322
+        }
3323 3323
 
3324 3324
         // Make sure that it is available for purchase.
3325
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3326
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3325
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3326
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3327 3327
         }
3328 3328
 
3329 3329
         // Do we have a recurring item?
3330
-		if ( $item->is_recurring() ) {
3331
-			$this->recurring_item = $item->get_id();
3330
+        if ( $item->is_recurring() ) {
3331
+            $this->recurring_item = $item->get_id();
3332 3332
         }
3333 3333
 
3334 3334
         // Invoice id.
3335 3335
         $item->invoice_id = (int) $this->get_id();
3336 3336
 
3337
-		// Remove duplicates.
3338
-		$this->remove_item( $item->get_id() );
3337
+        // Remove duplicates.
3338
+        $this->remove_item( $item->get_id() );
3339 3339
 
3340
-		if ( 0 == $item->get_quantity() ) {
3341
-			return;
3342
-		}
3340
+        if ( 0 == $item->get_quantity() ) {
3341
+            return;
3342
+        }
3343 3343
 
3344
-		// Retrieve all items.
3344
+        // Retrieve all items.
3345 3345
         $items   = $this->get_items();
3346 3346
 
3347
-		// Add new item.
3347
+        // Add new item.
3348 3348
         $items[] = $item;
3349 3349
 
3350 3350
         $this->set_prop( 'items', $items );
3351 3351
 
3352
-		return true;
3353
-	}
3352
+        return true;
3353
+    }
3354 3354
 
3355
-	/**
3356
-	 * Converts an array to an item.
3357
-	 *
3358
-	 * @since 1.0.19
3359
-	 * @return GetPaid_Form_Item
3360
-	 */
3361
-	protected function process_array_item( $array ) {
3355
+    /**
3356
+     * Converts an array to an item.
3357
+     *
3358
+     * @since 1.0.19
3359
+     * @return GetPaid_Form_Item
3360
+     */
3361
+    protected function process_array_item( $array ) {
3362 3362
 
3363
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3364
-		$item    = new GetPaid_Form_Item( $item_id );
3363
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3364
+        $item    = new GetPaid_Form_Item( $item_id );
3365 3365
 
3366
-		// Set item data.
3367
-		foreach ( array( 'name', 'price', 'description' ) as $key ) {
3368
-			if ( isset( $array[ "item_$key" ] ) ) {
3369
-				$method = "set_$key";
3370
-				$item->$method( $array[ "item_$key" ] );
3371
-			}
3372
-		}
3366
+        // Set item data.
3367
+        foreach ( array( 'name', 'price', 'description' ) as $key ) {
3368
+            if ( isset( $array[ "item_$key" ] ) ) {
3369
+                $method = "set_$key";
3370
+                $item->$method( $array[ "item_$key" ] );
3371
+            }
3372
+        }
3373 3373
 
3374
-		if ( isset( $array['quantity'] ) ) {
3375
-			$item->set_quantity( $array['quantity'] );
3376
-		}
3374
+        if ( isset( $array['quantity'] ) ) {
3375
+            $item->set_quantity( $array['quantity'] );
3376
+        }
3377 3377
 
3378
-		// Set item meta.
3379
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3380
-			$item->set_item_meta( $array['meta'] );
3381
-		}
3378
+        // Set item meta.
3379
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3380
+            $item->set_item_meta( $array['meta'] );
3381
+        }
3382 3382
 
3383
-		return $item;
3383
+        return $item;
3384 3384
 
3385
-	}
3385
+    }
3386 3386
 
3387 3387
     /**
3388
-	 * Retrieves a specific item.
3389
-	 *
3390
-	 * @since 1.0.19
3391
-	 * @return GetPaid_Form_Item|null
3392
-	 */
3393
-	public function get_item( $item_id ) {
3388
+     * Retrieves a specific item.
3389
+     *
3390
+     * @since 1.0.19
3391
+     * @return GetPaid_Form_Item|null
3392
+     */
3393
+    public function get_item( $item_id ) {
3394 3394
 
3395
-		foreach ( $this->get_items() as $item ) {
3396
-			if ( (int) $item_id == $item->get_id() ) {
3397
-				return $item;
3398
-			}
3399
-		}
3395
+        foreach ( $this->get_items() as $item ) {
3396
+            if ( (int) $item_id == $item->get_id() ) {
3397
+                return $item;
3398
+            }
3399
+        }
3400 3400
 
3401
-		return null;
3401
+        return null;
3402 3402
     }
3403 3403
 
3404 3404
     /**
3405
-	 * Removes a specific item.
3406
-	 *
3407
-	 * @since 1.0.19
3408
-	 */
3409
-	public function remove_item( $item_id ) {
3410
-		$items   = $this->get_items();
3411
-		$item_id = (int) $item_id;
3405
+     * Removes a specific item.
3406
+     *
3407
+     * @since 1.0.19
3408
+     */
3409
+    public function remove_item( $item_id ) {
3410
+        $items   = $this->get_items();
3411
+        $item_id = (int) $item_id;
3412 3412
 
3413
-		foreach ( $items as $index => $item ) {
3414
-			if ( (int) $item_id == $item->get_id() ) {
3415
-				unset( $items[ $index ] );
3416
-				$this->set_prop( 'items', $items );
3413
+        foreach ( $items as $index => $item ) {
3414
+            if ( (int) $item_id == $item->get_id() ) {
3415
+                unset( $items[ $index ] );
3416
+                $this->set_prop( 'items', $items );
3417 3417
 
3418
-				if ( $item_id == $this->recurring_item ) {
3419
-					$this->recurring_item = null;
3420
-				}
3418
+                if ( $item_id == $this->recurring_item ) {
3419
+                    $this->recurring_item = null;
3420
+                }
3421 3421
 
3422
-			}
3423
-		}
3422
+            }
3423
+        }
3424 3424
 
3425 3425
     }
3426 3426
 
3427 3427
     /**
3428
-	 * Adds a fee to the invoice.
3429
-	 *
3430
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3431
-	 * @since 1.0.19
3432
-	 */
3428
+     * Adds a fee to the invoice.
3429
+     *
3430
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3431
+     * @since 1.0.19
3432
+     */
3433 3433
     public function add_fee( $fee ) {
3434 3434
 
3435
-		$fees                 = $this->get_fees();
3436
-		$fees[ $fee['name'] ] = $fee;
3437
-		$this->set_prop( 'fees', $fees );
3435
+        $fees                 = $this->get_fees();
3436
+        $fees[ $fee['name'] ] = $fee;
3437
+        $this->set_prop( 'fees', $fees );
3438 3438
 
3439 3439
     }
3440 3440
 
3441 3441
     /**
3442
-	 * Retrieves a specific fee.
3443
-	 *
3444
-	 * @since 1.0.19
3445
-	 */
3446
-	public function get_fee( $fee ) {
3442
+     * Retrieves a specific fee.
3443
+     *
3444
+     * @since 1.0.19
3445
+     */
3446
+    public function get_fee( $fee ) {
3447 3447
         $fees = $this->get_fees();
3448
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3448
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3449 3449
     }
3450 3450
 
3451 3451
     /**
3452
-	 * Removes a specific fee.
3453
-	 *
3454
-	 * @since 1.0.19
3455
-	 */
3456
-	public function remove_fee( $fee ) {
3452
+     * Removes a specific fee.
3453
+     *
3454
+     * @since 1.0.19
3455
+     */
3456
+    public function remove_fee( $fee ) {
3457 3457
         $fees = $this->get_fees();
3458 3458
         if ( isset( $fees[ $fee ] ) ) {
3459 3459
             unset( $fees[ $fee ] );
@@ -3461,55 +3461,55 @@  discard block
 block discarded – undo
3461 3461
         }
3462 3462
     }
3463 3463
 
3464
-	/**
3465
-	 * Adds a discount to the invoice.
3466
-	 *
3467
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3468
-	 * @since 1.0.19
3469
-	 */
3470
-	public function add_discount( $discount ) {
3464
+    /**
3465
+     * Adds a discount to the invoice.
3466
+     *
3467
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3468
+     * @since 1.0.19
3469
+     */
3470
+    public function add_discount( $discount ) {
3471 3471
 
3472
-		$discounts = $this->get_discounts();
3473
-		$discounts[ $discount['name'] ] = $discount;
3474
-		$this->set_prop( 'discounts', $discounts );
3472
+        $discounts = $this->get_discounts();
3473
+        $discounts[ $discount['name'] ] = $discount;
3474
+        $this->set_prop( 'discounts', $discounts );
3475 3475
 
3476
-	}
3476
+    }
3477 3477
 
3478 3478
     /**
3479
-	 * Retrieves a specific discount.
3480
-	 *
3481
-	 * @since 1.0.19
3482
-	 * @return float
3483
-	 */
3484
-	public function get_discount( $discount = false ) {
3479
+     * Retrieves a specific discount.
3480
+     *
3481
+     * @since 1.0.19
3482
+     * @return float
3483
+     */
3484
+    public function get_discount( $discount = false ) {
3485 3485
 
3486
-		// Backwards compatibilty.
3487
-		if ( empty( $discount ) ) {
3488
-			return $this->get_total_discount();
3489
-		}
3486
+        // Backwards compatibilty.
3487
+        if ( empty( $discount ) ) {
3488
+            return $this->get_total_discount();
3489
+        }
3490 3490
 
3491 3491
         $discounts = $this->get_discounts();
3492
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3492
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3493 3493
     }
3494 3494
 
3495 3495
     /**
3496
-	 * Removes a specific discount.
3497
-	 *
3498
-	 * @since 1.0.19
3499
-	 */
3500
-	public function remove_discount( $discount ) {
3496
+     * Removes a specific discount.
3497
+     *
3498
+     * @since 1.0.19
3499
+     */
3500
+    public function remove_discount( $discount ) {
3501 3501
         $discounts = $this->get_discounts();
3502 3502
         if ( isset( $discounts[ $discount ] ) ) {
3503 3503
             unset( $discounts[ $discount ] );
3504 3504
             $this->set_prop( 'discounts', $discounts );
3505 3505
         }
3506 3506
 
3507
-		if ( 'discount_code' == $discount ) {
3508
-			foreach ( $this->get_items() as $item ) {
3509
-				$item->item_discount           = 0;
3510
-				$item->recurring_item_discount = 0;
3511
-			}
3512
-		}
3507
+        if ( 'discount_code' == $discount ) {
3508
+            foreach ( $this->get_items() as $item ) {
3509
+                $item->item_discount           = 0;
3510
+                $item->recurring_item_discount = 0;
3511
+            }
3512
+        }
3513 3513
 
3514 3514
     }
3515 3515
 
@@ -3522,34 +3522,34 @@  discard block
 block discarded – undo
3522 3522
         if ( $this->is_taxable() ) {
3523 3523
 
3524 3524
             $taxes                 = $this->get_taxes();
3525
-			$taxes[ $tax['name'] ] = $tax;
3526
-			$this->set_prop( 'taxes', $tax );
3525
+            $taxes[ $tax['name'] ] = $tax;
3526
+            $this->set_prop( 'taxes', $tax );
3527 3527
 
3528 3528
         }
3529 3529
     }
3530 3530
 
3531 3531
     /**
3532
-	 * Retrieves a specific tax.
3533
-	 *
3534
-	 * @since 1.0.19
3535
-	 */
3536
-	public function get_tax( $tax = null ) {
3532
+     * Retrieves a specific tax.
3533
+     *
3534
+     * @since 1.0.19
3535
+     */
3536
+    public function get_tax( $tax = null ) {
3537 3537
 
3538
-		// Backwards compatility.
3539
-		if ( empty( $tax ) ) {
3540
-			return $this->get_total_tax();
3541
-		}
3538
+        // Backwards compatility.
3539
+        if ( empty( $tax ) ) {
3540
+            return $this->get_total_tax();
3541
+        }
3542 3542
 
3543 3543
         $taxes = $this->get_taxes();
3544
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3544
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3545 3545
     }
3546 3546
 
3547 3547
     /**
3548
-	 * Removes a specific tax.
3549
-	 *
3550
-	 * @since 1.0.19
3551
-	 */
3552
-	public function remove_tax( $tax ) {
3548
+     * Removes a specific tax.
3549
+     *
3550
+     * @since 1.0.19
3551
+     */
3552
+    public function remove_tax( $tax ) {
3553 3553
         $taxes = $this->get_taxes();
3554 3554
         if ( isset( $taxes[ $tax ] ) ) {
3555 3555
             unset( $taxes[ $tax ] );
@@ -3558,185 +3558,185 @@  discard block
 block discarded – undo
3558 3558
     }
3559 3559
 
3560 3560
     /**
3561
-	 * Recalculates the invoice subtotal.
3562
-	 *
3563
-	 * @since 1.0.19
3564
-	 * @return float The recalculated subtotal
3565
-	 */
3566
-	public function recalculate_subtotal() {
3561
+     * Recalculates the invoice subtotal.
3562
+     *
3563
+     * @since 1.0.19
3564
+     * @return float The recalculated subtotal
3565
+     */
3566
+    public function recalculate_subtotal() {
3567 3567
         $items     = $this->get_items();
3568
-		$subtotal  = 0;
3569
-		$recurring = 0;
3568
+        $subtotal  = 0;
3569
+        $recurring = 0;
3570 3570
 
3571 3571
         foreach ( $items as $item ) {
3572
-			$subtotal  += $item->get_sub_total( 'edit' );
3573
-			$recurring += $item->get_recurring_sub_total( 'edit' );
3572
+            $subtotal  += $item->get_sub_total( 'edit' );
3573
+            $recurring += $item->get_recurring_sub_total( 'edit' );
3574 3574
         }
3575 3575
 
3576
-		if ( wpinv_prices_include_tax() ) {
3577
-			$subtotal  = max( 0, $subtotal - $this->totals['tax']['initial'] );
3578
-			$recurring = max( 0, $recurring - $this->totals['tax']['recurring'] );
3579
-		}
3576
+        if ( wpinv_prices_include_tax() ) {
3577
+            $subtotal  = max( 0, $subtotal - $this->totals['tax']['initial'] );
3578
+            $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] );
3579
+        }
3580 3580
 
3581
-		$current = $this->is_renewal() ? $recurring : $subtotal;
3582
-		$this->set_subtotal( $current );
3581
+        $current = $this->is_renewal() ? $recurring : $subtotal;
3582
+        $this->set_subtotal( $current );
3583 3583
 
3584
-		$this->totals['subtotal'] = array(
3585
-			'initial'   => $subtotal,
3586
-			'recurring' => $recurring,
3587
-		);
3584
+        $this->totals['subtotal'] = array(
3585
+            'initial'   => $subtotal,
3586
+            'recurring' => $recurring,
3587
+        );
3588 3588
 
3589 3589
         return $current;
3590 3590
     }
3591 3591
 
3592 3592
     /**
3593
-	 * Recalculates the invoice discount total.
3594
-	 *
3595
-	 * @since 1.0.19
3596
-	 * @return float The recalculated discount
3597
-	 */
3598
-	public function recalculate_total_discount() {
3593
+     * Recalculates the invoice discount total.
3594
+     *
3595
+     * @since 1.0.19
3596
+     * @return float The recalculated discount
3597
+     */
3598
+    public function recalculate_total_discount() {
3599 3599
         $discounts = $this->get_discounts();
3600
-		$discount  = 0;
3601
-		$recurring = 0;
3600
+        $discount  = 0;
3601
+        $recurring = 0;
3602 3602
 
3603 3603
         foreach ( $discounts as $data ) {
3604
-			$discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3605
-			$recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3606
-		}
3604
+            $discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3605
+            $recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3606
+        }
3607 3607
 
3608
-		$current = $this->is_renewal() ? $recurring : $discount;
3608
+        $current = $this->is_renewal() ? $recurring : $discount;
3609 3609
 
3610
-		$this->set_total_discount( $current );
3610
+        $this->set_total_discount( $current );
3611 3611
 
3612
-		$this->totals['discount'] = array(
3613
-			'initial'   => $discount,
3614
-			'recurring' => $recurring,
3615
-		);
3612
+        $this->totals['discount'] = array(
3613
+            'initial'   => $discount,
3614
+            'recurring' => $recurring,
3615
+        );
3616 3616
 
3617
-		return $current;
3617
+        return $current;
3618 3618
 
3619 3619
     }
3620 3620
 
3621 3621
     /**
3622
-	 * Recalculates the invoice tax total.
3623
-	 *
3624
-	 * @since 1.0.19
3625
-	 * @return float The recalculated tax
3626
-	 */
3627
-	public function recalculate_total_tax() {
3622
+     * Recalculates the invoice tax total.
3623
+     *
3624
+     * @since 1.0.19
3625
+     * @return float The recalculated tax
3626
+     */
3627
+    public function recalculate_total_tax() {
3628 3628
 
3629
-		// Maybe disable taxes.
3630
-		$vat_number = $this->get_vat_number();
3631
-		$skip_tax   = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number );
3629
+        // Maybe disable taxes.
3630
+        $vat_number = $this->get_vat_number();
3631
+        $skip_tax   = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number );
3632 3632
 
3633
-		if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
3634
-			$skip_tax = false;
3635
-		}
3633
+        if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
3634
+            $skip_tax = false;
3635
+        }
3636 3636
 
3637
-		if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax   ) {
3637
+        if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax   ) {
3638 3638
 
3639
-			$this->totals['tax'] = array(
3640
-				'initial'   => 0,
3641
-				'recurring' => 0,
3642
-			);
3639
+            $this->totals['tax'] = array(
3640
+                'initial'   => 0,
3641
+                'recurring' => 0,
3642
+            );
3643 3643
 
3644
-			$this->tax_rate = 0;
3644
+            $this->tax_rate = 0;
3645 3645
 
3646
-			$this->set_taxes( array() );
3647
-			$current = 0;
3648
-		} else {
3646
+            $this->set_taxes( array() );
3647
+            $current = 0;
3648
+        } else {
3649 3649
 
3650
-			$item_taxes = array();
3650
+            $item_taxes = array();
3651 3651
 
3652
-			foreach ( $this->get_items() as $item ) {
3653
-				$rates    = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() );
3654
-				$rates    = getpaid_filter_item_tax_rates( $item, $rates );
3655
-				$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
3656
-				$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
3657
-				foreach ( $taxes as $name => $amount ) {
3658
-					$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
3659
-					$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
3652
+            foreach ( $this->get_items() as $item ) {
3653
+                $rates    = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() );
3654
+                $rates    = getpaid_filter_item_tax_rates( $item, $rates );
3655
+                $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
3656
+                $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
3657
+                foreach ( $taxes as $name => $amount ) {
3658
+                    $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
3659
+                    $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
3660 3660
 
3661
-					if ( ! isset( $item_taxes[ $name ] ) ) {
3662
-						$item_taxes[ $name ] = $tax;
3663
-						continue;
3664
-					}
3661
+                    if ( ! isset( $item_taxes[ $name ] ) ) {
3662
+                        $item_taxes[ $name ] = $tax;
3663
+                        continue;
3664
+                    }
3665 3665
 
3666
-					$item_taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
3667
-					$item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
3666
+                    $item_taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
3667
+                    $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
3668 3668
 
3669
-				}
3669
+                }
3670 3670
 
3671
-			}
3671
+            }
3672 3672
 
3673
-			$item_taxes = array_replace( $this->get_taxes(), $item_taxes );
3674
-			$this->set_taxes( $item_taxes );
3673
+            $item_taxes = array_replace( $this->get_taxes(), $item_taxes );
3674
+            $this->set_taxes( $item_taxes );
3675 3675
 
3676
-			$initial_tax   = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) );
3677
-			$recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) );
3676
+            $initial_tax   = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) );
3677
+            $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) );
3678 3678
 
3679
-			$current = $this->is_renewal() ? $recurring_tax : $initial_tax;
3679
+            $current = $this->is_renewal() ? $recurring_tax : $initial_tax;
3680 3680
 
3681
-			$this->totals['tax'] = array(
3682
-				'initial'   => $initial_tax,
3683
-				'recurring' => $recurring_tax,
3684
-			);
3681
+            $this->totals['tax'] = array(
3682
+                'initial'   => $initial_tax,
3683
+                'recurring' => $recurring_tax,
3684
+            );
3685 3685
 
3686
-		}
3686
+        }
3687 3687
 
3688
-		$this->set_total_tax( $current );
3688
+        $this->set_total_tax( $current );
3689 3689
 
3690
-		return $current;
3690
+        return $current;
3691 3691
 
3692 3692
     }
3693 3693
 
3694 3694
     /**
3695
-	 * Recalculates the invoice fees total.
3696
-	 *
3697
-	 * @since 1.0.19
3698
-	 * @return float The recalculated fee
3699
-	 */
3700
-	public function recalculate_total_fees() {
3701
-		$fees      = $this->get_fees();
3702
-		$fee       = 0;
3703
-		$recurring = 0;
3695
+     * Recalculates the invoice fees total.
3696
+     *
3697
+     * @since 1.0.19
3698
+     * @return float The recalculated fee
3699
+     */
3700
+    public function recalculate_total_fees() {
3701
+        $fees      = $this->get_fees();
3702
+        $fee       = 0;
3703
+        $recurring = 0;
3704 3704
 
3705 3705
         foreach ( $fees as $data ) {
3706
-			$fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3707
-			$recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3708
-		}
3706
+            $fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3707
+            $recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3708
+        }
3709 3709
 
3710
-		$current = $this->is_renewal() ? $recurring : $fee;
3711
-		$this->set_total_fees( $current );
3710
+        $current = $this->is_renewal() ? $recurring : $fee;
3711
+        $this->set_total_fees( $current );
3712 3712
 
3713
-		$this->totals['fee'] = array(
3714
-			'initial'   => $fee,
3715
-			'recurring' => $recurring,
3716
-		);
3713
+        $this->totals['fee'] = array(
3714
+            'initial'   => $fee,
3715
+            'recurring' => $recurring,
3716
+        );
3717 3717
 
3718 3718
         $this->set_total_fees( $fee );
3719 3719
         return $current;
3720 3720
     }
3721 3721
 
3722 3722
     /**
3723
-	 * Recalculates the invoice total.
3724
-	 *
3725
-	 * @since 1.0.19
3723
+     * Recalculates the invoice total.
3724
+     *
3725
+     * @since 1.0.19
3726 3726
      * @return float The invoice total
3727
-	 */
3728
-	public function recalculate_total() {
3727
+     */
3728
+    public function recalculate_total() {
3729 3729
         $this->recalculate_total_fees();
3730 3730
         $this->recalculate_total_discount();
3731
-		$this->recalculate_total_tax();
3732
-		$this->recalculate_subtotal();
3733
-		$this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) );
3734
-		return $this->get_total();
3735
-	}
3736
-
3737
-	/**
3738
-	 * @deprecated
3739
-	 */
3731
+        $this->recalculate_total_tax();
3732
+        $this->recalculate_subtotal();
3733
+        $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) );
3734
+        return $this->get_total();
3735
+    }
3736
+
3737
+    /**
3738
+     * @deprecated
3739
+     */
3740 3740
     public function recalculate_totals() {
3741 3741
         $this->recalculate_total();
3742 3742
         $this->save( true );
@@ -3750,22 +3750,22 @@  discard block
 block discarded – undo
3750 3750
         return $this->get_data();
3751 3751
     }
3752 3752
 
3753
-	/**
3753
+    /**
3754 3754
      * Adds a system note to an invoice.
3755 3755
      *
3756 3756
      * @param string $note The note being added.
3757
-	 * @return int|false The new note's ID on success, false on failure.
3757
+     * @return int|false The new note's ID on success, false on failure.
3758 3758
      *
3759 3759
      */
3760 3760
     public function add_system_note( $note ) {
3761
-		return $this->add_note( $note, false, false, true );
3762
-	}
3761
+        return $this->add_note( $note, false, false, true );
3762
+    }
3763 3763
 
3764 3764
     /**
3765 3765
      * Adds a note to an invoice.
3766 3766
      *
3767 3767
      * @param string $note The note being added.
3768
-	 * @return int|false The new note's ID on success, false on failure.
3768
+     * @return int|false The new note's ID on success, false on failure.
3769 3769
      *
3770 3770
      */
3771 3771
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3775,21 +3775,21 @@  discard block
 block discarded – undo
3775 3775
             return false;
3776 3776
         }
3777 3777
 
3778
-		$author       = 'System';
3779
-		$author_email = '[email protected]';
3778
+        $author       = 'System';
3779
+        $author_email = '[email protected]';
3780 3780
 
3781
-		// If this is an admin comment or it has been added by the user.
3782
-		if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3783
-			$user         = get_user_by( 'id', get_current_user_id() );
3781
+        // If this is an admin comment or it has been added by the user.
3782
+        if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3783
+            $user         = get_user_by( 'id', get_current_user_id() );
3784 3784
             $author       = $user->display_name;
3785 3785
             $author_email = $user->user_email;
3786
-		}
3786
+        }
3787 3787
 
3788
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3788
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3789 3789
 
3790
-	}
3790
+    }
3791 3791
 
3792
-	/**
3792
+    /**
3793 3793
      * Generates a unique key for the invoice.
3794 3794
      */
3795 3795
     public function generate_key( $string = '' ) {
@@ -3809,113 +3809,113 @@  discard block
 block discarded – undo
3809 3809
             $number = wpinv_get_next_invoice_number( $this->get_post_type() );
3810 3810
         }
3811 3811
 
3812
-		return wpinv_format_invoice_number( $number, $this->get_post_type() );
3813
-
3814
-	}
3815
-
3816
-	/**
3817
-	 * Handle the status transition.
3818
-	 */
3819
-	protected function status_transition() {
3820
-		$status_transition = $this->status_transition;
3821
-
3822
-		// Reset status transition variable.
3823
-		$this->status_transition = false;
3812
+        return wpinv_format_invoice_number( $number, $this->get_post_type() );
3824 3813
 
3825
-		if ( $status_transition ) {
3826
-			try {
3827
-
3828
-				// Fire a hook for the status change.
3829
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3830
-
3831
-				// @deprecated this is deprecated and will be removed in the future.
3832
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3833
-
3834
-				if ( ! empty( $status_transition['from'] ) ) {
3835
-
3836
-					/* translators: 1: old invoice status 2: new invoice status */
3837
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3838
-
3839
-					// Fire another hook.
3840
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3841
-					do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3842
-
3843
-					// @deprecated this is deprecated and will be removed in the future.
3844
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3845
-
3846
-					// Note the transition occurred.
3847
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] );
3848
-
3849
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3850
-					if (
3851
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3852
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3853
-					) {
3854
-						do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3855
-					}
3856
-
3857
-					// Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3858
-					if (
3859
-						in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3860
-						&& in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3861
-					) {
3862
-						do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3863
-					}
3864
-				} else {
3865
-					/* translators: %s: new invoice status */
3866
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3867
-
3868
-					// Note the transition occurred.
3869
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3814
+    }
3870 3815
 
3871
-				}
3872
-			} catch ( Exception $e ) {
3873
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3874
-			}
3875
-		}
3876
-	}
3816
+    /**
3817
+     * Handle the status transition.
3818
+     */
3819
+    protected function status_transition() {
3820
+        $status_transition = $this->status_transition;
3821
+
3822
+        // Reset status transition variable.
3823
+        $this->status_transition = false;
3824
+
3825
+        if ( $status_transition ) {
3826
+            try {
3827
+
3828
+                // Fire a hook for the status change.
3829
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3830
+
3831
+                // @deprecated this is deprecated and will be removed in the future.
3832
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3833
+
3834
+                if ( ! empty( $status_transition['from'] ) ) {
3835
+
3836
+                    /* translators: 1: old invoice status 2: new invoice status */
3837
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3838
+
3839
+                    // Fire another hook.
3840
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3841
+                    do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3842
+
3843
+                    // @deprecated this is deprecated and will be removed in the future.
3844
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3845
+
3846
+                    // Note the transition occurred.
3847
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] );
3848
+
3849
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3850
+                    if (
3851
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3852
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3853
+                    ) {
3854
+                        do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3855
+                    }
3856
+
3857
+                    // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3858
+                    if (
3859
+                        in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3860
+                        && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3861
+                    ) {
3862
+                        do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3863
+                    }
3864
+                } else {
3865
+                    /* translators: %s: new invoice status */
3866
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3867
+
3868
+                    // Note the transition occurred.
3869
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3870
+
3871
+                }
3872
+            } catch ( Exception $e ) {
3873
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3874
+            }
3875
+        }
3876
+    }
3877 3877
 
3878
-	/**
3879
-	 * Updates an invoice status.
3880
-	 */
3881
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3878
+    /**
3879
+     * Updates an invoice status.
3880
+     */
3881
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3882 3882
 
3883
-		// Fires before updating a status.
3884
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3883
+        // Fires before updating a status.
3884
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3885 3885
 
3886
-		// Update the status.
3887
-		$this->set_status( $new_status, $note, $manual );
3886
+        // Update the status.
3887
+        $this->set_status( $new_status, $note, $manual );
3888 3888
 
3889
-		// Save the order.
3890
-		return $this->save();
3889
+        // Save the order.
3890
+        return $this->save();
3891 3891
 
3892
-	}
3892
+    }
3893 3893
 
3894
-	/**
3895
-	 * @deprecated
3896
-	 */
3897
-	public function refresh_item_ids() {
3894
+    /**
3895
+     * @deprecated
3896
+     */
3897
+    public function refresh_item_ids() {
3898 3898
         $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) );
3899 3899
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3900
-	}
3900
+    }
3901 3901
 
3902
-	/**
3903
-	 * @deprecated
3904
-	 */
3905
-	public function update_items( $temp = false ) {
3902
+    /**
3903
+     * @deprecated
3904
+     */
3905
+    public function update_items( $temp = false ) {
3906 3906
 
3907
-		$this->set_items( $this->get_items() );
3907
+        $this->set_items( $this->get_items() );
3908 3908
 
3909
-		if ( ! $temp ) {
3910
-			$this->save();
3911
-		}
3909
+        if ( ! $temp ) {
3910
+            $this->save();
3911
+        }
3912 3912
 
3913 3913
         return $this;
3914
-	}
3914
+    }
3915 3915
 
3916
-	/**
3917
-	 * @deprecated
3918
-	 */
3916
+    /**
3917
+     * @deprecated
3918
+     */
3919 3919
     public function validate_discount() {
3920 3920
 
3921 3921
         $discount_code = $this->get_discount_code();
@@ -3931,93 +3931,93 @@  discard block
 block discarded – undo
3931 3931
 
3932 3932
     }
3933 3933
 
3934
-	/**
3935
-	 * Refunds an invoice.
3936
-	 */
3934
+    /**
3935
+     * Refunds an invoice.
3936
+     */
3937 3937
     public function refund() {
3938
-		$this->set_status( 'wpi-refunded' );
3938
+        $this->set_status( 'wpi-refunded' );
3939 3939
         $this->save();
3940
-	}
3940
+    }
3941 3941
 
3942
-	/**
3943
-	 * Marks an invoice as paid.
3944
-	 * 
3945
-	 * @param string $transaction_id
3946
-	 */
3942
+    /**
3943
+     * Marks an invoice as paid.
3944
+     * 
3945
+     * @param string $transaction_id
3946
+     */
3947 3947
     public function mark_paid( $transaction_id = null, $note = '' ) {
3948 3948
 
3949
-		// Set the transaction id.
3950
-		if ( empty( $transaction_id ) ) {
3951
-			$transaction_id = $this->generate_key('trans_');
3952
-		}
3949
+        // Set the transaction id.
3950
+        if ( empty( $transaction_id ) ) {
3951
+            $transaction_id = $this->generate_key('trans_');
3952
+        }
3953 3953
 
3954
-		if ( ! $this->get_transaction_id() ) {
3955
-			$this->set_transaction_id( $transaction_id );
3956
-		}
3954
+        if ( ! $this->get_transaction_id() ) {
3955
+            $this->set_transaction_id( $transaction_id );
3956
+        }
3957 3957
 
3958
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3959
-			return $this->save();
3960
-		}
3958
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3959
+            return $this->save();
3960
+        }
3961 3961
 
3962
-		// Set the completed date.
3963
-		$this->set_date_completed( current_time( 'mysql' ) );
3962
+        // Set the completed date.
3963
+        $this->set_date_completed( current_time( 'mysql' ) );
3964 3964
 
3965
-		// Set the new status.
3966
-		$gateway = sanitize_text_field( $this->get_gateway_title() );
3967
-		if ( $this->is_renewal() || ! $this->is_parent() ) {
3965
+        // Set the new status.
3966
+        $gateway = sanitize_text_field( $this->get_gateway_title() );
3967
+        if ( $this->is_renewal() || ! $this->is_parent() ) {
3968 3968
 
3969
-			$_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway );
3970
-			$_note = $_note . empty( $note ) ? '' : " ($note)";
3969
+            $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway );
3970
+            $_note = $_note . empty( $note ) ? '' : " ($note)";
3971 3971
 
3972
-			if ( 'none' == $this->get_gateway() ) {
3973
-				$_note = $note;
3974
-			}
3972
+            if ( 'none' == $this->get_gateway() ) {
3973
+                $_note = $note;
3974
+            }
3975 3975
 
3976
-			$this->set_status( 'wpi-renewal', $_note );
3976
+            $this->set_status( 'wpi-renewal', $_note );
3977 3977
 
3978
-		} else {
3978
+        } else {
3979 3979
 
3980
-			$_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway );
3981
-			$_note = $_note . empty( $note ) ? '' : " ($note)";
3980
+            $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway );
3981
+            $_note = $_note . empty( $note ) ? '' : " ($note)";
3982 3982
 
3983
-			if ( 'none' == $this->get_gateway() ) {
3984
-				$_note = $note;
3985
-			}
3983
+            if ( 'none' == $this->get_gateway() ) {
3984
+                $_note = $note;
3985
+            }
3986 3986
 
3987
-			$this->set_status( 'publish', $_note );
3987
+            $this->set_status( 'publish', $_note );
3988 3988
 
3989
-		}
3989
+        }
3990 3990
 
3991
-		// Set checkout mode.
3992
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3993
-		$this->set_mode( $mode );
3991
+        // Set checkout mode.
3992
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3993
+        $this->set_mode( $mode );
3994 3994
 
3995
-		// Save the invoice.
3995
+        // Save the invoice.
3996 3996
         $this->save();
3997
-	}
3998
-
3999
-	/**
4000
-	 * Save data to the database.
4001
-	 *
4002
-	 * @since 1.0.19
4003
-	 * @return int invoice ID
4004
-	 */
4005
-	public function save() {
4006
-		$this->maybe_set_date_paid();
4007
-		$this->maybe_set_key();
4008
-		parent::save();
4009
-		$this->clear_cache();
4010
-		$this->status_transition();
4011
-		return $this->get_id();
4012
-	}
4013
-
4014
-	/**
3997
+    }
3998
+
3999
+    /**
4000
+     * Save data to the database.
4001
+     *
4002
+     * @since 1.0.19
4003
+     * @return int invoice ID
4004
+     */
4005
+    public function save() {
4006
+        $this->maybe_set_date_paid();
4007
+        $this->maybe_set_key();
4008
+        parent::save();
4009
+        $this->clear_cache();
4010
+        $this->status_transition();
4011
+        return $this->get_id();
4012
+    }
4013
+
4014
+    /**
4015 4015
      * Clears the subscription's cache.
4016 4016
      */
4017 4017
     public function clear_cache() {
4018
-		wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
4019
-		wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
4020
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
4021
-	}
4018
+        wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
4019
+        wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
4020
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
4021
+    }
4022 4022
 
4023 4023
 }
Please login to merge, or discard this patch.