Passed
Push — master ( c4c78b...c15536 )
by Brian
08:03 queued 02:54
created
vendor/ayecode/wp-super-duper/wp-super-duper.php 1 patch
Indentation   +1995 added lines, -1995 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  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
-	define( 'SUPER_DUPER_VER', '1.1.10' );
9
-
10
-	/**
11
-	 * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
12
-	 *
13
-	 * Should not be called direct but extended instead.
14
-	 *
15
-	 * Class WP_Super_Duper
16
-	 * @since 1.0.16 change log moved to file change-log.txt - CHANGED
17
-	 * @ver 1.1.1
18
-	 */
19
-	class WP_Super_Duper extends WP_Widget {
20
-
21
-		public $version = SUPER_DUPER_VER;
22
-		public $font_awesome_icon_version = "5.11.2";
23
-		public $block_code;
24
-		public $options;
25
-		public $base_id;
26
-		public $settings_hash;
27
-		public $arguments = array();
28
-		public $instance = array();
29
-		private $class_name;
30
-
31
-		/**
32
-		 * The relative url to the current folder.
33
-		 *
34
-		 * @var string
35
-		 */
36
-		public $url = '';
37
-
38
-		/**
39
-		 * Take the array options and use them to build.
40
-		 */
41
-		public function __construct( $options ) {
42
-			global $sd_widgets;
43
-
44
-			$sd_widgets[ $options['base_id'] ] = array(
45
-				'name'       => $options['name'],
46
-				'class_name' => $options['class_name'],
47
-				'output_types' => !empty($options['output_types']) ? $options['output_types'] : array()
48
-			);
49
-			$this->base_id                     = $options['base_id'];
50
-			// lets filter the options before we do anything
51
-			$options       = apply_filters( "wp_super_duper_options", $options );
52
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
53
-			$options       = $this->add_name_from_key( $options );
54
-			$this->options = $options;
55
-
56
-			$this->base_id   = $options['base_id'];
57
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
8
+    define( 'SUPER_DUPER_VER', '1.1.10' );
9
+
10
+    /**
11
+     * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
12
+     *
13
+     * Should not be called direct but extended instead.
14
+     *
15
+     * Class WP_Super_Duper
16
+     * @since 1.0.16 change log moved to file change-log.txt - CHANGED
17
+     * @ver 1.1.1
18
+     */
19
+    class WP_Super_Duper extends WP_Widget {
20
+
21
+        public $version = SUPER_DUPER_VER;
22
+        public $font_awesome_icon_version = "5.11.2";
23
+        public $block_code;
24
+        public $options;
25
+        public $base_id;
26
+        public $settings_hash;
27
+        public $arguments = array();
28
+        public $instance = array();
29
+        private $class_name;
30
+
31
+        /**
32
+         * The relative url to the current folder.
33
+         *
34
+         * @var string
35
+         */
36
+        public $url = '';
37
+
38
+        /**
39
+         * Take the array options and use them to build.
40
+         */
41
+        public function __construct( $options ) {
42
+            global $sd_widgets;
43
+
44
+            $sd_widgets[ $options['base_id'] ] = array(
45
+                'name'       => $options['name'],
46
+                'class_name' => $options['class_name'],
47
+                'output_types' => !empty($options['output_types']) ? $options['output_types'] : array()
48
+            );
49
+            $this->base_id                     = $options['base_id'];
50
+            // lets filter the options before we do anything
51
+            $options       = apply_filters( "wp_super_duper_options", $options );
52
+            $options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
53
+            $options       = $this->add_name_from_key( $options );
54
+            $this->options = $options;
55
+
56
+            $this->base_id   = $options['base_id'];
57
+            $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
58 58
 
59 59
             // nested blocks can't work as a widget
60 60
             if(!empty($this->options['nested-block'])){
@@ -65,234 +65,234 @@  discard block
 block discarded – undo
65 65
                 }
66 66
             }
67 67
 
68
-			// init parent
69
-			if(empty($this->options['output_types']) || in_array('widget',$this->options['output_types'])){
68
+            // init parent
69
+            if(empty($this->options['output_types']) || in_array('widget',$this->options['output_types'])){
70 70
                 parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
71
-			}
71
+            }
72 72
 
73 73
 
74
-			if ( isset( $options['class_name'] ) ) {
75
-				// register widget
76
-				$this->class_name = $options['class_name'];
74
+            if ( isset( $options['class_name'] ) ) {
75
+                // register widget
76
+                $this->class_name = $options['class_name'];
77 77
 
78
-				// register shortcode, this needs to be done even for blocks and widgets
78
+                // register shortcode, this needs to be done even for blocks and widgets
79 79
                 $this->register_shortcode();
80 80
 
81 81
 
82
-				// Fusion Builder (avada) support
83
-				if ( function_exists( 'fusion_builder_map' ) ) {
84
-					add_action( 'init', array( $this, 'register_fusion_element' ) );
85
-				}
82
+                // Fusion Builder (avada) support
83
+                if ( function_exists( 'fusion_builder_map' ) ) {
84
+                    add_action( 'init', array( $this, 'register_fusion_element' ) );
85
+                }
86 86
 
87
-				// register block
88
-				if(empty($this->options['output_types']) || in_array('block',$this->options['output_types'])){
89
-				    add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
87
+                // register block
88
+                if(empty($this->options['output_types']) || in_array('block',$this->options['output_types'])){
89
+                    add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
90 90
                 }
91
-			}
91
+            }
92 92
 
93
-			// add the CSS and JS we need ONCE
94
-			global $sd_widget_scripts;
93
+            // add the CSS and JS we need ONCE
94
+            global $sd_widget_scripts;
95 95
 
96
-			if ( ! $sd_widget_scripts ) {
97
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
98
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
99
-				wp_add_inline_style( 'widgets', $this->widget_css() );
96
+            if ( ! $sd_widget_scripts ) {
97
+                wp_add_inline_script( 'admin-widgets', $this->widget_js() );
98
+                wp_add_inline_script( 'customize-controls', $this->widget_js() );
99
+                wp_add_inline_style( 'widgets', $this->widget_css() );
100 100
 
101
-				// maybe add elementor editor styles
102
-				add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) );
101
+                // maybe add elementor editor styles
102
+                add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) );
103 103
 
104
-				$sd_widget_scripts = true;
104
+                $sd_widget_scripts = true;
105 105
 
106
-				// add shortcode insert button once
107
-				add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
108
-				// generatepress theme sections compatibility
109
-				if ( function_exists( 'generate_sections_sections_metabox' ) ) {
110
-					add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) );
111
-				}
112
-				/* Load script on Divi theme builder page */
113
-				if ( function_exists( 'et_builder_is_tb_admin_screen' ) && et_builder_is_tb_admin_screen() ) {
114
-					add_thickbox();
115
-					add_action( 'admin_footer', array( $this, 'shortcode_insert_button_script' ) );
116
-				}
106
+                // add shortcode insert button once
107
+                add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
108
+                // generatepress theme sections compatibility
109
+                if ( function_exists( 'generate_sections_sections_metabox' ) ) {
110
+                    add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) );
111
+                }
112
+                /* Load script on Divi theme builder page */
113
+                if ( function_exists( 'et_builder_is_tb_admin_screen' ) && et_builder_is_tb_admin_screen() ) {
114
+                    add_thickbox();
115
+                    add_action( 'admin_footer', array( $this, 'shortcode_insert_button_script' ) );
116
+                }
117 117
 
118
-				if ( $this->is_preview() ) {
119
-					add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
120
-					// this makes the insert button work for elementor
121
-					add_action( 'elementor/editor/after_enqueue_scripts', array(
122
-						$this,
123
-						'shortcode_insert_button_script'
124
-					) ); // for elementor
125
-				}
126
-				// this makes the insert button work for cornerstone
127
-				add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) );
118
+                if ( $this->is_preview() ) {
119
+                    add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
120
+                    // this makes the insert button work for elementor
121
+                    add_action( 'elementor/editor/after_enqueue_scripts', array(
122
+                        $this,
123
+                        'shortcode_insert_button_script'
124
+                    ) ); // for elementor
125
+                }
126
+                // this makes the insert button work for cornerstone
127
+                add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) );
128 128
 
129
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
130
-				add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
129
+                add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
130
+                add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
131 131
 
132
-				// add generator text to admin head
133
-				add_action( 'admin_head', array( $this, 'generator' ) );
134
-			}
132
+                // add generator text to admin head
133
+                add_action( 'admin_head', array( $this, 'generator' ) );
134
+            }
135 135
 
136
-			do_action( 'wp_super_duper_widget_init', $options, $this );
137
-		}
136
+            do_action( 'wp_super_duper_widget_init', $options, $this );
137
+        }
138 138
 
139 139
         /**
140 140
          * The register widget function
141 141
          * @return void
142 142
          */
143
-		public function _register() {
143
+        public function _register() {
144 144
             if(empty($this->options['output_types']) || in_array('widget',$this->options['output_types'])){
145 145
                 parent::_register();
146
-			}
147
-		}
146
+            }
147
+        }
148 148
 
149
-		/**
150
-		 * Add our widget CSS to elementor editor.
151
-		 */
152
-		public function elementor_editor_styles() {
153
-			wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) );
154
-		}
149
+        /**
150
+         * Add our widget CSS to elementor editor.
151
+         */
152
+        public function elementor_editor_styles() {
153
+            wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) );
154
+        }
155 155
 
156
-		public function register_fusion_element() {
156
+        public function register_fusion_element() {
157 157
 
158
-			$options = $this->options;
158
+            $options = $this->options;
159 159
 
160
-			if ( $this->base_id ) {
160
+            if ( $this->base_id ) {
161 161
 
162
-				$params = $this->get_fusion_params();
162
+                $params = $this->get_fusion_params();
163 163
 
164
-				$args = array(
165
-					'name'            => $options['name'],
166
-					'shortcode'       => $this->base_id,
167
-					'icon'            => $options['block-icon'] ? $options['block-icon'] : 'far fa-square',
168
-					'allow_generator' => true,
169
-				);
164
+                $args = array(
165
+                    'name'            => $options['name'],
166
+                    'shortcode'       => $this->base_id,
167
+                    'icon'            => $options['block-icon'] ? $options['block-icon'] : 'far fa-square',
168
+                    'allow_generator' => true,
169
+                );
170 170
 
171
-				if ( ! empty( $params ) ) {
172
-					$args['params'] = $params;
173
-				}
171
+                if ( ! empty( $params ) ) {
172
+                    $args['params'] = $params;
173
+                }
174 174
 
175
-				fusion_builder_map( $args );
176
-			}
175
+                fusion_builder_map( $args );
176
+            }
177 177
 
178
-		}
178
+        }
179 179
 
180
-		public function get_fusion_params() {
181
-			$params    = array();
182
-			$arguments = $this->get_arguments();
183
-
184
-			if ( ! empty( $arguments ) ) {
185
-				foreach ( $arguments as $key => $val ) {
186
-					$param = array();
187
-					// type
188
-					$param['type'] = str_replace(
189
-						array(
190
-							"text",
191
-							"number",
192
-							"email",
193
-							"color",
194
-							"checkbox"
195
-						),
196
-						array(
197
-							"textfield",
198
-							"textfield",
199
-							"textfield",
200
-							"colorpicker",
201
-							"select",
202
-
203
-						),
204
-						$val['type'] );
205
-
206
-					// multiselect
207
-					if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) {
208
-						$param['type']     = 'multiple_select';
209
-						$param['multiple'] = true;
210
-					}
180
+        public function get_fusion_params() {
181
+            $params    = array();
182
+            $arguments = $this->get_arguments();
183
+
184
+            if ( ! empty( $arguments ) ) {
185
+                foreach ( $arguments as $key => $val ) {
186
+                    $param = array();
187
+                    // type
188
+                    $param['type'] = str_replace(
189
+                        array(
190
+                            "text",
191
+                            "number",
192
+                            "email",
193
+                            "color",
194
+                            "checkbox"
195
+                        ),
196
+                        array(
197
+                            "textfield",
198
+                            "textfield",
199
+                            "textfield",
200
+                            "colorpicker",
201
+                            "select",
211 202
 
212
-					// heading
213
-					$param['heading'] = $val['title'];
203
+                        ),
204
+                        $val['type'] );
214 205
 
215
-					// description
216
-					$param['description'] = isset( $val['desc'] ) ? $val['desc'] : '';
206
+                    // multiselect
207
+                    if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) {
208
+                        $param['type']     = 'multiple_select';
209
+                        $param['multiple'] = true;
210
+                    }
217 211
 
218
-					// param_name
219
-					$param['param_name'] = $key;
212
+                    // heading
213
+                    $param['heading'] = $val['title'];
220 214
 
221
-					// Default
222
-					$param['default'] = isset( $val['default'] ) ? $val['default'] : '';
215
+                    // description
216
+                    $param['description'] = isset( $val['desc'] ) ? $val['desc'] : '';
223 217
 
224
-					// Group
225
-					if ( isset( $val['group'] ) ) {
226
-						$param['group'] = $val['group'];
227
-					}
218
+                    // param_name
219
+                    $param['param_name'] = $key;
228 220
 
229
-					// value
230
-					if ( $val['type'] == 'checkbox' ) {
231
-						if ( isset( $val['default'] ) && $val['default'] == '0' ) {
232
-							unset( $param['default'] );
233
-						}
234
-						$param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) );
235
-					} elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) {
236
-						$param['value'] = isset( $val['options'] ) ? $val['options'] : array();
237
-					} else {
238
-						$param['value'] = isset( $val['default'] ) ? $val['default'] : '';
239
-					}
221
+                    // Default
222
+                    $param['default'] = isset( $val['default'] ) ? $val['default'] : '';
240 223
 
241
-					// setup the param
242
-					$params[] = $param;
224
+                    // Group
225
+                    if ( isset( $val['group'] ) ) {
226
+                        $param['group'] = $val['group'];
227
+                    }
243 228
 
244
-				}
245
-			}
229
+                    // value
230
+                    if ( $val['type'] == 'checkbox' ) {
231
+                        if ( isset( $val['default'] ) && $val['default'] == '0' ) {
232
+                            unset( $param['default'] );
233
+                        }
234
+                        $param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) );
235
+                    } elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) {
236
+                        $param['value'] = isset( $val['options'] ) ? $val['options'] : array();
237
+                    } else {
238
+                        $param['value'] = isset( $val['default'] ) ? $val['default'] : '';
239
+                    }
246 240
 
241
+                    // setup the param
242
+                    $params[] = $param;
247 243
 
248
-			return $params;
249
-		}
244
+                }
245
+            }
250 246
 
251
-		/**
252
-		 * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder
253
-		 */
254
-		public static function maybe_cornerstone_builder() {
255
-			if ( did_action( 'cornerstone_before_boot_app' ) ) {
256
-				self::shortcode_insert_button_script();
257
-			}
258
-		}
259 247
 
260
-		/**
261
-		 * A function to ge the shortcode builder picker html.
262
-		 *
263
-		 * @param string $editor_id
264
-		 *
265
-		 * @return string
266
-		 */
267
-		public static function get_picker( $editor_id = '' ) {
268
-
269
-			ob_start();
270
-			if ( isset( $_POST['editor_id'] ) ) {
271
-				$editor_id = esc_attr( $_POST['editor_id'] );
272
-			} elseif ( isset( $_REQUEST['et_fb'] ) ) {
273
-				$editor_id = 'main_content_content_vb_tiny_mce';
274
-			}
248
+            return $params;
249
+        }
250
+
251
+        /**
252
+         * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder
253
+         */
254
+        public static function maybe_cornerstone_builder() {
255
+            if ( did_action( 'cornerstone_before_boot_app' ) ) {
256
+                self::shortcode_insert_button_script();
257
+            }
258
+        }
259
+
260
+        /**
261
+         * A function to ge the shortcode builder picker html.
262
+         *
263
+         * @param string $editor_id
264
+         *
265
+         * @return string
266
+         */
267
+        public static function get_picker( $editor_id = '' ) {
268
+
269
+            ob_start();
270
+            if ( isset( $_POST['editor_id'] ) ) {
271
+                $editor_id = esc_attr( $_POST['editor_id'] );
272
+            } elseif ( isset( $_REQUEST['et_fb'] ) ) {
273
+                $editor_id = 'main_content_content_vb_tiny_mce';
274
+            }
275 275
 
276
-			global $sd_widgets;
276
+            global $sd_widgets;
277 277
 
278 278
 //			print_r($sd_widgets);exit;
279
-			?>
279
+            ?>
280 280
 
281 281
 			<div class="sd-shortcode-left-wrap">
282 282
 				<?php
283
-				ksort( $sd_widgets );
284
-				//				print_r($sd_widgets);exit;
285
-				if ( ! empty( $sd_widgets ) ) {
286
-					echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
287
-					echo "<option>" . __( 'Select shortcode' ) . "</option>";
288
-					foreach ( $sd_widgets as $shortcode => $class ) {
289
-						if(!empty($class['output_types']) && !in_array('shortcode', $class['output_types'])){ continue; }
290
-						echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
291
-					}
292
-					echo "</select>";
283
+                ksort( $sd_widgets );
284
+                //				print_r($sd_widgets);exit;
285
+                if ( ! empty( $sd_widgets ) ) {
286
+                    echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
287
+                    echo "<option>" . __( 'Select shortcode' ) . "</option>";
288
+                    foreach ( $sd_widgets as $shortcode => $class ) {
289
+                        if(!empty($class['output_types']) && !in_array('shortcode', $class['output_types'])){ continue; }
290
+                        echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
291
+                    }
292
+                    echo "</select>";
293 293
 
294
-				}
295
-				?>
294
+                }
295
+                ?>
296 296
 				<div class="sd-shortcode-settings"></div>
297 297
 
298 298
 			</div>
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
 					<?php if ( $editor_id != '' ) { ?>
304 304
 						<button class="button sd-insert-shortcode-button"
305 305
 						        onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) {
306
-							        echo "'" . $editor_id . "'";
307
-						        } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
306
+                                    echo "'" . $editor_id . "'";
307
+                                } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
308 308
 					<?php } ?>
309 309
 					<button class="button"
310 310
 					        onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button>
@@ -312,135 +312,135 @@  discard block
 block discarded – undo
312 312
 			</div>
313 313
 			<?php
314 314
 
315
-			$html = ob_get_clean();
315
+            $html = ob_get_clean();
316 316
 
317
-			if ( wp_doing_ajax() ) {
318
-				echo $html;
319
-				$should_die = true;
317
+            if ( wp_doing_ajax() ) {
318
+                echo $html;
319
+                $should_die = true;
320 320
 
321
-				// some builder get the editor via ajax so we should not die on those occasions
322
-				$dont_die = array(
323
-					'parent_tag',// WP Bakery
324
-					'avia_request' // enfold
325
-				);
321
+                // some builder get the editor via ajax so we should not die on those occasions
322
+                $dont_die = array(
323
+                    'parent_tag',// WP Bakery
324
+                    'avia_request' // enfold
325
+                );
326 326
 
327
-				foreach ( $dont_die as $request ) {
328
-					if ( isset( $_REQUEST[ $request ] ) ) {
329
-						$should_die = false;
330
-					}
331
-				}
327
+                foreach ( $dont_die as $request ) {
328
+                    if ( isset( $_REQUEST[ $request ] ) ) {
329
+                        $should_die = false;
330
+                    }
331
+                }
332 332
 
333
-				if ( $should_die ) {
334
-					wp_die();
335
-				}
333
+                if ( $should_die ) {
334
+                    wp_die();
335
+                }
336 336
 
337
-			} else {
338
-				return $html;
339
-			}
337
+            } else {
338
+                return $html;
339
+            }
340 340
 
341
-			return '';
341
+            return '';
342 342
 
343
-		}
343
+        }
344 344
 
345
-		/**
346
-		 * Output the version in the admin header.
347
-		 */
348
-		public function generator() {
349
-			echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />';
350
-		}
345
+        /**
346
+         * Output the version in the admin header.
347
+         */
348
+        public function generator() {
349
+            echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />';
350
+        }
351 351
 
352
-		/**
353
-		 * Get widget settings.
354
-		 *
355
-		 * @since 1.0.0
356
-		 */
357
-		public static function get_widget_settings() {
358
-			global $sd_widgets;
359
-
360
-			$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
361
-			if ( ! $shortcode ) {
362
-				wp_die();
363
-			}
364
-			$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
365
-			if ( ! $widget_args ) {
366
-				wp_die();
367
-			}
368
-			$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
369
-			if ( ! $class_name ) {
370
-				wp_die();
371
-			}
352
+        /**
353
+         * Get widget settings.
354
+         *
355
+         * @since 1.0.0
356
+         */
357
+        public static function get_widget_settings() {
358
+            global $sd_widgets;
359
+
360
+            $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
361
+            if ( ! $shortcode ) {
362
+                wp_die();
363
+            }
364
+            $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
365
+            if ( ! $widget_args ) {
366
+                wp_die();
367
+            }
368
+            $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
369
+            if ( ! $class_name ) {
370
+                wp_die();
371
+            }
372 372
 
373
-			// invoke an instance method
374
-			$widget = new $class_name;
373
+            // invoke an instance method
374
+            $widget = new $class_name;
375 375
 
376
-			ob_start();
377
-			$widget->form( array() );
378
-			$form = ob_get_clean();
379
-			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
380
-			echo "<style>" . $widget->widget_css() . "</style>";
381
-			echo "<script>" . $widget->widget_js() . "</script>";
382
-			?>
376
+            ob_start();
377
+            $widget->form( array() );
378
+            $form = ob_get_clean();
379
+            echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
380
+            echo "<style>" . $widget->widget_css() . "</style>";
381
+            echo "<script>" . $widget->widget_js() . "</script>";
382
+            ?>
383 383
 			<?php
384
-			wp_die();
385
-		}
384
+            wp_die();
385
+        }
386 386
 
387
-		/**
388
-		 * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
389
-		 *
390
-		 * @param string $editor_id Optional. Shortcode editor id. Default null.
391
-		 * @param string $insert_shortcode_function Optional. Insert shortcode function. Default null.
392
-		 *
393
-		 *@since 1.0.0
394
-		 *
395
-		 */
396
-		public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
397
-			global $sd_widgets, $shortcode_insert_button_once;
398
-			if ( $shortcode_insert_button_once ) {
399
-				return;
400
-			}
401
-			add_thickbox();
387
+        /**
388
+         * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
389
+         *
390
+         * @param string $editor_id Optional. Shortcode editor id. Default null.
391
+         * @param string $insert_shortcode_function Optional. Insert shortcode function. Default null.
392
+         *
393
+         *@since 1.0.0
394
+         *
395
+         */
396
+        public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
397
+            global $sd_widgets, $shortcode_insert_button_once;
398
+            if ( $shortcode_insert_button_once ) {
399
+                return;
400
+            }
401
+            add_thickbox();
402 402
 
403 403
 
404
-			/**
405
-			 * Cornerstone makes us play dirty tricks :/
406
-			 * 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.
407
-			 */
408
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
409
-				echo '<span id="insert-media-button">';
410
-			}
404
+            /**
405
+             * Cornerstone makes us play dirty tricks :/
406
+             * 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.
407
+             */
408
+            if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
409
+                echo '<span id="insert-media-button">';
410
+            }
411 411
 
412
-			echo self::shortcode_button( 'this', 'true' );
412
+            echo self::shortcode_button( 'this', 'true' );
413 413
 
414
-			// see opening note
415
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
416
-				echo '</span>'; // end #insert-media-button
417
-			}
414
+            // see opening note
415
+            if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
416
+                echo '</span>'; // end #insert-media-button
417
+            }
418 418
 
419
-			// Add separate script for generatepress theme sections
420
-			if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) {
421
-			} else {
422
-				self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
423
-			}
419
+            // Add separate script for generatepress theme sections
420
+            if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) {
421
+            } else {
422
+                self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
423
+            }
424 424
 
425
-			$shortcode_insert_button_once = true;
426
-		}
425
+            $shortcode_insert_button_once = true;
426
+        }
427 427
 
428
-		/**
429
-		 * Gets the shortcode insert button html.
430
-		 *
431
-		 * @param string $id
432
-		 * @param string $search_for_id
433
-		 *
434
-		 * @return mixed
435
-		 */
436
-		public static function shortcode_button( $id = '', $search_for_id = '' ) {
437
-			ob_start();
438
-			?>
428
+        /**
429
+         * Gets the shortcode insert button html.
430
+         *
431
+         * @param string $id
432
+         * @param string $search_for_id
433
+         *
434
+         * @return mixed
435
+         */
436
+        public static function shortcode_button( $id = '', $search_for_id = '' ) {
437
+            ob_start();
438
+            ?>
439 439
 			<span class="sd-lable-shortcode-inserter">
440 440
 				<a onclick="sd_ajax_get_picker(<?php echo $id;
441
-				if ( $search_for_id ) {
442
-					echo "," . $search_for_id;
443
-				} ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
441
+                if ( $search_for_id ) {
442
+                    echo "," . $search_for_id;
443
+                } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
444 444
 				   class="thickbox button super-duper-content-open" title="Add Shortcode">
445 445
 					<span style="vertical-align: middle;line-height: 18px;font-size: 20px;"
446 446
 					      class="dashicons dashicons-screenoptions"></span>
@@ -451,21 +451,21 @@  discard block
 block discarded – undo
451 451
 			</span>
452 452
 
453 453
 			<?php
454
-			$html = ob_get_clean();
454
+            $html = ob_get_clean();
455 455
 
456
-			// remove line breaks so we can use it in js
457
-			return preg_replace( "/\r|\n/", "", trim( $html ) );
458
-		}
456
+            // remove line breaks so we can use it in js
457
+            return preg_replace( "/\r|\n/", "", trim( $html ) );
458
+        }
459 459
 
460
-		/**
461
-		 * Makes SD work with the siteOrigin page builder.
462
-		 *
463
-		 * @return mixed
464
-		 *@since 1.0.6
465
-		 */
466
-		public static function siteorigin_js() {
467
-			ob_start();
468
-			?>
460
+        /**
461
+         * Makes SD work with the siteOrigin page builder.
462
+         *
463
+         * @return mixed
464
+         *@since 1.0.6
465
+         */
466
+        public static function siteorigin_js() {
467
+            ob_start();
468
+            ?>
469 469
 			<script>
470 470
 				/**
471 471
 				 * Check a form to see what items should be shown or hidden.
@@ -541,29 +541,29 @@  discard block
 block discarded – undo
541 541
 				});
542 542
 			</script>
543 543
 			<?php
544
-			$output = ob_get_clean();
544
+            $output = ob_get_clean();
545 545
 
546
-			/*
546
+            /*
547 547
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
548 548
 			 */
549 549
 
550
-			return str_replace( array(
551
-				'<script>',
552
-				'</script>'
553
-			), '', $output );
554
-		}
550
+            return str_replace( array(
551
+                '<script>',
552
+                '</script>'
553
+            ), '', $output );
554
+        }
555 555
 
556
-		/**
557
-		 * Output the JS and CSS for the shortcode insert button.
558
-		 *
559
-		 * @param string $editor_id
560
-		 * @param string $insert_shortcode_function
561
-		 *
562
-		 *@since 1.0.6
563
-		 *
564
-		 */
565
-		public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
566
-			?>
556
+        /**
557
+         * Output the JS and CSS for the shortcode insert button.
558
+         *
559
+         * @param string $editor_id
560
+         * @param string $insert_shortcode_function
561
+         *
562
+         *@since 1.0.6
563
+         *
564
+         */
565
+        public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
566
+            ?>
567 567
 			<style>
568 568
 				.sd-shortcode-left-wrap {
569 569
 					float: left;
@@ -691,35 +691,35 @@  discard block
 block discarded – undo
691 691
 				<?php } ?>
692 692
 			</style>
693 693
 			<?php
694
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
695
-				echo "<script>" . self::siteorigin_js() . "</script>";
696
-			}
697
-			?>
694
+            if ( class_exists( 'SiteOrigin_Panels' ) ) {
695
+                echo "<script>" . self::siteorigin_js() . "</script>";
696
+            }
697
+            ?>
698 698
 			<script>
699 699
 				<?php
700
-				if(! empty( $insert_shortcode_function )){
701
-					echo $insert_shortcode_function;
702
-				}else{
703
-
704
-				/**
705
-				 * Function for super duper insert shortcode.
706
-				 *
707
-				 * @since 1.0.0
708
-				 */
709
-				?>
700
+                if(! empty( $insert_shortcode_function )){
701
+                    echo $insert_shortcode_function;
702
+                }else{
703
+
704
+                /**
705
+                 * Function for super duper insert shortcode.
706
+                 *
707
+                 * @since 1.0.0
708
+                 */
709
+                ?>
710 710
 				function sd_insert_shortcode($editor_id) {
711 711
 					$shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val();
712 712
 					if ($shortcode) {
713 713
 						if (!$editor_id) {
714 714
 							<?php
715
-							if ( isset( $_REQUEST['et_fb'] ) ) {
716
-								echo '$editor_id = "#main_content_content_vb_tiny_mce";';
717
-							} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
718
-								echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
719
-							} else {
720
-								echo '$editor_id = "#wp-content-editor-container textarea";';
721
-							}
722
-							?>
715
+                            if ( isset( $_REQUEST['et_fb'] ) ) {
716
+                                echo '$editor_id = "#main_content_content_vb_tiny_mce";';
717
+                            } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
718
+                                echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
719
+                            } else {
720
+                                echo '$editor_id = "#wp-content-editor-container textarea";';
721
+                            }
722
+                            ?>
723 723
 						} else {
724 724
 							$editor_id = '#' + $editor_id;
725 725
 						}
@@ -1046,18 +1046,18 @@  discard block
 block discarded – undo
1046 1046
 
1047 1047
 			</script>
1048 1048
 			<?php
1049
-		}
1049
+        }
1050 1050
 
1051
-		/**
1052
-		 * Gets some CSS for the widgets screen.
1053
-		 *
1054
-		 * @param bool $advanced If we should include advanced CSS.
1055
-		 *
1056
-		 * @return mixed
1057
-		 */
1058
-		public function widget_css( $advanced = true ) {
1059
-			ob_start();
1060
-			?>
1051
+        /**
1052
+         * Gets some CSS for the widgets screen.
1053
+         *
1054
+         * @param bool $advanced If we should include advanced CSS.
1055
+         *
1056
+         * @return mixed
1057
+         */
1058
+        public function widget_css( $advanced = true ) {
1059
+            ob_start();
1060
+            ?>
1061 1061
 			<style>
1062 1062
 				<?php if( $advanced ){ ?>
1063 1063
 				.sd-advanced-setting {
@@ -1095,26 +1095,26 @@  discard block
 block discarded – undo
1095 1095
 				}
1096 1096
 			</style>
1097 1097
 			<?php
1098
-			$output = ob_get_clean();
1098
+            $output = ob_get_clean();
1099 1099
 
1100
-			/*
1100
+            /*
1101 1101
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1102 1102
 			 */
1103 1103
 
1104
-			return str_replace( array(
1105
-				'<style>',
1106
-				'</style>'
1107
-			), '', $output );
1108
-		}
1104
+            return str_replace( array(
1105
+                '<style>',
1106
+                '</style>'
1107
+            ), '', $output );
1108
+        }
1109 1109
 
1110
-		/**
1111
-		 * Gets some JS for the widgets screen.
1112
-		 *
1113
-		 * @return mixed
1114
-		 */
1115
-		public function widget_js() {
1116
-			ob_start();
1117
-			?>
1110
+        /**
1111
+         * Gets some JS for the widgets screen.
1112
+         *
1113
+         * @return mixed
1114
+         */
1115
+        public function widget_js() {
1116
+            ob_start();
1117
+            ?>
1118 1118
 			<script>
1119 1119
 
1120 1120
 				/**
@@ -1265,471 +1265,471 @@  discard block
 block discarded – undo
1265 1265
 				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
1266 1266
 			</script>
1267 1267
 			<?php
1268
-			$output = ob_get_clean();
1268
+            $output = ob_get_clean();
1269 1269
 
1270
-			/*
1270
+            /*
1271 1271
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1272 1272
 			 */
1273 1273
 
1274
-			return str_replace( array(
1275
-				'<script>',
1276
-				'</script>'
1277
-			), '', $output );
1278
-		}
1274
+            return str_replace( array(
1275
+                '<script>',
1276
+                '</script>'
1277
+            ), '', $output );
1278
+        }
1279 1279
 
1280 1280
 
1281
-		/**
1282
-		 * Set the name from the argument key.
1283
-		 *
1284
-		 * @param $options
1285
-		 *
1286
-		 * @return mixed
1287
-		 */
1288
-		private function add_name_from_key( $options, $arguments = false ) {
1289
-			if ( ! empty( $options['arguments'] ) ) {
1290
-				foreach ( $options['arguments'] as $key => $val ) {
1291
-					$options['arguments'][ $key ]['name'] = $key;
1292
-				}
1293
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1294
-				foreach ( $options as $key => $val ) {
1295
-					$options[ $key ]['name'] = $key;
1296
-				}
1297
-			}
1281
+        /**
1282
+         * Set the name from the argument key.
1283
+         *
1284
+         * @param $options
1285
+         *
1286
+         * @return mixed
1287
+         */
1288
+        private function add_name_from_key( $options, $arguments = false ) {
1289
+            if ( ! empty( $options['arguments'] ) ) {
1290
+                foreach ( $options['arguments'] as $key => $val ) {
1291
+                    $options['arguments'][ $key ]['name'] = $key;
1292
+                }
1293
+            } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1294
+                foreach ( $options as $key => $val ) {
1295
+                    $options[ $key ]['name'] = $key;
1296
+                }
1297
+            }
1298 1298
 
1299
-			return $options;
1300
-		}
1299
+            return $options;
1300
+        }
1301 1301
 
1302
-		/**
1303
-		 * Register the parent shortcode.
1304
-		 *
1305
-		 * @since 1.0.0
1306
-		 */
1307
-		public function register_shortcode() {
1308
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1309
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( $this, 'render_shortcode' ) );
1310
-		}
1302
+        /**
1303
+         * Register the parent shortcode.
1304
+         *
1305
+         * @since 1.0.0
1306
+         */
1307
+        public function register_shortcode() {
1308
+            add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1309
+            add_action( 'wp_ajax_super_duper_output_shortcode', array( $this, 'render_shortcode' ) );
1310
+        }
1311 1311
 
1312
-		/**
1313
-		 * Render the shortcode via ajax so we can return it to Gutenberg.
1314
-		 *
1315
-		 * @since 1.0.0
1316
-		 */
1317
-		public function render_shortcode() {
1318
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1319
-			if ( ! current_user_can( 'manage_options' ) ) {
1320
-				wp_die();
1321
-			}
1312
+        /**
1313
+         * Render the shortcode via ajax so we can return it to Gutenberg.
1314
+         *
1315
+         * @since 1.0.0
1316
+         */
1317
+        public function render_shortcode() {
1318
+            check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1319
+            if ( ! current_user_can( 'manage_options' ) ) {
1320
+                wp_die();
1321
+            }
1322 1322
 
1323
-			// we might need the $post value here so lets set it.
1324
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1325
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
1326
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
1327
-					global $post;
1328
-					$post = $post_obj;
1329
-				}
1330
-			}
1323
+            // we might need the $post value here so lets set it.
1324
+            if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1325
+                $post_obj = get_post( absint( $_POST['post_id'] ) );
1326
+                if ( ! empty( $post_obj ) && empty( $post ) ) {
1327
+                    global $post;
1328
+                    $post = $post_obj;
1329
+                }
1330
+            }
1331 1331
 
1332
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1333
-				$is_preview = $this->is_preview();
1334
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1335
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1336
-				$attributes       = '';
1337
-				if ( ! empty( $attributes_array ) ) {
1338
-					foreach ( $attributes_array as $key => $value ) {
1339
-						if ( is_array( $value ) ) {
1340
-							$value = implode( ",", $value );
1341
-						}
1332
+            if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1333
+                $is_preview = $this->is_preview();
1334
+                $shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1335
+                $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1336
+                $attributes       = '';
1337
+                if ( ! empty( $attributes_array ) ) {
1338
+                    foreach ( $attributes_array as $key => $value ) {
1339
+                        if ( is_array( $value ) ) {
1340
+                            $value = implode( ",", $value );
1341
+                        }
1342 1342
 
1343
-						if ( ! empty( $value ) ) {
1344
-							$value = wp_unslash( $value );
1343
+                        if ( ! empty( $value ) ) {
1344
+                            $value = wp_unslash( $value );
1345 1345
 
1346
-							// Encode [ and ].
1347
-							if ( $is_preview ) {
1348
-								$value = $this->encode_shortcodes( $value );
1349
-							}
1350
-						}
1351
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . esc_attr( $value ) . "' ";
1352
-					}
1353
-				}
1346
+                            // Encode [ and ].
1347
+                            if ( $is_preview ) {
1348
+                                $value = $this->encode_shortcodes( $value );
1349
+                            }
1350
+                        }
1351
+                        $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . esc_attr( $value ) . "' ";
1352
+                    }
1353
+                }
1354 1354
 
1355
-				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1355
+                $shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1356 1356
 
1357
-				$content = do_shortcode( $shortcode );
1357
+                $content = do_shortcode( $shortcode );
1358 1358
 
1359
-				// Decode [ and ].
1360
-				if ( ! empty( $content ) && $is_preview ) {
1361
-					$content = $this->decode_shortcodes( $content );
1362
-				}
1359
+                // Decode [ and ].
1360
+                if ( ! empty( $content ) && $is_preview ) {
1361
+                    $content = $this->decode_shortcodes( $content );
1362
+                }
1363 1363
 
1364
-				echo $content;
1365
-			}
1366
-			wp_die();
1367
-		}
1364
+                echo $content;
1365
+            }
1366
+            wp_die();
1367
+        }
1368 1368
 
1369
-		/**
1370
-		 * Output the shortcode.
1371
-		 *
1372
-		 * @param array $args
1373
-		 * @param string $content
1374
-		 *
1375
-		 * @return string
1376
-		 */
1377
-		public function shortcode_output( $args = array(), $content = '' ) {
1378
-			$_instance = $args;
1379
-
1380
-			$args = $this->argument_values( $args );
1381
-
1382
-			// add extra argument so we know its a output to gutenberg
1383
-			//$args
1384
-			$args = $this->string_to_bool( $args );
1385
-
1386
-			// if we have a enclosed shortcode we add it to the special `html` argument
1387
-			if ( ! empty( $content ) ) {
1388
-				$args['html'] = $content;
1389
-			}
1369
+        /**
1370
+         * Output the shortcode.
1371
+         *
1372
+         * @param array $args
1373
+         * @param string $content
1374
+         *
1375
+         * @return string
1376
+         */
1377
+        public function shortcode_output( $args = array(), $content = '' ) {
1378
+            $_instance = $args;
1390 1379
 
1391
-			if ( ! $this->is_preview() ) {
1392
-				/**
1393
-				 * Filters the settings for a particular widget args.
1394
-				 *
1395
-				 * @param array          $args      The current widget instance's settings.
1396
-				 * @param WP_Super_Duper $widget    The current widget settings.
1397
-				 * @param array          $_instance An array of default widget arguments.
1398
-				 *
1399
-				 *@since 1.0.28
1400
-				 *
1401
-				 */
1402
-				$args = apply_filters( 'wp_super_duper_widget_display_callback', $args, $this, $_instance );
1380
+            $args = $this->argument_values( $args );
1403 1381
 
1404
-				if ( ! is_array( $args ) ) {
1405
-					return $args;
1406
-				}
1407
-			}
1382
+            // add extra argument so we know its a output to gutenberg
1383
+            //$args
1384
+            $args = $this->string_to_bool( $args );
1408 1385
 
1409
-			$class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1410
-			$class .= " sdel-".$this->get_instance_hash();
1386
+            // if we have a enclosed shortcode we add it to the special `html` argument
1387
+            if ( ! empty( $content ) ) {
1388
+                $args['html'] = $content;
1389
+            }
1411 1390
 
1412
-			$class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
1413
-			$class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
1391
+            if ( ! $this->is_preview() ) {
1392
+                /**
1393
+                 * Filters the settings for a particular widget args.
1394
+                 *
1395
+                 * @param array          $args      The current widget instance's settings.
1396
+                 * @param WP_Super_Duper $widget    The current widget settings.
1397
+                 * @param array          $_instance An array of default widget arguments.
1398
+                 *
1399
+                 *@since 1.0.28
1400
+                 *
1401
+                 */
1402
+                $args = apply_filters( 'wp_super_duper_widget_display_callback', $args, $this, $_instance );
1403
+
1404
+                if ( ! is_array( $args ) ) {
1405
+                    return $args;
1406
+                }
1407
+            }
1414 1408
 
1415
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1416
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1409
+            $class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1410
+            $class .= " sdel-".$this->get_instance_hash();
1417 1411
 
1418
-			$shortcode_args = array();
1419
-			$output         = '';
1420
-			$no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1421
-			if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) {
1422
-				$no_wrap = true;
1423
-			}
1424
-			$main_content = $this->output( $args, $shortcode_args, $content );
1425
-			if ( $main_content && ! $no_wrap ) {
1426
-				// wrap the shortcode in a div with the same class as the widget
1427
-				$output .= '<div class="' . $class . '" ' . $attrs . '>';
1428
-				if ( ! empty( $args['title'] ) ) {
1429
-					// if its a shortcode and there is a title try to grab the title wrappers
1430
-					$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1431
-					if ( empty( $instance ) ) {
1432
-						global $wp_registered_sidebars;
1433
-						if ( ! empty( $wp_registered_sidebars ) ) {
1434
-							foreach ( $wp_registered_sidebars as $sidebar ) {
1435
-								if ( ! empty( $sidebar['before_title'] ) ) {
1436
-									$shortcode_args['before_title'] = $sidebar['before_title'];
1437
-									$shortcode_args['after_title']  = $sidebar['after_title'];
1438
-									break;
1439
-								}
1440
-							}
1441
-						}
1442
-					}
1443
-					$output .= $this->output_title( $shortcode_args, $args );
1444
-				}
1445
-				$output .= $main_content;
1446
-				$output .= '</div>';
1447
-			} elseif ( $main_content && $no_wrap ) {
1448
-				$output .= $main_content;
1449
-			}
1412
+            $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
1413
+            $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
1450 1414
 
1451
-			// if preview show a placeholder if empty
1452
-			if ( $this->is_preview() && $output == '' ) {
1453
-				$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1454
-			}
1415
+            $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1416
+            $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1455 1417
 
1456
-			return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this );
1457
-		}
1418
+            $shortcode_args = array();
1419
+            $output         = '';
1420
+            $no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1421
+            if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) {
1422
+                $no_wrap = true;
1423
+            }
1424
+            $main_content = $this->output( $args, $shortcode_args, $content );
1425
+            if ( $main_content && ! $no_wrap ) {
1426
+                // wrap the shortcode in a div with the same class as the widget
1427
+                $output .= '<div class="' . $class . '" ' . $attrs . '>';
1428
+                if ( ! empty( $args['title'] ) ) {
1429
+                    // if its a shortcode and there is a title try to grab the title wrappers
1430
+                    $shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1431
+                    if ( empty( $instance ) ) {
1432
+                        global $wp_registered_sidebars;
1433
+                        if ( ! empty( $wp_registered_sidebars ) ) {
1434
+                            foreach ( $wp_registered_sidebars as $sidebar ) {
1435
+                                if ( ! empty( $sidebar['before_title'] ) ) {
1436
+                                    $shortcode_args['before_title'] = $sidebar['before_title'];
1437
+                                    $shortcode_args['after_title']  = $sidebar['after_title'];
1438
+                                    break;
1439
+                                }
1440
+                            }
1441
+                        }
1442
+                    }
1443
+                    $output .= $this->output_title( $shortcode_args, $args );
1444
+                }
1445
+                $output .= $main_content;
1446
+                $output .= '</div>';
1447
+            } elseif ( $main_content && $no_wrap ) {
1448
+                $output .= $main_content;
1449
+            }
1458 1450
 
1459
-		/**
1460
-		 * Placeholder text to show if output is empty and we are on a preview/builder page.
1461
-		 *
1462
-		 * @param string $name
1463
-		 *
1464
-		 * @return string
1465
-		 */
1466
-		public function preview_placeholder_text( $name = '' ) {
1467
-			return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1468
-		}
1451
+            // if preview show a placeholder if empty
1452
+            if ( $this->is_preview() && $output == '' ) {
1453
+                $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1454
+            }
1469 1455
 
1470
-		/**
1471
-		 * Sometimes booleans values can be turned to strings, so we fix that.
1472
-		 *
1473
-		 * @param $options
1474
-		 *
1475
-		 * @return mixed
1476
-		 */
1477
-		public function string_to_bool( $options ) {
1478
-			// convert bool strings to booleans
1479
-			foreach ( $options as $key => $val ) {
1480
-				if ( $val == 'false' ) {
1481
-					$options[ $key ] = false;
1482
-				} elseif ( $val == 'true' ) {
1483
-					$options[ $key ] = true;
1484
-				}
1485
-			}
1456
+            return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this );
1457
+        }
1486 1458
 
1487
-			return $options;
1488
-		}
1459
+        /**
1460
+         * Placeholder text to show if output is empty and we are on a preview/builder page.
1461
+         *
1462
+         * @param string $name
1463
+         *
1464
+         * @return string
1465
+         */
1466
+        public function preview_placeholder_text( $name = '' ) {
1467
+            return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1468
+        }
1489 1469
 
1490
-		/**
1491
-		 * Get the argument values that are also filterable.
1492
-		 *
1493
-		 * @param $instance
1494
-		 *
1495
-		 * @return array
1496
-		 *@since 1.0.12 Don't set checkbox default value if the value is empty.
1497
-		 *
1498
-		 */
1499
-		public function argument_values( $instance ) {
1500
-			$argument_values = array();
1501
-
1502
-			// set widget instance
1503
-			$this->instance = $instance;
1504
-
1505
-			if ( empty( $this->arguments ) ) {
1506
-				$this->arguments = $this->get_arguments();
1507
-			}
1470
+        /**
1471
+         * Sometimes booleans values can be turned to strings, so we fix that.
1472
+         *
1473
+         * @param $options
1474
+         *
1475
+         * @return mixed
1476
+         */
1477
+        public function string_to_bool( $options ) {
1478
+            // convert bool strings to booleans
1479
+            foreach ( $options as $key => $val ) {
1480
+                if ( $val == 'false' ) {
1481
+                    $options[ $key ] = false;
1482
+                } elseif ( $val == 'true' ) {
1483
+                    $options[ $key ] = true;
1484
+                }
1485
+            }
1508 1486
 
1509
-			if ( ! empty( $this->arguments ) ) {
1510
-				foreach ( $this->arguments as $key => $args ) {
1511
-					// set the input name from the key
1512
-					$args['name'] = $key;
1513
-					//
1514
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1515
-					if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) {
1516
-						// don't set default for an empty checkbox
1517
-					} elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1518
-						$argument_values[ $key ] = $args['default'];
1519
-					}
1520
-				}
1521
-			}
1487
+            return $options;
1488
+        }
1522 1489
 
1523
-			return $argument_values;
1524
-		}
1490
+        /**
1491
+         * Get the argument values that are also filterable.
1492
+         *
1493
+         * @param $instance
1494
+         *
1495
+         * @return array
1496
+         *@since 1.0.12 Don't set checkbox default value if the value is empty.
1497
+         *
1498
+         */
1499
+        public function argument_values( $instance ) {
1500
+            $argument_values = array();
1525 1501
 
1526
-		/**
1527
-		 * Set arguments in super duper.
1528
-		 *
1529
-		 * @return array Set arguments.
1530
-		 *@since 1.0.0
1531
-		 *
1532
-		 */
1533
-		public function set_arguments() {
1534
-			return $this->arguments;
1535
-		}
1502
+            // set widget instance
1503
+            $this->instance = $instance;
1536 1504
 
1537
-		/**
1538
-		 * Get arguments in super duper.
1539
-		 *
1540
-		 * @return array Get arguments.
1541
-		 *@since 1.0.0
1542
-		 *
1543
-		 */
1544
-		public function get_arguments() {
1545
-			if ( empty( $this->arguments ) ) {
1546
-				$this->arguments = $this->set_arguments();
1547
-			}
1505
+            if ( empty( $this->arguments ) ) {
1506
+                $this->arguments = $this->get_arguments();
1507
+            }
1548 1508
 
1549
-			$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1550
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
1509
+            if ( ! empty( $this->arguments ) ) {
1510
+                foreach ( $this->arguments as $key => $args ) {
1511
+                    // set the input name from the key
1512
+                    $args['name'] = $key;
1513
+                    //
1514
+                    $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1515
+                    if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) {
1516
+                        // don't set default for an empty checkbox
1517
+                    } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1518
+                        $argument_values[ $key ] = $args['default'];
1519
+                    }
1520
+                }
1521
+            }
1551 1522
 
1552
-			return $this->arguments;
1553
-		}
1523
+            return $argument_values;
1524
+        }
1554 1525
 
1555
-		/**
1556
-		 * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
1557
-		 *
1558
-		 * @param array $args
1559
-		 * @param array $widget_args
1560
-		 * @param string $content
1561
-		 */
1562
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
1526
+        /**
1527
+         * Set arguments in super duper.
1528
+         *
1529
+         * @return array Set arguments.
1530
+         *@since 1.0.0
1531
+         *
1532
+         */
1533
+        public function set_arguments() {
1534
+            return $this->arguments;
1535
+        }
1563 1536
 
1564
-		}
1537
+        /**
1538
+         * Get arguments in super duper.
1539
+         *
1540
+         * @return array Get arguments.
1541
+         *@since 1.0.0
1542
+         *
1543
+         */
1544
+        public function get_arguments() {
1545
+            if ( empty( $this->arguments ) ) {
1546
+                $this->arguments = $this->set_arguments();
1547
+            }
1565 1548
 
1566
-		/**
1567
-		 * Add the dynamic block code inline when the wp-block in enqueued.
1568
-		 */
1569
-		public function register_block() {
1570
-			wp_add_inline_script( 'wp-blocks', $this->block() );
1571
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
1572
-				wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1573
-			}
1574
-		}
1549
+            $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1550
+            $this->arguments = $this->add_name_from_key( $this->arguments, true );
1575 1551
 
1576
-		/**
1577
-		 * Check if we need to show advanced options.
1578
-		 *
1579
-		 * @return bool
1580
-		 */
1581
-		public function block_show_advanced() {
1582
-
1583
-			$show      = false;
1584
-			$arguments = $this->get_arguments();
1585
-
1586
-			if ( ! empty( $arguments ) ) {
1587
-				foreach ( $arguments as $argument ) {
1588
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1589
-						$show = true;
1590
-						break; // no need to continue if we know we have it
1591
-					}
1592
-				}
1593
-			}
1552
+            return $this->arguments;
1553
+        }
1594 1554
 
1595
-			return $show;
1596
-		}
1555
+        /**
1556
+         * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
1557
+         *
1558
+         * @param array $args
1559
+         * @param array $widget_args
1560
+         * @param string $content
1561
+         */
1562
+        public function output( $args = array(), $widget_args = array(), $content = '' ) {
1597 1563
 
1598
-		/**
1599
-		 * Get the url path to the current folder.
1600
-		 *
1601
-		 * @return string
1602
-		 */
1603
-		public function get_url() {
1604
-			$url = $this->url;
1605
-
1606
-			if ( ! $url ) {
1607
-				$content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
1608
-				$content_url = untrailingslashit( WP_CONTENT_URL );
1609
-
1610
-				// Replace http:// to https://.
1611
-				if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
1612
-					$content_url = str_replace( 'http://', 'https://', $content_url );
1613
-				}
1564
+        }
1614 1565
 
1615
-				// Check if we are inside a plugin
1616
-				$file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
1617
-				$url = str_replace( $content_dir, $content_url, $file_dir );
1618
-				$url = trailingslashit( $url );
1619
-				$this->url = $url;
1620
-			}
1566
+        /**
1567
+         * Add the dynamic block code inline when the wp-block in enqueued.
1568
+         */
1569
+        public function register_block() {
1570
+            wp_add_inline_script( 'wp-blocks', $this->block() );
1571
+            if ( class_exists( 'SiteOrigin_Panels' ) ) {
1572
+                wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1573
+            }
1574
+        }
1621 1575
 
1622
-			return $url;
1623
-		}
1576
+        /**
1577
+         * Check if we need to show advanced options.
1578
+         *
1579
+         * @return bool
1580
+         */
1581
+        public function block_show_advanced() {
1624 1582
 
1625
-		/**
1626
-		 * Get the url path to the current folder.
1627
-		 *
1628
-		 * @return string
1629
-		 */
1630
-		public function get_url_old() {
1583
+            $show      = false;
1584
+            $arguments = $this->get_arguments();
1631 1585
 
1632
-			$url = $this->url;
1586
+            if ( ! empty( $arguments ) ) {
1587
+                foreach ( $arguments as $argument ) {
1588
+                    if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1589
+                        $show = true;
1590
+                        break; // no need to continue if we know we have it
1591
+                    }
1592
+                }
1593
+            }
1633 1594
 
1634
-			if ( ! $url ) {
1635
-				// check if we are inside a plugin
1636
-				$file_dir = str_replace( "/includes", "", dirname( __FILE__ ) );
1595
+            return $show;
1596
+        }
1637 1597
 
1638
-				$dir_parts = explode( "/wp-content/", $file_dir );
1639
-				$url_parts = explode( "/wp-content/", plugins_url() );
1598
+        /**
1599
+         * Get the url path to the current folder.
1600
+         *
1601
+         * @return string
1602
+         */
1603
+        public function get_url() {
1604
+            $url = $this->url;
1640 1605
 
1641
-				if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) {
1642
-					$url       = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] );
1643
-					$this->url = $url;
1644
-				}
1645
-			}
1606
+            if ( ! $url ) {
1607
+                $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
1608
+                $content_url = untrailingslashit( WP_CONTENT_URL );
1646 1609
 
1610
+                // Replace http:// to https://.
1611
+                if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
1612
+                    $content_url = str_replace( 'http://', 'https://', $content_url );
1613
+                }
1647 1614
 
1648
-			return $url;
1649
-		}
1615
+                // Check if we are inside a plugin
1616
+                $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
1617
+                $url = str_replace( $content_dir, $content_url, $file_dir );
1618
+                $url = trailingslashit( $url );
1619
+                $this->url = $url;
1620
+            }
1650 1621
 
1651
-		/**
1652
-		 * Generate the block icon.
1653
-		 *
1654
-		 * Enables the use of Font Awesome icons.
1655
-		 *
1656
-		 * @note xlink:href is actually deprecated but href is not supported by all so we use both.
1657
-		 *
1658
-		 * @param $icon
1659
-		 *
1660
-		 * @return string
1661
-		 *@since 1.1.0
1662
-		 */
1663
-		public function get_block_icon( $icon ) {
1664
-
1665
-			// check if we have a Font Awesome icon
1666
-			$fa_type = '';
1667
-			if ( substr( $icon, 0, 7 ) === "fas fa-" ) {
1668
-				$fa_type = 'solid';
1669
-			} elseif ( substr( $icon, 0, 7 ) === "far fa-" ) {
1670
-				$fa_type = 'regular';
1671
-			} elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) {
1672
-				$fa_type = 'brands';
1673
-			} else {
1674
-				$icon = "'" . $icon . "'";
1675
-			}
1622
+            return $url;
1623
+        }
1676 1624
 
1677
-			// set the icon if we found one
1678
-			if ( $fa_type ) {
1679
-				$fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon );
1680
-				$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 . "'}))";
1681
-			}
1625
+        /**
1626
+         * Get the url path to the current folder.
1627
+         *
1628
+         * @return string
1629
+         */
1630
+        public function get_url_old() {
1682 1631
 
1683
-			return $icon;
1684
-		}
1632
+            $url = $this->url;
1633
+
1634
+            if ( ! $url ) {
1635
+                // check if we are inside a plugin
1636
+                $file_dir = str_replace( "/includes", "", dirname( __FILE__ ) );
1637
+
1638
+                $dir_parts = explode( "/wp-content/", $file_dir );
1639
+                $url_parts = explode( "/wp-content/", plugins_url() );
1640
+
1641
+                if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) {
1642
+                    $url       = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] );
1643
+                    $this->url = $url;
1644
+                }
1645
+            }
1646
+
1647
+
1648
+            return $url;
1649
+        }
1650
+
1651
+        /**
1652
+         * Generate the block icon.
1653
+         *
1654
+         * Enables the use of Font Awesome icons.
1655
+         *
1656
+         * @note xlink:href is actually deprecated but href is not supported by all so we use both.
1657
+         *
1658
+         * @param $icon
1659
+         *
1660
+         * @return string
1661
+         *@since 1.1.0
1662
+         */
1663
+        public function get_block_icon( $icon ) {
1664
+
1665
+            // check if we have a Font Awesome icon
1666
+            $fa_type = '';
1667
+            if ( substr( $icon, 0, 7 ) === "fas fa-" ) {
1668
+                $fa_type = 'solid';
1669
+            } elseif ( substr( $icon, 0, 7 ) === "far fa-" ) {
1670
+                $fa_type = 'regular';
1671
+            } elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) {
1672
+                $fa_type = 'brands';
1673
+            } else {
1674
+                $icon = "'" . $icon . "'";
1675
+            }
1685 1676
 
1686
-		public function group_arguments( $arguments ) {
1677
+            // set the icon if we found one
1678
+            if ( $fa_type ) {
1679
+                $fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon );
1680
+                $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 . "'}))";
1681
+            }
1682
+
1683
+            return $icon;
1684
+        }
1685
+
1686
+        public function group_arguments( $arguments ) {
1687 1687
 //			echo '###';print_r($arguments);
1688
-			if ( ! empty( $arguments ) ) {
1689
-				$temp_arguments = array();
1690
-				$general        = __( "General" );
1691
-				$add_sections   = false;
1692
-				foreach ( $arguments as $key => $args ) {
1693
-					if ( isset( $args['group'] ) ) {
1694
-						$temp_arguments[ $args['group'] ][ $key ] = $args;
1695
-						$add_sections                             = true;
1696
-					} else {
1697
-						$temp_arguments[ $general ][ $key ] = $args;
1698
-					}
1699
-				}
1688
+            if ( ! empty( $arguments ) ) {
1689
+                $temp_arguments = array();
1690
+                $general        = __( "General" );
1691
+                $add_sections   = false;
1692
+                foreach ( $arguments as $key => $args ) {
1693
+                    if ( isset( $args['group'] ) ) {
1694
+                        $temp_arguments[ $args['group'] ][ $key ] = $args;
1695
+                        $add_sections                             = true;
1696
+                    } else {
1697
+                        $temp_arguments[ $general ][ $key ] = $args;
1698
+                    }
1699
+                }
1700 1700
 
1701
-				// only add sections if more than one
1702
-				if ( $add_sections ) {
1703
-					$arguments = $temp_arguments;
1704
-				}
1705
-			}
1701
+                // only add sections if more than one
1702
+                if ( $add_sections ) {
1703
+                    $arguments = $temp_arguments;
1704
+                }
1705
+            }
1706 1706
 
1707 1707
 //			echo '###';print_r($arguments);
1708
-			return $arguments;
1709
-		}
1708
+            return $arguments;
1709
+        }
1710 1710
 
1711 1711
 
1712
-		/**
1713
-		 * Output the JS for building the dynamic Guntenberg block.
1714
-		 *
1715
-		 * @return mixed
1716
-		 *@since 1.0.9 Save numbers as numbers and not strings.
1717
-		 * @since 1.1.0 Font Awesome classes can be used for icons.
1718
-		 * @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.
1719
-		 */
1720
-		public function block() {
1712
+        /**
1713
+         * Output the JS for building the dynamic Guntenberg block.
1714
+         *
1715
+         * @return mixed
1716
+         *@since 1.0.9 Save numbers as numbers and not strings.
1717
+         * @since 1.1.0 Font Awesome classes can be used for icons.
1718
+         * @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.
1719
+         */
1720
+        public function block() {
1721 1721
             global $sd_is_js_functions_loaded;
1722 1722
 
1723
-			ob_start();
1723
+            ob_start();
1724 1724
 
1725
-			$show_advanced = $this->block_show_advanced();
1725
+            $show_advanced = $this->block_show_advanced();
1726 1726
 
1727 1727
 
1728
-			?>
1728
+            ?>
1729 1729
 			<script>
1730 1730
 
1731 1731
 			<?php
1732
-			if(!$sd_is_js_functions_loaded){
1732
+            if(!$sd_is_js_functions_loaded){
1733 1733
                 $sd_is_js_functions_loaded = true;
1734 1734
             ?>
1735 1735
 
@@ -2103,10 +2103,10 @@  discard block
 block discarded – undo
2103 2103
 
2104 2104
             }
2105 2105
 
2106
-			if(method_exists($this,'block_global_js')){
2107
-					echo $this->block_global_js();
2108
-			}
2109
-			?>
2106
+            if(method_exists($this,'block_global_js')){
2107
+                    echo $this->block_global_js();
2108
+            }
2109
+            ?>
2110 2110
 
2111 2111
 jQuery(function() {
2112 2112
 
@@ -2156,14 +2156,14 @@  discard block
 block discarded – undo
2156 2156
 						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/.
2157 2157
 						supports: {
2158 2158
 							<?php
2159
-							if ( isset( $this->options['block-supports'] ) ) {
2160
-								echo $this->array_to_attributes( $this->options['block-supports'] );
2161
-							}
2162
-							?>
2159
+                            if ( isset( $this->options['block-supports'] ) ) {
2160
+                                echo $this->array_to_attributes( $this->options['block-supports'] );
2161
+                            }
2162
+                            ?>
2163 2163
 						},
2164 2164
 						<?php
2165
-						if ( isset( $this->options['block-label'] ) ) {
2166
-						?>
2165
+                        if ( isset( $this->options['block-label'] ) ) {
2166
+                        ?>
2167 2167
 						__experimentalLabel( attributes, { context } ) {
2168 2168
                             return <?php echo $this->options['block-label']; ?>;
2169 2169
                         },
@@ -2172,7 +2172,7 @@  discard block
 block discarded – undo
2172 2172
                         ?>
2173 2173
 						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.
2174 2174
 						<?php if ( isset( $this->options['block-keywords'] ) ) {
2175
-						echo "keywords : " . $this->options['block-keywords'] . ",";
2175
+                        echo "keywords : " . $this->options['block-keywords'] . ",";
2176 2176
 
2177 2177
 //						// block hover preview.
2178 2178
 //						$example_args = array();
@@ -2197,86 +2197,86 @@  discard block
 block discarded – undo
2197 2197
 
2198 2198
                         }
2199 2199
 
2200
-						// maybe set no_wrap
2201
-						$no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
2202
-						if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) {
2203
-							$no_wrap = true;
2204
-						}
2205
-						if ( $no_wrap ) {
2206
-							$this->options['block-wrap'] = '';
2207
-						}
2200
+                        // maybe set no_wrap
2201
+                        $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
2202
+                        if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) {
2203
+                            $no_wrap = true;
2204
+                        }
2205
+                        if ( $no_wrap ) {
2206
+                            $this->options['block-wrap'] = '';
2207
+                        }
2208 2208
 
2209
-						// maybe load the drag/drop functions.
2210
-						$img_drag_drop = false;
2209
+                        // maybe load the drag/drop functions.
2210
+                        $img_drag_drop = false;
2211 2211
 
2212
-						$show_alignment = false;
2213
-						// align feature
2214
-						/*echo "supports: {";
2212
+                        $show_alignment = false;
2213
+                        // align feature
2214
+                        /*echo "supports: {";
2215 2215
 						echo "	align: true,";
2216 2216
 						echo "  html: false";
2217 2217
 						echo "},";*/
2218 2218
 
2219
-						if ( ! empty( $this->arguments ) ) {
2220
-							echo "attributes : {";
2219
+                        if ( ! empty( $this->arguments ) ) {
2220
+                            echo "attributes : {";
2221 2221
 
2222
-							if ( $show_advanced ) {
2223
-								echo "show_advanced: {";
2224
-								echo "	type: 'boolean',";
2225
-								echo "  default: false,";
2226
-								echo "},";
2227
-							}
2222
+                            if ( $show_advanced ) {
2223
+                                echo "show_advanced: {";
2224
+                                echo "	type: 'boolean',";
2225
+                                echo "  default: false,";
2226
+                                echo "},";
2227
+                            }
2228 2228
 
2229
-							// block wrap element
2230
-							if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this?
2231
-								echo "block_wrap: {";
2232
-								echo "	type: 'string',";
2233
-								echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
2234
-								echo "},";
2235
-							}
2229
+                            // block wrap element
2230
+                            if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this?
2231
+                                echo "block_wrap: {";
2232
+                                echo "	type: 'string',";
2233
+                                echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
2234
+                                echo "},";
2235
+                            }
2236 2236
 
2237 2237
 
2238 2238
 
2239
-							foreach ( $this->arguments as $key => $args ) {
2239
+                            foreach ( $this->arguments as $key => $args ) {
2240 2240
 
2241
-								if( $args['type'] == 'image' ||  $args['type'] == 'images' ){
2242
-									$img_drag_drop = true;
2243
-								}
2241
+                                if( $args['type'] == 'image' ||  $args['type'] == 'images' ){
2242
+                                    $img_drag_drop = true;
2243
+                                }
2244 2244
 
2245
-								// set if we should show alignment
2246
-								if ( $key == 'alignment' ) {
2247
-									$show_alignment = true;
2248
-								}
2245
+                                // set if we should show alignment
2246
+                                if ( $key == 'alignment' ) {
2247
+                                    $show_alignment = true;
2248
+                                }
2249 2249
 
2250
-								$extra = '';
2250
+                                $extra = '';
2251 2251
 
2252
-								if ( $args['type'] == 'notice' ||  $args['type'] == 'tab' ) {
2253
-									continue;
2254
-								}
2255
-								elseif ( $args['type'] == 'checkbox' ) {
2256
-									$type    = 'boolean';
2257
-									$default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
2258
-								} elseif ( $args['type'] == 'number' ) {
2259
-									$type    = 'number';
2260
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2261
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
2262
-									$type = 'array';
2263
-									if ( isset( $args['default'] ) && is_array( $args['default'] ) ) {
2264
-										$default = ! empty( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
2265
-									} else {
2266
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2267
-									}
2268
-								} elseif ( $args['type'] == 'tagselect' ) {
2269
-									$type    = 'array';
2270
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2271
-								} elseif ( $args['type'] == 'multiselect' ) {
2272
-									$type    = 'array';
2273
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2274
-								} elseif ( $args['type'] == 'image_xy' ) {
2275
-									$type    = 'object';
2276
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2277
-								} elseif ( $args['type'] == 'image' ) {
2278
-									$type    = 'string';
2279
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2252
+                                if ( $args['type'] == 'notice' ||  $args['type'] == 'tab' ) {
2253
+                                    continue;
2254
+                                }
2255
+                                elseif ( $args['type'] == 'checkbox' ) {
2256
+                                    $type    = 'boolean';
2257
+                                    $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
2258
+                                } elseif ( $args['type'] == 'number' ) {
2259
+                                    $type    = 'number';
2260
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2261
+                                } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
2262
+                                    $type = 'array';
2263
+                                    if ( isset( $args['default'] ) && is_array( $args['default'] ) ) {
2264
+                                        $default = ! empty( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
2265
+                                    } else {
2266
+                                        $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2267
+                                    }
2268
+                                } elseif ( $args['type'] == 'tagselect' ) {
2269
+                                    $type    = 'array';
2270
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2271
+                                } elseif ( $args['type'] == 'multiselect' ) {
2272
+                                    $type    = 'array';
2273
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2274
+                                } elseif ( $args['type'] == 'image_xy' ) {
2275
+                                    $type    = 'object';
2276
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2277
+                                } elseif ( $args['type'] == 'image' ) {
2278
+                                    $type    = 'string';
2279
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2280 2280
 
2281 2281
                                     // add a field for ID
2282 2282
 //                                    echo $key . "_id : {";
@@ -2286,25 +2286,25 @@  discard block
 block discarded – undo
2286 2286
 //                                    echo "type : 'object',";
2287 2287
 //                                    echo "},";
2288 2288
 
2289
-								} else {
2290
-									$type    = !empty($args['hidden_type']) ? esc_attr($args['hidden_type']) : 'string';
2291
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2289
+                                } else {
2290
+                                    $type    = !empty($args['hidden_type']) ? esc_attr($args['hidden_type']) : 'string';
2291
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
2292 2292
 
2293
-								}
2294
-								echo $key . " : {";
2295
-								echo "type : '$type',";
2296
-								echo "default : $default,";
2297
-								echo "},";
2298
-							}
2293
+                                }
2294
+                                echo $key . " : {";
2295
+                                echo "type : '$type',";
2296
+                                echo "default : $default,";
2297
+                                echo "},";
2298
+                            }
2299 2299
 
2300
-							echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
2301
-							echo "className: { type: 'string', default: '' },";
2300
+                            echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
2301
+                            echo "className: { type: 'string', default: '' },";
2302 2302
 
2303
-							echo "},";
2303
+                            echo "},";
2304 2304
 
2305
-						}
2305
+                        }
2306 2306
 
2307
-						?>
2307
+                        ?>
2308 2308
 
2309 2309
 						// The "edit" property must be a valid function.
2310 2310
 						edit: function (props) {
@@ -2404,9 +2404,9 @@  discard block
 block discarded – undo
2404 2404
 
2405 2405
 							var $value = '';
2406 2406
 							<?php
2407
-							// if we have a post_type and a category then link them
2408
-							if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){
2409
-							?>
2407
+                            // if we have a post_type and a category then link them
2408
+                            if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){
2409
+                            ?>
2410 2410
 							if(typeof(prev_attributes[props.clientId]) != 'undefined' ){
2411 2411
 								$pt = props.attributes.post_type;
2412 2412
 								if(post_type_rest_slugs.length){
@@ -2469,7 +2469,7 @@  discard block
 block discarded – undo
2469 2469
 <?php
2470 2470
 $current_screen = function_exists('get_current_screen') ? get_current_screen() : '';
2471 2471
 if(!empty($current_screen->base) && $current_screen->base==='widgets'){
2472
-	echo 'const { deviceType } = "";';
2472
+    echo 'const { deviceType } = "";';
2473 2473
 }else{
2474 2474
 ?>
2475 2475
 /** Get device type const. */
@@ -2503,8 +2503,8 @@  discard block
 block discarded – undo
2503 2503
 										'attributes': props.attributes,
2504 2504
 										'block_parent_name': parentBlocks.length ? parentBlocks[parentBlocks.length - 1].name : '',
2505 2505
 										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
2506
-										echo $post->ID;
2507
-									}else{echo '0';}?>,
2506
+                                        echo $post->ID;
2507
+                                    }else{echo '0';}?>,
2508 2508
 										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
2509 2509
 									};
2510 2510
 
@@ -2581,10 +2581,10 @@  discard block
 block discarded – undo
2581 2581
 
2582 2582
 									<?php
2583 2583
 
2584
-									if(! empty( $this->arguments )){
2584
+                                    if(! empty( $this->arguments )){
2585 2585
 
2586
-									if ( $show_advanced ) {
2587
-									?>
2586
+                                    if ( $show_advanced ) {
2587
+                                    ?>
2588 2588
 									el('div', {
2589 2589
 											style: {'padding-left': '16px','padding-right': '16px'}
2590 2590
 										},
@@ -2602,146 +2602,146 @@  discard block
 block discarded – undo
2602 2602
 									,
2603 2603
 									<?php
2604 2604
 
2605
-									}
2605
+                                    }
2606 2606
 
2607
-								//	print_r( $this->arguments);
2607
+                                //	print_r( $this->arguments);
2608 2608
 
2609
-									//echo '####';
2609
+                                    //echo '####';
2610 2610
 
2611
-									$arguments = $this->group_arguments( $this->arguments );
2611
+                                    $arguments = $this->group_arguments( $this->arguments );
2612 2612
 //print_r($arguments ); exit;
2613
-									// Do we have sections?
2614
-									$has_sections = $arguments == $this->arguments ? false : true;
2613
+                                    // Do we have sections?
2614
+                                    $has_sections = $arguments == $this->arguments ? false : true;
2615 2615
 
2616 2616
 
2617
-									if($has_sections){
2618
-									$panel_count = 0;
2619
-									$open_tab = '';
2617
+                                    if($has_sections){
2618
+                                    $panel_count = 0;
2619
+                                    $open_tab = '';
2620 2620
 
2621
-									$open_tab_groups = array();
2622
-									$used_tabs = array();
2623
-									foreach($arguments as $key => $args){
2621
+                                    $open_tab_groups = array();
2622
+                                    $used_tabs = array();
2623
+                                    foreach($arguments as $key => $args){
2624 2624
 
2625
-										$close_tab = false;
2626
-										$close_tabs = false;
2625
+                                        $close_tab = false;
2626
+                                        $close_tabs = false;
2627 2627
 
2628
-										 if(!empty($this->options['block_group_tabs'])) {
2629
-											foreach($this->options['block_group_tabs'] as $tab_name => $tab_args){
2630
-												if(in_array($key,$tab_args['groups'])){
2628
+                                            if(!empty($this->options['block_group_tabs'])) {
2629
+                                            foreach($this->options['block_group_tabs'] as $tab_name => $tab_args){
2630
+                                                if(in_array($key,$tab_args['groups'])){
2631 2631
 
2632
-													$open_tab_groups[] = $key;
2632
+                                                    $open_tab_groups[] = $key;
2633 2633
 
2634
-													if($open_tab != $tab_name){
2635
-														$tab_args['tab']['tabs_open'] = $open_tab == '' ? true : false;
2636
-														$tab_args['tab']['open'] = true;
2634
+                                                    if($open_tab != $tab_name){
2635
+                                                        $tab_args['tab']['tabs_open'] = $open_tab == '' ? true : false;
2636
+                                                        $tab_args['tab']['open'] = true;
2637 2637
 
2638
-														$this->block_tab_start( '', $tab_args );
2638
+                                                        $this->block_tab_start( '', $tab_args );
2639 2639
 //														echo '###open'.$tab_name;print_r($tab_args);
2640
-														$open_tab = $tab_name;
2641
-														$used_tabs[] = $tab_name;
2642
-													}
2640
+                                                        $open_tab = $tab_name;
2641
+                                                        $used_tabs[] = $tab_name;
2642
+                                                    }
2643 2643
 
2644
-													if($open_tab_groups == $tab_args['groups']){
2645
-														//$open_tab = '';
2646
-														$close_tab = true;
2647
-														$open_tab_groups = array();
2644
+                                                    if($open_tab_groups == $tab_args['groups']){
2645
+                                                        //$open_tab = '';
2646
+                                                        $close_tab = true;
2647
+                                                        $open_tab_groups = array();
2648 2648
 
2649 2649
 //													print_r(array_keys($this->options['block_group_tabs']));echo '####';print_r($used_tabs);
2650
-													if($used_tabs == array_keys($this->options['block_group_tabs'])){
2650
+                                                    if($used_tabs == array_keys($this->options['block_group_tabs'])){
2651 2651
 //														echo '@@@';
2652
-															$close_tabs = true;
2653
-														}
2654
-													}
2652
+                                                            $close_tabs = true;
2653
+                                                        }
2654
+                                                    }
2655 2655
 
2656
-												}
2657
-											}
2658
-										}
2656
+                                                }
2657
+                                            }
2658
+                                        }
2659 2659
 
2660 2660
 //
2661 2661
 
2662
-									//	print_r($arguments);exit;
2662
+                                    //	print_r($arguments);exit;
2663 2663
 
2664
-										?>
2664
+                                        ?>
2665 2665
 										el(wp.components.PanelBody, {
2666 2666
 												title: '<?php esc_attr_e( $key ); ?>',
2667 2667
 												initialOpen: <?php if ( $panel_count ) {
2668
-												echo "false";
2669
-											} else {
2670
-												echo "true";
2671
-											}?>
2668
+                                                echo "false";
2669
+                                            } else {
2670
+                                                echo "true";
2671
+                                            }?>
2672 2672
 											},
2673 2673
 											<?php
2674 2674
 
2675 2675
 
2676 2676
 
2677
-											foreach ( $args as $k => $a ) {
2677
+                                            foreach ( $args as $k => $a ) {
2678 2678
 
2679
-												$this->block_tab_start( $k, $a );
2680
-												$this->block_row_start( $k, $a );
2681
-												$this->build_block_arguments( $k, $a );
2682
-												$this->block_row_end( $k, $a );
2683
-												$this->block_tab_end( $k, $a );
2684
-											}
2685
-											?>
2679
+                                                $this->block_tab_start( $k, $a );
2680
+                                                $this->block_row_start( $k, $a );
2681
+                                                $this->build_block_arguments( $k, $a );
2682
+                                                $this->block_row_end( $k, $a );
2683
+                                                $this->block_tab_end( $k, $a );
2684
+                                            }
2685
+                                            ?>
2686 2686
 										),
2687 2687
 										<?php
2688
-										$panel_count ++;
2688
+                                        $panel_count ++;
2689 2689
 
2690 2690
 
2691
-										if($close_tab || $close_tabs){
2692
-											$tab_args = array(
2693
-												'tab'	=> array(
2694
-													'tabs_close' => $close_tabs,
2695
-												'close' => true,
2696
-												)
2691
+                                        if($close_tab || $close_tabs){
2692
+                                            $tab_args = array(
2693
+                                                'tab'	=> array(
2694
+                                                    'tabs_close' => $close_tabs,
2695
+                                                'close' => true,
2696
+                                                )
2697 2697
 
2698
-											);
2699
-											$this->block_tab_end( '', $tab_args );
2698
+                                            );
2699
+                                            $this->block_tab_end( '', $tab_args );
2700 2700
 //											echo '###close'; print_r($tab_args);
2701
-											$panel_count = 0;
2702
-										}
2701
+                                            $panel_count = 0;
2702
+                                        }
2703 2703
 //
2704 2704
 
2705
-									}
2706
-									}else {
2707
-									?>
2705
+                                    }
2706
+                                    }else {
2707
+                                    ?>
2708 2708
 									el(wp.components.PanelBody, {
2709 2709
 											title: '<?php esc_attr_e( "Settings" ); ?>',
2710 2710
 											initialOpen: true
2711 2711
 										},
2712 2712
 										<?php
2713
-										foreach ( $this->arguments as $key => $args ) {
2714
-											$this->block_row_start( $key, $args );
2715
-											$this->build_block_arguments( $key, $args );
2716
-											$this->block_row_end( $key, $args );
2717
-										}
2718
-										?>
2713
+                                        foreach ( $this->arguments as $key => $args ) {
2714
+                                            $this->block_row_start( $key, $args );
2715
+                                            $this->build_block_arguments( $key, $args );
2716
+                                            $this->block_row_end( $key, $args );
2717
+                                        }
2718
+                                        ?>
2719 2719
 									),
2720 2720
 									<?php
2721
-									}
2721
+                                    }
2722 2722
 
2723
-									}
2724
-									?>
2723
+                                    }
2724
+                                    ?>
2725 2725
 
2726 2726
 								),
2727 2727
 
2728 2728
 								<?php
2729
-								// If the user sets block-output array then build it
2730
-								if ( ! empty( $this->options['block-output'] ) ) {
2731
-								$this->block_element( $this->options['block-output'] );
2732
-							}elseif(!empty($this->options['block-edit-return'])){
2733
-                                   echo $this->options['block-edit-return'];
2734
-							}else{
2735
-								// if no block-output is set then we try and get the shortcode html output via ajax.
2736
-								?>
2729
+                                // If the user sets block-output array then build it
2730
+                                if ( ! empty( $this->options['block-output'] ) ) {
2731
+                                $this->block_element( $this->options['block-output'] );
2732
+                            }elseif(!empty($this->options['block-edit-return'])){
2733
+                                    echo $this->options['block-edit-return'];
2734
+                            }else{
2735
+                                // if no block-output is set then we try and get the shortcode html output via ajax.
2736
+                                ?>
2737 2737
 								el('div', wp.blockEditor.useBlockProps({
2738 2738
 									dangerouslySetInnerHTML: {__html: onChangeContent()},
2739 2739
 									className: props.className,
2740 2740
 									style: {'minHeight': '30px'}
2741 2741
 								}))
2742 2742
 								<?php
2743
-								}
2744
-								?>
2743
+                                }
2744
+                                ?>
2745 2745
 							]; // end return
2746 2746
 
2747 2747
 							<?php
@@ -2760,11 +2760,11 @@  discard block
 block discarded – undo
2760 2760
 							$html = '';
2761 2761
 							<?php
2762 2762
 
2763
-							if(! empty( $this->arguments )){
2763
+                            if(! empty( $this->arguments )){
2764 2764
 
2765
-							foreach($this->arguments as $key => $args){
2766
-                               // if($args['type']=='tabs'){continue;}
2767
-							?>
2765
+                            foreach($this->arguments as $key => $args){
2766
+                                // if($args['type']=='tabs'){continue;}
2767
+                            ?>
2768 2768
 							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
2769 2769
 								if ('<?php echo esc_attr( $key );?>' == 'html') {
2770 2770
 									$html = attr.<?php echo esc_attr( $key );?>;
@@ -2775,10 +2775,10 @@  discard block
 block discarded – undo
2775 2775
 								}
2776 2776
 							}
2777 2777
 							<?php
2778
-							}
2779
-							}
2778
+                            }
2779
+                            }
2780 2780
 
2781
-							?>
2781
+                            ?>
2782 2782
 							content += "]";
2783 2783
 
2784 2784
                             <?php
@@ -2825,7 +2825,7 @@  discard block
 block discarded – undo
2825 2825
 //                               $this->block_element( $this->options['block-output'], true );
2826 2826
 //                               echo ";";
2827 2827
 
2828
-                               ?>
2828
+                                ?>
2829 2829
                               return el(
2830 2830
                                    '',
2831 2831
                                    {},
@@ -2835,9 +2835,9 @@  discard block
 block discarded – undo
2835 2835
                                );
2836 2836
                                 <?php
2837 2837
 
2838
-							}elseif(!empty($this->options['block-save-return'])){
2839
-                                   echo 'return ' . $this->options['block-save-return'];
2840
-							}elseif(!empty($this->options['nested-block'])){
2838
+                            }elseif(!empty($this->options['block-save-return'])){
2839
+                                    echo 'return ' . $this->options['block-save-return'];
2840
+                            }elseif(!empty($this->options['nested-block'])){
2841 2841
                                 ?>
2842 2842
                               return el(
2843 2843
                                    '',
@@ -2847,22 +2847,22 @@  discard block
 block discarded – undo
2847 2847
                                    el('', {dangerouslySetInnerHTML: {__html: "[/<?php echo $this->options['base_id'];?>]"}})
2848 2848
                                );
2849 2849
                                 <?php
2850
-							}elseif(!empty( $this->options['block-save-return'] ) ){
2850
+                            }elseif(!empty( $this->options['block-save-return'] ) ){
2851 2851
                                 echo "return ". $this->options['block-edit-return'].";";
2852
-							}elseif(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){
2853
-							?>
2852
+                            }elseif(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){
2853
+                            ?>
2854 2854
 							return content;
2855 2855
 							<?php
2856
-							}else{
2857
-							?>
2856
+                            }else{
2857
+                            ?>
2858 2858
 							var block_wrap = 'div';
2859 2859
 							if (attr.hasOwnProperty("block_wrap")) {
2860 2860
 								block_wrap = attr.block_wrap;
2861 2861
 							}
2862 2862
 							return el(block_wrap, wp.blockEditor.useBlockProps.save( {dangerouslySetInnerHTML: {__html: content}, className: align} ));
2863 2863
 							<?php
2864
-							}
2865
-							?>
2864
+                            }
2865
+                            ?>
2866 2866
 
2867 2867
 
2868 2868
 						}
@@ -2876,29 +2876,29 @@  discard block
 block discarded – undo
2876 2876
                 });
2877 2877
 			</script>
2878 2878
 			<?php
2879
-			$output = ob_get_clean();
2879
+            $output = ob_get_clean();
2880 2880
 
2881
-			/*
2881
+            /*
2882 2882
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
2883 2883
 			 */
2884 2884
 
2885
-			return str_replace( array(
2886
-				'<script>',
2887
-				'</script>'
2888
-			), '', $output );
2889
-		}
2885
+            return str_replace( array(
2886
+                '<script>',
2887
+                '</script>'
2888
+            ), '', $output );
2889
+        }
2890 2890
 
2891 2891
 
2892 2892
 
2893
-		public function block_row_start($key, $args){
2893
+        public function block_row_start($key, $args){
2894 2894
 
2895
-			// check for row
2896
-			if(!empty($args['row'])){
2895
+            // check for row
2896
+            if(!empty($args['row'])){
2897 2897
 
2898
-				if(!empty($args['row']['open'])){
2898
+                if(!empty($args['row']['open'])){
2899 2899
 
2900
-				// element require
2901
-				$element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
2900
+                // element require
2901
+                $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
2902 2902
                 $device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : '';
2903 2903
                 $device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : '';
2904 2904
                 $device_type_icon = '';
@@ -2909,10 +2909,10 @@  discard block
 block discarded – undo
2909 2909
                 }elseif($device_type=='Mobile'){
2910 2910
                     $device_type_icon = '<span class="dashicons dashicons-smartphone" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
2911 2911
                 }
2912
-				echo $element_require;
2912
+                echo $element_require;
2913 2913
                 echo $device_type_require;
2914 2914
 
2915
-					if(false){?><script><?php }?>
2915
+                    if(false){?><script><?php }?>
2916 2916
 						el('div', {
2917 2917
 								className: 'bsui components-base-control',
2918 2918
 							},
@@ -2950,51 +2950,51 @@  discard block
 block discarded – undo
2950 2950
 									},
2951 2951
 
2952 2952
 					<?php
2953
-					if(false){?></script><?php }
2954
-				}elseif(!empty($args['row']['close'])){
2955
-					if(false){?><script><?php }?>
2953
+                    if(false){?></script><?php }
2954
+                }elseif(!empty($args['row']['close'])){
2955
+                    if(false){?><script><?php }?>
2956 2956
 						el(
2957 2957
 							'div',
2958 2958
 							{
2959 2959
 								className: 'col pl-0',
2960 2960
 							},
2961 2961
 					<?php
2962
-					if(false){?></script><?php }
2963
-				}else{
2964
-					if(false){?><script><?php }?>
2962
+                    if(false){?></script><?php }
2963
+                }else{
2964
+                    if(false){?><script><?php }?>
2965 2965
 						el(
2966 2966
 							'div',
2967 2967
 							{
2968 2968
 								className: 'col pl-0 pr-2',
2969 2969
 							},
2970 2970
 					<?php
2971
-					if(false){?></script><?php }
2972
-				}
2971
+                    if(false){?></script><?php }
2972
+                }
2973 2973
 
2974
-			}
2974
+            }
2975 2975
 
2976
-		}
2976
+        }
2977 2977
 
2978
-		public function block_row_end($key, $args){
2978
+        public function block_row_end($key, $args){
2979 2979
 
2980
-			if(!empty($args['row'])){
2981
-				// maybe close
2982
-				if(!empty($args['row']['close'])){
2983
-					echo "))";
2984
-				}
2980
+            if(!empty($args['row'])){
2981
+                // maybe close
2982
+                if(!empty($args['row']['close'])){
2983
+                    echo "))";
2984
+                }
2985 2985
 
2986
-				echo "),";
2987
-			}
2988
-		}
2986
+                echo "),";
2987
+            }
2988
+        }
2989 2989
 
2990
-		public function block_tab_start($key, $args){
2990
+        public function block_tab_start($key, $args){
2991 2991
 
2992
-			// check for row
2993
-			if(!empty($args['tab'])){
2992
+            // check for row
2993
+            if(!empty($args['tab'])){
2994 2994
 
2995
-				if(!empty($args['tab']['tabs_open'])){
2995
+                if(!empty($args['tab']['tabs_open'])){
2996 2996
 
2997
-					if(false){?><script><?php }?>
2997
+                    if(false){?><script><?php }?>
2998 2998
 
2999 2999
 el('div',{className: 'bsui'},
3000 3000
 
@@ -3007,12 +3007,12 @@  discard block
 block discarded – undo
3007 3007
 										tabs: [
3008 3008
 
3009 3009
 					<?php
3010
-					if(false){?></script><?php }
3011
-				}
3010
+                    if(false){?></script><?php }
3011
+                }
3012 3012
 
3013
-				if(!empty($args['tab']['open'])){
3013
+                if(!empty($args['tab']['open'])){
3014 3014
 
3015
-					if(false){?><script><?php }?>
3015
+                    if(false){?><script><?php }?>
3016 3016
 							{
3017 3017
 												name: '<?php echo addslashes( esc_attr( $args['tab']['key']) ); ?>',
3018 3018
 												title: el('div', {dangerouslySetInnerHTML: {__html: '<?php echo addslashes( esc_attr( $args['tab']['title']) ); ?>'}}),
@@ -3021,23 +3021,23 @@  discard block
 block discarded – undo
3021 3021
 									className: 'components-base-control__help mb-0',
3022 3022
 									dangerouslySetInnerHTML: {__html:'<?php echo addslashes( $args['tab']['desc'] ); ?>'}
3023 3023
 								}),<?php }
3024
-					if(false){?></script><?php }
3025
-				}
3024
+                    if(false){?></script><?php }
3025
+                }
3026 3026
 
3027
-			}
3027
+            }
3028 3028
 
3029
-		}
3029
+        }
3030 3030
 
3031
-		public function block_tab_end($key, $args){
3031
+        public function block_tab_end($key, $args){
3032 3032
 
3033
-			if(!empty($args['tab'])){
3034
-				// maybe close
3035
-				if(!empty($args['tab']['close'])){
3036
-					echo ")}, /* tab close */";
3037
-				}
3033
+            if(!empty($args['tab'])){
3034
+                // maybe close
3035
+                if(!empty($args['tab']['close'])){
3036
+                    echo ")}, /* tab close */";
3037
+                }
3038 3038
 
3039
-				if(!empty($args['tab']['tabs_close'])){
3040
-					if(false){?><script><?php }?>
3039
+                if(!empty($args['tab']['tabs_close'])){
3040
+                    if(false){?><script><?php }?>
3041 3041
 							],
3042 3042
 									},
3043 3043
 									( tab ) => {
@@ -3047,22 +3047,22 @@  discard block
 block discarded – undo
3047 3047
 								}
3048 3048
 								)), /* tabs close */
3049 3049
 					<?php if(false){ ?></script><?php }
3050
-				}
3051
-			}
3052
-		}
3050
+                }
3051
+            }
3052
+        }
3053 3053
 
3054
-		public function build_block_arguments( $key, $args ) {
3055
-			$custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
3056
-			$options           = '';
3057
-			$extra             = '';
3058
-			$require           = '';
3054
+        public function build_block_arguments( $key, $args ) {
3055
+            $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
3056
+            $options           = '';
3057
+            $extra             = '';
3058
+            $require           = '';
3059 3059
             $inside_elements   = '';
3060
-			$after_elements	   = '';
3060
+            $after_elements	   = '';
3061 3061
 
3062
-			// `content` is a protected and special argument
3063
-			if ( $key == 'content' ) {
3064
-				return;
3065
-			}
3062
+            // `content` is a protected and special argument
3063
+            if ( $key == 'content' ) {
3064
+                return;
3065
+            }
3066 3066
 
3067 3067
             $device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : '';
3068 3068
             $device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : '';
@@ -3075,51 +3075,51 @@  discard block
 block discarded – undo
3075 3075
                 $device_type_icon = '<span class="dashicons dashicons-smartphone" style="font-size: 18px;" onclick="sd_show_view_options(this);"></span>';
3076 3076
             }
3077 3077
 
3078
-			// icon
3079
-			$icon = '';
3080
-			if( !empty( $args['icon'] ) ){
3081
-				$icon .= "el('div', {";
3082
-									$icon .= "dangerouslySetInnerHTML: {__html: '".self::get_widget_icon( esc_attr($args['icon']))."'},";
3083
-									$icon .= "className: 'text-center',";
3084
-									$icon .= "title: '".addslashes( $args['title'] )."',";
3085
-								$icon .= "}),";
3086
-
3087
-				// blank title as its added to the icon.
3088
-				$args['title'] = '';
3089
-			}
3078
+            // icon
3079
+            $icon = '';
3080
+            if( !empty( $args['icon'] ) ){
3081
+                $icon .= "el('div', {";
3082
+                                    $icon .= "dangerouslySetInnerHTML: {__html: '".self::get_widget_icon( esc_attr($args['icon']))."'},";
3083
+                                    $icon .= "className: 'text-center',";
3084
+                                    $icon .= "title: '".addslashes( $args['title'] )."',";
3085
+                                $icon .= "}),";
3086
+
3087
+                // blank title as its added to the icon.
3088
+                $args['title'] = '';
3089
+            }
3090 3090
 
3091
-			// require advanced
3092
-			$require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : "";
3091
+            // require advanced
3092
+            $require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : "";
3093 3093
 
3094
-			// element require
3095
-			$element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
3094
+            // element require
3095
+            $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
3096 3096
 
3097 3097
 
3098
-			$onchange  = "props.setAttributes({ $key: $key } )";
3099
-			$onchangecomplete  = "";
3100
-			$value     = "props.attributes.$key";
3101
-			$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx','range' );
3102
-			if ( in_array( $args['type'], $text_type ) ) {
3103
-				$type = 'TextControl';
3104
-				// Save numbers as numbers and not strings
3105
-				if ( $args['type'] == 'number' ) {
3106
-					$onchange = "props.setAttributes({ $key: $key ? Number($key) : '' } )";
3107
-				}
3108
-			}else if ( $args['type'] == 'styleid' ) {
3109
-				$type = 'TextControl';
3110
-				$args['type'] == 'text';
3111
-				// Save numbers as numbers and not strings
3112
-				$value     = "props.attributes.$key ? props.attributes.$key : 'aaabbbccc'";
3113
-			}else if ( $args['type'] == 'notice' ) {
3114
-
3115
-				$notice_message = !empty($args['desc']) ? addslashes($args['desc']) : '';
3116
-				$notice_status = !empty($args['status']) ? esc_attr($args['status']) : 'info';
3117
-
3118
-				$notice = "el('div',{className:'bsui'},el(wp.components.Notice, {status: '$notice_status',isDismissible: false,className: 'm-0 pr-0 mb-3'},el('div',{dangerouslySetInnerHTML: {__html: '$notice_message'}}))),";
3119
-				echo $notice_message ? $element_require . $notice : '';
3120
-				return;
3121
-			}
3122
-			/*
3098
+            $onchange  = "props.setAttributes({ $key: $key } )";
3099
+            $onchangecomplete  = "";
3100
+            $value     = "props.attributes.$key";
3101
+            $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx','range' );
3102
+            if ( in_array( $args['type'], $text_type ) ) {
3103
+                $type = 'TextControl';
3104
+                // Save numbers as numbers and not strings
3105
+                if ( $args['type'] == 'number' ) {
3106
+                    $onchange = "props.setAttributes({ $key: $key ? Number($key) : '' } )";
3107
+                }
3108
+            }else if ( $args['type'] == 'styleid' ) {
3109
+                $type = 'TextControl';
3110
+                $args['type'] == 'text';
3111
+                // Save numbers as numbers and not strings
3112
+                $value     = "props.attributes.$key ? props.attributes.$key : 'aaabbbccc'";
3113
+            }else if ( $args['type'] == 'notice' ) {
3114
+
3115
+                $notice_message = !empty($args['desc']) ? addslashes($args['desc']) : '';
3116
+                $notice_status = !empty($args['status']) ? esc_attr($args['status']) : 'info';
3117
+
3118
+                $notice = "el('div',{className:'bsui'},el(wp.components.Notice, {status: '$notice_status',isDismissible: false,className: 'm-0 pr-0 mb-3'},el('div',{dangerouslySetInnerHTML: {__html: '$notice_message'}}))),";
3119
+                echo $notice_message ? $element_require . $notice : '';
3120
+                return;
3121
+            }
3122
+            /*
3123 3123
 			 * https://www.wptricks.com/question/set-current-tab-on-a-gutenberg-tabpanel-component-from-outside-that-component/ es5 layout
3124 3124
 						elseif($args['type']=='tabs'){
3125 3125
 							?>
@@ -3172,23 +3172,23 @@  discard block
 block discarded – undo
3172 3172
 							return;
3173 3173
 						}
3174 3174
 */
3175
-			elseif ( $args['type'] == 'color' ) {
3176
-				$type = 'ColorPicker';
3177
-				$onchange = "";
3178
-				$extra = "color: $value,";
3179
-				if(!empty($args['disable_alpha'])){
3180
-					$extra .= "disableAlpha: true,";
3181
-				}
3182
-				$onchangecomplete = "onChangeComplete: function($key) {
3175
+            elseif ( $args['type'] == 'color' ) {
3176
+                $type = 'ColorPicker';
3177
+                $onchange = "";
3178
+                $extra = "color: $value,";
3179
+                if(!empty($args['disable_alpha'])){
3180
+                    $extra .= "disableAlpha: true,";
3181
+                }
3182
+                $onchangecomplete = "onChangeComplete: function($key) {
3183 3183
 				value =  $key.rgb.a && $key.rgb.a < 1 ? \"rgba(\"+$key.rgb.r+\",\"+$key.rgb.g+\",\"+$key.rgb.b+\",\"+$key.rgb.a+\")\" : $key.hex;
3184 3184
                         props.setAttributes({
3185 3185
                             $key: value
3186 3186
                         });
3187 3187
                     },";
3188
-			}elseif ( $args['type'] == 'gradient' ) {
3189
-				$type = 'GradientPicker';
3188
+            }elseif ( $args['type'] == 'gradient' ) {
3189
+                $type = 'GradientPicker';
3190 3190
 
3191
-			}elseif ( $args['type'] == 'image' ) {
3191
+            }elseif ( $args['type'] == 'image' ) {
3192 3192
 //                print_r($args);
3193 3193
 
3194 3194
                 $img_preview = isset($args['focalpoint']) && !$args['focalpoint'] ? " props.attributes.$key && el('img', { src: props.attributes.$key,style: {maxWidth:'100%',background: '#ccc'}})," : " ( props.attributes.$key ||  props.attributes.{$key}_use_featured ) && el(wp.components.FocalPointPicker,{
@@ -3213,15 +3213,15 @@  discard block
 block discarded – undo
3213 3213
 
3214 3214
 
3215 3215
                 $value = '""';
3216
-				$type = 'MediaUpload';
3216
+                $type = 'MediaUpload';
3217 3217
                 $extra .= "onSelect: function(media){
3218 3218
                       return props.setAttributes({
3219 3219
                           $key: media.url,
3220 3220
                           {$key}_id: media.id
3221 3221
                         });
3222 3222
                       },";
3223
-                   $extra .= "type: 'image',";
3224
-                   $extra .= "render: function (obj) {
3223
+                    $extra .= "type: 'image',";
3224
+                    $extra .= "render: function (obj) {
3225 3225
                         return el( 'div',{},
3226 3226
                         ( !props.attributes.$key && !props.attributes.{$key}_use_featured ) && el( wp.components.Button, {
3227 3227
                           className: 'components-button components-circular-option-picker__clear is-primary is-smallx',
@@ -3250,8 +3250,8 @@  discard block
 block discarded – undo
3250 3250
                 $onchange = "";
3251 3251
 
3252 3252
                 //$inside_elements = ",el('div',{},'file upload')";
3253
-			}elseif ( $args['type'] == 'images' ) {
3254
-				//                print_r($args);
3253
+            }elseif ( $args['type'] == 'images' ) {
3254
+                //                print_r($args);
3255 3255
 
3256 3256
                 $img_preview = "props.attributes.$key && (function() {
3257 3257
 
@@ -3280,7 +3280,7 @@  discard block
 block discarded – undo
3280 3280
 
3281 3281
 
3282 3282
                 $value = '""';
3283
-				$type = 'MediaUpload';
3283
+                $type = 'MediaUpload';
3284 3284
                 $extra .= "onSelect: function(media){
3285 3285
 
3286 3286
                 let slim_images = props.attributes.$key ? JSON.parse('['+props.attributes.$key+']') : [];
@@ -3294,9 +3294,9 @@  discard block
 block discarded – undo
3294 3294
                           $key: JSON.stringify(slim_images).replace('[','').replace(']',''),
3295 3295
                         });
3296 3296
                       },";
3297
-                   $extra .= "type: 'image',";
3298
-                   $extra .= "multiple: true,";
3299
-                   $extra .= "render: function (obj) {
3297
+                    $extra .= "type: 'image',";
3298
+                    $extra .= "multiple: true,";
3299
+                    $extra .= "render: function (obj) {
3300 3300
 
3301 3301
                    // init the sort
3302 3302
 				enableDragSort('sd-sortable');
@@ -3335,37 +3335,37 @@  discard block
 block discarded – undo
3335 3335
                 $onchange = "";
3336 3336
 
3337 3337
                 //$inside_elements = ",el('div',{},'file upload')";
3338
-			}
3339
-			elseif ( $args['type'] == 'checkbox' ) {
3340
-				$type = 'CheckboxControl';
3341
-				$extra .= "checked: props.attributes.$key,";
3342
-				$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
3343
-			} elseif ( $args['type'] == 'textarea' ) {
3344
-				$type = 'TextareaControl';
3345
-
3346
-			} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
3347
-				$type = 'SelectControl';
3348
-
3349
-				if($args['name'] == 'category' && !empty($args['post_type_linked'])){
3350
-					$options .= "options: taxonomies_".str_replace("-","_", $this->id).",";
3351
-				}elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){
3352
-					$options .= "options: sort_by_".str_replace("-","_", $this->id).",";
3353
-				}else {
3354
-
3355
-					if ( ! empty( $args['options'] ) ) {
3356
-						$options .= "options: [";
3357
-						foreach ( $args['options'] as $option_val => $option_label ) {
3358
-							$options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },";
3359
-						}
3360
-						$options .= "],";
3361
-					}
3362
-				}
3363
-				if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
3364
-					$extra .= ' multiple:true,style:{height:"auto",paddingRight:"8px","overflow-y":"auto"}, ';
3365
-				}
3338
+            }
3339
+            elseif ( $args['type'] == 'checkbox' ) {
3340
+                $type = 'CheckboxControl';
3341
+                $extra .= "checked: props.attributes.$key,";
3342
+                $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
3343
+            } elseif ( $args['type'] == 'textarea' ) {
3344
+                $type = 'TextareaControl';
3345
+
3346
+            } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
3347
+                $type = 'SelectControl';
3348
+
3349
+                if($args['name'] == 'category' && !empty($args['post_type_linked'])){
3350
+                    $options .= "options: taxonomies_".str_replace("-","_", $this->id).",";
3351
+                }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){
3352
+                    $options .= "options: sort_by_".str_replace("-","_", $this->id).",";
3353
+                }else {
3354
+
3355
+                    if ( ! empty( $args['options'] ) ) {
3356
+                        $options .= "options: [";
3357
+                        foreach ( $args['options'] as $option_val => $option_label ) {
3358
+                            $options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },";
3359
+                        }
3360
+                        $options .= "],";
3361
+                    }
3362
+                }
3363
+                if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
3364
+                    $extra .= ' multiple:true,style:{height:"auto",paddingRight:"8px","overflow-y":"auto"}, ';
3365
+                }
3366 3366
 
3367
-				if($args['type'] == 'multiselect' ||  ( isset( $args['multiple'] ) && $args['multiple'] ) ){
3368
-					$after_elements	 .= "props.attributes.$key && el( wp.components.Button, {
3367
+                if($args['type'] == 'multiselect' ||  ( isset( $args['multiple'] ) && $args['multiple'] ) ){
3368
+                    $after_elements	 .= "props.attributes.$key && el( wp.components.Button, {
3369 3369
                                       className: 'components-button components-circular-option-picker__clear is-secondary is-small',
3370 3370
                                       style: {margin:'-8px 0 8px 0',display: 'block'},
3371 3371
                                       onClick: function(){
@@ -3376,8 +3376,8 @@  discard block
 block discarded – undo
3376 3376
                                     },
3377 3377
                                     'Clear'
3378 3378
                             ),";
3379
-				}
3380
-			} elseif ( $args['type'] == 'tagselect' ) {
3379
+                }
3380
+            } elseif ( $args['type'] == 'tagselect' ) {
3381 3381
 //				$type = 'FormTokenField';
3382 3382
 //
3383 3383
 //				if ( ! empty( $args['options'] ) ) {
@@ -3412,39 +3412,39 @@  discard block
 block discarded – undo
3412 3412
 //				$value     = "[]";
3413 3413
 //				$extra .= ' __experimentalExpandOnFocus: true,';
3414 3414
 
3415
-			} elseif ( $args['type'] == 'alignment' ) {
3416
-				$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
3417
-			}elseif ( $args['type'] == 'margins' ) {
3415
+            } elseif ( $args['type'] == 'alignment' ) {
3416
+                $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
3417
+            }elseif ( $args['type'] == 'margins' ) {
3418 3418
 
3419
-			} else {
3420
-				return;// if we have not implemented the control then don't break the JS.
3421
-			}
3419
+            } else {
3420
+                return;// if we have not implemented the control then don't break the JS.
3421
+            }
3422 3422
 
3423 3423
 
3424 3424
 
3425
-			// color input does not show the labels so we add them
3426
-			if($args['type']=='color'){
3427
-				// add show only if advanced
3428
-				echo $require_advanced;
3429
-				// add setting require if defined
3430
-				echo $element_require;
3431
-				echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),";
3432
-			}
3425
+            // color input does not show the labels so we add them
3426
+            if($args['type']=='color'){
3427
+                // add show only if advanced
3428
+                echo $require_advanced;
3429
+                // add setting require if defined
3430
+                echo $element_require;
3431
+                echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),";
3432
+            }
3433 3433
 
3434
-			// add show only if advanced
3435
-			echo $require_advanced;
3436
-			// add setting require if defined
3437
-			echo $element_require;
3434
+            // add show only if advanced
3435
+            echo $require_advanced;
3436
+            // add setting require if defined
3437
+            echo $element_require;
3438 3438
             echo $device_type_require;
3439 3439
 
3440
-			// icon
3441
-			echo $icon;
3442
-			?>
3440
+            // icon
3441
+            echo $icon;
3442
+            ?>
3443 3443
 			el( <?php echo $args['type'] == 'image' || $args['type'] == 'images' ? $type  : "wp.components.".$type; ?>, {
3444 3444
 			label: <?php
3445
-			if(empty($args['title'])){
3445
+            if(empty($args['title'])){
3446 3446
                 echo "''";
3447
-			}elseif(empty($args['row']) && !empty($args['device_type'])){
3447
+            }elseif(empty($args['row']) && !empty($args['device_type'])){
3448 3448
                 ?>el('label', {
3449 3449
 									className: 'components-base-control__label',
3450 3450
 									style: {width:"100%"}
@@ -3459,22 +3459,22 @@  discard block
 block discarded – undo
3459 3459
 
3460 3460
 							)<?php
3461 3461
 
3462
-			}else{
3463
-                 ?>'<?php echo addslashes( $args['title'] ); ?>'<?php
3462
+            }else{
3463
+                    ?>'<?php echo addslashes( $args['title'] ); ?>'<?php
3464 3464
 
3465
-			}
3465
+            }
3466 3466
 
3467
-			?>,
3467
+            ?>,
3468 3468
 			help: <?php if ( isset( $args['desc'] ) ) {
3469
-				echo "el('span',{dangerouslySetInnerHTML: {__html: '".wp_kses_post( addslashes($args['desc']) )."'}})";
3470
-			}else{ echo "''"; } ?>,
3469
+                echo "el('span',{dangerouslySetInnerHTML: {__html: '".wp_kses_post( addslashes($args['desc']) )."'}})";
3470
+            }else{ echo "''"; } ?>,
3471 3471
 			value: <?php echo $value; ?>,
3472 3472
 			<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
3473
-				echo "type: '" . addslashes( $args['type'] ) . "',";
3474
-			} ?>
3473
+                echo "type: '" . addslashes( $args['type'] ) . "',";
3474
+            } ?>
3475 3475
 			<?php if ( ! empty( $args['placeholder'] ) ) {
3476
-				echo "placeholder: '" . addslashes( $args['placeholder'] ) . "',";
3477
-			} ?>
3476
+                echo "placeholder: '" . addslashes( $args['placeholder'] ) . "',";
3477
+            } ?>
3478 3478
 			<?php echo $options; ?>
3479 3479
 			<?php echo $extra; ?>
3480 3480
 			<?php echo $custom_attributes; ?>
@@ -3487,69 +3487,69 @@  discard block
 block discarded – undo
3487 3487
 			<?php }?>
3488 3488
 			} <?php echo $inside_elements; ?> ),
3489 3489
 			<?php
3490
-			echo $after_elements;
3490
+            echo $after_elements;
3491 3491
 
3492
-		}
3492
+        }
3493 3493
 
3494
-		/**
3495
-		 * Convert an array of attributes to block string.
3496
-		 *
3497
-		 * @param $custom_attributes
3498
-		 *
3499
-		 * @return string
3500
-		 *@todo there is prob a faster way to do this, also we could add some validation here.
3501
-		 *
3502
-		 */
3503
-		public function array_to_attributes( $custom_attributes, $html = false ) {
3504
-			$attributes = '';
3505
-			if ( ! empty( $custom_attributes ) ) {
3506
-
3507
-				foreach ( $custom_attributes as $key => $val ) {
3508
-					if(is_array($val)){
3509
-						$attributes .= $key.': {'.$this->array_to_attributes( $val, $html ).'},';
3510
-					}else{
3511
-						$attributes .= $html ?  " $key='$val' " : "'$key': '$val',";
3512
-					}
3513
-				}
3494
+        /**
3495
+         * Convert an array of attributes to block string.
3496
+         *
3497
+         * @param $custom_attributes
3498
+         *
3499
+         * @return string
3500
+         *@todo there is prob a faster way to do this, also we could add some validation here.
3501
+         *
3502
+         */
3503
+        public function array_to_attributes( $custom_attributes, $html = false ) {
3504
+            $attributes = '';
3505
+            if ( ! empty( $custom_attributes ) ) {
3514 3506
 
3515
-			}
3507
+                foreach ( $custom_attributes as $key => $val ) {
3508
+                    if(is_array($val)){
3509
+                        $attributes .= $key.': {'.$this->array_to_attributes( $val, $html ).'},';
3510
+                    }else{
3511
+                        $attributes .= $html ?  " $key='$val' " : "'$key': '$val',";
3512
+                    }
3513
+                }
3516 3514
 
3517
-			return $attributes;
3518
-		}
3515
+            }
3516
+
3517
+            return $attributes;
3518
+        }
3519 3519
 
3520 3520
 
3521 3521
 
3522
-		/**
3523
-		 * A self looping function to create the output for JS block elements.
3524
-		 *
3525
-		 * This is what is output in the WP Editor visual view.
3526
-		 *
3527
-		 * @param $args
3528
-		 */
3529
-		public function block_element( $args, $save = false ) {
3522
+        /**
3523
+         * A self looping function to create the output for JS block elements.
3524
+         *
3525
+         * This is what is output in the WP Editor visual view.
3526
+         *
3527
+         * @param $args
3528
+         */
3529
+        public function block_element( $args, $save = false ) {
3530 3530
 
3531 3531
 
3532
-			if ( ! empty( $args ) ) {
3533
-				foreach ( $args as $element => $new_args ) {
3532
+            if ( ! empty( $args ) ) {
3533
+                foreach ( $args as $element => $new_args ) {
3534 3534
 
3535
-					if ( is_array( $new_args ) ) { // its an element
3535
+                    if ( is_array( $new_args ) ) { // its an element
3536 3536
 
3537 3537
 
3538
-						if ( isset( $new_args['element'] ) ) {
3538
+                        if ( isset( $new_args['element'] ) ) {
3539 3539
 
3540
-							if ( isset( $new_args['element_require'] ) ) {
3541
-								echo str_replace( array(
3542
-										"'+",
3543
-										"+'"
3544
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
3545
-								unset( $new_args['element_require'] );
3546
-							}
3540
+                            if ( isset( $new_args['element_require'] ) ) {
3541
+                                echo str_replace( array(
3542
+                                        "'+",
3543
+                                        "+'"
3544
+                                    ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
3545
+                                unset( $new_args['element_require'] );
3546
+                            }
3547 3547
 
3548 3548
                             if($new_args['element']=='InnerBlocks'){
3549 3549
                                 echo "\n el( InnerBlocks, {";
3550 3550
                             }elseif($new_args['element']=='innerBlocksProps'){
3551 3551
                                 $element = isset($new_args['inner_element']) ? esc_attr($new_args['inner_element']) : 'div';
3552
-                              //  echo "\n el( 'section', wp.blockEditor.useInnerBlocksProps( blockProps, {";
3552
+                                //  echo "\n el( 'section', wp.blockEditor.useInnerBlocksProps( blockProps, {";
3553 3553
 //                                echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( ";
3554 3554
                                 echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( ";
3555 3555
                                 echo $save ? "wp.blockEditor.useBlockProps.save( {" : "wp.blockEditor.useBlockProps( {";
@@ -3559,74 +3559,74 @@  discard block
 block discarded – undo
3559 3559
                                 echo !empty($new_args['innerBlocksProps']) && !$save ? $this->block_element( $new_args['innerBlocksProps'],$save ) : '';
3560 3560
                             //    echo '###';
3561 3561
 
3562
-                              //  echo '###';
3562
+                                //  echo '###';
3563 3563
                             }elseif($new_args['element']=='BlocksProps'){
3564 3564
 
3565
-								if ( isset($new_args['if_inner_element']) ) {
3566
-									$element = $new_args['if_inner_element'];
3567
-								}else {
3568
-									$element = isset($new_args['inner_element']) ? "'".esc_attr($new_args['inner_element'])."'" : "'div'";
3569
-								}
3565
+                                if ( isset($new_args['if_inner_element']) ) {
3566
+                                    $element = $new_args['if_inner_element'];
3567
+                                }else {
3568
+                                    $element = isset($new_args['inner_element']) ? "'".esc_attr($new_args['inner_element'])."'" : "'div'";
3569
+                                }
3570 3570
 
3571
-								unset($new_args['inner_element']);
3571
+                                unset($new_args['inner_element']);
3572 3572
                                 echo $save ? "\n el( $element, wp.blockEditor.useBlockProps.save( {" : "\n el( $element, wp.blockEditor.useBlockProps( {";
3573 3573
                                 echo !empty($new_args['blockProps']) ? $this->block_element( $new_args['blockProps'],$save ) : '';
3574 3574
 
3575 3575
 
3576
-                               // echo "} ),";
3576
+                                // echo "} ),";
3577 3577
 
3578 3578
                             }else{
3579 3579
                                 echo "\n el( '" . $new_args['element'] . "', {";
3580 3580
                             }
3581 3581
 
3582 3582
 
3583
-							// get the attributes
3584
-							foreach ( $new_args as $new_key => $new_value ) {
3583
+                            // get the attributes
3584
+                            foreach ( $new_args as $new_key => $new_value ) {
3585 3585
 
3586 3586
 
3587
-								if ( $new_key == 'element' || $new_key == 'content'|| $new_key == 'if_content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
3588
-									// do nothing
3589
-								} else {
3590
-									echo $this->block_element( array( $new_key => $new_value ),$save );
3591
-								}
3592
-							}
3587
+                                if ( $new_key == 'element' || $new_key == 'content'|| $new_key == 'if_content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
3588
+                                    // do nothing
3589
+                                } else {
3590
+                                    echo $this->block_element( array( $new_key => $new_value ),$save );
3591
+                                }
3592
+                            }
3593 3593
 
3594
-							echo $new_args['element']=='BlocksProps' ? '} ),' : "},";// end attributes
3594
+                            echo $new_args['element']=='BlocksProps' ? '} ),' : "},";// end attributes
3595 3595
 
3596
-							// get the content
3597
-							$first_item = 0;
3598
-							foreach ( $new_args as $new_key => $new_value ) {
3599
-								if ( $new_key === 'content' || $new_key === 'if_content' || is_array( $new_value ) ) {
3596
+                            // get the content
3597
+                            $first_item = 0;
3598
+                            foreach ( $new_args as $new_key => $new_value ) {
3599
+                                if ( $new_key === 'content' || $new_key === 'if_content' || is_array( $new_value ) ) {
3600 3600
 
3601
-									if ( $new_key === 'content' ) {
3602
-										echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'";
3603
-									}else if ( $new_key === 'if_content' ) {
3604
-										echo  $this->block_props_replace(  $new_value  );
3605
-									}
3601
+                                    if ( $new_key === 'content' ) {
3602
+                                        echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'";
3603
+                                    }else if ( $new_key === 'if_content' ) {
3604
+                                        echo  $this->block_props_replace(  $new_value  );
3605
+                                    }
3606 3606
 
3607
-									if ( is_array( $new_value ) ) {
3607
+                                    if ( is_array( $new_value ) ) {
3608 3608
 
3609
-										if ( isset( $new_value['element_require'] ) ) {
3610
-											echo str_replace( array(
3611
-													"'+",
3612
-													"+'"
3613
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
3614
-											unset( $new_value['element_require'] );
3615
-										}
3609
+                                        if ( isset( $new_value['element_require'] ) ) {
3610
+                                            echo str_replace( array(
3611
+                                                    "'+",
3612
+                                                    "+'"
3613
+                                                ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
3614
+                                            unset( $new_value['element_require'] );
3615
+                                        }
3616 3616
 
3617
-										if ( isset( $new_value['element_repeat'] ) ) {
3618
-											$x = 1;
3619
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
3620
-												$this->block_element( array( '' => $new_value ),$save );
3621
-												$x ++;
3622
-											}
3623
-										} else {
3624
-											$this->block_element( array( '' => $new_value ),$save );
3625
-										}
3626
-									}
3627
-									$first_item ++;
3628
-								}
3629
-							}
3617
+                                        if ( isset( $new_value['element_repeat'] ) ) {
3618
+                                            $x = 1;
3619
+                                            while ( $x <= absint( $new_value['element_repeat'] ) ) {
3620
+                                                $this->block_element( array( '' => $new_value ),$save );
3621
+                                                $x ++;
3622
+                                            }
3623
+                                        } else {
3624
+                                            $this->block_element( array( '' => $new_value ),$save );
3625
+                                        }
3626
+                                    }
3627
+                                    $first_item ++;
3628
+                                }
3629
+                            }
3630 3630
 
3631 3631
                             if($new_args['element']=='innerBlocksProps' || $new_args['element']=='xBlocksProps'){
3632 3632
                                 echo "))";// end content
@@ -3635,517 +3635,517 @@  discard block
 block discarded – undo
3635 3635
                             }
3636 3636
 
3637 3637
 
3638
-							echo ", \n";
3638
+                            echo ", \n";
3639 3639
 
3640
-						}
3641
-					} else {
3640
+                        }
3641
+                    } else {
3642 3642
 
3643
-						if ( substr( $element, 0, 3 ) === "if_" ) {
3644
-							$extra = '';
3645
-							if( strpos($new_args, '[%WrapClass%]') !== false ){
3646
-								$new_args = str_replace('[%WrapClass%]"','" + sd_build_aui_class(props.attributes)',$new_args);
3647
-								$new_args = str_replace('[%WrapClass%]','+ sd_build_aui_class(props.attributes)',$new_args);
3648
-							}
3649
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
3650
-						} elseif ( $element == 'style' &&  strpos($new_args, '[%WrapStyle%]') !== false ) {
3643
+                        if ( substr( $element, 0, 3 ) === "if_" ) {
3644
+                            $extra = '';
3645
+                            if( strpos($new_args, '[%WrapClass%]') !== false ){
3646
+                                $new_args = str_replace('[%WrapClass%]"','" + sd_build_aui_class(props.attributes)',$new_args);
3647
+                                $new_args = str_replace('[%WrapClass%]','+ sd_build_aui_class(props.attributes)',$new_args);
3648
+                            }
3649
+                            echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
3650
+                        } elseif ( $element == 'style' &&  strpos($new_args, '[%WrapStyle%]') !== false ) {
3651 3651
                             $new_args = str_replace('[%WrapStyle%]','',$new_args);
3652 3652
                             echo $element . ": {..." . $this->block_props_replace( $new_args ) . " , ...sd_build_aui_styles(props.attributes) },";
3653 3653
 //                            echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
3654
-						} elseif ( $element == 'style' ) {
3655
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
3656
-						} elseif ( ( $element == 'class' || $element == 'className'  ) &&  strpos($new_args, '[%WrapClass%]') !== false ) {
3654
+                        } elseif ( $element == 'style' ) {
3655
+                            echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
3656
+                        } elseif ( ( $element == 'class' || $element == 'className'  ) &&  strpos($new_args, '[%WrapClass%]') !== false ) {
3657 3657
                             $new_args = str_replace('[%WrapClass%]','',$new_args);
3658 3658
                             echo $element . ": '" . $this->block_props_replace( $new_args ) . "' + sd_build_aui_class(props.attributes),";
3659
-						} elseif ( $element == 'template' && $new_args ) {
3660
-							echo $element . ": $new_args,";
3661
-						} else {
3662
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
3663
-						}
3659
+                        } elseif ( $element == 'template' && $new_args ) {
3660
+                            echo $element . ": $new_args,";
3661
+                        } else {
3662
+                            echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
3663
+                        }
3664 3664
 
3665
-					}
3666
-				}
3667
-			}
3668
-		}
3665
+                    }
3666
+                }
3667
+            }
3668
+        }
3669 3669
 
3670
-		/**
3671
-		 * Replace block attributes placeholders with the proper naming.
3672
-		 *
3673
-		 * @param $string
3674
-		 *
3675
-		 * @return mixed
3676
-		 */
3677
-		public function block_props_replace( $string, $no_wrap = false ) {
3678
-
3679
-			if ( $no_wrap ) {
3680
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
3681
-			} else {
3682
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
3683
-			}
3670
+        /**
3671
+         * Replace block attributes placeholders with the proper naming.
3672
+         *
3673
+         * @param $string
3674
+         *
3675
+         * @return mixed
3676
+         */
3677
+        public function block_props_replace( $string, $no_wrap = false ) {
3684 3678
 
3685
-			return $string;
3686
-		}
3679
+            if ( $no_wrap ) {
3680
+                $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
3681
+            } else {
3682
+                $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
3683
+            }
3687 3684
 
3688
-		/**
3689
-		 * Outputs the content of the widget
3690
-		 *
3691
-		 * @param array $args
3692
-		 * @param array $instance
3693
-		 */
3694
-		public function widget( $args, $instance ) {
3695
-
3696
-			// get the filtered values
3697
-			$argument_values = $this->argument_values( $instance );
3698
-			$argument_values = $this->string_to_bool( $argument_values );
3699
-			$output          = $this->output( $argument_values, $args );
3700
-
3701
-			$no_wrap = false;
3702
-			if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) {
3703
-				$no_wrap = true;
3704
-			}
3685
+            return $string;
3686
+        }
3705 3687
 
3706
-			ob_start();
3707
-			if ( $output && ! $no_wrap ) {
3688
+        /**
3689
+         * Outputs the content of the widget
3690
+         *
3691
+         * @param array $args
3692
+         * @param array $instance
3693
+         */
3694
+        public function widget( $args, $instance ) {
3708 3695
 
3709
-				$class_original = $this->options['widget_ops']['classname'];
3710
-				$class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash();
3696
+            // get the filtered values
3697
+            $argument_values = $this->argument_values( $instance );
3698
+            $argument_values = $this->string_to_bool( $argument_values );
3699
+            $output          = $this->output( $argument_values, $args );
3711 3700
 
3712
-				// Before widget
3713
-				$before_widget = $args['before_widget'];
3714
-				$before_widget = str_replace($class_original,$class,$before_widget);
3715
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
3716
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
3701
+            $no_wrap = false;
3702
+            if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) {
3703
+                $no_wrap = true;
3704
+            }
3717 3705
 
3718
-				// After widget
3719
-				$after_widget = $args['after_widget'];
3720
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
3721
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
3706
+            ob_start();
3707
+            if ( $output && ! $no_wrap ) {
3722 3708
 
3723
-				echo $before_widget;
3724
-				// elementor strips the widget wrapping div so we check for and add it back if needed
3725
-				if ( $this->is_elementor_widget_output() ) {
3726
-					// Filter class & attrs for elementor widget output.
3727
-					$class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
3728
-					$class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
3709
+                $class_original = $this->options['widget_ops']['classname'];
3710
+                $class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash();
3729 3711
 
3730
-					$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
3731
-					$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
3712
+                // Before widget
3713
+                $before_widget = $args['before_widget'];
3714
+                $before_widget = str_replace($class_original,$class,$before_widget);
3715
+                $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
3716
+                $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
3732 3717
 
3733
-					echo "<span class='" . esc_attr( $class  ) . "' " . $attrs . ">";
3734
-				}
3735
-				echo $this->output_title( $args, $instance );
3736
-				echo $output;
3737
-				if ( $this->is_elementor_widget_output() ) {
3738
-					echo "</span>";
3739
-				}
3740
-				echo $after_widget;
3741
-			} elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
3742
-				$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
3743
-				echo $output;
3744
-			} elseif ( $output && $no_wrap ) {
3745
-				echo $output;
3746
-			}
3747
-			$output = ob_get_clean();
3718
+                // After widget
3719
+                $after_widget = $args['after_widget'];
3720
+                $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
3721
+                $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
3748 3722
 
3749
-			$output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this );
3723
+                echo $before_widget;
3724
+                // elementor strips the widget wrapping div so we check for and add it back if needed
3725
+                if ( $this->is_elementor_widget_output() ) {
3726
+                    // Filter class & attrs for elementor widget output.
3727
+                    $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
3728
+                    $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
3750 3729
 
3751
-			echo $output;
3752
-		}
3730
+                    $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
3731
+                    $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
3753 3732
 
3754
-		/**
3755
-		 * Tests if the current output is inside a elementor container.
3756
-		 *
3757
-		 * @return bool
3758
-		 *@since 1.0.4
3759
-		 */
3760
-		public function is_elementor_widget_output() {
3761
-			$result = false;
3762
-			if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
3763
-				$result = true;
3764
-			}
3733
+                    echo "<span class='" . esc_attr( $class  ) . "' " . $attrs . ">";
3734
+                }
3735
+                echo $this->output_title( $args, $instance );
3736
+                echo $output;
3737
+                if ( $this->is_elementor_widget_output() ) {
3738
+                    echo "</span>";
3739
+                }
3740
+                echo $after_widget;
3741
+            } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
3742
+                $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
3743
+                echo $output;
3744
+            } elseif ( $output && $no_wrap ) {
3745
+                echo $output;
3746
+            }
3747
+            $output = ob_get_clean();
3765 3748
 
3766
-			return $result;
3767
-		}
3749
+            $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this );
3768 3750
 
3769
-		/**
3770
-		 * Tests if the current output is inside a elementor preview.
3771
-		 *
3772
-		 * @return bool
3773
-		 *@since 1.0.4
3774
-		 */
3775
-		public function is_elementor_preview() {
3776
-			$result = false;
3777
-			if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
3778
-				$result = true;
3779
-			}
3751
+            echo $output;
3752
+        }
3780 3753
 
3781
-			return $result;
3782
-		}
3754
+        /**
3755
+         * Tests if the current output is inside a elementor container.
3756
+         *
3757
+         * @return bool
3758
+         *@since 1.0.4
3759
+         */
3760
+        public function is_elementor_widget_output() {
3761
+            $result = false;
3762
+            if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
3763
+                $result = true;
3764
+            }
3783 3765
 
3784
-		/**
3785
-		 * Tests if the current output is inside a Divi preview.
3786
-		 *
3787
-		 * @return bool
3788
-		 *@since 1.0.6
3789
-		 */
3790
-		public function is_divi_preview() {
3791
-			$result = false;
3792
-			if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
3793
-				$result = true;
3794
-			}
3766
+            return $result;
3767
+        }
3795 3768
 
3796
-			return $result;
3797
-		}
3769
+        /**
3770
+         * Tests if the current output is inside a elementor preview.
3771
+         *
3772
+         * @return bool
3773
+         *@since 1.0.4
3774
+         */
3775
+        public function is_elementor_preview() {
3776
+            $result = false;
3777
+            if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
3778
+                $result = true;
3779
+            }
3798 3780
 
3799
-		/**
3800
-		 * Tests if the current output is inside a Beaver builder preview.
3801
-		 *
3802
-		 * @return bool
3803
-		 *@since 1.0.6
3804
-		 */
3805
-		public function is_beaver_preview() {
3806
-			$result = false;
3807
-			if ( isset( $_REQUEST['fl_builder'] ) ) {
3808
-				$result = true;
3809
-			}
3781
+            return $result;
3782
+        }
3810 3783
 
3811
-			return $result;
3812
-		}
3784
+        /**
3785
+         * Tests if the current output is inside a Divi preview.
3786
+         *
3787
+         * @return bool
3788
+         *@since 1.0.6
3789
+         */
3790
+        public function is_divi_preview() {
3791
+            $result = false;
3792
+            if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
3793
+                $result = true;
3794
+            }
3813 3795
 
3814
-		/**
3815
-		 * Tests if the current output is inside a siteorigin builder preview.
3816
-		 *
3817
-		 * @return bool
3818
-		 *@since 1.0.6
3819
-		 */
3820
-		public function is_siteorigin_preview() {
3821
-			$result = false;
3822
-			if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
3823
-				$result = true;
3824
-			}
3796
+            return $result;
3797
+        }
3825 3798
 
3826
-			return $result;
3827
-		}
3799
+        /**
3800
+         * Tests if the current output is inside a Beaver builder preview.
3801
+         *
3802
+         * @return bool
3803
+         *@since 1.0.6
3804
+         */
3805
+        public function is_beaver_preview() {
3806
+            $result = false;
3807
+            if ( isset( $_REQUEST['fl_builder'] ) ) {
3808
+                $result = true;
3809
+            }
3828 3810
 
3829
-		/**
3830
-		 * Tests if the current output is inside a cornerstone builder preview.
3831
-		 *
3832
-		 * @return bool
3833
-		 *@since 1.0.8
3834
-		 */
3835
-		public function is_cornerstone_preview() {
3836
-			$result = false;
3837
-			if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
3838
-				$result = true;
3839
-			}
3811
+            return $result;
3812
+        }
3840 3813
 
3841
-			return $result;
3842
-		}
3814
+        /**
3815
+         * Tests if the current output is inside a siteorigin builder preview.
3816
+         *
3817
+         * @return bool
3818
+         *@since 1.0.6
3819
+         */
3820
+        public function is_siteorigin_preview() {
3821
+            $result = false;
3822
+            if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
3823
+                $result = true;
3824
+            }
3843 3825
 
3844
-		/**
3845
-		 * Tests if the current output is inside a fusion builder preview.
3846
-		 *
3847
-		 * @return bool
3848
-		 *@since 1.1.0
3849
-		 */
3850
-		public function is_fusion_preview() {
3851
-			$result = false;
3852
-			if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) {
3853
-				$result = true;
3854
-			}
3826
+            return $result;
3827
+        }
3855 3828
 
3856
-			return $result;
3857
-		}
3829
+        /**
3830
+         * Tests if the current output is inside a cornerstone builder preview.
3831
+         *
3832
+         * @return bool
3833
+         *@since 1.0.8
3834
+         */
3835
+        public function is_cornerstone_preview() {
3836
+            $result = false;
3837
+            if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
3838
+                $result = true;
3839
+            }
3858 3840
 
3859
-		/**
3860
-		 * Tests if the current output is inside a Oxygen builder preview.
3861
-		 *
3862
-		 * @return bool
3863
-		 *@since 1.0.18
3864
-		 */
3865
-		public function is_oxygen_preview() {
3866
-			$result = false;
3867
-			if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) {
3868
-				$result = true;
3869
-			}
3841
+            return $result;
3842
+        }
3870 3843
 
3871
-			return $result;
3872
-		}
3844
+        /**
3845
+         * Tests if the current output is inside a fusion builder preview.
3846
+         *
3847
+         * @return bool
3848
+         *@since 1.1.0
3849
+         */
3850
+        public function is_fusion_preview() {
3851
+            $result = false;
3852
+            if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) {
3853
+                $result = true;
3854
+            }
3873 3855
 
3874
-		/**
3875
-		 * General function to check if we are in a preview situation.
3876
-		 *
3877
-		 * @return bool
3878
-		 *@since 1.0.6
3879
-		 */
3880
-		public function is_preview() {
3881
-			$preview = false;
3882
-			if ( $this->is_divi_preview() ) {
3883
-				$preview = true;
3884
-			} elseif ( $this->is_elementor_preview() ) {
3885
-				$preview = true;
3886
-			} elseif ( $this->is_beaver_preview() ) {
3887
-				$preview = true;
3888
-			} elseif ( $this->is_siteorigin_preview() ) {
3889
-				$preview = true;
3890
-			} elseif ( $this->is_cornerstone_preview() ) {
3891
-				$preview = true;
3892
-			} elseif ( $this->is_fusion_preview() ) {
3893
-				$preview = true;
3894
-			} elseif ( $this->is_oxygen_preview() ) {
3895
-				$preview = true;
3896
-			} elseif( $this->is_block_content_call() ) {
3897
-				$preview = true;
3898
-			}
3856
+            return $result;
3857
+        }
3899 3858
 
3900
-			return $preview;
3901
-		}
3859
+        /**
3860
+         * Tests if the current output is inside a Oxygen builder preview.
3861
+         *
3862
+         * @return bool
3863
+         *@since 1.0.18
3864
+         */
3865
+        public function is_oxygen_preview() {
3866
+            $result = false;
3867
+            if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) {
3868
+                $result = true;
3869
+            }
3902 3870
 
3903
-		/**
3904
-		 * Output the super title.
3905
-		 *
3906
-		 * @param $args
3907
-		 * @param array $instance
3908
-		 *
3909
-		 * @return string
3910
-		 */
3911
-		public function output_title( $args, $instance = array() ) {
3912
-			$output = '';
3913
-			if ( ! empty( $instance['title'] ) ) {
3914
-				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
3915
-				$title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
3916
-
3917
-				if(empty($instance['widget_title_tag'])){
3918
-					$output = $args['before_title'] . $title . $args['after_title'];
3919
-				}else{
3920
-					$title_tag = esc_attr( $instance['widget_title_tag'] );
3921
-
3922
-					// classes
3923
-					$title_classes = array();
3924
-					$title_classes[] = !empty( $instance['widget_title_size_class'] ) ? sanitize_html_class( $instance['widget_title_size_class'] ) : '';
3925
-					$title_classes[] = !empty( $instance['widget_title_align_class'] ) ? sanitize_html_class( $instance['widget_title_align_class'] ) : '';
3926
-					$title_classes[] = !empty( $instance['widget_title_color_class'] ) ? "text-".sanitize_html_class( $instance['widget_title_color_class'] ) : '';
3927
-					$title_classes[] = !empty( $instance['widget_title_border_class'] ) ? sanitize_html_class( $instance['widget_title_border_class'] ) : '';
3928
-					$title_classes[] = !empty( $instance['widget_title_border_color_class'] ) ? "border-".sanitize_html_class( $instance['widget_title_border_color_class'] ) : '';
3929
-					$title_classes[] = !empty( $instance['widget_title_mt_class'] ) ? "mt-".absint( $instance['widget_title_mt_class'] ) : '';
3930
-					$title_classes[] = !empty( $instance['widget_title_mr_class'] ) ? "mr-".absint( $instance['widget_title_mr_class'] ) : '';
3931
-					$title_classes[] = !empty( $instance['widget_title_mb_class'] ) ? "mb-".absint( $instance['widget_title_mb_class'] ) : '';
3932
-					$title_classes[] = !empty( $instance['widget_title_ml_class'] ) ? "ml-".absint( $instance['widget_title_ml_class'] ) : '';
3933
-					$title_classes[] = !empty( $instance['widget_title_pt_class'] ) ? "pt-".absint( $instance['widget_title_pt_class'] ) : '';
3934
-					$title_classes[] = !empty( $instance['widget_title_pr_class'] ) ? "pr-".absint( $instance['widget_title_pr_class'] ) : '';
3935
-					$title_classes[] = !empty( $instance['widget_title_pb_class'] ) ? "pb-".absint( $instance['widget_title_pb_class'] ) : '';
3936
-					$title_classes[] = !empty( $instance['widget_title_pl_class'] ) ? "pl-".absint( $instance['widget_title_pl_class'] ) : '';
3937
-
3938
-					$class = !empty( $title_classes ) ? implode(" ",$title_classes) : '';
3939
-					$output = "<$title_tag class='$class' >$title</$title_tag>";
3940
-				}
3871
+            return $result;
3872
+        }
3941 3873
 
3942
-			}
3874
+        /**
3875
+         * General function to check if we are in a preview situation.
3876
+         *
3877
+         * @return bool
3878
+         *@since 1.0.6
3879
+         */
3880
+        public function is_preview() {
3881
+            $preview = false;
3882
+            if ( $this->is_divi_preview() ) {
3883
+                $preview = true;
3884
+            } elseif ( $this->is_elementor_preview() ) {
3885
+                $preview = true;
3886
+            } elseif ( $this->is_beaver_preview() ) {
3887
+                $preview = true;
3888
+            } elseif ( $this->is_siteorigin_preview() ) {
3889
+                $preview = true;
3890
+            } elseif ( $this->is_cornerstone_preview() ) {
3891
+                $preview = true;
3892
+            } elseif ( $this->is_fusion_preview() ) {
3893
+                $preview = true;
3894
+            } elseif ( $this->is_oxygen_preview() ) {
3895
+                $preview = true;
3896
+            } elseif( $this->is_block_content_call() ) {
3897
+                $preview = true;
3898
+            }
3943 3899
 
3944
-			return $output;
3945
-		}
3900
+            return $preview;
3901
+        }
3902
+
3903
+        /**
3904
+         * Output the super title.
3905
+         *
3906
+         * @param $args
3907
+         * @param array $instance
3908
+         *
3909
+         * @return string
3910
+         */
3911
+        public function output_title( $args, $instance = array() ) {
3912
+            $output = '';
3913
+            if ( ! empty( $instance['title'] ) ) {
3914
+                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
3915
+                $title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
3916
+
3917
+                if(empty($instance['widget_title_tag'])){
3918
+                    $output = $args['before_title'] . $title . $args['after_title'];
3919
+                }else{
3920
+                    $title_tag = esc_attr( $instance['widget_title_tag'] );
3921
+
3922
+                    // classes
3923
+                    $title_classes = array();
3924
+                    $title_classes[] = !empty( $instance['widget_title_size_class'] ) ? sanitize_html_class( $instance['widget_title_size_class'] ) : '';
3925
+                    $title_classes[] = !empty( $instance['widget_title_align_class'] ) ? sanitize_html_class( $instance['widget_title_align_class'] ) : '';
3926
+                    $title_classes[] = !empty( $instance['widget_title_color_class'] ) ? "text-".sanitize_html_class( $instance['widget_title_color_class'] ) : '';
3927
+                    $title_classes[] = !empty( $instance['widget_title_border_class'] ) ? sanitize_html_class( $instance['widget_title_border_class'] ) : '';
3928
+                    $title_classes[] = !empty( $instance['widget_title_border_color_class'] ) ? "border-".sanitize_html_class( $instance['widget_title_border_color_class'] ) : '';
3929
+                    $title_classes[] = !empty( $instance['widget_title_mt_class'] ) ? "mt-".absint( $instance['widget_title_mt_class'] ) : '';
3930
+                    $title_classes[] = !empty( $instance['widget_title_mr_class'] ) ? "mr-".absint( $instance['widget_title_mr_class'] ) : '';
3931
+                    $title_classes[] = !empty( $instance['widget_title_mb_class'] ) ? "mb-".absint( $instance['widget_title_mb_class'] ) : '';
3932
+                    $title_classes[] = !empty( $instance['widget_title_ml_class'] ) ? "ml-".absint( $instance['widget_title_ml_class'] ) : '';
3933
+                    $title_classes[] = !empty( $instance['widget_title_pt_class'] ) ? "pt-".absint( $instance['widget_title_pt_class'] ) : '';
3934
+                    $title_classes[] = !empty( $instance['widget_title_pr_class'] ) ? "pr-".absint( $instance['widget_title_pr_class'] ) : '';
3935
+                    $title_classes[] = !empty( $instance['widget_title_pb_class'] ) ? "pb-".absint( $instance['widget_title_pb_class'] ) : '';
3936
+                    $title_classes[] = !empty( $instance['widget_title_pl_class'] ) ? "pl-".absint( $instance['widget_title_pl_class'] ) : '';
3937
+
3938
+                    $class = !empty( $title_classes ) ? implode(" ",$title_classes) : '';
3939
+                    $output = "<$title_tag class='$class' >$title</$title_tag>";
3940
+                }
3941
+
3942
+            }
3946 3943
 
3947
-		/**
3948
-		 * Outputs the options form inputs for the widget.
3949
-		 *
3950
-		 * @param array $instance The widget options.
3951
-		 */
3952
-		public function form( $instance ) {
3944
+            return $output;
3945
+        }
3946
+
3947
+        /**
3948
+         * Outputs the options form inputs for the widget.
3949
+         *
3950
+         * @param array $instance The widget options.
3951
+         */
3952
+        public function form( $instance ) {
3953 3953
 
3954
-			// set widget instance
3955
-			$this->instance = $instance;
3954
+            // set widget instance
3955
+            $this->instance = $instance;
3956 3956
 
3957
-			// set it as a SD widget
3958
-			echo $this->widget_advanced_toggle();
3957
+            // set it as a SD widget
3958
+            echo $this->widget_advanced_toggle();
3959 3959
 
3960
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
3961
-			$arguments_raw = $this->get_arguments();
3960
+            echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
3961
+            $arguments_raw = $this->get_arguments();
3962 3962
 
3963
-			if ( is_array( $arguments_raw ) ) {
3963
+            if ( is_array( $arguments_raw ) ) {
3964 3964
 
3965
-				$arguments = $this->group_arguments( $arguments_raw );
3965
+                $arguments = $this->group_arguments( $arguments_raw );
3966 3966
 
3967
-				// Do we have sections?
3968
-				$has_sections = $arguments == $arguments_raw ? false : true;
3967
+                // Do we have sections?
3968
+                $has_sections = $arguments == $arguments_raw ? false : true;
3969 3969
 
3970 3970
 
3971
-				if ( $has_sections ) {
3972
-					$panel_count = 0;
3973
-					foreach ( $arguments as $key => $args ) {
3971
+                if ( $has_sections ) {
3972
+                    $panel_count = 0;
3973
+                    foreach ( $arguments as $key => $args ) {
3974 3974
 
3975
-						?>
3975
+                        ?>
3976 3976
 						<script>
3977 3977
 							//							jQuery(this).find("i").toggleClass("fas fa-chevron-up fas fa-chevron-down");jQuery(this).next().toggle();
3978 3978
 						</script>
3979 3979
 						<?php
3980 3980
 
3981
-						$hide       = $panel_count ? ' style="display:none;" ' : '';
3982
-						$icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down';
3983
-						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>";
3984
-						echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>";
3981
+                        $hide       = $panel_count ? ' style="display:none;" ' : '';
3982
+                        $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down';
3983
+                        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>";
3984
+                        echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>";
3985 3985
 
3986
-						foreach ( $args as $k => $a ) {
3986
+                        foreach ( $args as $k => $a ) {
3987 3987
 
3988
-							$this->widget_inputs_row_start($k, $a);
3989
-							$this->widget_inputs( $a, $instance );
3990
-							$this->widget_inputs_row_end($k, $a);
3988
+                            $this->widget_inputs_row_start($k, $a);
3989
+                            $this->widget_inputs( $a, $instance );
3990
+                            $this->widget_inputs_row_end($k, $a);
3991 3991
 
3992
-						}
3992
+                        }
3993 3993
 
3994
-						echo "</div>";
3994
+                        echo "</div>";
3995 3995
 
3996
-						$panel_count ++;
3996
+                        $panel_count ++;
3997 3997
 
3998
-					}
3999
-				} else {
4000
-					foreach ( $arguments as $key => $args ) {
4001
-						$this->widget_inputs_row_start($key, $args);
4002
-						$this->widget_inputs( $args, $instance );
4003
-						$this->widget_inputs_row_end($key, $args);
4004
-					}
4005
-				}
3998
+                    }
3999
+                } else {
4000
+                    foreach ( $arguments as $key => $args ) {
4001
+                        $this->widget_inputs_row_start($key, $args);
4002
+                        $this->widget_inputs( $args, $instance );
4003
+                        $this->widget_inputs_row_end($key, $args);
4004
+                    }
4005
+                }
4006 4006
 
4007
-			}
4008
-		}
4007
+            }
4008
+        }
4009 4009
 
4010
-		public function widget_inputs_row_start($key, $args){
4011
-			if(!empty($args['row'])){
4012
-				// maybe open
4013
-				if(!empty($args['row']['open'])){
4014
-					?>
4010
+        public function widget_inputs_row_start($key, $args){
4011
+            if(!empty($args['row'])){
4012
+                // maybe open
4013
+                if(!empty($args['row']['open'])){
4014
+                    ?>
4015 4015
 					<div class='bsui sd-argument ' data-argument='<?php echo esc_attr( $args['row']['key'] ); ?>' data-element_require='<?php if ( !empty($args['row']['element_require'])) {
4016
-						echo $this->convert_element_require( $args['row']['element_require'] );
4017
-					} ?>'>
4016
+                        echo $this->convert_element_require( $args['row']['element_require'] );
4017
+                    } ?>'>
4018 4018
 					<?php if(!empty($args['row']['title'])){ ?>
4019 4019
 					<label class="mb-0 "><?php echo esc_attr( $args['row']['title'] ); ?><?php echo $this->widget_field_desc( $args['row'] ); ?></label>
4020 4020
 					<?php }?>
4021 4021
 					<div class='row <?php if(!empty($args['row']['class'])){ echo esc_attr($args['row']['class']);} ?>'>
4022 4022
 					<div class='col pr-2'>
4023 4023
 					<?php
4024
-				}elseif(!empty($args['row']['close'])){
4025
-					echo "<div class='col pl-0'>";
4026
-				}else{
4027
-					echo "<div class='col pl-0 pr-2'>";
4028
-				}
4029
-			}
4030
-		}
4024
+                }elseif(!empty($args['row']['close'])){
4025
+                    echo "<div class='col pl-0'>";
4026
+                }else{
4027
+                    echo "<div class='col pl-0 pr-2'>";
4028
+                }
4029
+            }
4030
+        }
4031 4031
 
4032
-		public function widget_inputs_row_end($key, $args){
4032
+        public function widget_inputs_row_end($key, $args){
4033 4033
 
4034
-			if(!empty($args['row'])){
4035
-				// maybe close
4036
-				if(!empty($args['row']['close'])){
4037
-					echo "</div></div>";
4038
-				}
4034
+            if(!empty($args['row'])){
4035
+                // maybe close
4036
+                if(!empty($args['row']['close'])){
4037
+                    echo "</div></div>";
4038
+                }
4039 4039
 
4040
-				echo "</div>";
4041
-			}
4042
-		}
4040
+                echo "</div>";
4041
+            }
4042
+        }
4043 4043
 
4044
-		/**
4045
-		 * Get the hidden input that when added makes the advanced button show on widget settings.
4046
-		 *
4047
-		 * @return string
4048
-		 */
4049
-		public function widget_advanced_toggle() {
4050
-
4051
-			$output = '';
4052
-			if ( $this->block_show_advanced() ) {
4053
-				$val = 1;
4054
-			} else {
4055
-				$val = 0;
4056
-			}
4044
+        /**
4045
+         * Get the hidden input that when added makes the advanced button show on widget settings.
4046
+         *
4047
+         * @return string
4048
+         */
4049
+        public function widget_advanced_toggle() {
4057 4050
 
4058
-			$output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
4051
+            $output = '';
4052
+            if ( $this->block_show_advanced() ) {
4053
+                $val = 1;
4054
+            } else {
4055
+                $val = 0;
4056
+            }
4059 4057
 
4060
-			return $output;
4061
-		}
4058
+            $output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
4062 4059
 
4063
-		/**
4064
-		 * Convert require element.
4065
-		 *
4066
-		 * @param string $input Input element.
4067
-		 *
4068
-		 * @return string $output
4069
-		 *@since 1.0.0
4070
-		 *
4071
-		 */
4072
-		public function convert_element_require( $input ) {
4073
-
4074
-			$input = str_replace( "'", '"', $input );// we only want double quotes
4075
-
4076
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
4077
-				"jQuery(form).find('[data-argument=\"",
4078
-				"\"]').find('input,select,textarea').val()"
4079
-			), $input ) );
4080
-
4081
-			return $output;
4082
-		}
4060
+            return $output;
4061
+        }
4083 4062
 
4084
-		/**
4085
-		 * Builds the inputs for the widget options.
4086
-		 *
4087
-		 * @param $args
4088
-		 * @param $instance
4089
-		 */
4090
-		public function widget_inputs( $args, $instance ) {
4091
-
4092
-			$class             = "";
4093
-			$element_require   = "";
4094
-			$custom_attributes = "";
4095
-
4096
-			// get value
4097
-			if ( isset( $instance[ $args['name'] ] ) ) {
4098
-				$value = $instance[ $args['name'] ];
4099
-			} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
4100
-				$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
4101
-			} else {
4102
-				$value = '';
4103
-			}
4063
+        /**
4064
+         * Convert require element.
4065
+         *
4066
+         * @param string $input Input element.
4067
+         *
4068
+         * @return string $output
4069
+         *@since 1.0.0
4070
+         *
4071
+         */
4072
+        public function convert_element_require( $input ) {
4104 4073
 
4105
-			// get placeholder
4106
-			if ( ! empty( $args['placeholder'] ) ) {
4107
-				$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
4108
-			} else {
4109
-				$placeholder = '';
4110
-			}
4074
+            $input = str_replace( "'", '"', $input );// we only want double quotes
4111 4075
 
4112
-			// get if advanced
4113
-			if ( isset( $args['advanced'] ) && $args['advanced'] ) {
4114
-				$class .= " sd-advanced-setting ";
4115
-			}
4076
+            $output = esc_attr( str_replace( array( "[%", "%]" ), array(
4077
+                "jQuery(form).find('[data-argument=\"",
4078
+                "\"]').find('input,select,textarea').val()"
4079
+            ), $input ) );
4116 4080
 
4117
-			// element_require
4118
-			if ( isset( $args['element_require'] ) && $args['element_require'] ) {
4119
-				$element_require = $args['element_require'];
4120
-			}
4081
+            return $output;
4082
+        }
4121 4083
 
4122
-			// custom_attributes
4123
-			if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
4124
-				$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
4125
-			}
4084
+        /**
4085
+         * Builds the inputs for the widget options.
4086
+         *
4087
+         * @param $args
4088
+         * @param $instance
4089
+         */
4090
+        public function widget_inputs( $args, $instance ) {
4091
+
4092
+            $class             = "";
4093
+            $element_require   = "";
4094
+            $custom_attributes = "";
4095
+
4096
+            // get value
4097
+            if ( isset( $instance[ $args['name'] ] ) ) {
4098
+                $value = $instance[ $args['name'] ];
4099
+            } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
4100
+                $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
4101
+            } else {
4102
+                $value = '';
4103
+            }
4104
+
4105
+            // get placeholder
4106
+            if ( ! empty( $args['placeholder'] ) ) {
4107
+                $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
4108
+            } else {
4109
+                $placeholder = '';
4110
+            }
4126 4111
 
4112
+            // get if advanced
4113
+            if ( isset( $args['advanced'] ) && $args['advanced'] ) {
4114
+                $class .= " sd-advanced-setting ";
4115
+            }
4127 4116
 
4128
-			// before wrapper
4129
-			?>
4117
+            // element_require
4118
+            if ( isset( $args['element_require'] ) && $args['element_require'] ) {
4119
+                $element_require = $args['element_require'];
4120
+            }
4121
+
4122
+            // custom_attributes
4123
+            if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
4124
+                $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
4125
+            }
4126
+
4127
+
4128
+            // before wrapper
4129
+            ?>
4130 4130
 			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
4131 4131
 			data-argument='<?php echo esc_attr( $args['name'] ); ?>'
4132 4132
 			data-element_require='<?php if ( $element_require ) {
4133
-				echo $this->convert_element_require( $element_require );
4134
-			} ?>'
4133
+                echo $this->convert_element_require( $element_require );
4134
+            } ?>'
4135 4135
 			>
4136 4136
 			<?php
4137 4137
 
4138 4138
 
4139
-			switch ( $args['type'] ) {
4140
-				//array('text','password','number','email','tel','url','color')
4141
-				case "text":
4142
-				case "password":
4143
-				case "number":
4144
-				case "email":
4145
-				case "tel":
4146
-				case "url":
4147
-				case "color":
4148
-					?>
4139
+            switch ( $args['type'] ) {
4140
+                //array('text','password','number','email','tel','url','color')
4141
+                case "text":
4142
+                case "password":
4143
+                case "number":
4144
+                case "email":
4145
+                case "tel":
4146
+                case "url":
4147
+                case "color":
4148
+                    ?>
4149 4149
 					<label
4150 4150
 						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>
4151 4151
 					<input <?php echo $placeholder; ?> class="widefat"
@@ -4156,47 +4156,47 @@  discard block
 block discarded – undo
4156 4156
 						                               value="<?php echo esc_attr( $value ); ?>">
4157 4157
 					<?php
4158 4158
 
4159
-					break;
4160
-				case "select":
4161
-					$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
4162
-					if ( $multiple ) {
4163
-						if ( empty( $value ) ) {
4164
-							$value = array();
4165
-						}
4166
-					}
4167
-					?>
4159
+                    break;
4160
+                case "select":
4161
+                    $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
4162
+                    if ( $multiple ) {
4163
+                        if ( empty( $value ) ) {
4164
+                            $value = array();
4165
+                        }
4166
+                    }
4167
+                    ?>
4168 4168
 					<label
4169 4169
 						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>
4170 4170
 					<select <?php echo $placeholder; ?> class="widefat"
4171 4171
 						<?php echo $custom_attributes; ?>
4172 4172
 						                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
4173 4173
 						                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) );
4174
-						                                if ( $multiple ) {
4175
-							                                echo "[]";
4176
-						                                } ?>"
4174
+                                                        if ( $multiple ) {
4175
+                                                            echo "[]";
4176
+                                                        } ?>"
4177 4177
 						<?php if ( $multiple ) {
4178
-							echo "multiple";
4179
-						} //@todo not implemented yet due to gutenberg not supporting it
4180
-						?>
4178
+                            echo "multiple";
4179
+                        } //@todo not implemented yet due to gutenberg not supporting it
4180
+                        ?>
4181 4181
 					>
4182 4182
 						<?php
4183 4183
 
4184
-						if ( ! empty( $args['options'] ) ) {
4185
-							foreach ( $args['options'] as $val => $label ) {
4186
-								if ( $multiple ) {
4187
-									$selected = in_array( $val, $value ) ? 'selected="selected"' : '';
4188
-								} else {
4189
-									$selected = selected( $value, $val, false );
4190
-								}
4191
-								echo "<option value='$val' " . $selected . ">$label</option>";
4192
-							}
4193
-						}
4194
-						?>
4184
+                        if ( ! empty( $args['options'] ) ) {
4185
+                            foreach ( $args['options'] as $val => $label ) {
4186
+                                if ( $multiple ) {
4187
+                                    $selected = in_array( $val, $value ) ? 'selected="selected"' : '';
4188
+                                } else {
4189
+                                    $selected = selected( $value, $val, false );
4190
+                                }
4191
+                                echo "<option value='$val' " . $selected . ">$label</option>";
4192
+                            }
4193
+                        }
4194
+                        ?>
4195 4195
 					</select>
4196 4196
 					<?php
4197
-					break;
4198
-				case "checkbox":
4199
-					?>
4197
+                    break;
4198
+                case "checkbox":
4199
+                    ?>
4200 4200
 					<input <?php echo $placeholder; ?>
4201 4201
 						<?php checked( 1, $value, true ) ?>
4202 4202
 						<?php echo $custom_attributes; ?>
@@ -4206,9 +4206,9 @@  discard block
 block discarded – undo
4206 4206
 					<label
4207 4207
 						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>
4208 4208
 					<?php
4209
-					break;
4210
-				case "textarea":
4211
-					?>
4209
+                    break;
4210
+                case "textarea":
4211
+                    ?>
4212 4212
 					<label
4213 4213
 						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>
4214 4214
 					<textarea <?php echo $placeholder; ?> class="widefat"
@@ -4218,282 +4218,282 @@  discard block
 block discarded – undo
4218 4218
 					><?php echo esc_attr( $value ); ?></textarea>
4219 4219
 					<?php
4220 4220
 
4221
-					break;
4222
-				case "hidden":
4223
-					?>
4221
+                    break;
4222
+                case "hidden":
4223
+                    ?>
4224 4224
 					<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
4225 4225
 					       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
4226 4226
 					       value="<?php echo esc_attr( $value ); ?>">
4227 4227
 					<?php
4228
-					break;
4229
-				default:
4230
-					echo "No input type found!"; // @todo we need to add more input types.
4231
-			}
4228
+                    break;
4229
+                default:
4230
+                    echo "No input type found!"; // @todo we need to add more input types.
4231
+            }
4232 4232
 
4233
-			// after wrapper
4234
-			?>
4233
+            // after wrapper
4234
+            ?>
4235 4235
 			</p>
4236 4236
 			<?php
4237 4237
 
4238 4238
 
4239
-		}
4239
+        }
4240 4240
 
4241
-		public function get_widget_icon($icon = 'box-top', $title = ''){
4242
-			if($icon=='box-top'){
4243
-				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>';
4244
-			}elseif($icon=='box-right'){
4245
-				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>';
4246
-			}elseif($icon=='box-bottom'){
4247
-				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>';
4248
-			}elseif($icon=='box-left'){
4249
-				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>';
4250
-			}
4251
-		}
4241
+        public function get_widget_icon($icon = 'box-top', $title = ''){
4242
+            if($icon=='box-top'){
4243
+                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>';
4244
+            }elseif($icon=='box-right'){
4245
+                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>';
4246
+            }elseif($icon=='box-bottom'){
4247
+                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>';
4248
+            }elseif($icon=='box-left'){
4249
+                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>';
4250
+            }
4251
+        }
4252 4252
 
4253
-		/**
4254
-		 * Get the widget input description html.
4255
-		 *
4256
-		 * @param $args
4257
-		 *
4258
-		 * @return string
4259
-		 * @todo, need to make its own tooltip script
4260
-		 */
4261
-		public function widget_field_desc( $args ) {
4262
-
4263
-			$description = '';
4264
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
4265
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
4266
-					$description = $this->desc_tip( $args['desc'] );
4267
-				} else {
4268
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
4269
-				}
4270
-			}
4253
+        /**
4254
+         * Get the widget input description html.
4255
+         *
4256
+         * @param $args
4257
+         *
4258
+         * @return string
4259
+         * @todo, need to make its own tooltip script
4260
+         */
4261
+        public function widget_field_desc( $args ) {
4262
+
4263
+            $description = '';
4264
+            if ( isset( $args['desc'] ) && $args['desc'] ) {
4265
+                if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
4266
+                    $description = $this->desc_tip( $args['desc'] );
4267
+                } else {
4268
+                    $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
4269
+                }
4270
+            }
4271 4271
 
4272
-			return $description;
4273
-		}
4272
+            return $description;
4273
+        }
4274 4274
 
4275
-		/**
4276
-		 * Get the widget input title html.
4277
-		 *
4278
-		 * @param $args
4279
-		 *
4280
-		 * @return string
4281
-		 */
4282
-		public function widget_field_title( $args ) {
4283
-
4284
-			$title = '';
4285
-			if ( isset( $args['title'] ) && $args['title'] ) {
4286
-				if ( isset( $args['icon'] ) && $args['icon'] ) {
4287
-					$title = self::get_widget_icon( $args['icon'], $args['title']  );
4288
-				} else {
4289
-					$title = esc_attr($args['title']);
4290
-				}
4291
-			}
4275
+        /**
4276
+         * Get the widget input title html.
4277
+         *
4278
+         * @param $args
4279
+         *
4280
+         * @return string
4281
+         */
4282
+        public function widget_field_title( $args ) {
4283
+
4284
+            $title = '';
4285
+            if ( isset( $args['title'] ) && $args['title'] ) {
4286
+                if ( isset( $args['icon'] ) && $args['icon'] ) {
4287
+                    $title = self::get_widget_icon( $args['icon'], $args['title']  );
4288
+                } else {
4289
+                    $title = esc_attr($args['title']);
4290
+                }
4291
+            }
4292 4292
 
4293
-			return $title;
4294
-		}
4293
+            return $title;
4294
+        }
4295 4295
 
4296
-		/**
4297
-		 * Get the tool tip html.
4298
-		 *
4299
-		 * @param $tip
4300
-		 * @param bool $allow_html
4301
-		 *
4302
-		 * @return string
4303
-		 */
4304
-		function desc_tip( $tip, $allow_html = false ) {
4305
-			if ( $allow_html ) {
4306
-				$tip = $this->sanitize_tooltip( $tip );
4307
-			} else {
4308
-				$tip = esc_attr( $tip );
4309
-			}
4296
+        /**
4297
+         * Get the tool tip html.
4298
+         *
4299
+         * @param $tip
4300
+         * @param bool $allow_html
4301
+         *
4302
+         * @return string
4303
+         */
4304
+        function desc_tip( $tip, $allow_html = false ) {
4305
+            if ( $allow_html ) {
4306
+                $tip = $this->sanitize_tooltip( $tip );
4307
+            } else {
4308
+                $tip = esc_attr( $tip );
4309
+            }
4310 4310
 
4311
-			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
4312
-		}
4311
+            return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
4312
+        }
4313 4313
 
4314
-		/**
4315
-		 * Sanitize a string destined to be a tooltip.
4316
-		 *
4317
-		 * @param string $var
4318
-		 *
4319
-		 * @return string
4320
-		 */
4321
-		public function sanitize_tooltip( $var ) {
4322
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
4323
-				'br'     => array(),
4324
-				'em'     => array(),
4325
-				'strong' => array(),
4326
-				'small'  => array(),
4327
-				'span'   => array(),
4328
-				'ul'     => array(),
4329
-				'li'     => array(),
4330
-				'ol'     => array(),
4331
-				'p'      => array(),
4332
-			) ) );
4333
-		}
4314
+        /**
4315
+         * Sanitize a string destined to be a tooltip.
4316
+         *
4317
+         * @param string $var
4318
+         *
4319
+         * @return string
4320
+         */
4321
+        public function sanitize_tooltip( $var ) {
4322
+            return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
4323
+                'br'     => array(),
4324
+                'em'     => array(),
4325
+                'strong' => array(),
4326
+                'small'  => array(),
4327
+                'span'   => array(),
4328
+                'ul'     => array(),
4329
+                'li'     => array(),
4330
+                'ol'     => array(),
4331
+                'p'      => array(),
4332
+            ) ) );
4333
+        }
4334 4334
 
4335
-		/**
4336
-		 * Processing widget options on save
4337
-		 *
4338
-		 * @param array $new_instance The new options
4339
-		 * @param array $old_instance The previous options
4340
-		 *
4341
-		 * @return array
4342
-		 * @todo we should add some sanitation here.
4343
-		 */
4344
-		public function update( $new_instance, $old_instance ) {
4345
-
4346
-			//save the widget
4347
-			$instance = array_merge( (array) $old_instance, (array) $new_instance );
4348
-
4349
-			// set widget instance
4350
-			$this->instance = $instance;
4351
-
4352
-			if ( empty( $this->arguments ) ) {
4353
-				$this->get_arguments();
4354
-			}
4335
+        /**
4336
+         * Processing widget options on save
4337
+         *
4338
+         * @param array $new_instance The new options
4339
+         * @param array $old_instance The previous options
4340
+         *
4341
+         * @return array
4342
+         * @todo we should add some sanitation here.
4343
+         */
4344
+        public function update( $new_instance, $old_instance ) {
4355 4345
 
4356
-			// check for checkboxes
4357
-			if ( ! empty( $this->arguments ) ) {
4358
-				foreach ( $this->arguments as $argument ) {
4359
-					if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
4360
-						$instance[ $argument['name'] ] = '0';
4361
-					}
4362
-				}
4363
-			}
4346
+            //save the widget
4347
+            $instance = array_merge( (array) $old_instance, (array) $new_instance );
4364 4348
 
4365
-			return $instance;
4366
-		}
4349
+            // set widget instance
4350
+            $this->instance = $instance;
4367 4351
 
4368
-		/**
4369
-		 * Checks if the current call is a ajax call to get the block content.
4370
-		 *
4371
-		 * This can be used in your widget to return different content as the block content.
4372
-		 *
4373
-		 * @return bool
4374
-		 *@since 1.0.3
4375
-		 */
4376
-		public function is_block_content_call() {
4377
-			$result = false;
4378
-			if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
4379
-				$result = true;
4380
-			}
4352
+            if ( empty( $this->arguments ) ) {
4353
+                $this->get_arguments();
4354
+            }
4381 4355
 
4382
-			return $result;
4383
-		}
4356
+            // check for checkboxes
4357
+            if ( ! empty( $this->arguments ) ) {
4358
+                foreach ( $this->arguments as $argument ) {
4359
+                    if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
4360
+                        $instance[ $argument['name'] ] = '0';
4361
+                    }
4362
+                }
4363
+            }
4384 4364
 
4385
-		/**
4386
-		 * Get an instance hash that will be unique to the type and settings.
4387
-		 *
4388
-		 * @return string
4389
-		 *@since 1.0.20
4390
-		 */
4391
-		public function get_instance_hash(){
4392
-			$instance_string = $this->base_id.serialize($this->instance);
4393
-			return hash('crc32b',$instance_string);
4394
-		}
4365
+            return $instance;
4366
+        }
4395 4367
 
4396
-		/**
4397
-		 * Generate and return inline styles from CSS rules that will match the unique class of the instance.
4398
-		 *
4399
-		 * @param array $rules
4400
-		 *
4401
-		 * @return string
4402
-		 *@since 1.0.20
4403
-		 */
4404
-		public function get_instance_style($rules = array()){
4405
-			$css = '';
4406
-
4407
-			if(!empty($rules)){
4408
-				$rules = array_unique($rules);
4409
-				$instance_hash = $this->get_instance_hash();
4410
-				$css .= "<style>";
4411
-				foreach($rules as $rule){
4412
-					$css .= ".sdel-$instance_hash $rule";
4413
-				}
4414
-				$css .= "</style>";
4415
-			}
4368
+        /**
4369
+         * Checks if the current call is a ajax call to get the block content.
4370
+         *
4371
+         * This can be used in your widget to return different content as the block content.
4372
+         *
4373
+         * @return bool
4374
+         *@since 1.0.3
4375
+         */
4376
+        public function is_block_content_call() {
4377
+            $result = false;
4378
+            if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
4379
+                $result = true;
4380
+            }
4416 4381
 
4417
-			return $css;
4418
-		}
4382
+            return $result;
4383
+        }
4384
+
4385
+        /**
4386
+         * Get an instance hash that will be unique to the type and settings.
4387
+         *
4388
+         * @return string
4389
+         *@since 1.0.20
4390
+         */
4391
+        public function get_instance_hash(){
4392
+            $instance_string = $this->base_id.serialize($this->instance);
4393
+            return hash('crc32b',$instance_string);
4394
+        }
4395
+
4396
+        /**
4397
+         * Generate and return inline styles from CSS rules that will match the unique class of the instance.
4398
+         *
4399
+         * @param array $rules
4400
+         *
4401
+         * @return string
4402
+         *@since 1.0.20
4403
+         */
4404
+        public function get_instance_style($rules = array()){
4405
+            $css = '';
4406
+
4407
+            if(!empty($rules)){
4408
+                $rules = array_unique($rules);
4409
+                $instance_hash = $this->get_instance_hash();
4410
+                $css .= "<style>";
4411
+                foreach($rules as $rule){
4412
+                    $css .= ".sdel-$instance_hash $rule";
4413
+                }
4414
+                $css .= "</style>";
4415
+            }
4416
+
4417
+            return $css;
4418
+        }
4419 4419
 
4420
-		/**
4421
-		 * Encode shortcodes tags.
4422
-		 *
4423
-		 * @param string $content Content to search for shortcode tags.
4424
-		 *
4420
+        /**
4421
+         * Encode shortcodes tags.
4422
+         *
4423
+         * @param string $content Content to search for shortcode tags.
4424
+         *
4425 4425
 *@return string Content with shortcode tags removed.
4426
-		 *@since 1.0.28
4427
-		 *
4428
-		 */
4429
-		public function encode_shortcodes( $content ) {
4430
-			// Avoids existing encoded tags.
4431
-			$trans   = array(
4432
-				'&#91;' => '&#091;',
4433
-				'&#93;' => '&#093;',
4434
-				'&amp;#91;' => '&#091;',
4435
-				'&amp;#93;' => '&#093;',
4436
-				'&lt;' => '&0lt;',
4437
-				'&gt;' => '&0gt;',
4438
-				'&amp;lt;' => '&0lt;',
4439
-				'&amp;gt;' => '&0gt;',
4440
-			);
4441
-
4442
-			$content = strtr( $content, $trans );
4443
-
4444
-			$trans   = array(
4445
-				'[' => '&#91;',
4446
-				']' => '&#93;',
4447
-				'<' => '&lt;',
4448
-				'>' => '&gt;',
4449
-				'"' => '&quot;',
4450
-				"'" => '&apos;',
4451
-			);
4452
-
4453
-			$content = strtr( $content, $trans );
4454
-
4455
-			return $content;
4456
-		}
4426
+         *@since 1.0.28
4427
+         *
4428
+         */
4429
+        public function encode_shortcodes( $content ) {
4430
+            // Avoids existing encoded tags.
4431
+            $trans   = array(
4432
+                '&#91;' => '&#091;',
4433
+                '&#93;' => '&#093;',
4434
+                '&amp;#91;' => '&#091;',
4435
+                '&amp;#93;' => '&#093;',
4436
+                '&lt;' => '&0lt;',
4437
+                '&gt;' => '&0gt;',
4438
+                '&amp;lt;' => '&0lt;',
4439
+                '&amp;gt;' => '&0gt;',
4440
+            );
4441
+
4442
+            $content = strtr( $content, $trans );
4443
+
4444
+            $trans   = array(
4445
+                '[' => '&#91;',
4446
+                ']' => '&#93;',
4447
+                '<' => '&lt;',
4448
+                '>' => '&gt;',
4449
+                '"' => '&quot;',
4450
+                "'" => '&apos;',
4451
+            );
4452
+
4453
+            $content = strtr( $content, $trans );
4454
+
4455
+            return $content;
4456
+        }
4457 4457
 
4458
-		/**
4459
-		 * Remove encoded shortcod tags.
4460
-		 *
4461
-		 * @param string $content Content to search for shortcode tags.
4462
-		 *
4458
+        /**
4459
+         * Remove encoded shortcod tags.
4460
+         *
4461
+         * @param string $content Content to search for shortcode tags.
4462
+         *
4463 4463
 *@return string Content with decoded shortcode tags.
4464
-		 *@since 1.0.28
4465
-		 *
4466
-		 */
4467
-		public function decode_shortcodes( $content ) {
4468
-			$trans   = array(
4469
-				'&#91;' => '[',
4470
-				'&#93;' => ']',
4471
-				'&amp;#91;' => '[',
4472
-				'&amp;#93;' => ']',
4473
-				'&lt;' => '<',
4474
-				'&gt;' => '>',
4475
-				'&amp;lt;' => '<',
4476
-				'&amp;gt;' => '>',
4477
-				'&quot;' => '"',
4478
-				'&apos;' => "'",
4479
-			);
4480
-
4481
-			$content = strtr( $content, $trans );
4482
-
4483
-			$trans   = array(
4484
-				'&#091;' => '&#91;',
4485
-				'&#093;' => '&#93;',
4486
-				'&amp;#091;' => '&#91;',
4487
-				'&amp;#093;' => '&#93;',
4488
-				'&0lt;' => '&lt;',
4489
-				'&0gt;' => '&gt;',
4490
-				'&amp;0lt;' => '&lt;',
4491
-				'&amp;0gt;' => '&gt;',
4492
-			);
4493
-
4494
-			$content = strtr( $content, $trans );
4495
-
4496
-			return $content;
4497
-		}
4498
-	}
4464
+         *@since 1.0.28
4465
+         *
4466
+         */
4467
+        public function decode_shortcodes( $content ) {
4468
+            $trans   = array(
4469
+                '&#91;' => '[',
4470
+                '&#93;' => ']',
4471
+                '&amp;#91;' => '[',
4472
+                '&amp;#93;' => ']',
4473
+                '&lt;' => '<',
4474
+                '&gt;' => '>',
4475
+                '&amp;lt;' => '<',
4476
+                '&amp;gt;' => '>',
4477
+                '&quot;' => '"',
4478
+                '&apos;' => "'",
4479
+            );
4480
+
4481
+            $content = strtr( $content, $trans );
4482
+
4483
+            $trans   = array(
4484
+                '&#091;' => '&#91;',
4485
+                '&#093;' => '&#93;',
4486
+                '&amp;#091;' => '&#91;',
4487
+                '&amp;#093;' => '&#93;',
4488
+                '&0lt;' => '&lt;',
4489
+                '&0gt;' => '&gt;',
4490
+                '&amp;0lt;' => '&lt;',
4491
+                '&amp;0gt;' => '&gt;',
4492
+            );
4493
+
4494
+            $content = strtr( $content, $trans );
4495
+
4496
+            return $content;
4497
+        }
4498
+    }
4499 4499
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscriptions-query.php 1 patch
Indentation   +505 added lines, -505 removed lines patch added patch discarded remove patch
@@ -16,512 +16,512 @@
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Subscriptions_Query {
18 18
 
19
-	/**
20
-	 * Query vars, after parsing
21
-	 *
22
-	 * @since 1.0.19
23
-	 * @var array
24
-	 */
25
-	public $query_vars = array();
26
-
27
-	/**
28
-	 * List of found subscriptions.
29
-	 *
30
-	 * @since 1.0.19
31
-	 * @var array
32
-	 */
33
-	private $results;
34
-
35
-	/**
36
-	 * Total number of found subscriptions for the current query
37
-	 *
38
-	 * @since 1.0.19
39
-	 * @var int
40
-	 */
41
-	private $total_subscriptions = 0;
42
-
43
-	/**
44
-	 * The SQL query used to fetch matching subscriptions.
45
-	 *
46
-	 * @since 1.0.19
47
-	 * @var string
48
-	 */
49
-	public $request;
50
-
51
-	// SQL clauses
52
-
53
-	/**
54
-	 * Contains the 'FIELDS' sql clause
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @var string
58
-	 */
59
-	public $query_fields;
60
-
61
-	/**
62
-	 * Contains the 'FROM' sql clause
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @var string
66
-	 */
67
-	public $query_from;
68
-
69
-	/**
70
-	 * Contains the 'WHERE' sql clause
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $query_where;
76
-
77
-	/**
78
-	 * Contains the 'ORDER BY' sql clause
79
-	 *
80
-	 * @since 1.0.19
81
-	 * @var string
82
-	 */
83
-	public $query_orderby;
84
-
85
-	/**
86
-	 * Contains the 'LIMIT' sql clause
87
-	 *
88
-	 * @since 1.0.19
89
-	 * @var string
90
-	 */
91
-	public $query_limit;
92
-
93
-	/**
94
-	 * Class constructor.
95
-	 *
96
-	 * @since 1.0.19
97
-	 *
98
-	 * @param null|string|array $query Optional. The query variables.
99
-	 */
100
-	public function __construct( $query = null ) {
101
-		if ( ! is_null( $query ) ) {
102
-			$this->prepare_query( $query );
103
-			$this->query();
104
-		}
105
-	}
106
-
107
-	/**
108
-	 * Fills in missing query variables with default values.
109
-	 *
110
-	 * @since 1.0.19
111
-	 *
112
-	 * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
-	 * @return array Complete query variables with undefined ones filled in with defaults.
114
-	 */
115
-	public static function fill_query_vars( $args ) {
116
-		$defaults = array(
117
-			'status'          => 'all',
118
-			'customer_in'     => array(),
119
-			'customer_not_in' => array(),
120
-			'product_in'      => array(),
121
-			'product_not_in'  => array(),
122
-			'include'         => array(),
123
-			'exclude'         => array(),
124
-			'orderby'         => 'id',
125
-			'order'           => 'DESC',
126
-			'offset'          => '',
127
-			'number'          => 10,
128
-			'paged'           => 1,
129
-			'count_total'     => true,
130
-			'fields'          => 'all',
131
-		);
132
-
133
-		return wp_parse_args( $args, $defaults );
134
-	}
135
-
136
-	/**
137
-	 * Prepare the query variables.
138
-	 *
139
-	 * @since 1.0.19
140
-	 *
141
-	 * @global wpdb $wpdb WordPress database abstraction object.
142
-	 *
143
-	 * @param string|array $query {
144
-	 *     Optional. Array or string of Query parameters.
145
-	 *
146
-	 *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
-	 *                                             Default is all.
148
-	 *     @type int[]        $customer_in         An array of customer ids to filter by.
149
-	 *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
-	 *     @type int[]        $invoice_in          An array of invoice ids to filter by.
151
-	 *     @type int[]        $invoice_not_in      An array of invoice ids whose subscriptions should be excluded.
152
-	 *     @type int[]        $product_in          An array of product ids to filter by.
153
-	 *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
154
-	 *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
155
-	 *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
156
-	 *     @type array        $include             An array of subscription IDs to include. Default empty array.
157
-	 *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
158
-	 *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
159
-	 *                                             an array of values, or a multi-dimensional array with fields as
160
-	 *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
161
-	 *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
162
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
163
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
164
-	 *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
165
-	 *                                             passed as part of an `$orderby` array take precedence over this
166
-	 *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
167
-	 *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
168
-	 *                                             conjunction with pagination. Default 0.
169
-	 *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
170
-	 *                                             conjunction with pagination. Value -1 (all) is supported, but
171
-	 *                                             should be used with caution on larger sites.
172
-	 *                                             Default 10.
173
-	 *     @type int          $paged               When used with number, defines the page of results to return.
174
-	 *                                             Default 1.
175
-	 *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
176
-	 *                                             is not needed, setting this to false can improve performance.
177
-	 *                                             Default true.
178
-	 *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
179
-	 *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
180
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
181
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
182
-	 *                                             Use 'all' for all fields. Default 'all'.
183
-	 * }
184
-	 */
185
-	public function prepare_query( $query = array() ) {
186
-		global $wpdb;
187
-
188
-		if ( empty( $this->query_vars ) || ! empty( $query ) ) {
189
-			$this->query_limit = null;
190
-			$this->query_vars  = $this->fill_query_vars( $query );
191
-		}
192
-
193
-		if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
194
-			$this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
195
-		}
196
-
197
-		do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
198
-
199
-		// Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
200
-		$qv                =& $this->query_vars;
201
-		$qv                = $this->fill_query_vars( $qv );
202
-		$table             = $wpdb->prefix . 'wpinv_subscriptions';
203
-		$this->query_from  = "FROM $table";
204
-
205
-		// Prepare query fields.
206
-		$this->prepare_query_fields( $qv, $table );
207
-
208
-		// Prepare query where.
209
-		$this->prepare_query_where( $qv, $table );
210
-
211
-		// Prepare query order.
212
-		$this->prepare_query_order( $qv, $table );
213
-
214
-		// limit
215
-		if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
216
-			if ( $qv['offset'] ) {
217
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
218
-			} else {
219
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
220
-			}
221
-		}
222
-
223
-		do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
224
-	}
225
-
226
-	/**
227
-	 * Prepares the query fields.
228
-	 *
229
-	 * @since 1.0.19
230
-	 *
231
-	 * @param array $qv Query vars.
232
-	 * @param string $table Table name.
233
-	 */
234
-	protected function prepare_query_fields( &$qv, $table ) {
235
-
236
-		if ( is_array( $qv['fields'] ) ) {
237
-			$qv['fields'] = array_unique( $qv['fields'] );
238
-
239
-			$query_fields = array();
240
-			foreach ( $qv['fields'] as $field ) {
241
-				$field          = sanitize_key( $field );
242
-				$query_fields[] = "$table.`$field`";
243
-			}
244
-			$this->query_fields = implode( ',', $query_fields );
245
-		} else {
246
-			$this->query_fields = "$table.*";
247
-		}
248
-
249
-		if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
250
-			$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
251
-		}
252
-
253
-	}
254
-
255
-	/**
256
-	 * Prepares the query where.
257
-	 *
258
-	 * @since 1.0.19
259
-	 *
260
-	 * @param array $qv Query vars.
261
-	 * @param string $table Table name.
262
-	 */
263
-	protected function prepare_query_where( &$qv, $table ) {
264
-		global $wpdb;
265
-		$this->query_where = 'WHERE 1=1';
266
-
267
-		// Status.
268
-		if ( 'all' !== $qv['status'] ) {
269
-			$statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
270
-			$prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
271
-			$this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
272
-		}
273
-
274
-		if ( ! empty( $qv['customer_in'] ) ) {
275
-			$customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
276
-			$this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
277
-		} elseif ( ! empty( $qv['customer_not_in'] ) ) {
278
-			$customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
279
-			$this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
280
-		}
281
-
282
-		if ( ! empty( $qv['product_in'] ) ) {
283
-			$product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
284
-			$this->query_where .= " AND $table.`product_id` IN ($product_in)";
285
-		} elseif ( ! empty( $qv['product_not_in'] ) ) {
286
-			$product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
287
-			$this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
288
-		}
289
-
290
-		if ( ! empty( $qv['invoice_in'] ) ) {
291
-			$invoice_in         = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) );
292
-			$this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)";
293
-		} elseif ( ! empty( $qv['invoice_not_in'] ) ) {
294
-			$invoice_not_in     = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) );
295
-			$this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)";
296
-		}
297
-
298
-		if ( ! empty( $qv['include'] ) ) {
299
-			$include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
300
-			$this->query_where .= " AND $table.`id` IN ($include)";
301
-		} elseif ( ! empty( $qv['exclude'] ) ) {
302
-			$exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
303
-			$this->query_where .= " AND $table.`id` NOT IN ($exclude)";
304
-		}
305
-
306
-		// Date queries are allowed for the subscription creation date.
307
-		if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
308
-			$date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
309
-			$this->query_where .= $date_created_query->get_sql();
310
-		}
311
-
312
-		// Date queries are also allowed for the subscription expiration date.
313
-		if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
314
-			$date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
315
-			$this->query_where .= $date_expires_query->get_sql();
316
-		}
317
-
318
-	}
319
-
320
-	/**
321
-	 * Prepares the query order.
322
-	 *
323
-	 * @since 1.0.19
324
-	 *
325
-	 * @param array $qv Query vars.
326
-	 * @param string $table Table name.
327
-	 */
328
-	protected function prepare_query_order( &$qv, $table ) {
329
-
330
-		// sorting.
331
-		$qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
332
-		$order       = $this->parse_order( $qv['order'] );
333
-
334
-		// Default order is by 'id' (latest subscriptions).
335
-		if ( empty( $qv['orderby'] ) ) {
336
-			$qv['orderby'] = array( 'id' );
337
-		}
338
-
339
-		// 'orderby' values may be an array, comma- or space-separated list.
340
-		$ordersby      = array_filter( wpinv_parse_list( $qv['orderby'] ) );
341
-
342
-		$orderby_array = array();
343
-		foreach ( $ordersby as $_key => $_value ) {
344
-
345
-			if ( is_int( $_key ) ) {
346
-				// Integer key means this is a flat array of 'orderby' fields.
347
-				$_orderby = $_value;
348
-				$_order   = $order;
349
-			} else {
350
-				// Non-integer key means that the key is the field and the value is ASC/DESC.
351
-				$_orderby = $_key;
352
-				$_order   = $_value;
353
-			}
354
-
355
-			$parsed = $this->parse_orderby( $_orderby, $table );
356
-
357
-			if ( $parsed ) {
358
-				$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
359
-			}
19
+    /**
20
+     * Query vars, after parsing
21
+     *
22
+     * @since 1.0.19
23
+     * @var array
24
+     */
25
+    public $query_vars = array();
26
+
27
+    /**
28
+     * List of found subscriptions.
29
+     *
30
+     * @since 1.0.19
31
+     * @var array
32
+     */
33
+    private $results;
34
+
35
+    /**
36
+     * Total number of found subscriptions for the current query
37
+     *
38
+     * @since 1.0.19
39
+     * @var int
40
+     */
41
+    private $total_subscriptions = 0;
42
+
43
+    /**
44
+     * The SQL query used to fetch matching subscriptions.
45
+     *
46
+     * @since 1.0.19
47
+     * @var string
48
+     */
49
+    public $request;
50
+
51
+    // SQL clauses
52
+
53
+    /**
54
+     * Contains the 'FIELDS' sql clause
55
+     *
56
+     * @since 1.0.19
57
+     * @var string
58
+     */
59
+    public $query_fields;
60
+
61
+    /**
62
+     * Contains the 'FROM' sql clause
63
+     *
64
+     * @since 1.0.19
65
+     * @var string
66
+     */
67
+    public $query_from;
68
+
69
+    /**
70
+     * Contains the 'WHERE' sql clause
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $query_where;
76
+
77
+    /**
78
+     * Contains the 'ORDER BY' sql clause
79
+     *
80
+     * @since 1.0.19
81
+     * @var string
82
+     */
83
+    public $query_orderby;
84
+
85
+    /**
86
+     * Contains the 'LIMIT' sql clause
87
+     *
88
+     * @since 1.0.19
89
+     * @var string
90
+     */
91
+    public $query_limit;
92
+
93
+    /**
94
+     * Class constructor.
95
+     *
96
+     * @since 1.0.19
97
+     *
98
+     * @param null|string|array $query Optional. The query variables.
99
+     */
100
+    public function __construct( $query = null ) {
101
+        if ( ! is_null( $query ) ) {
102
+            $this->prepare_query( $query );
103
+            $this->query();
104
+        }
105
+    }
106
+
107
+    /**
108
+     * Fills in missing query variables with default values.
109
+     *
110
+     * @since 1.0.19
111
+     *
112
+     * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
+     * @return array Complete query variables with undefined ones filled in with defaults.
114
+     */
115
+    public static function fill_query_vars( $args ) {
116
+        $defaults = array(
117
+            'status'          => 'all',
118
+            'customer_in'     => array(),
119
+            'customer_not_in' => array(),
120
+            'product_in'      => array(),
121
+            'product_not_in'  => array(),
122
+            'include'         => array(),
123
+            'exclude'         => array(),
124
+            'orderby'         => 'id',
125
+            'order'           => 'DESC',
126
+            'offset'          => '',
127
+            'number'          => 10,
128
+            'paged'           => 1,
129
+            'count_total'     => true,
130
+            'fields'          => 'all',
131
+        );
132
+
133
+        return wp_parse_args( $args, $defaults );
134
+    }
135
+
136
+    /**
137
+     * Prepare the query variables.
138
+     *
139
+     * @since 1.0.19
140
+     *
141
+     * @global wpdb $wpdb WordPress database abstraction object.
142
+     *
143
+     * @param string|array $query {
144
+     *     Optional. Array or string of Query parameters.
145
+     *
146
+     *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
+     *                                             Default is all.
148
+     *     @type int[]        $customer_in         An array of customer ids to filter by.
149
+     *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
+     *     @type int[]        $invoice_in          An array of invoice ids to filter by.
151
+     *     @type int[]        $invoice_not_in      An array of invoice ids whose subscriptions should be excluded.
152
+     *     @type int[]        $product_in          An array of product ids to filter by.
153
+     *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
154
+     *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
155
+     *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
156
+     *     @type array        $include             An array of subscription IDs to include. Default empty array.
157
+     *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
158
+     *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
159
+     *                                             an array of values, or a multi-dimensional array with fields as
160
+     *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
161
+     *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
162
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
163
+     *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
164
+     *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
165
+     *                                             passed as part of an `$orderby` array take precedence over this
166
+     *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
167
+     *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
168
+     *                                             conjunction with pagination. Default 0.
169
+     *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
170
+     *                                             conjunction with pagination. Value -1 (all) is supported, but
171
+     *                                             should be used with caution on larger sites.
172
+     *                                             Default 10.
173
+     *     @type int          $paged               When used with number, defines the page of results to return.
174
+     *                                             Default 1.
175
+     *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
176
+     *                                             is not needed, setting this to false can improve performance.
177
+     *                                             Default true.
178
+     *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
179
+     *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
180
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
181
+     *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
182
+     *                                             Use 'all' for all fields. Default 'all'.
183
+     * }
184
+     */
185
+    public function prepare_query( $query = array() ) {
186
+        global $wpdb;
187
+
188
+        if ( empty( $this->query_vars ) || ! empty( $query ) ) {
189
+            $this->query_limit = null;
190
+            $this->query_vars  = $this->fill_query_vars( $query );
191
+        }
192
+
193
+        if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
194
+            $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
195
+        }
196
+
197
+        do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
198
+
199
+        // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
200
+        $qv                =& $this->query_vars;
201
+        $qv                = $this->fill_query_vars( $qv );
202
+        $table             = $wpdb->prefix . 'wpinv_subscriptions';
203
+        $this->query_from  = "FROM $table";
204
+
205
+        // Prepare query fields.
206
+        $this->prepare_query_fields( $qv, $table );
207
+
208
+        // Prepare query where.
209
+        $this->prepare_query_where( $qv, $table );
210
+
211
+        // Prepare query order.
212
+        $this->prepare_query_order( $qv, $table );
213
+
214
+        // limit
215
+        if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
216
+            if ( $qv['offset'] ) {
217
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
218
+            } else {
219
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
220
+            }
221
+        }
222
+
223
+        do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
224
+    }
225
+
226
+    /**
227
+     * Prepares the query fields.
228
+     *
229
+     * @since 1.0.19
230
+     *
231
+     * @param array $qv Query vars.
232
+     * @param string $table Table name.
233
+     */
234
+    protected function prepare_query_fields( &$qv, $table ) {
235
+
236
+        if ( is_array( $qv['fields'] ) ) {
237
+            $qv['fields'] = array_unique( $qv['fields'] );
238
+
239
+            $query_fields = array();
240
+            foreach ( $qv['fields'] as $field ) {
241
+                $field          = sanitize_key( $field );
242
+                $query_fields[] = "$table.`$field`";
243
+            }
244
+            $this->query_fields = implode( ',', $query_fields );
245
+        } else {
246
+            $this->query_fields = "$table.*";
247
+        }
248
+
249
+        if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
250
+            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
251
+        }
252
+
253
+    }
254
+
255
+    /**
256
+     * Prepares the query where.
257
+     *
258
+     * @since 1.0.19
259
+     *
260
+     * @param array $qv Query vars.
261
+     * @param string $table Table name.
262
+     */
263
+    protected function prepare_query_where( &$qv, $table ) {
264
+        global $wpdb;
265
+        $this->query_where = 'WHERE 1=1';
266
+
267
+        // Status.
268
+        if ( 'all' !== $qv['status'] ) {
269
+            $statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
270
+            $prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
271
+            $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
272
+        }
273
+
274
+        if ( ! empty( $qv['customer_in'] ) ) {
275
+            $customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
276
+            $this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
277
+        } elseif ( ! empty( $qv['customer_not_in'] ) ) {
278
+            $customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
279
+            $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
280
+        }
281
+
282
+        if ( ! empty( $qv['product_in'] ) ) {
283
+            $product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
284
+            $this->query_where .= " AND $table.`product_id` IN ($product_in)";
285
+        } elseif ( ! empty( $qv['product_not_in'] ) ) {
286
+            $product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
287
+            $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
288
+        }
289
+
290
+        if ( ! empty( $qv['invoice_in'] ) ) {
291
+            $invoice_in         = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) );
292
+            $this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)";
293
+        } elseif ( ! empty( $qv['invoice_not_in'] ) ) {
294
+            $invoice_not_in     = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) );
295
+            $this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)";
296
+        }
297
+
298
+        if ( ! empty( $qv['include'] ) ) {
299
+            $include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
300
+            $this->query_where .= " AND $table.`id` IN ($include)";
301
+        } elseif ( ! empty( $qv['exclude'] ) ) {
302
+            $exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
303
+            $this->query_where .= " AND $table.`id` NOT IN ($exclude)";
304
+        }
305
+
306
+        // Date queries are allowed for the subscription creation date.
307
+        if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
308
+            $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
309
+            $this->query_where .= $date_created_query->get_sql();
310
+        }
311
+
312
+        // Date queries are also allowed for the subscription expiration date.
313
+        if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
314
+            $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
315
+            $this->query_where .= $date_expires_query->get_sql();
316
+        }
317
+
318
+    }
319
+
320
+    /**
321
+     * Prepares the query order.
322
+     *
323
+     * @since 1.0.19
324
+     *
325
+     * @param array $qv Query vars.
326
+     * @param string $table Table name.
327
+     */
328
+    protected function prepare_query_order( &$qv, $table ) {
329
+
330
+        // sorting.
331
+        $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
332
+        $order       = $this->parse_order( $qv['order'] );
333
+
334
+        // Default order is by 'id' (latest subscriptions).
335
+        if ( empty( $qv['orderby'] ) ) {
336
+            $qv['orderby'] = array( 'id' );
337
+        }
338
+
339
+        // 'orderby' values may be an array, comma- or space-separated list.
340
+        $ordersby      = array_filter( wpinv_parse_list( $qv['orderby'] ) );
341
+
342
+        $orderby_array = array();
343
+        foreach ( $ordersby as $_key => $_value ) {
344
+
345
+            if ( is_int( $_key ) ) {
346
+                // Integer key means this is a flat array of 'orderby' fields.
347
+                $_orderby = $_value;
348
+                $_order   = $order;
349
+            } else {
350
+                // Non-integer key means that the key is the field and the value is ASC/DESC.
351
+                $_orderby = $_key;
352
+                $_order   = $_value;
353
+            }
354
+
355
+            $parsed = $this->parse_orderby( $_orderby, $table );
356
+
357
+            if ( $parsed ) {
358
+                $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
359
+            }
360 360
 }
361 361
 
362
-		// If no valid clauses were found, order by id.
363
-		if ( empty( $orderby_array ) ) {
364
-			$orderby_array[] = "id $order";
365
-		}
366
-
367
-		$this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
368
-
369
-	}
370
-
371
-	/**
372
-	 * Execute the query, with the current variables.
373
-	 *
374
-	 * @since 1.0.19
375
-	 *
376
-	 * @global wpdb $wpdb WordPress database abstraction object.
377
-	 */
378
-	public function query() {
379
-		global $wpdb;
380
-
381
-		$qv =& $this->query_vars;
382
-
383
-		// Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
384
-		// total_subscriptions property.
385
-		$this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
386
-
387
-		if ( null === $this->results ) {
388
-			$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
389
-
390
-			if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
391
-				$this->results = $wpdb->get_results( $this->request );
392
-			} else {
393
-				$this->results = $wpdb->get_col( $this->request );
394
-			}
395
-
396
-			if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
397
-				$found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
398
-				$this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
399
-			}
400
-		}
401
-
402
-		if ( 'all' == $qv['fields'] ) {
403
-			foreach ( $this->results as $key => $subscription ) {
404
-				$this->set_cache( $subscription->id, $subscription, 'getpaid_subscriptions' );
405
-				$this->set_cache( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' );
406
-				$this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
407
-				$this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
408
-				$this->results[ $key ] = new WPInv_Subscription( $subscription );
409
-			}
410
-		}
411
-
412
-	}
413
-
414
-	/**
415
-	 * Set cache
416
-	 *
417
-	 * @param string  $id
418
-	 * @param mixed   $data
419
-	 * @param string  $group
420
-	 * @param integer $expire
421
-	 * @return boolean
422
-	 */
423
-	public function set_cache( $key, $data, $group = '', $expire = 0 ) {
424
-
425
-		if ( empty( $key ) ) {
426
-			return false;
427
-		}
428
-
429
-		wp_cache_set( $key, $data, $group, $expire );
430
-	}
431
-
432
-	/**
433
-	 * Retrieve query variable.
434
-	 *
435
-	 * @since 1.0.19
436
-	 *
437
-	 * @param string $query_var Query variable key.
438
-	 * @return mixed
439
-	 */
440
-	public function get( $query_var ) {
441
-		if ( isset( $this->query_vars[ $query_var ] ) ) {
442
-			return $this->query_vars[ $query_var ];
443
-		}
444
-
445
-		return null;
446
-	}
447
-
448
-	/**
449
-	 * Set query variable.
450
-	 *
451
-	 * @since 1.0.19
452
-	 *
453
-	 * @param string $query_var Query variable key.
454
-	 * @param mixed $value Query variable value.
455
-	 */
456
-	public function set( $query_var, $value ) {
457
-		$this->query_vars[ $query_var ] = $value;
458
-	}
459
-
460
-	/**
461
-	 * Return the list of subscriptions.
462
-	 *
463
-	 * @since 1.0.19
464
-	 *
465
-	 * @return WPInv_Subscription[]|array Found subscriptions.
466
-	 */
467
-	public function get_results() {
468
-		return $this->results;
469
-	}
470
-
471
-	/**
472
-	 * Return the total number of subscriptions for the current query.
473
-	 *
474
-	 * @since 1.0.19
475
-	 *
476
-	 * @return int Number of total subscriptions.
477
-	 */
478
-	public function get_total() {
479
-		return $this->total_subscriptions;
480
-	}
481
-
482
-	/**
483
-	 * Parse and sanitize 'orderby' keys passed to the subscriptions query.
484
-	 *
485
-	 * @since 1.0.19
486
-	 *
487
-	 * @param string $orderby Alias for the field to order by.
488
-	 *  @param string $table The current table.
489
-	 * @return string Value to use in the ORDER clause, if `$orderby` is valid.
490
-	 */
491
-	protected function parse_orderby( $orderby, $table ) {
492
-
493
-		$_orderby = '';
494
-		if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) {
495
-			$_orderby = "$table.`$orderby`";
496
-		} elseif ( 'id' === strtolower( $orderby ) ) {
497
-			$_orderby = "$table.id";
498
-		} elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
499
-			$include     = wp_parse_id_list( $this->query_vars['include'] );
500
-			$include_sql = implode( ',', $include );
501
-			$_orderby    = "FIELD( $table.id, $include_sql )";
502
-		}
503
-
504
-		return $_orderby;
505
-	}
506
-
507
-	/**
508
-	 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
509
-	 *
510
-	 * @since 1.0.19
511
-	 *
512
-	 * @param string $order The 'order' query variable.
513
-	 * @return string The sanitized 'order' query variable.
514
-	 */
515
-	protected function parse_order( $order ) {
516
-		if ( ! is_string( $order ) || empty( $order ) ) {
517
-			return 'DESC';
518
-		}
519
-
520
-		if ( 'ASC' === strtoupper( $order ) ) {
521
-			return 'ASC';
522
-		} else {
523
-			return 'DESC';
524
-		}
525
-	}
362
+        // If no valid clauses were found, order by id.
363
+        if ( empty( $orderby_array ) ) {
364
+            $orderby_array[] = "id $order";
365
+        }
366
+
367
+        $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
368
+
369
+    }
370
+
371
+    /**
372
+     * Execute the query, with the current variables.
373
+     *
374
+     * @since 1.0.19
375
+     *
376
+     * @global wpdb $wpdb WordPress database abstraction object.
377
+     */
378
+    public function query() {
379
+        global $wpdb;
380
+
381
+        $qv =& $this->query_vars;
382
+
383
+        // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
384
+        // total_subscriptions property.
385
+        $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
386
+
387
+        if ( null === $this->results ) {
388
+            $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
389
+
390
+            if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
391
+                $this->results = $wpdb->get_results( $this->request );
392
+            } else {
393
+                $this->results = $wpdb->get_col( $this->request );
394
+            }
395
+
396
+            if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
397
+                $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
398
+                $this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
399
+            }
400
+        }
401
+
402
+        if ( 'all' == $qv['fields'] ) {
403
+            foreach ( $this->results as $key => $subscription ) {
404
+                $this->set_cache( $subscription->id, $subscription, 'getpaid_subscriptions' );
405
+                $this->set_cache( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' );
406
+                $this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
407
+                $this->set_cache( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
408
+                $this->results[ $key ] = new WPInv_Subscription( $subscription );
409
+            }
410
+        }
411
+
412
+    }
413
+
414
+    /**
415
+     * Set cache
416
+     *
417
+     * @param string  $id
418
+     * @param mixed   $data
419
+     * @param string  $group
420
+     * @param integer $expire
421
+     * @return boolean
422
+     */
423
+    public function set_cache( $key, $data, $group = '', $expire = 0 ) {
424
+
425
+        if ( empty( $key ) ) {
426
+            return false;
427
+        }
428
+
429
+        wp_cache_set( $key, $data, $group, $expire );
430
+    }
431
+
432
+    /**
433
+     * Retrieve query variable.
434
+     *
435
+     * @since 1.0.19
436
+     *
437
+     * @param string $query_var Query variable key.
438
+     * @return mixed
439
+     */
440
+    public function get( $query_var ) {
441
+        if ( isset( $this->query_vars[ $query_var ] ) ) {
442
+            return $this->query_vars[ $query_var ];
443
+        }
444
+
445
+        return null;
446
+    }
447
+
448
+    /**
449
+     * Set query variable.
450
+     *
451
+     * @since 1.0.19
452
+     *
453
+     * @param string $query_var Query variable key.
454
+     * @param mixed $value Query variable value.
455
+     */
456
+    public function set( $query_var, $value ) {
457
+        $this->query_vars[ $query_var ] = $value;
458
+    }
459
+
460
+    /**
461
+     * Return the list of subscriptions.
462
+     *
463
+     * @since 1.0.19
464
+     *
465
+     * @return WPInv_Subscription[]|array Found subscriptions.
466
+     */
467
+    public function get_results() {
468
+        return $this->results;
469
+    }
470
+
471
+    /**
472
+     * Return the total number of subscriptions for the current query.
473
+     *
474
+     * @since 1.0.19
475
+     *
476
+     * @return int Number of total subscriptions.
477
+     */
478
+    public function get_total() {
479
+        return $this->total_subscriptions;
480
+    }
481
+
482
+    /**
483
+     * Parse and sanitize 'orderby' keys passed to the subscriptions query.
484
+     *
485
+     * @since 1.0.19
486
+     *
487
+     * @param string $orderby Alias for the field to order by.
488
+     *  @param string $table The current table.
489
+     * @return string Value to use in the ORDER clause, if `$orderby` is valid.
490
+     */
491
+    protected function parse_orderby( $orderby, $table ) {
492
+
493
+        $_orderby = '';
494
+        if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) {
495
+            $_orderby = "$table.`$orderby`";
496
+        } elseif ( 'id' === strtolower( $orderby ) ) {
497
+            $_orderby = "$table.id";
498
+        } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
499
+            $include     = wp_parse_id_list( $this->query_vars['include'] );
500
+            $include_sql = implode( ',', $include );
501
+            $_orderby    = "FIELD( $table.id, $include_sql )";
502
+        }
503
+
504
+        return $_orderby;
505
+    }
506
+
507
+    /**
508
+     * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
509
+     *
510
+     * @since 1.0.19
511
+     *
512
+     * @param string $order The 'order' query variable.
513
+     * @return string The sanitized 'order' query variable.
514
+     */
515
+    protected function parse_order( $order ) {
516
+        if ( ! is_string( $order ) || empty( $order ) ) {
517
+            return 'DESC';
518
+        }
519
+
520
+        if ( 'ASC' === strtoupper( $order ) ) {
521
+            return 'ASC';
522
+        } else {
523
+            return 'DESC';
524
+        }
525
+    }
526 526
 
527 527
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'bank_transfer';
21 21
 
22
-	/**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
27
-	protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
22
+    /**
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27
+    protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 8;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 8;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title                = __( 'Direct bank transfer', 'invoicing' );
@@ -44,24 +44,24 @@  discard block
 block discarded – undo
44 44
         $this->checkout_button_text = __( 'Proceed', 'invoicing' );
45 45
         $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
46 46
 
47
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
48
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
49
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
50
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
51
-		add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
52
-		add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
47
+        add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
48
+        add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
49
+        add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
50
+        add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
51
+        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
52
+        add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
53 53
 
54 54
     }
55 55
 
56 56
     /**
57
-	 * Process Payment.
58
-	 *
59
-	 * @param WPInv_Invoice $invoice Invoice.
60
-	 * @param array $submission_data Posted checkout fields.
61
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
-	 * @return array
63
-	 */
64
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+     * Process Payment.
58
+     *
59
+     * @param WPInv_Invoice $invoice Invoice.
60
+     * @param array $submission_data Posted checkout fields.
61
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
+     * @return array
63
+     */
64
+    public function process_payment( $invoice, $submission_data, $submission ) {
65 65
 
66 66
         // Add a transaction id.
67 67
         $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) );
@@ -82,66 +82,66 @@  discard block
 block discarded – undo
82 82
     }
83 83
 
84 84
     /**
85
-	 * Output for the order received page.
86
-	 *
87
-	 * @param WPInv_Invoice $invoice Invoice.
88
-	 */
89
-	public function thankyou_page( $invoice ) {
85
+     * Output for the order received page.
86
+     *
87
+     * @param WPInv_Invoice $invoice Invoice.
88
+     */
89
+    public function thankyou_page( $invoice ) {
90 90
 
91 91
         if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
92 92
 
93
-			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
93
+            echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
94 94
 
95 95
             if ( ! empty( $this->instructions ) ) {
96 96
                 echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
97
-			}
97
+            }
98 98
 
99
-			$this->bank_details( $invoice );
99
+            $this->bank_details( $invoice );
100 100
 
101
-			echo '</div>';
101
+            echo '</div>';
102 102
 
103 103
         }
104 104
 
105
-	}
105
+    }
106 106
 
107 107
     /**
108
-	 * Add content to the WPI emails.
109
-	 *
110
-	 * @param WPInv_Invoice $invoice Invoice.
111
-	 * @param string     $email_type Email format: plain text or HTML.
112
-	 * @param bool     $sent_to_admin Sent to admin.
113
-	 */
114
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
108
+     * Add content to the WPI emails.
109
+     *
110
+     * @param WPInv_Invoice $invoice Invoice.
111
+     * @param string     $email_type Email format: plain text or HTML.
112
+     * @param bool     $sent_to_admin Sent to admin.
113
+     */
114
+    public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
115 115
 
116
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
116
+        if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
117 117
 
118
-			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
118
+            echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
119 119
 
120
-			if ( $this->instructions ) {
121
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
120
+            if ( $this->instructions ) {
121
+                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
122 122
             }
123 123
 
124
-			$this->bank_details( $invoice );
124
+            $this->bank_details( $invoice );
125 125
 
126
-			echo '</div>';
126
+            echo '</div>';
127 127
 
128
-		}
128
+        }
129 129
 
130 130
     }
131 131
 
132 132
     /**
133
-	 * Get bank details and place into a list format.
134
-	 *
135
-	 * @param WPInv_Invoice $invoice Invoice.
136
-	 */
137
-	protected function bank_details( $invoice ) {
133
+     * Get bank details and place into a list format.
134
+     *
135
+     * @param WPInv_Invoice $invoice Invoice.
136
+     */
137
+    protected function bank_details( $invoice ) {
138 138
 
139
-		// Get the invoice country and country $locale.
140
-		$country = $invoice->get_country();
141
-		$locale  = $this->get_country_locale();
139
+        // Get the invoice country and country $locale.
140
+        $country = $invoice->get_country();
141
+        $locale  = $this->get_country_locale();
142 142
 
143
-		// Get sortcode label in the $locale array and use appropriate one.
144
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
143
+        // Get sortcode label in the $locale array and use appropriate one.
144
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
145 145
 
146 146
         $bank_fields = array(
147 147
             'ac_name'   => __( 'Account Name', 'invoicing' ),
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 
161 161
             if ( ! empty( $value ) ) {
162 162
                 $bank_info[ $field ] = array(
163
-					'label' => $label,
164
-					'value' => $value,
165
-				);
163
+                    'label' => $label,
164
+                    'value' => $value,
165
+                );
166 166
             }
167
-		}
167
+        }
168 168
 
169 169
         $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice );
170 170
 
@@ -172,139 +172,139 @@  discard block
 block discarded – undo
172 172
             return;
173 173
         }
174 174
 
175
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
175
+        echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
176
+
177
+        echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
178
+
179
+        foreach ( $bank_info as $key => $data ) {
180
+            echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
181
+        }
182
+
183
+        echo '</table>';
176 184
 
177
-		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
185
+    }
178 186
 
179
-		foreach ( $bank_info as $key => $data ) {
180
-			echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
181
-		}
187
+    /**
188
+     * Get country locale if localized.
189
+     *
190
+     * @return array
191
+     */
192
+    public function get_country_locale() {
193
+
194
+        if ( empty( $this->locale ) ) {
195
+
196
+            // Locale information to be used - only those that are not 'Sort Code'.
197
+            $this->locale = apply_filters(
198
+                'getpaid_get_bank_transfer_locale',
199
+                array(
200
+                    'AU' => array(
201
+                        'sortcode' => array(
202
+                            'label' => __( 'BSB', 'invoicing' ),
203
+                        ),
204
+                    ),
205
+                    'CA' => array(
206
+                        'sortcode' => array(
207
+                            'label' => __( 'Bank transit number', 'invoicing' ),
208
+                        ),
209
+                    ),
210
+                    'IN' => array(
211
+                        'sortcode' => array(
212
+                            'label' => __( 'IFSC', 'invoicing' ),
213
+                        ),
214
+                    ),
215
+                    'IT' => array(
216
+                        'sortcode' => array(
217
+                            'label' => __( 'Branch sort', 'invoicing' ),
218
+                        ),
219
+                    ),
220
+                    'NZ' => array(
221
+                        'sortcode' => array(
222
+                            'label' => __( 'Bank code', 'invoicing' ),
223
+                        ),
224
+                    ),
225
+                    'SE' => array(
226
+                        'sortcode' => array(
227
+                            'label' => __( 'Bank code', 'invoicing' ),
228
+                        ),
229
+                    ),
230
+                    'US' => array(
231
+                        'sortcode' => array(
232
+                            'label' => __( 'Routing number', 'invoicing' ),
233
+                        ),
234
+                    ),
235
+                    'ZA' => array(
236
+                        'sortcode' => array(
237
+                            'label' => __( 'Branch code', 'invoicing' ),
238
+                        ),
239
+                    ),
240
+                )
241
+            );
182 242
 
183
-		echo '</table>';
243
+        }
244
+
245
+        return $this->locale;
184 246
 
185 247
     }
186 248
 
187 249
     /**
188
-	 * Get country locale if localized.
189
-	 *
190
-	 * @return array
191
-	 */
192
-	public function get_country_locale() {
193
-
194
-		if ( empty( $this->locale ) ) {
195
-
196
-			// Locale information to be used - only those that are not 'Sort Code'.
197
-			$this->locale = apply_filters(
198
-				'getpaid_get_bank_transfer_locale',
199
-				array(
200
-					'AU' => array(
201
-						'sortcode' => array(
202
-							'label' => __( 'BSB', 'invoicing' ),
203
-						),
204
-					),
205
-					'CA' => array(
206
-						'sortcode' => array(
207
-							'label' => __( 'Bank transit number', 'invoicing' ),
208
-						),
209
-					),
210
-					'IN' => array(
211
-						'sortcode' => array(
212
-							'label' => __( 'IFSC', 'invoicing' ),
213
-						),
214
-					),
215
-					'IT' => array(
216
-						'sortcode' => array(
217
-							'label' => __( 'Branch sort', 'invoicing' ),
218
-						),
219
-					),
220
-					'NZ' => array(
221
-						'sortcode' => array(
222
-							'label' => __( 'Bank code', 'invoicing' ),
223
-						),
224
-					),
225
-					'SE' => array(
226
-						'sortcode' => array(
227
-							'label' => __( 'Bank code', 'invoicing' ),
228
-						),
229
-					),
230
-					'US' => array(
231
-						'sortcode' => array(
232
-							'label' => __( 'Routing number', 'invoicing' ),
233
-						),
234
-					),
235
-					'ZA' => array(
236
-						'sortcode' => array(
237
-							'label' => __( 'Branch code', 'invoicing' ),
238
-						),
239
-					),
240
-				)
241
-			);
242
-
243
-		}
244
-
245
-		return $this->locale;
246
-
247
-	}
248
-
249
-	/**
250
-	 * Filters the gateway settings.
251
-	 *
252
-	 * @param array $admin_settings
253
-	 */
254
-	public function admin_settings( $admin_settings ) {
250
+     * Filters the gateway settings.
251
+     *
252
+     * @param array $admin_settings
253
+     */
254
+    public function admin_settings( $admin_settings ) {
255 255
 
256 256
         $admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
257
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
257
+        $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
258 258
 
259
-		$locale  = $this->get_country_locale();
259
+        $locale  = $this->get_country_locale();
260 260
 
261
-		// Get sortcode label in the $locale array and use appropriate one.
262
-		$country  = wpinv_default_billing_country();
263
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
261
+        // Get sortcode label in the $locale array and use appropriate one.
262
+        $country  = wpinv_default_billing_country();
263
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
264 264
 
265
-		$admin_settings['bank_transfer_ac_name'] = array(
265
+        $admin_settings['bank_transfer_ac_name'] = array(
266 266
             'type' => 'text',
267 267
             'id'   => 'bank_transfer_ac_name',
268 268
             'name' => __( 'Account Name', 'invoicing' ),
269
-		);
269
+        );
270 270
 
271
-		$admin_settings['bank_transfer_ac_no'] = array(
271
+        $admin_settings['bank_transfer_ac_no'] = array(
272 272
             'type' => 'text',
273 273
             'id'   => 'bank_transfer_ac_no',
274 274
             'name' => __( 'Account Number', 'invoicing' ),
275
-		);
275
+        );
276 276
 
277
-		$admin_settings['bank_transfer_bank_name'] = array(
277
+        $admin_settings['bank_transfer_bank_name'] = array(
278 278
             'type' => 'text',
279 279
             'id'   => 'bank_transfer_bank_name',
280 280
             'name' => __( 'Bank Name', 'invoicing' ),
281
-		);
281
+        );
282 282
 
283
-		$admin_settings['bank_transfer_ifsc'] = array(
283
+        $admin_settings['bank_transfer_ifsc'] = array(
284 284
             'type' => 'text',
285 285
             'id'   => 'bank_transfer_ifsc',
286 286
             'name' => __( 'IFSC Code', 'invoicing' ),
287
-		);
287
+        );
288 288
 
289
-		$admin_settings['bank_transfer_iban'] = array(
289
+        $admin_settings['bank_transfer_iban'] = array(
290 290
             'type' => 'text',
291 291
             'id'   => 'bank_transfer_iban',
292 292
             'name' => __( 'IBAN', 'invoicing' ),
293
-		);
293
+        );
294 294
 
295
-		$admin_settings['bank_transfer_bic'] = array(
295
+        $admin_settings['bank_transfer_bic'] = array(
296 296
             'type' => 'text',
297 297
             'id'   => 'bank_transfer_bic',
298 298
             'name' => __( 'BIC/Swift Code', 'invoicing' ),
299
-		);
299
+        );
300 300
 
301
-		$admin_settings['bank_transfer_sort_code'] = array(
302
-			'type' => 'text',
303
-			'id'   => 'bank_transfer_sort_code',
304
-			'name' => $sortcode,
305
-		);
301
+        $admin_settings['bank_transfer_sort_code'] = array(
302
+            'type' => 'text',
303
+            'id'   => 'bank_transfer_sort_code',
304
+            'name' => $sortcode,
305
+        );
306 306
 
307
-		$admin_settings['bank_transfer_info'] = array(
307
+        $admin_settings['bank_transfer_info'] = array(
308 308
             'id'   => 'bank_transfer_info',
309 309
             'name' => __( 'Instructions', 'invoicing' ),
310 310
             'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
@@ -314,17 +314,17 @@  discard block
 block discarded – undo
314 314
             'rows' => 5,
315 315
         );
316 316
 
317
-		return $admin_settings;
318
-	}
317
+        return $admin_settings;
318
+    }
319 319
 
320
-	/**
321
-	 * Processes invoice addons.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 * @param GetPaid_Form_Item[] $items
325
-	 * @return WPInv_Invoice
326
-	 */
327
-	public function process_addons( $invoice, $items ) {
320
+    /**
321
+     * Processes invoice addons.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     * @param GetPaid_Form_Item[] $items
325
+     * @return WPInv_Invoice
326
+     */
327
+    public function process_addons( $invoice, $items ) {
328 328
 
329 329
         foreach ( $items as $item ) {
330 330
             $invoice->add_item( $item );
@@ -332,66 +332,66 @@  discard block
 block discarded – undo
332 332
 
333 333
         $invoice->recalculate_total();
334 334
         $invoice->save();
335
-	}
335
+    }
336 336
 
337
-	/**
338
-	 * (Maybe) renews a bank transfer subscription profile.
339
-	 *
340
-	 *
337
+    /**
338
+     * (Maybe) renews a bank transfer subscription profile.
339
+     *
340
+     *
341 341
      * @param WPInv_Subscription $subscription
342
-	 */
343
-	public function maybe_renew_subscription( $subscription ) {
342
+     */
343
+    public function maybe_renew_subscription( $subscription ) {
344 344
 
345 345
         // Ensure its our subscription && it's active.
346 346
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
347
-			$subscription->create_payment();
347
+            $subscription->create_payment();
348 348
         }
349 349
 
350 350
     }
351 351
 
352
-	/**
353
-	 * Process a bank transfer payment.
354
-	 *
355
-	 *
352
+    /**
353
+     * Process a bank transfer payment.
354
+     *
355
+     *
356 356
      * @param WPInv_Invoice $invoice
357
-	 */
358
-	public function invoice_paid( $invoice ) {
359
-
360
-		// Abort if not paid by bank transfer.
361
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
362
-			return;
363
-		}
364
-
365
-		// Is it a parent payment?
366
-		if ( 0 == $invoice->get_parent_id() ) {
367
-
368
-			// (Maybe) activate subscriptions.
369
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
370
-
371
-			if ( ! empty( $subscriptions ) ) {
372
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
373
-
374
-				foreach ( $subscriptions as $subscription ) {
375
-					if ( $subscription->exists() ) {
376
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
377
-						$expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
378
-
379
-						$subscription->set_next_renewal_date( $expiry );
380
-						$subscription->set_date_created( current_time( 'mysql' ) );
381
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
382
-						$subscription->activate();
383
-					}
384
-				}
357
+     */
358
+    public function invoice_paid( $invoice ) {
359
+
360
+        // Abort if not paid by bank transfer.
361
+        if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
362
+            return;
363
+        }
364
+
365
+        // Is it a parent payment?
366
+        if ( 0 == $invoice->get_parent_id() ) {
367
+
368
+            // (Maybe) activate subscriptions.
369
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
370
+
371
+            if ( ! empty( $subscriptions ) ) {
372
+                $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
373
+
374
+                foreach ( $subscriptions as $subscription ) {
375
+                    if ( $subscription->exists() ) {
376
+                        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
377
+                        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
378
+
379
+                        $subscription->set_next_renewal_date( $expiry );
380
+                        $subscription->set_date_created( current_time( 'mysql' ) );
381
+                        $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
382
+                        $subscription->activate();
383
+                    }
384
+                }
385 385
 }
386 386
 } else {
387 387
 
388
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
388
+            $subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
389 389
 
390
-			// Renew the subscription.
391
-			if ( $subscription && $subscription->exists() ) {
392
-				$subscription->add_payment( array(), $invoice );
393
-				$subscription->renew( strtotime( $invoice->get_date_created() ) );
394
-					}
390
+            // Renew the subscription.
391
+            if ( $subscription && $subscription->exists() ) {
392
+                $subscription->add_payment( array(), $invoice );
393
+                $subscription->renew( strtotime( $invoice->get_date_created() ) );
394
+                    }
395 395
 }
396 396
 
397 397
     }
Please login to merge, or discard this patch.
templates/payment-forms/cart-item.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -26,71 +26,71 @@  discard block
 block discarded – undo
26 26
 
27 27
 				<?php
28 28
 
29
-					// Fires before printing a line item column.
30
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29
+                    // Fires before printing a line item column.
30
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
31 31
 
32
-					// Item name.
33
-					if ( 'name' === $key ) {
32
+                    // Item name.
33
+                    if ( 'name' === $key ) {
34 34
 
35 35
 
36
-						ob_start();
36
+                        ob_start();
37 37
 
38
-						// Add an optional description.
39
-						$description = $item->get_description();
38
+                        // Add an optional description.
39
+                        $description = $item->get_description();
40 40
 
41
-						if ( ! empty( $description ) ) {
42
-							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
43
-						}
41
+                        if ( ! empty( $description ) ) {
42
+                            echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
43
+                        }
44 44
 
45
-						// Price help text.
46
-						$description = getpaid_item_recurring_price_help_text( $item, $currency );
47
-						if ( $description ) {
48
-							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
49
-						}
45
+                        // Price help text.
46
+                        $description = getpaid_item_recurring_price_help_text( $item, $currency );
47
+                        if ( $description ) {
48
+                            echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
49
+                        }
50 50
 
51
-						do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
51
+                        do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
52 52
 
53
-						if ( wpinv_current_user_can_manage_invoicing() ) {
53
+                        if ( wpinv_current_user_can_manage_invoicing() ) {
54 54
 
55
-							edit_post_link(
56
-								__( 'Edit this item.', 'invoicing' ),
57
-								'<small class="form-text text-muted">',
58
-								'</small>',
59
-								$item->get_id(),
60
-								'text-danger'
61
-							);
55
+                            edit_post_link(
56
+                                __( 'Edit this item.', 'invoicing' ),
57
+                                '<small class="form-text text-muted">',
58
+                                '</small>',
59
+                                $item->get_id(),
60
+                                'text-danger'
61
+                            );
62 62
 
63
-						}
63
+                        }
64 64
 
65
-						$description = ob_get_clean();
65
+                        $description = ob_get_clean();
66 66
 
67
-						// Display the name.
68
-						$tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
67
+                        // Display the name.
68
+                        $tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
69 69
 
70
-						$has_featured_image = has_post_thumbnail( $item->get_id() );
70
+                        $has_featured_image = has_post_thumbnail( $item->get_id() );
71 71
 
72
-						if ( $has_featured_image ) {
73
-							echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">';
74
-							echo '<div class="getpaid-form-item-image-container mr-2">';
75
-							echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
76
-							echo '</div>';
77
-							echo '<div class="getpaid-form-item-name-container">';
78
-						}
72
+                        if ( $has_featured_image ) {
73
+                            echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">';
74
+                            echo '<div class="getpaid-form-item-image-container mr-2">';
75
+                            echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
76
+                            echo '</div>';
77
+                            echo '<div class="getpaid-form-item-name-container">';
78
+                        }
79 79
 
80
-						echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
80
+                        echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
81 81
 
82
-						if ( ! empty( $description ) ) {
83
-							printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
84
-						}
82
+                        if ( ! empty( $description ) ) {
83
+                            printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
84
+                        }
85 85
 
86
-						if ( $item->allows_quantities() ) {
87
-							printf(
88
-								'<small class="d-sm-none text-muted form-text">%s</small>',
89
-								sprintf(
90
-									// translators: %s is the item quantity.
91
-									esc_html__( 'Qty %s', 'invoicing' ),
92
-									sprintf(
93
-										'<input
86
+                        if ( $item->allows_quantities() ) {
87
+                            printf(
88
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
89
+                                sprintf(
90
+                                    // translators: %s is the item quantity.
91
+                                    esc_html__( 'Qty %s', 'invoicing' ),
92
+                                    sprintf(
93
+                                        '<input
94 94
 												type="number"
95 95
 												step="0.01"
96 96
 												style="width: 48px;"
@@ -99,62 +99,62 @@  discard block
 block discarded – undo
99 99
 												min="1"
100 100
 												max="%s"
101 101
 												>',
102
-										(float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
103
-										floatval( null !== $max_qty ? $max_qty : 1000000000000 )
104
-									)
105
-								)
106
-							);
107
-						} else {
108
-							printf(
109
-								'<small class="d-sm-none text-muted form-text">%s</small>',
110
-								sprintf(
111
-									// translators: %s is the item quantity.
112
-									esc_html__( 'Qty %s', 'invoicing' ),
113
-									(float) $item->get_quantity()
114
-								)
115
-							);
116
-						}
117
-
118
-						if ( $has_featured_image ) {
119
-							echo '</div>';
120
-							echo '</div>';
121
-						}
122
-					}
123
-
124
-					// Item price.
125
-					if ( 'price' === $key ) {
126
-
127
-					// Set the currency position.
128
-					$position = wpinv_currency_position();
129
-
130
-					if ( 'left_space' === $position ) {
131
-						$position = 'left';
132
-					}
133
-
134
-					if ( 'right_space' === $position ) {
135
-						$position = 'right';
136
-					}
137
-
138
-					if ( $item->user_can_set_their_price() ) {
139
-						$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
140
-						$minimum          = (float) $item->get_minimum_price();
141
-						$validate_minimum = '';
142
-						$class            = '';
143
-						$data_minimum     = '';
144
-
145
-						if ( $minimum > 0 ) {
146
-							$validate_minimum = sprintf(
147
-								// translators: %s is the minimum price.
148
-								esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
149
-								wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
150
-							);
151
-
152
-							$class = 'getpaid-validate-minimum-amount';
153
-
154
-							$data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
155
-						}
156
-
157
-						?>
102
+                                        (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
103
+                                        floatval( null !== $max_qty ? $max_qty : 1000000000000 )
104
+                                    )
105
+                                )
106
+                            );
107
+                        } else {
108
+                            printf(
109
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
110
+                                sprintf(
111
+                                    // translators: %s is the item quantity.
112
+                                    esc_html__( 'Qty %s', 'invoicing' ),
113
+                                    (float) $item->get_quantity()
114
+                                )
115
+                            );
116
+                        }
117
+
118
+                        if ( $has_featured_image ) {
119
+                            echo '</div>';
120
+                            echo '</div>';
121
+                        }
122
+                    }
123
+
124
+                    // Item price.
125
+                    if ( 'price' === $key ) {
126
+
127
+                    // Set the currency position.
128
+                    $position = wpinv_currency_position();
129
+
130
+                    if ( 'left_space' === $position ) {
131
+                        $position = 'left';
132
+                    }
133
+
134
+                    if ( 'right_space' === $position ) {
135
+                        $position = 'right';
136
+                    }
137
+
138
+                    if ( $item->user_can_set_their_price() ) {
139
+                        $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
140
+                        $minimum          = (float) $item->get_minimum_price();
141
+                        $validate_minimum = '';
142
+                        $class            = '';
143
+                        $data_minimum     = '';
144
+
145
+                        if ( $minimum > 0 ) {
146
+                            $validate_minimum = sprintf(
147
+                                // translators: %s is the minimum price.
148
+                                esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
149
+                                wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
150
+                            );
151
+
152
+                            $class = 'getpaid-validate-minimum-amount';
153
+
154
+                            $data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
155
+                        }
156
+
157
+                        ?>
158 158
 								<div class="input-group input-group-sm">
159 159
 									<?php if ( 'left' === $position ) : ?>
160 160
 										<?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
@@ -195,44 +195,44 @@  discard block
 block discarded – undo
195 195
 
196 196
 							<?php
197 197
 
198
-						} else {
199
-						echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) );
198
+                        } else {
199
+                        echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) );
200 200
 
201
-						?>
201
+                        ?>
202 202
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
203 203
 						<?php
204
-						}
204
+                        }
205 205
 
206
-					printf(
206
+                    printf(
207 207
                         '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>',
208
-						// translators: %s is the item subtotal.
208
+                        // translators: %s is the item subtotal.
209 209
                         sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) )
210 210
                     );
211
-					}
211
+                    }
212 212
 
213
-					// Item quantity.
214
-					if ( 'quantity' === $key ) {
213
+                    // Item quantity.
214
+                    if ( 'quantity' === $key ) {
215 215
 
216
-					if ( $item->allows_quantities() ) {
217
-						?>
216
+                    if ( $item->allows_quantities() ) {
217
+                        ?>
218 218
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required>
219 219
 							<?php
220
-						} else {
221
-						echo (float) $item->get_quantity();
222
-						echo '&nbsp;&nbsp;&nbsp;';
223
-						?>
220
+                        } else {
221
+                        echo (float) $item->get_quantity();
222
+                        echo '&nbsp;&nbsp;&nbsp;';
223
+                        ?>
224 224
 								<input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'>
225 225
 						<?php
226
-						}
226
+                        }
227 227
 }
228 228
 
229
-					// Item sub total.
230
-					if ( 'subtotal' === $key ) {
231
-					echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
232
-					}
229
+                    // Item sub total.
230
+                    if ( 'subtotal' === $key ) {
231
+                    echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
232
+                    }
233 233
 
234
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
235
-				?>
234
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
235
+                ?>
236 236
 
237 237
 			</div>
238 238
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -13,464 +13,464 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a user's saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-
141
-		do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this );
142
-
143
-		// Register gateway.
144
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
145
-
146
-		$this->enabled = wpinv_is_gateway_active( $this->id );
147
-
148
-		// Add support for various features.
149
-		foreach ( $this->supports as $feature ) {
150
-			add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' );
151
-			add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' );
152
-			add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
153
-		}
154
-
155
-		// Invoice addons.
156
-		if ( $this->supports( 'addons' ) ) {
157
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
158
-		}
159
-
160
-		// Gateway settings.
161
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
162
-
163
-		// Gateway checkout fiellds.
164
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
165
-
166
-		// Process payment.
167
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
168
-
169
-		// Change the checkout button text.
170
-		if ( ! empty( $this->checkout_button_text ) ) {
171
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
172
-		}
173
-
174
-		// Check if a gateway is valid for a given currency.
175
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
176
-
177
-		// Generate the transaction url.
178
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
179
-
180
-		// Generate the subscription url.
181
-		add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
182
-
183
-		// Confirm payments.
184
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
185
-
186
-		// Verify IPNs.
187
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
188
-
189
-	}
190
-
191
-	/**
192
-	 * Checks if this gateway is a given gateway.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @return bool
196
-	 */
197
-	public function is( $gateway ) {
198
-		return $gateway == $this->id;
199
-	}
200
-
201
-	/**
202
-	 * Returns a users saved tokens for this gateway.
203
-	 *
204
-	 * @since 1.0.19
205
-	 * @return array
206
-	 */
207
-	public function get_tokens( $sandbox = null ) {
208
-
209
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
210
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
211
-
212
-			if ( is_array( $tokens ) ) {
213
-				$this->tokens = $tokens;
214
-			}
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a user's saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+
141
+        do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this );
142
+
143
+        // Register gateway.
144
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
145
+
146
+        $this->enabled = wpinv_is_gateway_active( $this->id );
147
+
148
+        // Add support for various features.
149
+        foreach ( $this->supports as $feature ) {
150
+            add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' );
151
+            add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' );
152
+            add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' );
153
+        }
154
+
155
+        // Invoice addons.
156
+        if ( $this->supports( 'addons' ) ) {
157
+            add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
158
+        }
159
+
160
+        // Gateway settings.
161
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
162
+
163
+        // Gateway checkout fiellds.
164
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
165
+
166
+        // Process payment.
167
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
168
+
169
+        // Change the checkout button text.
170
+        if ( ! empty( $this->checkout_button_text ) ) {
171
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
172
+        }
173
+
174
+        // Check if a gateway is valid for a given currency.
175
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
176
+
177
+        // Generate the transaction url.
178
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
179
+
180
+        // Generate the subscription url.
181
+        add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
182
+
183
+        // Confirm payments.
184
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
185
+
186
+        // Verify IPNs.
187
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
188
+
189
+    }
190
+
191
+    /**
192
+     * Checks if this gateway is a given gateway.
193
+     *
194
+     * @since 1.0.19
195
+     * @return bool
196
+     */
197
+    public function is( $gateway ) {
198
+        return $gateway == $this->id;
199
+    }
200
+
201
+    /**
202
+     * Returns a users saved tokens for this gateway.
203
+     *
204
+     * @since 1.0.19
205
+     * @return array
206
+     */
207
+    public function get_tokens( $sandbox = null ) {
208
+
209
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
210
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
211
+
212
+            if ( is_array( $tokens ) ) {
213
+                $this->tokens = $tokens;
214
+            }
215 215
 }
216 216
 
217
-		if ( ! is_bool( $sandbox ) ) {
218
-			return $this->tokens;
219
-		}
220
-
221
-		// Filter tokens.
222
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
223
-		return wp_list_filter( $this->tokens, $args );
224
-
225
-	}
226
-
227
-	/**
228
-	 * Saves a token for this gateway.
229
-	 *
230
-	 * @since 1.0.19
231
-	 */
232
-	public function save_token( $token ) {
233
-
234
-		$tokens   = $this->get_tokens();
235
-		$tokens[] = $token;
236
-
237
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
238
-
239
-		$this->tokens = $tokens;
240
-
241
-	}
242
-
243
-	/**
244
-	 * Return the title for admin screens.
245
-	 *
246
-	 * @return string
247
-	 */
248
-	public function get_method_title() {
249
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
250
-	}
251
-
252
-	/**
253
-	 * Return the description for admin screens.
254
-	 *
255
-	 * @return string
256
-	 */
257
-	public function get_method_description() {
258
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
259
-	}
260
-
261
-	/**
262
-	 * Get the success url.
263
-	 *
264
-	 * @param WPInv_Invoice $invoice Invoice object.
265
-	 * @return string
266
-	 */
267
-	public function get_return_url( $invoice ) {
268
-
269
-		// Payment success url
270
-		$return_url = add_query_arg(
271
-			array(
272
-				'payment-confirm' => $this->id,
273
-				'invoice_key'     => $invoice->get_key(),
274
-				'utm_nooverride'  => 1,
275
-			),
276
-			wpinv_get_success_page_uri()
277
-		);
278
-
279
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
280
-	}
281
-
282
-	/**
283
-	 * Confirms payments when rendering the success page.
284
-	 *
285
-	 * @param string $content Success page content.
286
-	 * @return string
287
-	 */
288
-	public function confirm_payment( $content ) {
289
-
290
-		// Retrieve the invoice.
291
-		$invoice_id = getpaid_get_current_invoice_id();
292
-		$invoice    = wpinv_get_invoice( $invoice_id );
293
-
294
-		// Ensure that it exists and that it is pending payment.
295
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
296
-			return $content;
297
-		}
298
-
299
-		// Can the user view this invoice??
300
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
301
-			return $content;
302
-		}
303
-
304
-		// Show payment processing indicator.
305
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
306
-	}
307
-
308
-	/**
309
-	 * Processes ipns and marks payments as complete.
310
-	 *
311
-	 * @return void
312
-	 */
313
-	public function verify_ipn() {}
314
-
315
-	/**
316
-	 * Processes invoice addons.
317
-	 *
318
-	 * @param WPInv_Invoice $invoice
319
-	 * @param GetPaid_Form_Item[] $items
320
-	 * @return WPInv_Invoice
321
-	 */
322
-	public function process_addons( $invoice, $items ) {
323
-
324
-	}
325
-
326
-	/**
327
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
328
-	 *
329
-	 * @param string $transaction_url transaction url.
330
-	 * @param WPInv_Invoice $invoice Invoice object.
331
-	 * @return string transaction URL, or empty string.
332
-	 */
333
-	public function filter_transaction_url( $transaction_url, $invoice ) {
334
-
335
-		$transaction_id  = $invoice->get_transaction_id();
336
-
337
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
338
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
339
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
340
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
341
-		}
342
-
343
-		return $transaction_url;
344
-	}
345
-
346
-	/**
347
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
348
-	 *
349
-	 * @param string $subscription_url transaction url.
350
-	 * @param WPInv_Subscription $subscription Subscription objectt.
351
-	 * @return string subscription URL, or empty string.
352
-	 */
353
-	public function generate_subscription_url( $subscription_url, $subscription ) {
354
-
355
-		$profile_id      = $subscription->get_profile_id();
356
-
357
-		if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
358
-
359
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
360
-			$replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
361
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
362
-
363
-		}
364
-
365
-		return $subscription_url;
366
-	}
367
-
368
-	/**
369
-	 * Check if the gateway is available for use.
370
-	 *
371
-	 * @return bool
372
-	 */
373
-	public function is_available() {
374
-		return ! empty( $this->enabled );
375
-	}
376
-
377
-	/**
378
-	 * Return the gateway's title.
379
-	 *
380
-	 * @return string
381
-	 */
382
-	public function get_title() {
383
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
384
-	}
385
-
386
-	/**
387
-	 * Return the gateway's description.
388
-	 *
389
-	 * @return string
390
-	 */
391
-	public function get_description() {
392
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
393
-	}
394
-
395
-	/**
396
-	 * Process Payment.
397
-	 *
398
-	 *
399
-	 * @param WPInv_Invoice $invoice Invoice.
400
-	 * @param array $submission_data Posted checkout fields.
401
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
402
-	 * @return void
403
-	 */
404
-	public function process_payment( $invoice, $submission_data, $submission ) {
405
-		// Process the payment then either redirect to the success page or the gateway.
406
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
407
-	}
408
-
409
-	/**
410
-	 * Process refund.
411
-	 *
412
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
413
-	 * a passed in amount.
414
-	 *
415
-	 * @param WPInv_Invoice $invoice Invoice.
416
-	 * @param  float  $amount Refund amount.
417
-	 * @param  string $reason Refund reason.
418
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
419
-	 */
420
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
421
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
422
-	}
423
-
424
-	/**
425
-	 * Displays the payment fields, credit cards etc.
426
-	 *
427
-	 * @param int $invoice_id 0 or invoice id.
428
-	 * @param GetPaid_Payment_Form $form Current payment form.
429
-	 */
430
-	public function payment_fields( $invoice_id, $form ) {
431
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
432
-	}
433
-
434
-	/**
435
-	 * Filters the gateway settings.
436
-	 *
437
-	 * @param array $admin_settings
438
-	 */
439
-	public function admin_settings( $admin_settings ) {
440
-		return $admin_settings;
441
-	}
442
-
443
-	/**
444
-	 * Retrieves the value of a gateway setting.
445
-	 *
446
-	 * @param string $option
447
-	 */
448
-	public function get_option( $option, $default = false ) {
449
-		return wpinv_get_option( $this->id . '_' . $option, $default );
450
-	}
451
-
452
-	/**
453
-	 * Check if a gateway supports a given feature.
454
-	 *
455
-	 * Gateways should override this to declare support (or lack of support) for a feature.
456
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
457
-	 *
458
-	 * @param string $feature string The name of a feature to test support for.
459
-	 * @return bool True if the gateway supports the feature, false otherwise.
460
-	 * @since 1.0.19
461
-	 */
462
-	public function supports( $feature ) {
463
-		return getpaid_payment_gateway_supports( $this->id, $feature );
464
-	}
465
-
466
-	/**
467
-	 * Returns the credit card form html.
468
-	 *
469
-	 * @param bool $save whether or not to display the save button.
470
-	 */
217
+        if ( ! is_bool( $sandbox ) ) {
218
+            return $this->tokens;
219
+        }
220
+
221
+        // Filter tokens.
222
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
223
+        return wp_list_filter( $this->tokens, $args );
224
+
225
+    }
226
+
227
+    /**
228
+     * Saves a token for this gateway.
229
+     *
230
+     * @since 1.0.19
231
+     */
232
+    public function save_token( $token ) {
233
+
234
+        $tokens   = $this->get_tokens();
235
+        $tokens[] = $token;
236
+
237
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
238
+
239
+        $this->tokens = $tokens;
240
+
241
+    }
242
+
243
+    /**
244
+     * Return the title for admin screens.
245
+     *
246
+     * @return string
247
+     */
248
+    public function get_method_title() {
249
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
250
+    }
251
+
252
+    /**
253
+     * Return the description for admin screens.
254
+     *
255
+     * @return string
256
+     */
257
+    public function get_method_description() {
258
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
259
+    }
260
+
261
+    /**
262
+     * Get the success url.
263
+     *
264
+     * @param WPInv_Invoice $invoice Invoice object.
265
+     * @return string
266
+     */
267
+    public function get_return_url( $invoice ) {
268
+
269
+        // Payment success url
270
+        $return_url = add_query_arg(
271
+            array(
272
+                'payment-confirm' => $this->id,
273
+                'invoice_key'     => $invoice->get_key(),
274
+                'utm_nooverride'  => 1,
275
+            ),
276
+            wpinv_get_success_page_uri()
277
+        );
278
+
279
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
280
+    }
281
+
282
+    /**
283
+     * Confirms payments when rendering the success page.
284
+     *
285
+     * @param string $content Success page content.
286
+     * @return string
287
+     */
288
+    public function confirm_payment( $content ) {
289
+
290
+        // Retrieve the invoice.
291
+        $invoice_id = getpaid_get_current_invoice_id();
292
+        $invoice    = wpinv_get_invoice( $invoice_id );
293
+
294
+        // Ensure that it exists and that it is pending payment.
295
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
296
+            return $content;
297
+        }
298
+
299
+        // Can the user view this invoice??
300
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
301
+            return $content;
302
+        }
303
+
304
+        // Show payment processing indicator.
305
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
306
+    }
307
+
308
+    /**
309
+     * Processes ipns and marks payments as complete.
310
+     *
311
+     * @return void
312
+     */
313
+    public function verify_ipn() {}
314
+
315
+    /**
316
+     * Processes invoice addons.
317
+     *
318
+     * @param WPInv_Invoice $invoice
319
+     * @param GetPaid_Form_Item[] $items
320
+     * @return WPInv_Invoice
321
+     */
322
+    public function process_addons( $invoice, $items ) {
323
+
324
+    }
325
+
326
+    /**
327
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
328
+     *
329
+     * @param string $transaction_url transaction url.
330
+     * @param WPInv_Invoice $invoice Invoice object.
331
+     * @return string transaction URL, or empty string.
332
+     */
333
+    public function filter_transaction_url( $transaction_url, $invoice ) {
334
+
335
+        $transaction_id  = $invoice->get_transaction_id();
336
+
337
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
338
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
339
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
340
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
341
+        }
342
+
343
+        return $transaction_url;
344
+    }
345
+
346
+    /**
347
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
348
+     *
349
+     * @param string $subscription_url transaction url.
350
+     * @param WPInv_Subscription $subscription Subscription objectt.
351
+     * @return string subscription URL, or empty string.
352
+     */
353
+    public function generate_subscription_url( $subscription_url, $subscription ) {
354
+
355
+        $profile_id      = $subscription->get_profile_id();
356
+
357
+        if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
358
+
359
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
360
+            $replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
361
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
362
+
363
+        }
364
+
365
+        return $subscription_url;
366
+    }
367
+
368
+    /**
369
+     * Check if the gateway is available for use.
370
+     *
371
+     * @return bool
372
+     */
373
+    public function is_available() {
374
+        return ! empty( $this->enabled );
375
+    }
376
+
377
+    /**
378
+     * Return the gateway's title.
379
+     *
380
+     * @return string
381
+     */
382
+    public function get_title() {
383
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
384
+    }
385
+
386
+    /**
387
+     * Return the gateway's description.
388
+     *
389
+     * @return string
390
+     */
391
+    public function get_description() {
392
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
393
+    }
394
+
395
+    /**
396
+     * Process Payment.
397
+     *
398
+     *
399
+     * @param WPInv_Invoice $invoice Invoice.
400
+     * @param array $submission_data Posted checkout fields.
401
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
402
+     * @return void
403
+     */
404
+    public function process_payment( $invoice, $submission_data, $submission ) {
405
+        // Process the payment then either redirect to the success page or the gateway.
406
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
407
+    }
408
+
409
+    /**
410
+     * Process refund.
411
+     *
412
+     * If the gateway declares 'refunds' support, this will allow it to refund.
413
+     * a passed in amount.
414
+     *
415
+     * @param WPInv_Invoice $invoice Invoice.
416
+     * @param  float  $amount Refund amount.
417
+     * @param  string $reason Refund reason.
418
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
419
+     */
420
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
421
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
422
+    }
423
+
424
+    /**
425
+     * Displays the payment fields, credit cards etc.
426
+     *
427
+     * @param int $invoice_id 0 or invoice id.
428
+     * @param GetPaid_Payment_Form $form Current payment form.
429
+     */
430
+    public function payment_fields( $invoice_id, $form ) {
431
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
432
+    }
433
+
434
+    /**
435
+     * Filters the gateway settings.
436
+     *
437
+     * @param array $admin_settings
438
+     */
439
+    public function admin_settings( $admin_settings ) {
440
+        return $admin_settings;
441
+    }
442
+
443
+    /**
444
+     * Retrieves the value of a gateway setting.
445
+     *
446
+     * @param string $option
447
+     */
448
+    public function get_option( $option, $default = false ) {
449
+        return wpinv_get_option( $this->id . '_' . $option, $default );
450
+    }
451
+
452
+    /**
453
+     * Check if a gateway supports a given feature.
454
+     *
455
+     * Gateways should override this to declare support (or lack of support) for a feature.
456
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
457
+     *
458
+     * @param string $feature string The name of a feature to test support for.
459
+     * @return bool True if the gateway supports the feature, false otherwise.
460
+     * @since 1.0.19
461
+     */
462
+    public function supports( $feature ) {
463
+        return getpaid_payment_gateway_supports( $this->id, $feature );
464
+    }
465
+
466
+    /**
467
+     * Returns the credit card form html.
468
+     *
469
+     * @param bool $save whether or not to display the save button.
470
+     */
471 471
     public function get_cc_form( $save = false ) {
472 472
 
473
-		ob_start();
473
+        ob_start();
474 474
 
475 475
         $id_prefix = esc_attr( uniqid( $this->id ) );
476 476
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
             '11' => __( 'November', 'invoicing' ),
489 489
             '12' => __( 'December', 'invoicing' ),
490 490
         );
491
-		$months = apply_filters( 'getpaid_cc_months', $months, $this );
491
+        $months = apply_filters( 'getpaid_cc_months', $months, $this );
492 492
 
493 493
         $year  = (int) current_time( 'Y' );
494 494
         $years = array();
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
             $years[ $year + $i ] = $year + $i;
498 498
         }
499 499
 
500
-		$years = apply_filters( 'getpaid_cc_years', $years, $this );
500
+        $years = apply_filters( 'getpaid_cc_years', $years, $this );
501 501
 
502 502
         ?>
503 503
             <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1">
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 
540 540
                                             <?php
541 541
                                                 foreach ( $months as $key => $month ) {
542
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>';
542
+                                                echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>';
543 543
                                                 }
544 544
                                             ?>
545 545
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 
553 553
                                             <?php
554 554
                                                 foreach ( $years as $key => $year ) {
555
-												echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>';
555
+                                                echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>';
556 556
                                                 }
557 557
                                             ?>
558 558
 
@@ -570,13 +570,13 @@  discard block
 block discarded – undo
570 570
                                         'name'             => $this->id . '[cc_cvv2]',
571 571
                                         'id'               => "$id_prefix-cc-cvv2",
572 572
                                         'label'            => __( 'CCV', 'invoicing' ),
573
-										'label_type'       => 'vertical',
574
-										'class'            => 'form-control-sm',
575
-										'extra_attributes' => array(
576
-											'autocomplete' => 'cc-csc',
577
-										),
573
+                                        'label_type'       => 'vertical',
574
+                                        'class'            => 'form-control-sm',
575
+                                        'extra_attributes' => array(
576
+                                            'autocomplete' => 'cc-csc',
577
+                                        ),
578 578
                                     ),
579
-									true
579
+                                    true
580 580
                                 );
581 581
                             ?>
582 582
                         </div>
@@ -585,192 +585,192 @@  discard block
 block discarded – undo
585 585
 
586 586
 					<?php
587 587
 
588
-						if ( $save ) {
589
-							$this->save_payment_method_checkbox();
590
-						}
588
+                        if ( $save ) {
589
+                            $this->save_payment_method_checkbox();
590
+                        }
591 591
 
592
-					?>
592
+                    ?>
593 593
                 </div>
594 594
 
595 595
             </div>
596 596
 		<?php
597 597
 
598
-		return ob_get_clean();
598
+        return ob_get_clean();
599
+
600
+    }
601
+
602
+    /**
603
+     * Displays a new payment method entry form.
604
+     *
605
+     * @since 1.0.19
606
+     */
607
+    public function new_payment_method_entry( $form ) {
608
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>';
609
+    }
610
+
611
+    /**
612
+     * Grab and display our saved payment methods.
613
+     *
614
+     * @since 1.0.19
615
+     */
616
+    public function saved_payment_methods() {
617
+        echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
618
+
619
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
620
+            $this->get_saved_payment_method_option_html( $token );
621
+        }
622
+
623
+        $this->get_new_payment_method_option_html();
624
+        echo '</ul>';
599 625
 
600 626
     }
601 627
 
602
-	/**
603
-	 * Displays a new payment method entry form.
604
-	 *
605
-	 * @since 1.0.19
606
-	 */
607
-	public function new_payment_method_entry( $form ) {
608
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>';
609
-	}
610
-
611
-	/**
612
-	 * Grab and display our saved payment methods.
613
-	 *
614
-	 * @since 1.0.19
615
-	 */
616
-	public function saved_payment_methods() {
617
-		echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
618
-
619
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
620
-			$this->get_saved_payment_method_option_html( $token );
621
-		}
622
-
623
-		$this->get_new_payment_method_option_html();
624
-		echo '</ul>';
625
-
626
-	}
627
-
628
-	/**
629
-	 * Gets saved payment method HTML from a token.
630
-	 *
631
-	 * @since 1.0.19
632
-	 * @param  array $token Payment Token.
633
-	 * @return string Generated payment method HTML
634
-	 */
635
-	public function get_saved_payment_method_option_html( $token ) {
636
-
637
-		printf(
638
-			'<li class="getpaid-payment-method form-group mb-3">
628
+    /**
629
+     * Gets saved payment method HTML from a token.
630
+     *
631
+     * @since 1.0.19
632
+     * @param  array $token Payment Token.
633
+     * @return string Generated payment method HTML
634
+     */
635
+    public function get_saved_payment_method_option_html( $token ) {
636
+
637
+        printf(
638
+            '<li class="getpaid-payment-method form-group mb-3">
639 639
 				<label>
640 640
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
641 641
 					<span>%3$s</span>
642 642
 				</label>
643 643
 			</li>',
644
-			esc_attr( $this->id ),
645
-			esc_attr( $token['id'] ),
646
-			esc_html( $token['name'] ),
647
-			checked( empty( $token['default'] ), false, false ),
648
-			empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] )
649
-		);
650
-
651
-	}
652
-
653
-	/**
654
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
655
-	 *
656
-	 * @since 1.0.19
657
-	 */
658
-	public function get_new_payment_method_option_html() {
659
-
660
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
661
-
662
-		printf(
663
-			'<li class="getpaid-new-payment-method">
644
+            esc_attr( $this->id ),
645
+            esc_attr( $token['id'] ),
646
+            esc_html( $token['name'] ),
647
+            checked( empty( $token['default'] ), false, false ),
648
+            empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] )
649
+        );
650
+
651
+    }
652
+
653
+    /**
654
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
655
+     *
656
+     * @since 1.0.19
657
+     */
658
+    public function get_new_payment_method_option_html() {
659
+
660
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
661
+
662
+        printf(
663
+            '<li class="getpaid-new-payment-method">
664 664
 				<label>
665 665
 					<input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" />
666 666
 					<span>%2$s</span>
667 667
 				</label>
668 668
 			</li>',
669
-			esc_attr( $this->id ),
670
-			esc_html( $label )
671
-		);
672
-
673
-	}
674
-
675
-	/**
676
-	 * Outputs a checkbox for saving a new payment method to the database.
677
-	 *
678
-	 * @since 1.0.19
679
-	 */
680
-	public function save_payment_method_checkbox() {
681
-
682
-		aui()->input(
683
-			array(
684
-				'type'       => 'checkbox',
685
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
686
-				'id'         => esc_attr( uniqid( $this->id ) ),
687
-				'required'   => false,
688
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
689
-				'value'      => 'true',
690
-				'checked'    => true,
691
-				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
692
-			),
693
-			true
694
-		);
695
-
696
-	}
697
-
698
-	/**
699
-	 * Registers the gateway.
700
-	 *
701
-	 * @return array
702
-	 */
703
-	public function register_gateway( $gateways ) {
704
-
705
-		$gateways[ $this->id ] = array(
706
-
707
-			'admin_label'    => $this->method_title,
669
+            esc_attr( $this->id ),
670
+            esc_html( $label )
671
+        );
672
+
673
+    }
674
+
675
+    /**
676
+     * Outputs a checkbox for saving a new payment method to the database.
677
+     *
678
+     * @since 1.0.19
679
+     */
680
+    public function save_payment_method_checkbox() {
681
+
682
+        aui()->input(
683
+            array(
684
+                'type'       => 'checkbox',
685
+                'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
686
+                'id'         => esc_attr( uniqid( $this->id ) ),
687
+                'required'   => false,
688
+                'label'      => esc_html__( 'Save payment method', 'invoicing' ),
689
+                'value'      => 'true',
690
+                'checked'    => true,
691
+                'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
692
+            ),
693
+            true
694
+        );
695
+
696
+    }
697
+
698
+    /**
699
+     * Registers the gateway.
700
+     *
701
+     * @return array
702
+     */
703
+    public function register_gateway( $gateways ) {
704
+
705
+        $gateways[ $this->id ] = array(
706
+
707
+            'admin_label'    => $this->method_title,
708 708
             'checkout_label' => $this->title,
709
-			'ordering'       => $this->order,
709
+            'ordering'       => $this->order,
710 710
 
711
-		);
711
+        );
712 712
 
713
-		return $gateways;
713
+        return $gateways;
714 714
 
715
-	}
715
+    }
716 716
 
717
-	/**
718
-	 * Checks whether or not this is a sandbox request.
719
-	 *
720
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
721
-	 * @return bool
722
-	 */
723
-	public function is_sandbox( $invoice = null ) {
717
+    /**
718
+     * Checks whether or not this is a sandbox request.
719
+     *
720
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
721
+     * @return bool
722
+     */
723
+    public function is_sandbox( $invoice = null ) {
724 724
 
725
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
726
-			return $invoice->get_mode() == 'test';
727
-		}
725
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
726
+            return $invoice->get_mode() == 'test';
727
+        }
728 728
 
729
-		return wpinv_is_test_mode( $this->id );
729
+        return wpinv_is_test_mode( $this->id );
730 730
 
731
-	}
731
+    }
732 732
 
733
-	/**
734
-	 * Renames the checkout button
735
-	 *
736
-	 * @return string
737
-	 */
738
-	public function rename_checkout_button() {
739
-		return $this->checkout_button_text;
740
-	}
733
+    /**
734
+     * Renames the checkout button
735
+     *
736
+     * @return string
737
+     */
738
+    public function rename_checkout_button() {
739
+        return $this->checkout_button_text;
740
+    }
741 741
 
742
-	/**
743
-	 * Validate gateway currency
744
-	 *
745
-	 * @return bool
746
-	 */
747
-	public function validate_currency( $validation, $currency ) {
742
+    /**
743
+     * Validate gateway currency
744
+     *
745
+     * @return bool
746
+     */
747
+    public function validate_currency( $validation, $currency ) {
748 748
 
749
-		// Required currencies.
750
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
751
-			return false;
752
-		}
749
+        // Required currencies.
750
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
751
+            return false;
752
+        }
753 753
 
754
-		// Excluded currencies.
755
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
756
-			return false;
757
-		}
754
+        // Excluded currencies.
755
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
756
+            return false;
757
+        }
758 758
 
759
-		return $validation;
760
-	}
759
+        return $validation;
760
+    }
761 761
 
762
-	/**
763
-	 * Displays an error
764
-	 *
765
-	 */
766
-	public function show_error( $code, $message, $type ) {
762
+    /**
763
+     * Displays an error
764
+     *
765
+     */
766
+    public function show_error( $code, $message, $type ) {
767 767
 
768
-		if ( is_admin() ) {
769
-			getpaid_admin()->{"show_$type"}( $message );
770
-		}
768
+        if ( is_admin() ) {
769
+            getpaid_admin()->{"show_$type"}( $message );
770
+        }
771 771
 
772
-		wpinv_set_error( $code, $message, $type );
772
+        wpinv_set_error( $code, $message, $type );
773 773
 
774
-	}
774
+    }
775 775
 
776 776
 }
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
  */
137 137
 function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
138 138
 
139
-	$invoice_statuses = array(
140
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
139
+    $invoice_statuses = array(
140
+        'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
141 141
         'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
142 142
         'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
143
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
144
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
145
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
143
+        'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
144
+        'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
145
+        'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
146 146
         'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
147 147
         'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
148 148
     );
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         $invoice = $invoice->get_post_type();
160 160
     }
161 161
 
162
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
162
+    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
163 163
 }
164 164
 
165 165
 /**
@@ -277,25 +277,25 @@  discard block
 block discarded – undo
277 277
  * @return string
278 278
  */
279 279
 function getpaid_get_price_format() {
280
-	$currency_pos = wpinv_currency_position();
281
-	$format       = '%1$s%2$s';
282
-
283
-	switch ( $currency_pos ) {
284
-		case 'left':
285
-			$format = '%1$s%2$s';
286
-			break;
287
-		case 'right':
288
-			$format = '%2$s%1$s';
289
-			break;
290
-		case 'left_space':
291
-			$format = '%1$s&nbsp;%2$s';
292
-			break;
293
-		case 'right_space':
294
-			$format = '%2$s&nbsp;%1$s';
295
-			break;
296
-	}
297
-
298
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
280
+    $currency_pos = wpinv_currency_position();
281
+    $format       = '%1$s%2$s';
282
+
283
+    switch ( $currency_pos ) {
284
+        case 'left':
285
+            $format = '%1$s%2$s';
286
+            break;
287
+        case 'right':
288
+            $format = '%2$s%1$s';
289
+            break;
290
+        case 'left_space':
291
+            $format = '%1$s&nbsp;%2$s';
292
+            break;
293
+        case 'right_space':
294
+            $format = '%2$s&nbsp;%1$s';
295
+            break;
296
+    }
297
+
298
+    return apply_filters( 'getpaid_price_format', $format, $currency_pos );
299 299
 }
300 300
 
301 301
 /**
@@ -401,13 +401,13 @@  discard block
 block discarded – undo
401 401
  * @param mixed  $value Value.
402 402
  */
403 403
 function getpaid_maybe_define_constant( $name, $value ) {
404
-	if ( ! defined( $name ) ) {
405
-		define( $name, $value );
406
-	}
404
+    if ( ! defined( $name ) ) {
405
+        define( $name, $value );
406
+    }
407 407
 }
408 408
 
409 409
 function wpinv_get_php_arg_separator_output() {
410
-	return ini_get( 'arg_separator.output' );
410
+    return ini_get( 'arg_separator.output' );
411 411
 }
412 412
 
413 413
 function wpinv_rgb_from_hex( $color ) {
@@ -718,16 +718,16 @@  discard block
 block discarded – undo
718 718
     return wp_kses(
719 719
         html_entity_decode( $var ),
720 720
         array(
721
-			'br'     => array(),
722
-			'em'     => array(),
723
-			'strong' => array(),
724
-			'b'      => array(),
725
-			'small'  => array(),
726
-			'span'   => array(),
727
-			'ul'     => array(),
728
-			'li'     => array(),
729
-			'ol'     => array(),
730
-			'p'      => array(),
721
+            'br'     => array(),
722
+            'em'     => array(),
723
+            'strong' => array(),
724
+            'b'      => array(),
725
+            'small'  => array(),
726
+            'span'   => array(),
727
+            'ul'     => array(),
728
+            'li'     => array(),
729
+            'ol'     => array(),
730
+            'p'      => array(),
731 731
         )
732 732
     );
733 733
 }
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
         $list = array();
779 779
     }
780 780
 
781
-	if ( ! is_array( $list ) ) {
782
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
783
-	}
781
+    if ( ! is_array( $list ) ) {
782
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
783
+    }
784 784
 
785
-	return $list;
785
+    return $list;
786 786
 }
787 787
 
788 788
 /**
@@ -823,17 +823,17 @@  discard block
 block discarded – undo
823 823
  */
824 824
 function wpinv_clean( $var ) {
825 825
 
826
-	if ( is_array( $var ) ) {
827
-		return array_map( 'wpinv_clean', $var );
826
+    if ( is_array( $var ) ) {
827
+        return array_map( 'wpinv_clean', $var );
828 828
     }
829 829
 
830 830
     if ( is_object( $var ) ) {
831
-		$object_vars = get_object_vars( $var );
832
-		foreach ( $object_vars as $property_name => $property_value ) {
833
-			$var->$property_name = wpinv_clean( $property_value );
831
+        $object_vars = get_object_vars( $var );
832
+        foreach ( $object_vars as $property_name => $property_value ) {
833
+            $var->$property_name = wpinv_clean( $property_value );
834 834
         }
835 835
         return $var;
836
-	}
836
+    }
837 837
 
838 838
     return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var;
839 839
 }
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
  */
847 847
 function getpaid_convert_price_string_to_options( $str ) {
848 848
 
849
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
849
+    $raw_options = array_map( 'trim', explode( ',', $str ) );
850 850
     $options     = array();
851 851
 
852 852
     foreach ( $raw_options as $option ) {
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
  * @return string
936 936
  */
937 937
 function getpaid_date_format() {
938
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
938
+    return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
939 939
 }
940 940
 
941 941
 /**
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
  * @return string
945 945
  */
946 946
 function getpaid_time_format() {
947
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
947
+    return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
948 948
 }
949 949
 
950 950
 /**
@@ -957,15 +957,15 @@  discard block
 block discarded – undo
957 957
 function getpaid_limit_length( $string, $limit ) {
958 958
     $str_limit = $limit - 3;
959 959
 
960
-	if ( function_exists( 'mb_strimwidth' ) ) {
961
-		if ( mb_strlen( $string ) > $limit ) {
962
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
963
-		}
964
-	} else {
965
-		if ( strlen( $string ) > $limit ) {
966
-			$string = substr( $string, 0, $str_limit ) . '...';
967
-		}
968
-	}
960
+    if ( function_exists( 'mb_strimwidth' ) ) {
961
+        if ( mb_strlen( $string ) > $limit ) {
962
+            $string = mb_strimwidth( $string, 0, $str_limit ) . '...';
963
+        }
964
+    } else {
965
+        if ( strlen( $string ) > $limit ) {
966
+            $string = substr( $string, 0, $str_limit ) . '...';
967
+        }
968
+    }
969 969
     return $string;
970 970
 
971 971
 }
@@ -1095,12 +1095,12 @@  discard block
 block discarded – undo
1095 1095
     $types = get_allowed_mime_types();
1096 1096
 
1097 1097
     if ( isset( $types['htm|html'] ) ) {
1098
-		unset( $types['htm|html'] );
1099
-	}
1098
+        unset( $types['htm|html'] );
1099
+    }
1100 1100
 
1101 1101
     if ( isset( $types['js'] ) ) {
1102
-		unset( $types['js'] );
1103
-	}
1102
+        unset( $types['js'] );
1103
+    }
1104 1104
 
1105 1105
     return $types;
1106 1106
 
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -12,491 +12,491 @@
 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
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
-	}
167
-
168
-	/**
169
-	 * Helper function to send an email.
170
-	 *
171
-	 * @param WPInv_Invoice $invoice
172
-	 * @param GetPaid_Notification_Email $email
173
-	 * @param string $type
174
-	 * @param string|array $recipients
175
-	 * @param array $extra_args Extra template args.
176
-	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
-
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
-
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
-			return;
184
-		}
185
-
186
-		$mailer     = new GetPaid_Notification_Email_Sender();
187
-		$merge_tags = $email->get_merge_tags();
188
-
189
-		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
193
-			$email->get_attachments()
194
-		);
195
-
196
-		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
198
-			$mailer->send(
199
-				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
202
-				$email->get_attachments()
203
-			);
204
-		}
205
-
206
-		if ( $result ) {
207
-			$invoice->add_system_note(
208
-				sprintf(
209
-					// translators: %1 is the email type, %2 is the invoice recipient.
210
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
-					sanitize_key( $type ),
212
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
-				)
214
-			);
215
-		} else {
216
-			$invoice->add_system_note(
217
-				sprintf(
218
-					// translators: %1 is the email type, %2 is the invoice recipient.
219
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
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
-		return $recipients;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Sends a new invoice notification.
260
-	 *
261
-	 * @param WPInv_Invoice $invoice
262
-	 */
263
-	public function new_invoice( $invoice ) {
264
-
265
-		// Only send this email for invoices created via the admin page.
266
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
-			return;
268
-		}
269
-
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
-		$recipient = wpinv_get_admin_email();
272
-
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
-
275
-	}
276
-
277
-	/**
278
-	 * Sends a cancelled invoice notification.
279
-	 *
280
-	 * @param WPInv_Invoice $invoice
281
-	 */
282
-	public function cancelled_invoice( $invoice ) {
283
-
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
-		$recipient = $invoice->get_email();
286
-
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
-	}
289
-
290
-	/**
291
-	 * Sends a failed invoice notification.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice
294
-	 */
295
-	public function failed_invoice( $invoice ) {
296
-
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
-		$recipient = wpinv_get_admin_email();
299
-
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
-
302
-	}
303
-
304
-	/**
305
-	 * Sends a notification whenever an invoice is put on hold.
306
-	 *
307
-	 * @param WPInv_Invoice $invoice
308
-	 */
309
-	public function onhold_invoice( $invoice ) {
310
-
311
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
-		$recipient = $invoice->get_email();
313
-
314
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
-
316
-	}
317
-
318
-	/**
319
-	 * Sends a notification whenever an invoice is marked as processing payment.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 */
323
-	public function processing_invoice( $invoice ) {
324
-
325
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
-		$recipient = $invoice->get_email();
327
-
328
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
-
330
-	}
331
-
332
-	/**
333
-	 * Sends a notification whenever an invoice is paid.
334
-	 *
335
-	 * @param WPInv_Invoice $invoice
336
-	 */
337
-	public function completed_invoice( $invoice ) {
338
-
339
-		// (Maybe) abort if it is a renewal invoice.
340
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
-			return;
342
-		}
343
-
344
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
-		$recipient = $invoice->get_email();
346
-
347
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
-
349
-	}
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
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+    }
350 167
 
351
-	/**
352
-	 * Sends a notification whenever an invoice is refunded.
353
-	 *
354
-	 * @param WPInv_Invoice $invoice
355
-	 */
356
-	public function refunded_invoice( $invoice ) {
357
-
358
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
-		$recipient = $invoice->get_email();
360
-
361
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
-
363
-	}
168
+    /**
169
+     * Helper function to send an email.
170
+     *
171
+     * @param WPInv_Invoice $invoice
172
+     * @param GetPaid_Notification_Email $email
173
+     * @param string $type
174
+     * @param string|array $recipients
175
+     * @param array $extra_args Extra template args.
176
+     */
177
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
364 178
 
365
-	/**
366
-	 * Notifies a user about new invoices
367
-	 *
368
-	 * @param WPInv_Invoice $invoice
369
-	 * @param bool $force
370
-	 */
371
-	public function user_invoice( $invoice, $force = false ) {
179
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
372 180
 
373
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
-			return;
375
-		}
376
-
377
-		// Only send this email for invoices created via the admin page.
378
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
-			return;
380
-		}
381
-
382
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
-		$recipient = $invoice->get_email();
384
-
385
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
-
387
-	}
388
-
389
-	/**
390
-	 * Checks if an invoice is a payment form invoice.
391
-	 *
392
-	 * @param int $invoice
393
-	 * @return bool
394
-	 */
395
-	public function is_payment_form_invoice( $invoice ) {
396
-		$created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
397
-		$is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
398
-		$is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
-		return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
400
-	}
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();
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
181
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
+            return;
184
+        }
185
+
186
+        $mailer     = new GetPaid_Notification_Email_Sender();
187
+        $merge_tags = $email->get_merge_tags();
188
+
189
+        $result = $mailer->send(
190
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
+            $email->get_content( $merge_tags, $extra_args ),
193
+            $email->get_attachments()
194
+        );
195
+
196
+        // Maybe send a copy to the admin.
197
+        if ( $email->include_admin_bcc() ) {
198
+            $mailer->send(
199
+                wpinv_get_admin_email(),
200
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
+                $email->get_content( $merge_tags ),
202
+                $email->get_attachments()
203
+            );
204
+        }
205
+
206
+        if ( $result ) {
207
+            $invoice->add_system_note(
208
+                sprintf(
209
+                    // translators: %1 is the email type, %2 is the invoice recipient.
210
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
+                    sanitize_key( $type ),
212
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
+                )
214
+            );
215
+        } else {
216
+            $invoice->add_system_note(
217
+                sprintf(
218
+                    // translators: %1 is the email type, %2 is the invoice recipient.
219
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
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
+        return $recipients;
255
+
256
+    }
257
+
258
+    /**
259
+     * Sends a new invoice notification.
260
+     *
261
+     * @param WPInv_Invoice $invoice
262
+     */
263
+    public function new_invoice( $invoice ) {
264
+
265
+        // Only send this email for invoices created via the admin page.
266
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
+            return;
268
+        }
269
+
270
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+        $recipient = wpinv_get_admin_email();
272
+
273
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+
275
+    }
276
+
277
+    /**
278
+     * Sends a cancelled invoice notification.
279
+     *
280
+     * @param WPInv_Invoice $invoice
281
+     */
282
+    public function cancelled_invoice( $invoice ) {
283
+
284
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+        $recipient = $invoice->get_email();
286
+
287
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+    }
289
+
290
+    /**
291
+     * Sends a failed invoice notification.
292
+     *
293
+     * @param WPInv_Invoice $invoice
294
+     */
295
+    public function failed_invoice( $invoice ) {
296
+
297
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+        $recipient = wpinv_get_admin_email();
299
+
300
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+
302
+    }
303
+
304
+    /**
305
+     * Sends a notification whenever an invoice is put on hold.
306
+     *
307
+     * @param WPInv_Invoice $invoice
308
+     */
309
+    public function onhold_invoice( $invoice ) {
310
+
311
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+        $recipient = $invoice->get_email();
313
+
314
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+
316
+    }
317
+
318
+    /**
319
+     * Sends a notification whenever an invoice is marked as processing payment.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     */
323
+    public function processing_invoice( $invoice ) {
324
+
325
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
+        $recipient = $invoice->get_email();
327
+
328
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
+
330
+    }
331
+
332
+    /**
333
+     * Sends a notification whenever an invoice is paid.
334
+     *
335
+     * @param WPInv_Invoice $invoice
336
+     */
337
+    public function completed_invoice( $invoice ) {
338
+
339
+        // (Maybe) abort if it is a renewal invoice.
340
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
+            return;
342
+        }
343
+
344
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
+        $recipient = $invoice->get_email();
346
+
347
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
+
349
+    }
350
+
351
+    /**
352
+     * Sends a notification whenever an invoice is refunded.
353
+     *
354
+     * @param WPInv_Invoice $invoice
355
+     */
356
+    public function refunded_invoice( $invoice ) {
357
+
358
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
+        $recipient = $invoice->get_email();
360
+
361
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
+
363
+    }
364
+
365
+    /**
366
+     * Notifies a user about new invoices
367
+     *
368
+     * @param WPInv_Invoice $invoice
369
+     * @param bool $force
370
+     */
371
+    public function user_invoice( $invoice, $force = false ) {
372
+
373
+        if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
+            return;
375
+        }
376
+
377
+        // Only send this email for invoices created via the admin page.
378
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
+            return;
380
+        }
381
+
382
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
+        $recipient = $invoice->get_email();
384
+
385
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
+
387
+    }
388
+
389
+    /**
390
+     * Checks if an invoice is a payment form invoice.
391
+     *
392
+     * @param int $invoice
393
+     * @return bool
394
+     */
395
+    public function is_payment_form_invoice( $invoice ) {
396
+        $created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
397
+        $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
398
+        $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
+        return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
400
+    }
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();
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
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 457
 
458
-		foreach ( $invoices as $invoice ) {
458
+        foreach ( $invoices as $invoice ) {
459 459
 
460
-			// Only send this email for invoices created via the admin page.
461
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
462
-				$invoice       = new WPInv_Invoice( $invoice );
463
-				$email->object = $invoice;
460
+            // Only send this email for invoices created via the admin page.
461
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
462
+                $invoice       = new WPInv_Invoice( $invoice );
463
+                $email->object = $invoice;
464 464
 
465
-				if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) {
466
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
467
-				}
468
-			}
469
-		}
465
+                if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) {
466
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
467
+                }
468
+            }
469
+        }
470 470
 
471
-	}
471
+    }
472 472
 
473
-	/**
474
-	 * Calculates the date query for an invoices query
475
-	 *
476
-	 * @param array $reminder_days
477
-	 * @return string
478
-	 */
479
-	public function get_date_query( $reminder_days ) {
473
+    /**
474
+     * Calculates the date query for an invoices query
475
+     *
476
+     * @param array $reminder_days
477
+     * @return string
478
+     */
479
+    public function get_date_query( $reminder_days ) {
480 480
 
481
-		$date_query = array(
482
-			'relation' => 'OR',
483
-		);
481
+        $date_query = array(
482
+            'relation' => 'OR',
483
+        );
484 484
 
485
-		foreach ( $reminder_days as $days ) {
486
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
485
+        foreach ( $reminder_days as $days ) {
486
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
487 487
 
488
-			$date_query[] = array(
489
-				'year'  => $date['year'],
490
-				'month' => $date['month'],
491
-				'day'   => $date['day'],
492
-			);
488
+            $date_query[] = array(
489
+                'year'  => $date['year'],
490
+                'month' => $date['month'],
491
+                'day'   => $date['day'],
492
+            );
493 493
 
494
-		}
494
+        }
495 495
 
496
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
496
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497 497
 
498
-		return $date_query->get_sql();
498
+        return $date_query->get_sql();
499 499
 
500
-	}
500
+    }
501 501
 
502 502
 }
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Indentation   +1039 added lines, -1039 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => '',
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => '',
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
+            $this->set_id( $subscription_id );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id',
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id',
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,34 +141,34 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
-	}
158
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
+    }
163 163
 
164
-	/**
164
+    /**
165 165
      * Checks if a subscription key is set.
166 166
      */
167 167
     public function _isset( $key ) {
168 168
         return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
169
-	}
169
+    }
170 170
 
171
-	/*
171
+    /*
172 172
 	|--------------------------------------------------------------------------
173 173
 	| CRUD methods
174 174
 	|--------------------------------------------------------------------------
@@ -177,544 +177,544 @@  discard block
 block discarded – undo
177 177
 	|
178 178
     */
179 179
 
180
-	/*
180
+    /*
181 181
 	|--------------------------------------------------------------------------
182 182
 	| Getters
183 183
 	|--------------------------------------------------------------------------
184 184
 	*/
185 185
 
186
-	/**
187
-	 * Get customer id.
188
-	 *
189
-	 * @since 1.0.19
190
-	 * @param  string $context View or edit context.
191
-	 * @return int
192
-	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
195
-	}
196
-
197
-	/**
198
-	 * Get customer information.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @param  string $context View or edit context.
202
-	 * @return WP_User|false WP_User object on success, false on failure.
203
-	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
206
-	}
207
-
208
-	/**
209
-	 * Get parent invoice id.
210
-	 *
211
-	 * @since 1.0.19
212
-	 * @param  string $context View or edit context.
213
-	 * @return int
214
-	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
217
-	}
218
-
219
-	/**
220
-	 * Alias for self::get_parent_invoice_id().
221
-	 *
222
-	 * @since 1.0.19
223
-	 * @param  string $context View or edit context.
224
-	 * @return int
225
-	 */
186
+    /**
187
+     * Get customer id.
188
+     *
189
+     * @since 1.0.19
190
+     * @param  string $context View or edit context.
191
+     * @return int
192
+     */
193
+    public function get_customer_id( $context = 'view' ) {
194
+        return (int) $this->get_prop( 'customer_id', $context );
195
+    }
196
+
197
+    /**
198
+     * Get customer information.
199
+     *
200
+     * @since 1.0.19
201
+     * @param  string $context View or edit context.
202
+     * @return WP_User|false WP_User object on success, false on failure.
203
+     */
204
+    public function get_customer( $context = 'view' ) {
205
+        return get_userdata( $this->get_customer_id( $context ) );
206
+    }
207
+
208
+    /**
209
+     * Get parent invoice id.
210
+     *
211
+     * @since 1.0.19
212
+     * @param  string $context View or edit context.
213
+     * @return int
214
+     */
215
+    public function get_parent_invoice_id( $context = 'view' ) {
216
+        return (int) $this->get_prop( 'parent_payment_id', $context );
217
+    }
218
+
219
+    /**
220
+     * Alias for self::get_parent_invoice_id().
221
+     *
222
+     * @since 1.0.19
223
+     * @param  string $context View or edit context.
224
+     * @return int
225
+     */
226 226
     public function get_parent_payment_id( $context = 'view' ) {
227 227
         return $this->get_parent_invoice_id( $context );
228
-	}
228
+    }
229
+
230
+    /**
231
+     * Alias for self::get_parent_invoice_id().
232
+     *
233
+     * @since  1.0.0
234
+     * @return int
235
+     */
236
+    public function get_original_payment_id( $context = 'view' ) {
237
+        return $this->get_parent_invoice_id( $context );
238
+    }
239
+
240
+    /**
241
+     * Get parent invoice.
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return WPInv_Invoice
246
+     */
247
+    public function get_parent_invoice( $context = 'view' ) {
248
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
+    }
250
+
251
+    /**
252
+     * Alias for self::get_parent_invoice().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return WPInv_Invoice
257
+     */
258
+    public function get_parent_payment( $context = 'view' ) {
259
+        return $this->get_parent_invoice( $context );
260
+    }
261
+
262
+    /**
263
+     * Get subscription's product id.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return int
268
+     */
269
+    public function get_product_id( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'product_id', $context );
271
+    }
272
+
273
+    /**
274
+     * Get the subscription product.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return WPInv_Item
279
+     */
280
+    public function get_product( $context = 'view' ) {
281
+        return new WPInv_Item( $this->get_product_id( $context ) );
282
+    }
283
+
284
+    /**
285
+     * Get parent invoice's gateway.
286
+     *
287
+     * Here for backwards compatibility.
288
+     *
289
+     * @since 1.0.19
290
+     * @param  string $context View or edit context.
291
+     * @return string
292
+     */
293
+    public function get_gateway( $context = 'view' ) {
294
+        return $this->get_parent_invoice( $context )->get_gateway();
295
+    }
296
+
297
+    /**
298
+     * Get the period of a renewal.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_period( $context = 'view' ) {
305
+        return $this->get_prop( 'period', $context );
306
+    }
307
+
308
+    /**
309
+     * Get number of periods each renewal is valid for.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return int
314
+     */
315
+    public function get_frequency( $context = 'view' ) {
316
+        return (int) $this->get_prop( 'frequency', $context );
317
+    }
318
+
319
+    /**
320
+     * Get the initial amount for the subscription.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return float
325
+     */
326
+    public function get_initial_amount( $context = 'view' ) {
327
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
+    }
329
+
330
+    /**
331
+     * Get the recurring amount for the subscription.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return float
336
+     */
337
+    public function get_recurring_amount( $context = 'view' ) {
338
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
+    }
340
+
341
+    /**
342
+     * Get number of times that this subscription can be renewed.
343
+     *
344
+     * @since 1.0.19
345
+     * @param  string $context View or edit context.
346
+     * @return int
347
+     */
348
+    public function get_bill_times( $context = 'view' ) {
349
+        return (int) $this->get_prop( 'bill_times', $context );
350
+    }
351
+
352
+    /**
353
+     * Get transaction id of this subscription's parent invoice.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  string $context View or edit context.
357
+     * @return string
358
+     */
359
+    public function get_transaction_id( $context = 'view' ) {
360
+        return $this->get_prop( 'transaction_id', $context );
361
+    }
362
+
363
+    /**
364
+     * Get the date that the subscription was created.
365
+     *
366
+     * @since 1.0.19
367
+     * @param  string $context View or edit context.
368
+     * @return string
369
+     */
370
+    public function get_created( $context = 'view' ) {
371
+        return $this->get_prop( 'created', $context );
372
+    }
373
+
374
+    /**
375
+     * Alias for self::get_created().
376
+     *
377
+     * @since 1.0.19
378
+     * @param  string $context View or edit context.
379
+     * @return string
380
+     */
381
+    public function get_date_created( $context = 'view' ) {
382
+        return $this->get_created( $context );
383
+    }
384
+
385
+    /**
386
+     * Retrieves the creation date in a timestamp
387
+     *
388
+     * @since  1.0.0
389
+     * @return int
390
+     */
391
+    public function get_time_created() {
392
+        $created = $this->get_date_created();
393
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
+    }
395
+
396
+    /**
397
+     * Get GMT date when the subscription was created.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  string $context View or edit context.
401
+     * @return string
402
+     */
403
+    public function get_date_created_gmt( $context = 'view' ) {
404
+        $date = $this->get_date_created( $context );
405
+
406
+        if ( $date ) {
407
+            $date = get_gmt_from_date( $date );
408
+        }
409
+        return $date;
410
+    }
411
+
412
+    /**
413
+     * Get the date that the subscription will renew.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return string
418
+     */
419
+    public function get_next_renewal_date( $context = 'view' ) {
420
+        return $this->get_prop( 'expiration', $context );
421
+    }
422
+
423
+    /**
424
+     * Alias for self::get_next_renewal_date().
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return string
429
+     */
430
+    public function get_expiration( $context = 'view' ) {
431
+        return $this->get_next_renewal_date( $context );
432
+    }
433
+
434
+    /**
435
+     * Retrieves the expiration date in a timestamp
436
+     *
437
+     * @since  1.0.0
438
+     * @return int
439
+     */
440
+    public function get_expiration_time() {
441
+        $expiration = $this->get_expiration();
442
+
443
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
+            return current_time( 'timestamp' );
445
+        }
446
+
447
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
+    }
450
+
451
+    /**
452
+     * Get GMT date when the subscription will renew.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
459
+        $date = $this->get_next_renewal_date( $context );
460
+
461
+        if ( $date ) {
462
+            $date = get_gmt_from_date( $date );
463
+        }
464
+        return $date;
465
+    }
466
+
467
+    /**
468
+     * Get the subscription's trial period.
469
+     *
470
+     * @since 1.0.19
471
+     * @param  string $context View or edit context.
472
+     * @return string
473
+     */
474
+    public function get_trial_period( $context = 'view' ) {
475
+        return $this->get_prop( 'trial_period', $context );
476
+    }
477
+
478
+    /**
479
+     * Get the subscription's status.
480
+     *
481
+     * @since 1.0.19
482
+     * @param  string $context View or edit context.
483
+     * @return string
484
+     */
485
+    public function get_status( $context = 'view' ) {
486
+        return $this->get_prop( 'status', $context );
487
+    }
488
+
489
+    /**
490
+     * Get the subscription's profile id.
491
+     *
492
+     * @since 1.0.19
493
+     * @param  string $context View or edit context.
494
+     * @return string
495
+     */
496
+    public function get_profile_id( $context = 'view' ) {
497
+        return $this->get_prop( 'profile_id', $context );
498
+    }
499
+
500
+    /*
501
+	|--------------------------------------------------------------------------
502
+	| Setters
503
+	|--------------------------------------------------------------------------
504
+	*/
505
+
506
+    /**
507
+     * Set customer id.
508
+     *
509
+     * @since 1.0.19
510
+     * @param  int $value The customer's id.
511
+     */
512
+    public function set_customer_id( $value ) {
513
+        $this->set_prop( 'customer_id', (int) $value );
514
+    }
515
+
516
+    /**
517
+     * Set parent invoice id.
518
+     *
519
+     * @since 1.0.19
520
+     * @param  int $value The parent invoice id.
521
+     */
522
+    public function set_parent_invoice_id( $value ) {
523
+        $this->set_prop( 'parent_payment_id', (int) $value );
524
+    }
525
+
526
+    /**
527
+     * Alias for self::set_parent_invoice_id().
528
+     *
529
+     * @since 1.0.19
530
+     * @param  int $value The parent invoice id.
531
+     */
532
+    public function set_parent_payment_id( $value ) {
533
+        $this->set_parent_invoice_id( $value );
534
+    }
535
+
536
+    /**
537
+     * Alias for self::set_parent_invoice_id().
538
+     *
539
+     * @since 1.0.19
540
+     * @param  int $value The parent invoice id.
541
+     */
542
+    public function set_original_payment_id( $value ) {
543
+        $this->set_parent_invoice_id( $value );
544
+    }
545
+
546
+    /**
547
+     * Set subscription's product id.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  int $value The subscription product id.
551
+     */
552
+    public function set_product_id( $value ) {
553
+        $this->set_prop( 'product_id', (int) $value );
554
+    }
555
+
556
+    /**
557
+     * Set the period of a renewal.
558
+     *
559
+     * @since 1.0.19
560
+     * @param  string $value The renewal period.
561
+     */
562
+    public function set_period( $value ) {
563
+        $this->set_prop( 'period', $value );
564
+    }
565
+
566
+    /**
567
+     * Set number of periods each renewal is valid for.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  int $value The subscription frequency.
571
+     */
572
+    public function set_frequency( $value ) {
573
+        $value = empty( $value ) ? 1 : (int) $value;
574
+        $this->set_prop( 'frequency', absint( $value ) );
575
+    }
576
+
577
+    /**
578
+     * Set the initial amount for the subscription.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  float $value The initial subcription amount.
582
+     */
583
+    public function set_initial_amount( $value ) {
584
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
+    }
586
+
587
+    /**
588
+     * Set the recurring amount for the subscription.
589
+     *
590
+     * @since 1.0.19
591
+     * @param  float $value The recurring subcription amount.
592
+     */
593
+    public function set_recurring_amount( $value ) {
594
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
+    }
596
+
597
+    /**
598
+     * Set number of times that this subscription can be renewed.
599
+     *
600
+     * @since 1.0.19
601
+     * @param  int $value Bill times.
602
+     */
603
+    public function set_bill_times( $value ) {
604
+        $this->set_prop( 'bill_times', (int) $value );
605
+    }
606
+
607
+    /**
608
+     * Get transaction id of this subscription's parent invoice.
609
+     *
610
+     * @since 1.0.19
611
+     * @param string $value Bill times.
612
+     */
613
+    public function set_transaction_id( $value ) {
614
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
+    }
616
+
617
+    /**
618
+     * Set date when this subscription started.
619
+     *
620
+     * @since 1.0.19
621
+     * @param string $value strtotime compliant date.
622
+     */
623
+    public function set_created( $value ) {
624
+        $date = strtotime( $value );
625
+
626
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
+            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
628
+            return;
629
+        }
630
+
631
+        $this->set_prop( 'created', '' );
229 632
 
230
-	/**
231
-     * Alias for self::get_parent_invoice_id().
633
+    }
634
+
635
+    /**
636
+     * Alias for self::set_created().
232 637
      *
233
-     * @since  1.0.0
234
-     * @return int
638
+     * @since 1.0.19
639
+     * @param string $value strtotime compliant date.
235 640
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
641
+    public function set_date_created( $value ) {
642
+        $this->set_created( $value );
238 643
     }
239 644
 
240
-	/**
241
-	 * Get parent invoice.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return WPInv_Invoice
246
-	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
-	}
250
-
251
-	/**
252
-	 * Alias for self::get_parent_invoice().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return WPInv_Invoice
257
-	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
260
-	}
261
-
262
-	/**
263
-	 * Get subscription's product id.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return int
268
-	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
271
-	}
272
-
273
-	/**
274
-	 * Get the subscription product.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return WPInv_Item
279
-	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
282
-	}
283
-
284
-	/**
285
-	 * Get parent invoice's gateway.
286
-	 *
287
-	 * Here for backwards compatibility.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @param  string $context View or edit context.
291
-	 * @return string
292
-	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
295
-	}
296
-
297
-	/**
298
-	 * Get the period of a renewal.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
306
-	}
307
-
308
-	/**
309
-	 * Get number of periods each renewal is valid for.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return int
314
-	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
317
-	}
318
-
319
-	/**
320
-	 * Get the initial amount for the subscription.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return float
325
-	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
-	}
329
-
330
-	/**
331
-	 * Get the recurring amount for the subscription.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return float
336
-	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
-	}
340
-
341
-	/**
342
-	 * Get number of times that this subscription can be renewed.
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  string $context View or edit context.
346
-	 * @return int
347
-	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
350
-	}
351
-
352
-	/**
353
-	 * Get transaction id of this subscription's parent invoice.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  string $context View or edit context.
357
-	 * @return string
358
-	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
361
-	}
362
-
363
-	/**
364
-	 * Get the date that the subscription was created.
365
-	 *
366
-	 * @since 1.0.19
367
-	 * @param  string $context View or edit context.
368
-	 * @return string
369
-	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
372
-	}
373
-
374
-	/**
375
-	 * Alias for self::get_created().
376
-	 *
377
-	 * @since 1.0.19
378
-	 * @param  string $context View or edit context.
379
-	 * @return string
380
-	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
383
-	}
384
-
385
-	/**
386
-	 * Retrieves the creation date in a timestamp
387
-	 *
388
-	 * @since  1.0.0
389
-	 * @return int
390
-	 */
391
-	public function get_time_created() {
392
-		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
-	}
395
-
396
-	/**
397
-	 * Get GMT date when the subscription was created.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  string $context View or edit context.
401
-	 * @return string
402
-	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
645
+    /**
646
+     * Set the date that the subscription will renew.
647
+     *
648
+     * @since 1.0.19
649
+     * @param string $value strtotime compliant date.
650
+     */
651
+    public function set_next_renewal_date( $value ) {
652
+        $date = strtotime( $value );
405 653
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
654
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
+            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
+            return;
408 657
         }
409
-		return $date;
410
-	}
411
-
412
-	/**
413
-	 * Get the date that the subscription will renew.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return string
418
-	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
421
-	}
422
-
423
-	/**
424
-	 * Alias for self::get_next_renewal_date().
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return string
429
-	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
432
-	}
433
-
434
-	/**
435
-	 * Retrieves the expiration date in a timestamp
436
-	 *
437
-	 * @since  1.0.0
438
-	 * @return int
439
-	 */
440
-	public function get_expiration_time() {
441
-		$expiration = $this->get_expiration();
442
-
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
445
-		}
446
-
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
-	}
450
-
451
-	/**
452
-	 * Get GMT date when the subscription will renew.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
460 658
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
463
-        }
464
-		return $date;
465
-	}
466
-
467
-	/**
468
-	 * Get the subscription's trial period.
469
-	 *
470
-	 * @since 1.0.19
471
-	 * @param  string $context View or edit context.
472
-	 * @return string
473
-	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
476
-	}
477
-
478
-	/**
479
-	 * Get the subscription's status.
480
-	 *
481
-	 * @since 1.0.19
482
-	 * @param  string $context View or edit context.
483
-	 * @return string
484
-	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
487
-	}
488
-
489
-	/**
490
-	 * Get the subscription's profile id.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param  string $context View or edit context.
494
-	 * @return string
495
-	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
498
-	}
499
-
500
-	/*
501
-	|--------------------------------------------------------------------------
502
-	| Setters
503
-	|--------------------------------------------------------------------------
504
-	*/
659
+        $this->set_prop( 'expiration', '' );
505 660
 
506
-	/**
507
-	 * Set customer id.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param  int $value The customer's id.
511
-	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
514
-	}
515
-
516
-	/**
517
-	 * Set parent invoice id.
518
-	 *
519
-	 * @since 1.0.19
520
-	 * @param  int $value The parent invoice id.
521
-	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
524
-	}
525
-
526
-	/**
527
-	 * Alias for self::set_parent_invoice_id().
528
-	 *
529
-	 * @since 1.0.19
530
-	 * @param  int $value The parent invoice id.
531
-	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
534
-	}
661
+    }
535 662
 
536
-	/**
537
-     * Alias for self::set_parent_invoice_id().
663
+    /**
664
+     * Alias for self::set_next_renewal_date().
538 665
      *
539 666
      * @since 1.0.19
540
-	 * @param  int $value The parent invoice id.
667
+     * @param string $value strtotime compliant date.
541 668
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
544
-	}
545
-
546
-	/**
547
-	 * Set subscription's product id.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  int $value The subscription product id.
551
-	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
554
-	}
555
-
556
-	/**
557
-	 * Set the period of a renewal.
558
-	 *
559
-	 * @since 1.0.19
560
-	 * @param  string $value The renewal period.
561
-	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
564
-	}
565
-
566
-	/**
567
-	 * Set number of periods each renewal is valid for.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  int $value The subscription frequency.
571
-	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
575
-	}
576
-
577
-	/**
578
-	 * Set the initial amount for the subscription.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  float $value The initial subcription amount.
582
-	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
-	}
586
-
587
-	/**
588
-	 * Set the recurring amount for the subscription.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @param  float $value The recurring subcription amount.
592
-	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
-	}
596
-
597
-	/**
598
-	 * Set number of times that this subscription can be renewed.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @param  int $value Bill times.
602
-	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
605
-	}
606
-
607
-	/**
608
-	 * Get transaction id of this subscription's parent invoice.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param string $value Bill times.
612
-	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
-	}
616
-
617
-	/**
618
-	 * Set date when this subscription started.
619
-	 *
620
-	 * @since 1.0.19
621
-	 * @param string $value strtotime compliant date.
622
-	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
669
+    public function set_expiration( $value ) {
670
+        $this->set_next_renewal_date( $value );
671
+    }
625 672
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
673
+    /**
674
+     * Set the subscription's trial period.
675
+     *
676
+     * @since 1.0.19
677
+     * @param string $value trial period e.g 1 year.
678
+     */
679
+    public function set_trial_period( $value ) {
680
+        $this->set_prop( 'trial_period', $value );
681
+    }
682
+
683
+    /**
684
+     * Set the subscription's status.
685
+     *
686
+     * @since 1.0.19
687
+     * @param string $new_status    New subscription status.
688
+     */
689
+    public function set_status( $new_status ) {
690
+
691
+        // Abort if this is not a valid status;
692
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
628 693
             return;
629 694
         }
630 695
 
631
-		$this->set_prop( 'created', '' );
632
-
633
-	}
696
+        $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
697
+        if ( true === $this->object_read && $old_status !== $new_status ) {
698
+            $this->status_transition = array(
699
+                'from' => $old_status,
700
+                'to'   => $new_status,
701
+            );
702
+        }
634 703
 
635
-	/**
636
-	 * Alias for self::set_created().
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param string $value strtotime compliant date.
640
-	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
704
+        $this->set_prop( 'status', $new_status );
643 705
     }
644 706
 
645
-	/**
646
-	 * Set the date that the subscription will renew.
647
-	 *
648
-	 * @since 1.0.19
649
-	 * @param string $value strtotime compliant date.
650
-	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
707
+    /**
708
+     * Set the subscription's (remote) profile id.
709
+     *
710
+     * @since 1.0.19
711
+     * @param  string $value the remote profile id.
712
+     */
713
+    public function set_profile_id( $value ) {
714
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
715
+    }
653 716
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
-            return;
657
-		}
658
-
659
-		$this->set_prop( 'expiration', '' );
660
-
661
-	}
662
-
663
-	/**
664
-	 * Alias for self::set_next_renewal_date().
665
-	 *
666
-	 * @since 1.0.19
667
-	 * @param string $value strtotime compliant date.
668
-	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
671
-    }
672
-
673
-	/**
674
-	 * Set the subscription's trial period.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @param string $value trial period e.g 1 year.
678
-	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
681
-	}
682
-
683
-	/**
684
-	 * Set the subscription's status.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param string $new_status    New subscription status.
688
-	 */
689
-	public function set_status( $new_status ) {
690
-
691
-		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
693
-			return;
694
-		}
695
-
696
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
697
-		if ( true === $this->object_read && $old_status !== $new_status ) {
698
-			$this->status_transition = array(
699
-				'from' => $old_status,
700
-				'to'   => $new_status,
701
-			);
702
-		}
703
-
704
-		$this->set_prop( 'status', $new_status );
705
-	}
706
-
707
-	/**
708
-	 * Set the subscription's (remote) profile id.
709
-	 *
710
-	 * @since 1.0.19
711
-	 * @param  string $value the remote profile id.
712
-	 */
713
-	public function set_profile_id( $value ) {
714
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
715
-	}
716
-
717
-	/*
717
+    /*
718 718
 	|--------------------------------------------------------------------------
719 719
 	| Boolean methods
720 720
 	|--------------------------------------------------------------------------
@@ -723,55 +723,55 @@  discard block
 block discarded – undo
723 723
 	|
724 724
 	*/
725 725
 
726
-	/**
726
+    /**
727 727
      * Checks if the subscription has a given status.
728
-	 *
729
-	 * @param string|array String or array of strings to check for.
730
-	 * @return bool
728
+     *
729
+     * @param string|array String or array of strings to check for.
730
+     * @return bool
731 731
      */
732 732
     public function has_status( $status ) {
733 733
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
734
-	}
734
+    }
735 735
 
736
-	/**
736
+    /**
737 737
      * Checks if the subscription has a trial period.
738
-	 *
739
-	 * @return bool
738
+     *
739
+     * @return bool
740 740
      */
741 741
     public function has_trial_period() {
742
-		$period = $this->get_trial_period();
742
+        $period = $this->get_trial_period();
743 743
         return ! empty( $period );
744
-	}
745
-
746
-	/**
747
-	 * Is the subscription active?
748
-	 *
749
-	 * @return bool
750
-	 */
751
-	public function is_active() {
752
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
753
-	}
754
-
755
-	/**
756
-	 * Is the subscription expired?
757
-	 *
758
-	 * @return bool
759
-	 */
760
-	public function is_expired() {
761
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
762
-	}
763
-
764
-	/**
765
-	 * Is this the last renewals?
766
-	 *
767
-	 * @return bool
768
-	 */
769
-	public function is_last_renewal() {
770
-		$max_bills = $this->get_bill_times();
771
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
772
-	}
773
-
774
-	/*
744
+    }
745
+
746
+    /**
747
+     * Is the subscription active?
748
+     *
749
+     * @return bool
750
+     */
751
+    public function is_active() {
752
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
753
+    }
754
+
755
+    /**
756
+     * Is the subscription expired?
757
+     *
758
+     * @return bool
759
+     */
760
+    public function is_expired() {
761
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
762
+    }
763
+
764
+    /**
765
+     * Is this the last renewals?
766
+     *
767
+     * @return bool
768
+     */
769
+    public function is_last_renewal() {
770
+        $max_bills = $this->get_bill_times();
771
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
772
+    }
773
+
774
+    /*
775 775
 	|--------------------------------------------------------------------------
776 776
 	| Additional methods
777 777
 	|--------------------------------------------------------------------------
@@ -780,27 +780,27 @@  discard block
 block discarded – undo
780 780
 	|
781 781
 	*/
782 782
 
783
-	/**
784
-	 * Backwards compatibilty.
785
-	 */
786
-	public function create( $data = array() ) {
783
+    /**
784
+     * Backwards compatibilty.
785
+     */
786
+    public function create( $data = array() ) {
787 787
 
788
-		// Set the properties.
789
-		if ( is_array( $data ) ) {
790
-			$this->set_props( $data );
791
-		}
788
+        // Set the properties.
789
+        if ( is_array( $data ) ) {
790
+            $this->set_props( $data );
791
+        }
792 792
 
793
-		// Save the item.
794
-		return $this->save();
793
+        // Save the item.
794
+        return $this->save();
795 795
 
796
-	}
796
+    }
797 797
 
798
-	/**
799
-	 * Backwards compatibilty.
800
-	 */
801
-	public function update( $args = array() ) {
802
-		return $this->create( $args );
803
-	}
798
+    /**
799
+     * Backwards compatibilty.
800
+     */
801
+    public function update( $args = array() ) {
802
+        return $this->create( $args );
803
+    }
804 804
 
805 805
     /**
806 806
      * Retrieve renewal payments for a subscription
@@ -810,22 +810,22 @@  discard block
 block discarded – undo
810 810
      */
811 811
     public function get_child_payments( $hide_pending = true ) {
812 812
 
813
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
813
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814 814
 
815
-		if ( ! $hide_pending ) {
816
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
817
-		}
815
+        if ( ! $hide_pending ) {
816
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
817
+        }
818 818
 
819 819
         return get_posts(
820
-			array(
821
-            	'post_parent' => $this->get_parent_payment_id(),
822
-            	'numberposts' => -1,
823
-            	'post_status' => $statuses,
824
-            	'orderby'     => 'ID',
825
-            	'order'       => 'ASC',
826
-            	'post_type'   => 'wpi_invoice',
827
-			)
828
-		);
820
+            array(
821
+                'post_parent' => $this->get_parent_payment_id(),
822
+                'numberposts' => -1,
823
+                'post_status' => $statuses,
824
+                'orderby'     => 'ID',
825
+                'order'       => 'ASC',
826
+                'post_type'   => 'wpi_invoice',
827
+            )
828
+        );
829 829
     }
830 830
 
831 831
     /**
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
      * @return int
836 836
      */
837 837
     public function get_total_payments() {
838
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
838
+        return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
839 839
     }
840 840
 
841 841
     /**
@@ -859,186 +859,186 @@  discard block
 block discarded – undo
859 859
      *
860 860
      * @since  2.4
861 861
      * @param  array $args Array of values for the payment, including amount and transaction ID
862
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
862
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865 865
     public function add_payment( $args = array(), $invoice = false ) {
866 866
 
867
-		// Process each payment once.
867
+        // Process each payment once.
868 868
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869 869
             return false;
870 870
         }
871 871
 
872
-		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
874
-			$invoice = $this->create_payment( false );
872
+        // Are we creating a new invoice?
873
+        if ( empty( $invoice ) ) {
874
+            $invoice = $this->create_payment( false );
875 875
 
876
-			if ( empty( $invoice ) ) {
877
-				return false;
878
-			}
879
-		}
876
+            if ( empty( $invoice ) ) {
877
+                return false;
878
+            }
879
+        }
880 880
 
881
-		// Maybe set a transaction id.
882
-		if ( ! empty( $args['transaction_id'] ) ) {
883
-			$invoice->set_transaction_id( $args['transaction_id'] );
884
-		}
881
+        // Maybe set a transaction id.
882
+        if ( ! empty( $args['transaction_id'] ) ) {
883
+            $invoice->set_transaction_id( $args['transaction_id'] );
884
+        }
885 885
 
886
-		// Set the completed date.
887
-		$invoice->set_completed_date( current_time( 'mysql' ) );
886
+        // Set the completed date.
887
+        $invoice->set_completed_date( current_time( 'mysql' ) );
888 888
 
889
-		// And the gateway.
890
-		if ( ! empty( $args['gateway'] ) ) {
891
-			$invoice->set_gateway( $args['gateway'] );
892
-		}
889
+        // And the gateway.
890
+        if ( ! empty( $args['gateway'] ) ) {
891
+            $invoice->set_gateway( $args['gateway'] );
892
+        }
893 893
 
894
-		$invoice->save();
894
+        $invoice->save();
895 895
 
896
-		if ( ! $invoice->exists() ) {
897
-			return false;
898
-		}
896
+        if ( ! $invoice->exists() ) {
897
+            return false;
898
+        }
899 899
 
900
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
901
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
900
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
901
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
902 902
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
903 903
 
904 904
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
905 905
 
906 906
         return $invoice->get_id();
907
-	}
907
+    }
908 908
 
909
-	/**
909
+    /**
910 910
      * Creates a new invoice and returns it.
911 911
      *
912 912
      * @since  1.0.19
913
-	 * @param bool $save Whether we should save the invoice.
913
+     * @param bool $save Whether we should save the invoice.
914 914
      * @return WPInv_Invoice|bool
915 915
      */
916 916
     public function create_payment( $save = true ) {
917 917
 
918
-		$parent_invoice = $this->get_parent_payment();
919
-
920
-		if ( ! $parent_invoice->exists() ) {
921
-			return false;
922
-		}
923
-
924
-		// Duplicate the parent invoice.
925
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
926
-		$invoice->set_parent_id( $parent_invoice->get_id() );
927
-		$invoice->set_subscription_id( $this->get_id() );
928
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
929
-
930
-		// Set invoice items.
931
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
932
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
933
-		$invoice_items      = array();
934
-
935
-		foreach ( $invoice->get_items() as $item ) {
936
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
937
-				$invoice_items[] = $item;
938
-			}
939
-		}
940
-
941
-		$invoice->set_items( $invoice_items );
942
-
943
-		if ( ! empty( $subscription_group['fees'] ) ) {
944
-			$invoice->set_fees( $subscription_group['fees'] );
945
-		}
946
-
947
-		// Maybe recalculate discount (Pre-GetPaid Fix).
948
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
949
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
950
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
951
-		}
952
-
953
-		$invoice->recalculate_total();
954
-		$invoice->set_status( 'wpi-pending' );
955
-
956
-		if ( ! $save ) {
957
-			return $invoice;
958
-		}
959
-
960
-		$invoice->save();
961
-
962
-		return $invoice->exists() ? $invoice : false;
963
-    }
964
-
965
-	/**
966
-	 * Renews or completes a subscription
967
-	 *
968
-	 * @since  1.0.0
969
-	 * @return int The subscription's id
970
-	 */
971
-	public function renew( $calculate_from = null ) {
972
-
973
-		// Complete subscription if applicable
974
-		if ( $this->is_last_renewal() ) {
975
-			return $this->complete();
976
-		}
977
-
978
-		// Calculate new expiration
979
-		$frequency      = $this->get_frequency();
980
-		$period         = $this->get_period();
981
-		$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
982
-		$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
983
-
984
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
985
-		$this->set_status( 'active' );
986
-		$this->save();
987
-
988
-		do_action( 'getpaid_subscription_renewed', $this );
989
-
990
-		return $this->get_id();
991
-	}
992
-
993
-	/**
994
-	 * Marks a subscription as completed
995
-	 *
996
-	 * Subscription is completed when the number of payments matches the billing_times field
997
-	 *
998
-	 * @since  1.0.0
999
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
1000
-	 */
1001
-	public function complete() {
1002
-
1003
-		// Only mark a subscription as complete if it's not already cancelled.
1004
-		if ( $this->has_status( 'cancelled' ) ) {
1005
-			return false;
1006
-		}
1007
-
1008
-		$this->set_status( 'completed' );
1009
-		return $this->save();
1010
-
1011
-	}
1012
-
1013
-	/**
1014
-	 * Marks a subscription as expired
1015
-	 *
1016
-	 * @since  1.0.0
1017
-	 * @param  bool $check_expiration
1018
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1019
-	 */
1020
-	public function expire( $check_expiration = false ) {
1021
-
1022
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1023
-			// Do not mark as expired since real expiration date is in the future
1024
-			return false;
1025
-		}
1026
-
1027
-		$this->set_status( 'expired' );
1028
-		return $this->save();
1029
-
1030
-	}
1031
-
1032
-	/**
1033
-	 * Marks a subscription as failing
1034
-	 *
1035
-	 * @since  2.4.2
1036
-	 * @return int Subscription id.
1037
-	 */
1038
-	public function failing() {
1039
-		$this->set_status( 'failing' );
1040
-		return $this->save();
1041
-	}
918
+        $parent_invoice = $this->get_parent_payment();
919
+
920
+        if ( ! $parent_invoice->exists() ) {
921
+            return false;
922
+        }
923
+
924
+        // Duplicate the parent invoice.
925
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
926
+        $invoice->set_parent_id( $parent_invoice->get_id() );
927
+        $invoice->set_subscription_id( $this->get_id() );
928
+        $invoice->set_remote_subscription_id( $this->get_profile_id() );
929
+
930
+        // Set invoice items.
931
+        $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
932
+        $allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
933
+        $invoice_items      = array();
934
+
935
+        foreach ( $invoice->get_items() as $item ) {
936
+            if ( in_array( $item->get_id(), $allowed_items ) ) {
937
+                $invoice_items[] = $item;
938
+            }
939
+        }
940
+
941
+        $invoice->set_items( $invoice_items );
942
+
943
+        if ( ! empty( $subscription_group['fees'] ) ) {
944
+            $invoice->set_fees( $subscription_group['fees'] );
945
+        }
946
+
947
+        // Maybe recalculate discount (Pre-GetPaid Fix).
948
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
949
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
950
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
951
+        }
952
+
953
+        $invoice->recalculate_total();
954
+        $invoice->set_status( 'wpi-pending' );
955
+
956
+        if ( ! $save ) {
957
+            return $invoice;
958
+        }
959
+
960
+        $invoice->save();
961
+
962
+        return $invoice->exists() ? $invoice : false;
963
+    }
964
+
965
+    /**
966
+     * Renews or completes a subscription
967
+     *
968
+     * @since  1.0.0
969
+     * @return int The subscription's id
970
+     */
971
+    public function renew( $calculate_from = null ) {
972
+
973
+        // Complete subscription if applicable
974
+        if ( $this->is_last_renewal() ) {
975
+            return $this->complete();
976
+        }
977
+
978
+        // Calculate new expiration
979
+        $frequency      = $this->get_frequency();
980
+        $period         = $this->get_period();
981
+        $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
982
+        $new_expiration = strtotime( "+ $frequency $period", $calculate_from );
983
+
984
+        $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
985
+        $this->set_status( 'active' );
986
+        $this->save();
987
+
988
+        do_action( 'getpaid_subscription_renewed', $this );
989
+
990
+        return $this->get_id();
991
+    }
992
+
993
+    /**
994
+     * Marks a subscription as completed
995
+     *
996
+     * Subscription is completed when the number of payments matches the billing_times field
997
+     *
998
+     * @since  1.0.0
999
+     * @return int|bool Subscription id or false if the subscription is cancelled.
1000
+     */
1001
+    public function complete() {
1002
+
1003
+        // Only mark a subscription as complete if it's not already cancelled.
1004
+        if ( $this->has_status( 'cancelled' ) ) {
1005
+            return false;
1006
+        }
1007
+
1008
+        $this->set_status( 'completed' );
1009
+        return $this->save();
1010
+
1011
+    }
1012
+
1013
+    /**
1014
+     * Marks a subscription as expired
1015
+     *
1016
+     * @since  1.0.0
1017
+     * @param  bool $check_expiration
1018
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1019
+     */
1020
+    public function expire( $check_expiration = false ) {
1021
+
1022
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1023
+            // Do not mark as expired since real expiration date is in the future
1024
+            return false;
1025
+        }
1026
+
1027
+        $this->set_status( 'expired' );
1028
+        return $this->save();
1029
+
1030
+    }
1031
+
1032
+    /**
1033
+     * Marks a subscription as failing
1034
+     *
1035
+     * @since  2.4.2
1036
+     * @return int Subscription id.
1037
+     */
1038
+    public function failing() {
1039
+        $this->set_status( 'failing' );
1040
+        return $this->save();
1041
+    }
1042 1042
 
1043 1043
     /**
1044 1044
      * Marks a subscription as cancelled
@@ -1047,19 +1047,19 @@  discard block
 block discarded – undo
1047 1047
      * @return int Subscription id.
1048 1048
      */
1049 1049
     public function cancel() {
1050
-		$this->set_status( 'cancelled' );
1051
-		return $this->save();
1050
+        $this->set_status( 'cancelled' );
1051
+        return $this->save();
1052 1052
     }
1053 1053
 
1054
-	/**
1055
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1056
-	 *
1057
-	 * @since  1.0.0
1058
-	 * @return bool
1059
-	 */
1060
-	public function can_cancel() {
1061
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1062
-	}
1054
+    /**
1055
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1056
+     *
1057
+     * @since  1.0.0
1058
+     * @return bool
1059
+     */
1060
+    public function can_cancel() {
1061
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1062
+    }
1063 1063
 
1064 1064
     /**
1065 1065
      * Returns an array of subscription statuses that can be cancelled
@@ -1072,109 +1072,109 @@  discard block
 block discarded – undo
1072 1072
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1073 1073
     }
1074 1074
 
1075
-	/**
1076
-	 * Retrieves the URL to cancel subscription
1077
-	 *
1078
-	 * @since  1.0.0
1079
-	 * @return string
1080
-	 */
1081
-	public function get_cancel_url() {
1082
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1083
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1084
-	}
1085
-
1086
-	/**
1087
-	 * Retrieves the URL to view a subscription
1088
-	 *
1089
-	 * @since  1.0.19
1090
-	 * @return string
1091
-	 */
1092
-	public function get_view_url() {
1093
-
1094
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1095
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1096
-
1097
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1098
-	}
1099
-
1100
-	/**
1101
-	 * Determines if subscription can be manually renewed
1102
-	 *
1103
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1104
-	 * that can be renewed manually
1105
-	 *
1106
-	 * @since  2.5
1107
-	 * @return bool
1108
-	 */
1109
-	public function can_renew() {
1110
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1111
-	}
1112
-
1113
-	/**
1114
-	 * Retrieves the URL to renew a subscription
1115
-	 *
1116
-	 * @since  2.5
1117
-	 * @return string
1118
-	 */
1119
-	public function get_renew_url() {
1120
-		$url = wp_nonce_url(
1075
+    /**
1076
+     * Retrieves the URL to cancel subscription
1077
+     *
1078
+     * @since  1.0.0
1079
+     * @return string
1080
+     */
1081
+    public function get_cancel_url() {
1082
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1083
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1084
+    }
1085
+
1086
+    /**
1087
+     * Retrieves the URL to view a subscription
1088
+     *
1089
+     * @since  1.0.19
1090
+     * @return string
1091
+     */
1092
+    public function get_view_url() {
1093
+
1094
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1095
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1096
+
1097
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1098
+    }
1099
+
1100
+    /**
1101
+     * Determines if subscription can be manually renewed
1102
+     *
1103
+     * This method is filtered by payment gateways in order to return true on subscriptions
1104
+     * that can be renewed manually
1105
+     *
1106
+     * @since  2.5
1107
+     * @return bool
1108
+     */
1109
+    public function can_renew() {
1110
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1111
+    }
1112
+
1113
+    /**
1114
+     * Retrieves the URL to renew a subscription
1115
+     *
1116
+     * @since  2.5
1117
+     * @return string
1118
+     */
1119
+    public function get_renew_url() {
1120
+        $url = wp_nonce_url(
1121 1121
             add_query_arg(
1122 1122
                 array(
1123
-					'getpaid-action' => 'renew_subscription',
1124
-					'sub_id'         => $this->get_id,
1123
+                    'getpaid-action' => 'renew_subscription',
1124
+                    'sub_id'         => $this->get_id,
1125 1125
                 )
1126 1126
             ),
1127 1127
             'getpaid-nonce'
1128 1128
         );
1129
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1130
-	}
1131
-
1132
-	/**
1133
-	 * Determines if subscription can have their payment method updated
1134
-	 *
1135
-	 * @since  1.0.0
1136
-	 * @return bool
1137
-	 */
1138
-	public function can_update() {
1139
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1140
-	}
1141
-
1142
-	/**
1143
-	 * Retrieves the URL to update subscription
1144
-	 *
1145
-	 * @since  1.0.0
1146
-	 * @return string
1147
-	 */
1148
-	public function get_update_url() {
1149
-		$url = add_query_arg(
1129
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1130
+    }
1131
+
1132
+    /**
1133
+     * Determines if subscription can have their payment method updated
1134
+     *
1135
+     * @since  1.0.0
1136
+     * @return bool
1137
+     */
1138
+    public function can_update() {
1139
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1140
+    }
1141
+
1142
+    /**
1143
+     * Retrieves the URL to update subscription
1144
+     *
1145
+     * @since  1.0.0
1146
+     * @return string
1147
+     */
1148
+    public function get_update_url() {
1149
+        $url = add_query_arg(
1150 1150
             array(
1151
-				'action'          => 'update',
1152
-				'subscription_id' => $this->get_id(),
1151
+                'action'          => 'update',
1152
+                'subscription_id' => $this->get_id(),
1153 1153
             )
1154 1154
         );
1155
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1156
-	}
1157
-
1158
-	/**
1159
-	 * Retrieves the subscription status label
1160
-	 *
1161
-	 * @since  1.0.0
1162
-	 * @return string
1163
-	 */
1164
-	public function get_status_label() {
1165
-		return getpaid_get_subscription_status_label( $this->get_status() );
1166
-	}
1167
-
1168
-	/**
1169
-	 * Retrieves the subscription status class
1170
-	 *
1171
-	 * @since  1.0.19
1172
-	 * @return string
1173
-	 */
1174
-	public function get_status_class() {
1175
-		$statuses = getpaid_get_subscription_status_classes();
1176
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1177
-	}
1155
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1156
+    }
1157
+
1158
+    /**
1159
+     * Retrieves the subscription status label
1160
+     *
1161
+     * @since  1.0.0
1162
+     * @return string
1163
+     */
1164
+    public function get_status_label() {
1165
+        return getpaid_get_subscription_status_label( $this->get_status() );
1166
+    }
1167
+
1168
+    /**
1169
+     * Retrieves the subscription status class
1170
+     *
1171
+     * @since  1.0.19
1172
+     * @return string
1173
+     */
1174
+    public function get_status_class() {
1175
+        $statuses = getpaid_get_subscription_status_classes();
1176
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1177
+    }
1178 1178
 
1179 1179
     /**
1180 1180
      * Retrieves the subscription status label
@@ -1184,11 +1184,11 @@  discard block
 block discarded – undo
1184 1184
      */
1185 1185
     public function get_status_label_html() {
1186 1186
 
1187
-		$status_label = sanitize_text_field( $this->get_status_label() );
1188
-		$class        = esc_attr( $this->get_status_class() );
1189
-		$status       = sanitize_html_class( $this->get_status() );
1187
+        $status_label = sanitize_text_field( $this->get_status_label() );
1188
+        $class        = esc_attr( $this->get_status_class() );
1189
+        $status       = sanitize_html_class( $this->get_status() );
1190 1190
 
1191
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1191
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1192 1192
     }
1193 1193
 
1194 1194
     /**
@@ -1199,75 +1199,75 @@  discard block
 block discarded – undo
1199 1199
      * @return bool
1200 1200
      */
1201 1201
     public function payment_exists( $txn_id = '' ) {
1202
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1202
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1203 1203
         return ! empty( $invoice_id );
1204
-	}
1205
-
1206
-	/**
1207
-	 * Handle the status transition.
1208
-	 */
1209
-	protected function status_transition() {
1210
-		$status_transition = $this->status_transition;
1211
-
1212
-		// Reset status transition variable.
1213
-		$this->status_transition = false;
1214
-
1215
-		if ( $status_transition ) {
1216
-			try {
1217
-
1218
-				// Fire a hook for the status change.
1219
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1220
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1221
-
1222
-				if ( ! empty( $status_transition['from'] ) ) {
1223
-
1224
-					/* translators: 1: old subscription status 2: new subscription status */
1225
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1226
-
1227
-					// Note the transition occurred.
1228
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1229
-
1230
-					// Fire another hook.
1231
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1232
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1233
-
1234
-				} else {
1235
-					/* translators: %s: new invoice status */
1236
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1237
-
1238
-					// Note the transition occurred.
1239
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1240
-
1241
-				}
1242
-			} catch ( Exception $e ) {
1243
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1244
-			}
1245
-		}
1246
-
1247
-	}
1248
-
1249
-	/**
1250
-	 * Save data to the database.
1251
-	 *
1252
-	 * @since 1.0.19
1253
-	 * @return int subscription ID
1254
-	 */
1255
-	public function save() {
1256
-		parent::save();
1257
-		$this->status_transition();
1258
-		return $this->get_id();
1259
-	}
1260
-
1261
-	/**
1262
-	 * Activates a subscription.
1263
-	 *
1264
-	 * @since 1.0.19
1265
-	 * @return int subscription ID
1266
-	 */
1267
-	public function activate() {
1268
-		$status = 'trialling' === $this->get_status() ? 'trialling' : 'active';
1269
-		$this->set_status( $status );
1270
-		return $this->save();
1271
-	}
1204
+    }
1205
+
1206
+    /**
1207
+     * Handle the status transition.
1208
+     */
1209
+    protected function status_transition() {
1210
+        $status_transition = $this->status_transition;
1211
+
1212
+        // Reset status transition variable.
1213
+        $this->status_transition = false;
1214
+
1215
+        if ( $status_transition ) {
1216
+            try {
1217
+
1218
+                // Fire a hook for the status change.
1219
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1220
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1221
+
1222
+                if ( ! empty( $status_transition['from'] ) ) {
1223
+
1224
+                    /* translators: 1: old subscription status 2: new subscription status */
1225
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1226
+
1227
+                    // Note the transition occurred.
1228
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1229
+
1230
+                    // Fire another hook.
1231
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1232
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1233
+
1234
+                } else {
1235
+                    /* translators: %s: new invoice status */
1236
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1237
+
1238
+                    // Note the transition occurred.
1239
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1240
+
1241
+                }
1242
+            } catch ( Exception $e ) {
1243
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1244
+            }
1245
+        }
1246
+
1247
+    }
1248
+
1249
+    /**
1250
+     * Save data to the database.
1251
+     *
1252
+     * @since 1.0.19
1253
+     * @return int subscription ID
1254
+     */
1255
+    public function save() {
1256
+        parent::save();
1257
+        $this->status_transition();
1258
+        return $this->get_id();
1259
+    }
1260
+
1261
+    /**
1262
+     * Activates a subscription.
1263
+     *
1264
+     * @since 1.0.19
1265
+     * @return int subscription ID
1266
+     */
1267
+    public function activate() {
1268
+        $status = 'trialling' === $this->get_status() ? 'trialling' : 'active';
1269
+        $this->set_status( $status );
1270
+        return $this->save();
1271
+    }
1272 1272
 
1273 1273
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
 
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
 
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -258,11 +258,11 @@  discard block
 block discarded – undo
258 258
         global $getpaid_force_checkbox;
259 259
 
260 260
         // Is the request set up correctly?
261
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
262
-			aui()->alert(
263
-				array(
264
-					'type'    => 'warning',
265
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
261
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
262
+            aui()->alert(
263
+                array(
264
+                    'type'    => 'warning',
265
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
266 266
                 ),
267 267
                 true
268 268
             );
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
         }
271 271
 
272 272
         // Payment form or button?
273
-		if ( ! empty( $_GET['form'] ) ) {
273
+        if ( ! empty( $_GET['form'] ) ) {
274 274
             $form = sanitize_text_field( urldecode( $_GET['form'] ) );
275 275
 
276 276
             if ( false !== strpos( $form, '|' ) ) {
@@ -323,10 +323,10 @@  discard block
 block discarded – undo
323 323
                 getpaid_display_payment_form( $form );
324 324
             }
325 325
 } elseif ( ! empty( $_GET['invoice'] ) ) {
326
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
326
+            getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
327 327
         } else {
328
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
329
-		    getpaid_display_item_payment_form( $items );
328
+            $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
329
+            getpaid_display_item_payment_form( $items );
330 330
         }
331 331
 
332 332
         exit;
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
         if ( is_wp_error( $error ) ) {
644 644
             $alert = $error->get_error_message();
645 645
             wp_send_json_success( compact( 'alert' ) );
646
-         }
646
+            }
647 647
 
648 648
         // Update totals.
649 649
         $invoice->recalculate_total();
@@ -1072,12 +1072,12 @@  discard block
 block discarded – undo
1072 1072
     }
1073 1073
 
1074 1074
     /**
1075
-	 * Handles file uploads.
1076
-	 *
1077
-	 * @since       1.0.0
1078
-	 * @return      void
1079
-	 */
1080
-	public static function file_upload() {
1075
+     * Handles file uploads.
1076
+     *
1077
+     * @since       1.0.0
1078
+     * @return      void
1079
+     */
1080
+    public static function file_upload() {
1081 1081
 
1082 1082
         // Check nonce.
1083 1083
         check_ajax_referer( 'getpaid_form_nonce' );
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 
1139 1139
         wp_send_json_success( $response );
1140 1140
 
1141
-	}
1141
+    }
1142 1142
 
1143 1143
 }
1144 1144
 
Please login to merge, or discard this patch.