Passed
Push — master ( 3daa97...364f4a )
by Brian
05:00
created
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 1 patch
Indentation   +403 added lines, -403 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,300 +21,300 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @since 1.0.11 Font Awesome Pro now supported.
30
-	 * @since 1.0.11 Font Awesome Kits now supported.
31
-	 * @since 1.0.13 RTL language support added.
32
-	 * @ver 1.0.13
33
-	 * @todo decide how to implement textdomain
34
-	 */
35
-	class WP_Font_Awesome_Settings {
36
-
37
-		/**
38
-		 * Class version version.
39
-		 *
40
-		 * @var string
41
-		 */
42
-		public $version = '1.0.13';
43
-
44
-		/**
45
-		 * Class textdomain.
46
-		 *
47
-		 * @var string
48
-		 */
49
-		public $textdomain = 'font-awesome-settings';
50
-
51
-		/**
52
-		 * Latest version of Font Awesome at time of publish published.
53
-		 *
54
-		 * @var string
55
-		 */
56
-		public $latest = "5.8.2";
57
-
58
-		/**
59
-		 * The title.
60
-		 *
61
-		 * @var string
62
-		 */
63
-		public $name = 'Font Awesome';
64
-
65
-		/**
66
-		 * Holds the settings values.
67
-		 *
68
-		 * @var array
69
-		 */
70
-		private $settings;
71
-
72
-		/**
73
-		 * WP_Font_Awesome_Settings instance.
74
-		 *
75
-		 * @access private
76
-		 * @since  1.0.0
77
-		 * @var    WP_Font_Awesome_Settings There can be only one!
78
-		 */
79
-		private static $instance = null;
80
-
81
-		/**
82
-		 * Main WP_Font_Awesome_Settings Instance.
83
-		 *
84
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
-		 *
86
-		 * @since 1.0.0
87
-		 * @static
88
-		 * @return WP_Font_Awesome_Settings - Main instance.
89
-		 */
90
-		public static function instance() {
91
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
-				self::$instance = new WP_Font_Awesome_Settings;
93
-
94
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
-
96
-				if ( is_admin() ) {
97
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
-				}
100
-
101
-				do_action( 'wp_font_awesome_settings_loaded' );
102
-			}
103
-
104
-			return self::$instance;
105
-		}
106
-
107
-		/**
108
-		 * Initiate the settings and add the required action hooks.
109
-		 *
110
-		 * @since 1.0.8 Settings name wrong - FIXED
111
-		 */
112
-		public function init() {
113
-			$this->settings = $this->get_settings();
114
-
115
-			if ( $this->settings['type'] == 'CSS' ) {
116
-
117
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
-				}
120
-
121
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
-				}
124
-
125
-			} else {
126
-
127
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
-				}
130
-
131
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
-				}
134
-			}
135
-
136
-			// remove font awesome if set to do so
137
-			if ( $this->settings['dequeue'] == '1' ) {
138
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
-			}
140
-
141
-		}
142
-
143
-		/**
144
-		 * Adds the Font Awesome styles.
145
-		 */
146
-		public function enqueue_style() {
147
-			// build url
148
-			$url = $this->get_url();
149
-
150
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
-			wp_register_style( 'font-awesome', $url, array(), null );
152
-			wp_enqueue_style( 'font-awesome' );
153
-
154
-			// RTL language support CSS.
155
-			if ( is_rtl() ) {
156
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
-			}
158
-
159
-			if ( $this->settings['shims'] ) {
160
-				$url = $this->get_url( true );
161
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
163
-				wp_enqueue_style( 'font-awesome-shims' );
164
-			}
165
-		}
166
-
167
-		/**
168
-		 * Adds the Font Awesome JS.
169
-		 */
170
-		public function enqueue_scripts() {
171
-			// build url
172
-			$url = $this->get_url();
173
-
174
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
-			wp_register_script( 'font-awesome', $url, array(), null );
177
-			wp_enqueue_script( 'font-awesome' );
178
-
179
-			if ( $this->settings['shims'] ) {
180
-				$url = $this->get_url( true );
181
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
183
-				wp_enqueue_script( 'font-awesome-shims' );
184
-			}
185
-		}
186
-
187
-		/**
188
-		 * Get the url of the Font Awesome files.
189
-		 *
190
-		 * @param bool $shims If this is a shim file or not.
191
-		 *
192
-		 * @return string The url to the file.
193
-		 */
194
-		public function get_url( $shims = false ) {
195
-			$script  = $shims ? 'v4-shims' : 'all';
196
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
197
-			$type    = $this->settings['type'];
198
-			$version = $this->settings['version'];
199
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
-			$url     = '';
201
-
202
-			if ( $type == 'KIT' && $kit_url ) {
203
-				if ( $shims ) {
204
-					// if its a kit then we don't add shims here
205
-					return '';
206
-				}
207
-				$url .= $kit_url; // CDN
208
-				$url .= "?wpfas=true"; // set our var so our version is not removed
209
-			} else {
210
-				$url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
-				$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
-				$url .= "?wpfas=true"; // set our var so our version is not removed
215
-			}
216
-
217
-			return $url;
218
-		}
219
-
220
-		/**
221
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
-		 *
223
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
-		 *
225
-		 * @param $url
226
-		 * @param $original_url
227
-		 * @param $_context
228
-		 *
229
-		 * @return string The filtered url.
230
-		 */
231
-		public function remove_font_awesome( $url, $original_url, $_context ) {
232
-
233
-			if ( $_context == 'display'
234
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
-			) {// it's a font-awesome-url (probably)
237
-
238
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
239
-					if ( $this->settings['type'] == 'JS' ) {
240
-						if ( $this->settings['js-pseudo'] ) {
241
-							$url .= "' data-search-pseudo-elements defer='defer";
242
-						} else {
243
-							$url .= "' defer='defer";
244
-						}
245
-					}
246
-				} else {
247
-					$url = ''; // removing the url removes the file
248
-				}
249
-
250
-			}
251
-
252
-			return $url;
253
-		}
254
-
255
-		/**
256
-		 * Register the database settings with WordPress.
257
-		 */
258
-		public function register_settings() {
259
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
-		}
261
-
262
-		/**
263
-		 * Add the WordPress settings menu item.
264
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
-		 */
266
-		public function menu_item() {
267
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
-				$this,
270
-				'settings_page'
271
-			) );
272
-		}
273
-
274
-		/**
275
-		 * Get the current Font Awesome output settings.
276
-		 *
277
-		 * @return array The array of settings.
278
-		 */
279
-		public function get_settings() {
280
-
281
-			$db_settings = get_option( 'wp-font-awesome-settings' );
282
-
283
-			$defaults = array(
284
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
285
-				'version'   => '', // latest
286
-				'enqueue'   => '', // front and backend
287
-				'shims'     => '0', // default OFF now in 2020
288
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
-				'pro'       => '0', // if pro CDN url should be used
291
-				'kit-url'   => '', // the kit url
292
-			);
293
-
294
-			$settings = wp_parse_args( $db_settings, $defaults );
295
-
296
-			/**
297
-			 * Filter the Font Awesome settings.
298
-			 *
299
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
-			 */
301
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
-		}
303
-
304
-
305
-		/**
306
-		 * The settings page html output.
307
-		 */
308
-		public function settings_page() {
309
-			if ( ! current_user_can( 'manage_options' ) ) {
310
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
-			}
312
-
313
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
315
-				$this->get_latest_version( $force_api = true );
316
-			}
317
-			?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @since 1.0.11 Font Awesome Pro now supported.
30
+     * @since 1.0.11 Font Awesome Kits now supported.
31
+     * @since 1.0.13 RTL language support added.
32
+     * @ver 1.0.13
33
+     * @todo decide how to implement textdomain
34
+     */
35
+    class WP_Font_Awesome_Settings {
36
+
37
+        /**
38
+         * Class version version.
39
+         *
40
+         * @var string
41
+         */
42
+        public $version = '1.0.13';
43
+
44
+        /**
45
+         * Class textdomain.
46
+         *
47
+         * @var string
48
+         */
49
+        public $textdomain = 'font-awesome-settings';
50
+
51
+        /**
52
+         * Latest version of Font Awesome at time of publish published.
53
+         *
54
+         * @var string
55
+         */
56
+        public $latest = "5.8.2";
57
+
58
+        /**
59
+         * The title.
60
+         *
61
+         * @var string
62
+         */
63
+        public $name = 'Font Awesome';
64
+
65
+        /**
66
+         * Holds the settings values.
67
+         *
68
+         * @var array
69
+         */
70
+        private $settings;
71
+
72
+        /**
73
+         * WP_Font_Awesome_Settings instance.
74
+         *
75
+         * @access private
76
+         * @since  1.0.0
77
+         * @var    WP_Font_Awesome_Settings There can be only one!
78
+         */
79
+        private static $instance = null;
80
+
81
+        /**
82
+         * Main WP_Font_Awesome_Settings Instance.
83
+         *
84
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
+         *
86
+         * @since 1.0.0
87
+         * @static
88
+         * @return WP_Font_Awesome_Settings - Main instance.
89
+         */
90
+        public static function instance() {
91
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
+                self::$instance = new WP_Font_Awesome_Settings;
93
+
94
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
+
96
+                if ( is_admin() ) {
97
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
+                }
100
+
101
+                do_action( 'wp_font_awesome_settings_loaded' );
102
+            }
103
+
104
+            return self::$instance;
105
+        }
106
+
107
+        /**
108
+         * Initiate the settings and add the required action hooks.
109
+         *
110
+         * @since 1.0.8 Settings name wrong - FIXED
111
+         */
112
+        public function init() {
113
+            $this->settings = $this->get_settings();
114
+
115
+            if ( $this->settings['type'] == 'CSS' ) {
116
+
117
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
+                }
120
+
121
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
+                }
124
+
125
+            } else {
126
+
127
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
+                }
130
+
131
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
+                }
134
+            }
135
+
136
+            // remove font awesome if set to do so
137
+            if ( $this->settings['dequeue'] == '1' ) {
138
+                add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
+            }
140
+
141
+        }
142
+
143
+        /**
144
+         * Adds the Font Awesome styles.
145
+         */
146
+        public function enqueue_style() {
147
+            // build url
148
+            $url = $this->get_url();
149
+
150
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
+            wp_register_style( 'font-awesome', $url, array(), null );
152
+            wp_enqueue_style( 'font-awesome' );
153
+
154
+            // RTL language support CSS.
155
+            if ( is_rtl() ) {
156
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
+            }
158
+
159
+            if ( $this->settings['shims'] ) {
160
+                $url = $this->get_url( true );
161
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
+                wp_register_style( 'font-awesome-shims', $url, array(), null );
163
+                wp_enqueue_style( 'font-awesome-shims' );
164
+            }
165
+        }
166
+
167
+        /**
168
+         * Adds the Font Awesome JS.
169
+         */
170
+        public function enqueue_scripts() {
171
+            // build url
172
+            $url = $this->get_url();
173
+
174
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
+            wp_register_script( 'font-awesome', $url, array(), null );
177
+            wp_enqueue_script( 'font-awesome' );
178
+
179
+            if ( $this->settings['shims'] ) {
180
+                $url = $this->get_url( true );
181
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
183
+                wp_enqueue_script( 'font-awesome-shims' );
184
+            }
185
+        }
186
+
187
+        /**
188
+         * Get the url of the Font Awesome files.
189
+         *
190
+         * @param bool $shims If this is a shim file or not.
191
+         *
192
+         * @return string The url to the file.
193
+         */
194
+        public function get_url( $shims = false ) {
195
+            $script  = $shims ? 'v4-shims' : 'all';
196
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
197
+            $type    = $this->settings['type'];
198
+            $version = $this->settings['version'];
199
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
+            $url     = '';
201
+
202
+            if ( $type == 'KIT' && $kit_url ) {
203
+                if ( $shims ) {
204
+                    // if its a kit then we don't add shims here
205
+                    return '';
206
+                }
207
+                $url .= $kit_url; // CDN
208
+                $url .= "?wpfas=true"; // set our var so our version is not removed
209
+            } else {
210
+                $url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
+                $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
+                $url .= "?wpfas=true"; // set our var so our version is not removed
215
+            }
216
+
217
+            return $url;
218
+        }
219
+
220
+        /**
221
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
+         *
223
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
+         *
225
+         * @param $url
226
+         * @param $original_url
227
+         * @param $_context
228
+         *
229
+         * @return string The filtered url.
230
+         */
231
+        public function remove_font_awesome( $url, $original_url, $_context ) {
232
+
233
+            if ( $_context == 'display'
234
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
+            ) {// it's a font-awesome-url (probably)
237
+
238
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
239
+                    if ( $this->settings['type'] == 'JS' ) {
240
+                        if ( $this->settings['js-pseudo'] ) {
241
+                            $url .= "' data-search-pseudo-elements defer='defer";
242
+                        } else {
243
+                            $url .= "' defer='defer";
244
+                        }
245
+                    }
246
+                } else {
247
+                    $url = ''; // removing the url removes the file
248
+                }
249
+
250
+            }
251
+
252
+            return $url;
253
+        }
254
+
255
+        /**
256
+         * Register the database settings with WordPress.
257
+         */
258
+        public function register_settings() {
259
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
+        }
261
+
262
+        /**
263
+         * Add the WordPress settings menu item.
264
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
+         */
266
+        public function menu_item() {
267
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
+                $this,
270
+                'settings_page'
271
+            ) );
272
+        }
273
+
274
+        /**
275
+         * Get the current Font Awesome output settings.
276
+         *
277
+         * @return array The array of settings.
278
+         */
279
+        public function get_settings() {
280
+
281
+            $db_settings = get_option( 'wp-font-awesome-settings' );
282
+
283
+            $defaults = array(
284
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
285
+                'version'   => '', // latest
286
+                'enqueue'   => '', // front and backend
287
+                'shims'     => '0', // default OFF now in 2020
288
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
+                'pro'       => '0', // if pro CDN url should be used
291
+                'kit-url'   => '', // the kit url
292
+            );
293
+
294
+            $settings = wp_parse_args( $db_settings, $defaults );
295
+
296
+            /**
297
+             * Filter the Font Awesome settings.
298
+             *
299
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
+             */
301
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
+        }
303
+
304
+
305
+        /**
306
+         * The settings page html output.
307
+         */
308
+        public function settings_page() {
309
+            if ( ! current_user_can( 'manage_options' ) ) {
310
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
+            }
312
+
313
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
315
+                $this->get_latest_version( $force_api = true );
316
+            }
317
+            ?>
318 318
 			<style>
319 319
 				.wpfas-kit-show {
320 320
 					display: none;
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 				<h1><?php echo $this->name; ?></h1>
333 333
 				<form method="post" action="options.php">
334 334
 					<?php
335
-					settings_fields( 'wp-font-awesome-settings' );
336
-					do_settings_sections( 'wp-font-awesome-settings' );
337
-					$kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
-					?>
335
+                    settings_fields( 'wp-font-awesome-settings' );
336
+                    do_settings_sections( 'wp-font-awesome-settings' );
337
+                    $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
+                    ?>
339 339
 					<table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>">
340 340
 						<tr valign="top">
341 341
 							<th scope="row"><label
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
 								       value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>"
362 362
 								       placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
363 363
 								<span><?php
364
-									echo sprintf(
365
-										__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
-										'</a>'
368
-									);
369
-									?></span>
364
+                                    echo sprintf(
365
+                                        __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
+                                        '</a>'
368
+                                    );
369
+                                    ?></span>
370 370
 							</td>
371 371
 						</tr>
372 372
 
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
 								<input type="checkbox" name="wp-font-awesome-settings[pro]"
427 427
 								       value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/>
428 428
 								<span><?php
429
-									echo sprintf(
430
-										__( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
-										'</a>',
433
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
-										'</a>'
435
-									);
436
-									?></span>
429
+                                    echo sprintf(
430
+                                        __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
+                                        '</a>',
433
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
+                                        '</a>'
435
+                                    );
436
+                                    ?></span>
437 437
 							</td>
438 438
 						</tr>
439 439
 
@@ -476,100 +476,100 @@  discard block
 block discarded – undo
476 476
 
477 477
 					</table>
478 478
 					<?php
479
-					submit_button();
480
-					?>
479
+                    submit_button();
480
+                    ?>
481 481
 				</form>
482 482
 
483 483
 				<div id="wpfas-version"><?php echo $this->version; ?></div>
484 484
 			</div>
485 485
 
486 486
 			<?php
487
-		}
488
-
489
-		/**
490
-		 * Check a version number is valid and if so return it or else return an empty string.
491
-		 *
492
-		 * @param $version string The version number to check.
493
-		 *
494
-		 * @since 1.0.6
495
-		 *
496
-		 * @return string Either a valid version number or an empty string.
497
-		 */
498
-		public function validate_version_number( $version ) {
499
-
500
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
-				// valid
502
-			} else {
503
-				$version = '';// not validated
504
-			}
505
-
506
-			return $version;
507
-		}
508
-
509
-
510
-		/**
511
-		 * Get the latest version of Font Awesome.
512
-		 *
513
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
-		 *
515
-		 * @since 1.0.7
516
-		 * @return mixed|string The latest version number found.
517
-		 */
518
-		public function get_latest_version( $force_api = false ) {
519
-			$latest_version = $this->latest;
520
-
521
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
522
-
523
-			if ( $cache === false || $force_api ) { // its not set
524
-				$api_ver = $this->get_latest_version_from_api();
525
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
-					$latest_version = $api_ver;
527
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
-				}
529
-			} elseif ( $this->validate_version_number( $cache ) ) {
530
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
-					$latest_version = $cache;
532
-				}
533
-			}
534
-
535
-			return $latest_version;
536
-		}
537
-
538
-		/**
539
-		 * Get the latest Font Awesome version from the github API.
540
-		 *
541
-		 * @since 1.0.7
542
-		 * @return string The latest version number or `0` on API fail.
543
-		 */
544
-		public function get_latest_version_from_api() {
545
-			$version  = "0";
546
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
-					$version = $api_response['tag_name'];
551
-				}
552
-			}
553
-
554
-			return $version;
555
-		}
556
-
557
-		/**
558
-		 * Inline CSS for RTL language support.
559
-		 *
560
-		 * @since 1.0.13
561
-		 * @return string Inline CSS.
562
-		 */
563
-		public function rtl_inline_css() {
564
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
-
566
-			return $inline_css;
567
-		}
568
-
569
-	}
570
-
571
-	/**
572
-	 * Run the class if found.
573
-	 */
574
-	WP_Font_Awesome_Settings::instance();
487
+        }
488
+
489
+        /**
490
+         * Check a version number is valid and if so return it or else return an empty string.
491
+         *
492
+         * @param $version string The version number to check.
493
+         *
494
+         * @since 1.0.6
495
+         *
496
+         * @return string Either a valid version number or an empty string.
497
+         */
498
+        public function validate_version_number( $version ) {
499
+
500
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
+                // valid
502
+            } else {
503
+                $version = '';// not validated
504
+            }
505
+
506
+            return $version;
507
+        }
508
+
509
+
510
+        /**
511
+         * Get the latest version of Font Awesome.
512
+         *
513
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
+         *
515
+         * @since 1.0.7
516
+         * @return mixed|string The latest version number found.
517
+         */
518
+        public function get_latest_version( $force_api = false ) {
519
+            $latest_version = $this->latest;
520
+
521
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
522
+
523
+            if ( $cache === false || $force_api ) { // its not set
524
+                $api_ver = $this->get_latest_version_from_api();
525
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
+                    $latest_version = $api_ver;
527
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
+                }
529
+            } elseif ( $this->validate_version_number( $cache ) ) {
530
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
+                    $latest_version = $cache;
532
+                }
533
+            }
534
+
535
+            return $latest_version;
536
+        }
537
+
538
+        /**
539
+         * Get the latest Font Awesome version from the github API.
540
+         *
541
+         * @since 1.0.7
542
+         * @return string The latest version number or `0` on API fail.
543
+         */
544
+        public function get_latest_version_from_api() {
545
+            $version  = "0";
546
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
+                    $version = $api_response['tag_name'];
551
+                }
552
+            }
553
+
554
+            return $version;
555
+        }
556
+
557
+        /**
558
+         * Inline CSS for RTL language support.
559
+         *
560
+         * @since 1.0.13
561
+         * @return string Inline CSS.
562
+         */
563
+        public function rtl_inline_css() {
564
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
+
566
+            return $inline_css;
567
+        }
568
+
569
+    }
570
+
571
+    /**
572
+     * Run the class if found.
573
+     */
574
+    WP_Font_Awesome_Settings::instance();
575 575
 }
576 576
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Indentation   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_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 = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
90
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92 92
 
93 93
         parent::__construct();
94 94
     }
95 95
 
96 96
     /**
97
-	 * Process Payment.
98
-	 *
99
-	 *
100
-	 * @param WPInv_Invoice $invoice Invoice.
101
-	 * @param array $submission_data Posted checkout fields.
102
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
-	 * @return array
104
-	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
97
+     * Process Payment.
98
+     *
99
+     *
100
+     * @param WPInv_Invoice $invoice Invoice.
101
+     * @param array $submission_data Posted checkout fields.
102
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
+     * @return array
104
+     */
105
+    public function process_payment( $invoice, $submission_data, $submission ) {
106 106
 
107 107
         // Get redirect url.
108 108
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get the PayPal request URL for an invoice.
129
-	 *
130
-	 * @param  WPInv_Invoice $invoice Invoice object.
131
-	 * @return string
132
-	 */
133
-	public function get_request_url( $invoice ) {
128
+     * Get the PayPal request URL for an invoice.
129
+     *
130
+     * @param  WPInv_Invoice $invoice Invoice object.
131
+     * @return string
132
+     */
133
+    public function get_request_url( $invoice ) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139 139
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -146,45 +146,45 @@  discard block
 block discarded – undo
146 146
 
147 147
         return add_query_arg( $paypal_args, $this->endpoint );
148 148
 
149
-	}
149
+    }
150 150
 
151 151
     /**
152
-	 * Get PayPal Args for passing to PP.
153
-	 *
154
-	 * @param  WPInv_Invoice $invoice Invoice object.
155
-	 * @return array
156
-	 */
157
-	protected function get_paypal_args( $invoice ) {
152
+     * Get PayPal Args for passing to PP.
153
+     *
154
+     * @param  WPInv_Invoice $invoice Invoice object.
155
+     * @return array
156
+     */
157
+    protected function get_paypal_args( $invoice ) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
-
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
-			$force_one_line_item = true;
164
-		}
165
-
166
-		$paypal_args = apply_filters(
167
-			'getpaid_paypal_args',
168
-			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
171
-			),
172
-			$invoice
173
-		);
174
-
175
-		return $this->fix_request_length( $invoice, $paypal_args );
160
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+
162
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+            $force_one_line_item = true;
164
+        }
165
+
166
+        $paypal_args = apply_filters(
167
+            'getpaid_paypal_args',
168
+            array_merge(
169
+                $this->get_transaction_args( $invoice ),
170
+                $this->get_line_item_args( $invoice, $force_one_line_item )
171
+            ),
172
+            $invoice
173
+        );
174
+
175
+        return $this->fix_request_length( $invoice, $paypal_args );
176 176
     }
177 177
 
178 178
     /**
179
-	 * Get transaction args for paypal request.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 * @return array
183
-	 */
184
-	protected function get_transaction_args( $invoice ) {
185
-
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
-		return array(
179
+     * Get transaction args for paypal request.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     * @return array
183
+     */
184
+    protected function get_transaction_args( $invoice ) {
185
+
186
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
+        return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
190 190
             'no_shipping'   => '1',
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get line item args for paypal request.
213
-	 *
214
-	 * @param  WPInv_Invoice $invoice Invoice object.
215
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216
-	 * @return array
217
-	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
212
+     * Get line item args for paypal request.
213
+     *
214
+     * @param  WPInv_Invoice $invoice Invoice object.
215
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
216
+     * @return array
217
+     */
218
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
221
+        if ( $force_one_line_item ) {
222 222
             return $this->get_line_item_args_single_item( $invoice );
223 223
         }
224 224
 
@@ -238,129 +238,129 @@  discard block
 block discarded – undo
238 238
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+        return array_merge( $line_item_args, $this->get_line_items() );
242 242
 
243 243
     }
244 244
 
245 245
     /**
246
-	 * Get line item args for paypal request as a single line item.
247
-	 *
248
-	 * @param  WPInv_Invoice $invoice Invoice object.
249
-	 * @return array
250
-	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
252
-		$this->delete_line_items();
246
+     * Get line item args for paypal request as a single line item.
247
+     *
248
+     * @param  WPInv_Invoice $invoice Invoice object.
249
+     * @return array
250
+     */
251
+    protected function get_line_item_args_single_item( $invoice ) {
252
+        $this->delete_line_items();
253 253
 
254 254
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
256 256
 
257
-		return $this->get_line_items();
257
+        return $this->get_line_items();
258 258
     }
259 259
 
260 260
     /**
261
-	 * Return all line items.
262
-	 */
263
-	protected function get_line_items() {
264
-		return $this->line_items;
265
-	}
261
+     * Return all line items.
262
+     */
263
+    protected function get_line_items() {
264
+        return $this->line_items;
265
+    }
266 266
 
267 267
     /**
268
-	 * Remove all line items.
269
-	 */
270
-	protected function delete_line_items() {
271
-		$this->line_items = array();
268
+     * Remove all line items.
269
+     */
270
+    protected function delete_line_items() {
271
+        $this->line_items = array();
272 272
     }
273 273
 
274 274
     /**
275
-	 * Prepare line items to send to paypal.
276
-	 *
277
-	 * @param  WPInv_Invoice $invoice Invoice object.
278
-	 */
279
-	protected function prepare_line_items( $invoice ) {
280
-		$this->delete_line_items();
281
-
282
-		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
284
-			$amount   = $item->get_price();
285
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
275
+     * Prepare line items to send to paypal.
276
+     *
277
+     * @param  WPInv_Invoice $invoice Invoice object.
278
+     */
279
+    protected function prepare_line_items( $invoice ) {
280
+        $this->delete_line_items();
281
+
282
+        // Items.
283
+        foreach ( $invoice->get_items() as $item ) {
284
+            $amount   = $item->get_price();
285
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
290
+        foreach ( $invoice->get_fees() as $fee => $data ) {
291 291
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
292 292
         }
293 293
 
294 294
     }
295 295
 
296 296
     /**
297
-	 * Add PayPal Line Item.
298
-	 *
299
-	 * @param  string $item_name Item name.
300
-	 * @param  float    $quantity Item quantity.
301
-	 * @param  float  $amount Amount.
302
-	 * @param  string $item_number Item number.
303
-	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
306
-
307
-		$item = apply_filters(
308
-			'getpaid_paypal_line_item',
309
-			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
-				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
-				'item_number' => $item_number,
314
-			),
315
-			$item_name,
316
-			$quantity,
317
-			$amount,
318
-			$item_number
319
-		);
320
-
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
297
+     * Add PayPal Line Item.
298
+     *
299
+     * @param  string $item_name Item name.
300
+     * @param  float    $quantity Item quantity.
301
+     * @param  float  $amount Amount.
302
+     * @param  string $item_number Item number.
303
+     */
304
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
+        $index = ( count( $this->line_items ) / 4 ) + 1;
306
+
307
+        $item = apply_filters(
308
+            'getpaid_paypal_line_item',
309
+            array(
310
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
+                'quantity'    => (float) $quantity,
312
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
+                'item_number' => $item_number,
314
+            ),
315
+            $item_name,
316
+            $quantity,
317
+            $amount,
318
+            $item_number
319
+        );
320
+
321
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322 322
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
327 327
     }
328 328
 
329 329
     /**
330
-	 * If the default request with line items is too long, generate a new one with only one line item.
331
-	 *
332
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
-	 *
334
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336
-	 * @return array
337
-	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
339
-		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
341
-
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
-			return $paypal_args;
344
-		}
345
-
346
-		return apply_filters(
347
-			'getpaid_paypal_args',
348
-			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
351
-			),
352
-			$invoice
353
-		);
330
+     * If the default request with line items is too long, generate a new one with only one line item.
331
+     *
332
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
+     *
334
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
336
+     * @return array
337
+     */
338
+    protected function fix_request_length( $invoice, $paypal_args ) {
339
+        $max_paypal_length = 2083;
340
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
341
+
342
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
+            return $paypal_args;
344
+        }
345
+
346
+        return apply_filters(
347
+            'getpaid_paypal_args',
348
+            array_merge(
349
+                $this->get_transaction_args( $invoice ),
350
+                $this->get_line_item_args( $invoice, true )
351
+            ),
352
+            $invoice
353
+        );
354 354
 
355 355
     }
356 356
 
357 357
     /**
358
-	 * Processes recurring invoices.
359
-	 *
360
-	 * @param  array $paypal_args PayPal args.
361
-	 * @param  WPInv_Invoice    $invoice Invoice object.
362
-	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
358
+     * Processes recurring invoices.
359
+     *
360
+     * @param  array $paypal_args PayPal args.
361
+     * @param  WPInv_Invoice    $invoice Invoice object.
362
+     */
363
+    public function process_subscription( $paypal_args, $invoice ) {
364 364
 
365 365
         // Make sure this is a subscription.
366 366
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
 
386 386
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
387 387
 
388
-			// Trial period length.
389
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
388
+            // Trial period length.
389
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
390 390
 
391
-			// Trial period.
392
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
391
+            // Trial period.
392
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
393 393
 
394 394
         } else if ( $initial_amount != $recurring_amount ) {
395 395
 
@@ -412,40 +412,40 @@  discard block
 block discarded – undo
412 412
         }
413 413
 
414 414
         // We have a recurring payment
415
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
415
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
416 416
 
417
-			// Subscription price
418
-			$paypal_args['a3'] = $recurring_amount;
417
+            // Subscription price
418
+            $paypal_args['a3'] = $recurring_amount;
419 419
 
420
-			// Subscription duration
421
-			$paypal_args['p3'] = $interval;
420
+            // Subscription duration
421
+            $paypal_args['p3'] = $interval;
422 422
 
423
-			// Subscription period
424
-			$paypal_args['t3'] = $period;
423
+            // Subscription period
424
+            $paypal_args['t3'] = $period;
425 425
 
426 426
         }
427 427
 
428 428
         // Recurring payments
429
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
429
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
430 430
 
431
-			// Non-recurring payments
432
-			$paypal_args['src'] = 0;
431
+            // Non-recurring payments
432
+            $paypal_args['src'] = 0;
433 433
 
434
-		} else {
434
+        } else {
435 435
 
436
-			$paypal_args['src'] = 1;
436
+            $paypal_args['src'] = 1;
437 437
 
438
-			if ( $bill_times > 0 ) {
438
+            if ( $bill_times > 0 ) {
439 439
 
440
-				// An initial period is being used to charge a sign-up fee
441
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
442
-					$bill_times--;
443
-				}
440
+                // An initial period is being used to charge a sign-up fee
441
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
442
+                    $bill_times--;
443
+                }
444 444
 
445 445
                 // Make sure it's not over the max of 52
446 446
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
447 447
 
448
-			}
448
+            }
449 449
         }
450 450
 
451 451
         // Force return URL so that order description & instructions display
@@ -461,19 +461,19 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         return apply_filters(
464
-			'getpaid_paypal_subscription_args',
465
-			$paypal_args,
466
-			$invoice
464
+            'getpaid_paypal_subscription_args',
465
+            $paypal_args,
466
+            $invoice
467 467
         );
468 468
 
469 469
     }
470 470
 
471 471
     /**
472
-	 * Processes ipns and marks payments as complete.
473
-	 *
474
-	 * @return void
475
-	 */
476
-	public function verify_ipn() {
472
+     * Processes ipns and marks payments as complete.
473
+     *
474
+     * @return void
475
+     */
476
+    public function verify_ipn() {
477 477
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
478 478
     }
479 479
 
@@ -483,19 +483,19 @@  discard block
 block discarded – undo
483 483
     public function sandbox_notice() {
484 484
 
485 485
         return sprintf(
486
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
487
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
488
-			'</a>'
489
-		);
486
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
487
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
488
+            '</a>'
489
+        );
490 490
 
491 491
     }
492 492
 
493
-	/**
494
-	 * Filters the gateway settings.
495
-	 *
496
-	 * @param array $admin_settings
497
-	 */
498
-	public function admin_settings( $admin_settings ) {
493
+    /**
494
+     * Filters the gateway settings.
495
+     *
496
+     * @param array $admin_settings
497
+     */
498
+    public function admin_settings( $admin_settings ) {
499 499
 
500 500
         $currencies = sprintf(
501 501
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -505,39 +505,39 @@  discard block
 block discarded – undo
505 505
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
506 506
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
507 507
 
508
-		// Access tokens.
509
-		$live_email      = wpinv_get_option( 'paypal_email' );
510
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
511
-
512
-		$admin_settings['paypal_connect'] = array(
513
-			'type'       => 'raw_html',
514
-			'id'         => 'paypal_connect',
515
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
516
-			'desc'       => sprintf(
517
-				'<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
518
-				esc_url( self::get_connect_url( false ) ),
519
-				__( 'Connect to PayPal', 'invoicing' ),
520
-				esc_url( self::get_connect_url( true ) ),
521
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
522
-				$this->get_js()
523
-			),
524
-		);
508
+        // Access tokens.
509
+        $live_email      = wpinv_get_option( 'paypal_email' );
510
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
511
+
512
+        $admin_settings['paypal_connect'] = array(
513
+            'type'       => 'raw_html',
514
+            'id'         => 'paypal_connect',
515
+            'name'       => __( 'Connect to PayPal', 'invoicing' ),
516
+            'desc'       => sprintf(
517
+                '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
518
+                esc_url( self::get_connect_url( false ) ),
519
+                __( 'Connect to PayPal', 'invoicing' ),
520
+                esc_url( self::get_connect_url( true ) ),
521
+                __( 'Connect to PayPal Sandox', 'invoicing' ),
522
+                $this->get_js()
523
+            ),
524
+        );
525 525
 
526 526
         $admin_settings['paypal_email'] = array(
527 527
             'type'  => 'text',
528
-			'class' => 'live-auth-data',
528
+            'class' => 'live-auth-data',
529 529
             'id'    => 'paypal_email',
530 530
             'name'  => __( 'Live Email Address', 'invoicing' ),
531 531
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
532 532
         );
533 533
 
534
-		$admin_settings['paypal_sandbox_email'] = array(
534
+        $admin_settings['paypal_sandbox_email'] = array(
535 535
             'type'  => 'text',
536
-			'class' => 'sandbox-auth-data',
536
+            'class' => 'sandbox-auth-data',
537 537
             'id'    => 'paypal_sandbox_email',
538 538
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
539 539
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
540
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
540
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
541 541
         );
542 542
 
543 543
         $admin_settings['paypal_ipn_url'] = array(
@@ -549,29 +549,29 @@  discard block
 block discarded – undo
549 549
             'readonly' => true,
550 550
         );
551 551
 
552
-		return $admin_settings;
553
-	}
552
+        return $admin_settings;
553
+    }
554 554
 
555
-	/**
556
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
557
-	 *
558
-	 *
555
+    /**
556
+     * Retrieves the PayPal connect URL when using the setup wizzard.
557
+     *
558
+     *
559 559
      * @param array $data
560 560
      * @return string
561
-	 */
562
-	public static function maybe_get_connect_url( $url = '', $data ) {
563
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
564
-	}
565
-
566
-	/**
567
-	 * Retrieves the PayPal connect URL.
568
-	 *
569
-	 *
561
+     */
562
+    public static function maybe_get_connect_url( $url = '', $data ) {
563
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
564
+    }
565
+
566
+    /**
567
+     * Retrieves the PayPal connect URL.
568
+     *
569
+     *
570 570
      * @param bool $is_sandbox
571
-	 * @param string $redirect
571
+     * @param string $redirect
572 572
      * @return string
573
-	 */
574
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
573
+     */
574
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
575 575
 
576 576
         $redirect_url = add_query_arg(
577 577
             array(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
                 'tab'                  => 'gateways',
582 582
                 'section'              => 'paypal',
583 583
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
584
-				'redirect'             => urlencode( $redirect ),
584
+                'redirect'             => urlencode( $redirect ),
585 585
             ),
586 586
             admin_url( 'admin.php' )
587 587
         );
@@ -596,12 +596,12 @@  discard block
 block discarded – undo
596 596
 
597 597
     }
598 598
 
599
-	/**
600
-	 * Generates settings page js.
601
-	 *
599
+    /**
600
+     * Generates settings page js.
601
+     *
602 602
      * @return void
603
-	 */
604
-	public static function get_js() {
603
+     */
604
+    public static function get_js() {
605 605
         ob_start();
606 606
         ?>
607 607
             <script>
@@ -637,72 +637,72 @@  discard block
 block discarded – undo
637 637
         return ob_get_clean();
638 638
     }
639 639
 
640
-	/**
641
-	 * Connects to PayPal.
642
-	 *
643
-	 * @param array $data Connection data.
644
-	 * @return void
645
-	 */
646
-	public function connect_paypal( $data ) {
647
-
648
-		$sandbox      = $this->is_sandbox();
649
-		$data         = wp_unslash( $data );
650
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
651
-
652
-		if ( isset( $data['live_mode'] ) ) {
653
-			$sandbox = empty( $data['live_mode'] );
654
-		}
655
-
656
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
657
-		wpinv_update_option( 'paypal_active', 1 );
658
-
659
-		if ( ! empty( $data['error_description'] ) ) {
660
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
661
-		} else {
662
-
663
-			// Retrieve the user info.
664
-			$user_info = wp_remote_get(
665
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
666
-				array(
667
-
668
-					'headers' => array(
669
-						'Authorization' => 'Bearer ' . $access_token,
670
-						'Content-type'  => 'application/json',
671
-					)
672
-
673
-				)
674
-			);
675
-
676
-			if ( is_wp_error( $user_info ) ) {
677
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
678
-			} else {
679
-
680
-				// Create application.
681
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
682
-
683
-				if ( $sandbox ) {
684
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
685
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
686
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
687
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
688
-				} else {
689
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
690
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
691
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
692
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
693
-				}
694
-
695
-			}
696
-
697
-		}
698
-
699
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
-
701
-		if ( isset( $data['step'] ) ) {
702
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
703
-		}
704
-		wp_redirect( $redirect );
705
-		exit;
706
-	}
640
+    /**
641
+     * Connects to PayPal.
642
+     *
643
+     * @param array $data Connection data.
644
+     * @return void
645
+     */
646
+    public function connect_paypal( $data ) {
647
+
648
+        $sandbox      = $this->is_sandbox();
649
+        $data         = wp_unslash( $data );
650
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
651
+
652
+        if ( isset( $data['live_mode'] ) ) {
653
+            $sandbox = empty( $data['live_mode'] );
654
+        }
655
+
656
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
657
+        wpinv_update_option( 'paypal_active', 1 );
658
+
659
+        if ( ! empty( $data['error_description'] ) ) {
660
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
661
+        } else {
662
+
663
+            // Retrieve the user info.
664
+            $user_info = wp_remote_get(
665
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
666
+                array(
667
+
668
+                    'headers' => array(
669
+                        'Authorization' => 'Bearer ' . $access_token,
670
+                        'Content-type'  => 'application/json',
671
+                    )
672
+
673
+                )
674
+            );
675
+
676
+            if ( is_wp_error( $user_info ) ) {
677
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
678
+            } else {
679
+
680
+                // Create application.
681
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
682
+
683
+                if ( $sandbox ) {
684
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
685
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
686
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
687
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
688
+                } else {
689
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
690
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
691
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
692
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
693
+                }
694
+
695
+            }
696
+
697
+        }
698
+
699
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
+
701
+        if ( isset( $data['step'] ) ) {
702
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
703
+        }
704
+        wp_redirect( $redirect );
705
+        exit;
706
+    }
707 707
 
708 708
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +477 added lines, -477 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,542 +15,542 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'_wpinv_phone',
34
-		'_wpinv_company_id',
35
-		'wpinv_email_cc',
36
-		'wpinv_template',
37
-		'wpinv_created_via'
38
-	);
39
-
40
-	/**
41
-	 * A map of meta keys to data props.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $meta_key_to_props = array(
48
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
49
-		'_wpinv_subscription_id'   => 'subscription_id',
50
-		'_wpinv_taxes'             => 'taxes',
51
-		'_wpinv_fees'              => 'fees',
52
-		'_wpinv_discounts'         => 'discounts',
53
-		'_wpinv_submission_id'     => 'submission_id',
54
-		'_wpinv_payment_form'      => 'payment_form',
55
-		'_wpinv_is_viewed'         => 'is_viewed',
56
-		'wpinv_email_cc'           => 'email_cc',
57
-		'wpinv_template'           => 'template',
58
-		'wpinv_created_via'        => 'created_via',
59
-		'_wpinv_phone'             => 'phone',
60
-		'_wpinv_company_id'        => 'company_id',
61
-	);
62
-
63
-	/**
64
-	 * A map of database fields to data props.
65
-	 *
66
-	 * @since 1.0.19
67
-	 *
68
-	 * @var array
69
-	 */
70
-	protected $database_fields_to_props = array(
71
-		'post_id'            => 'id',
72
-		'number'             => 'number',
73
-		'currency'           => 'currency',
74
-		'key'                => 'key',
75
-		'type'               => 'type',
76
-		'mode'               => 'mode',
77
-		'user_ip'            => 'user_ip',
78
-		'first_name'         => 'first_name',
79
-		'last_name'          => 'last_name',
80
-		'address'            => 'address',
81
-		'city'               => 'city',
82
-		'state'              => 'state',
83
-		'country'            => 'country',
84
-		'zip'                => 'zip',
85
-		'zip'                => 'zip',
86
-		'adddress_confirmed' => 'address_confirmed',
87
-		'gateway'            => 'gateway',
88
-		'transaction_id'     => 'transaction_id',
89
-		'currency'           => 'currency',
90
-		'subtotal'           => 'subtotal',
91
-		'tax'                => 'total_tax',
92
-		'fees_total'         => 'total_fees',
93
-		'discount'           => 'total_discount',
94
-		'total'              => 'total',
95
-		'discount_code'      => 'discount_code',
96
-		'disable_taxes'      => 'disable_taxes',
97
-		'due_date'           => 'due_date',
98
-		'completed_date'     => 'completed_date',
99
-		'company'            => 'company',
100
-		'vat_number'         => 'vat_number',
101
-		'vat_rate'           => 'vat_rate',
102
-	);
103
-
104
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        '_wpinv_phone',
34
+        '_wpinv_company_id',
35
+        'wpinv_email_cc',
36
+        'wpinv_template',
37
+        'wpinv_created_via'
38
+    );
39
+
40
+    /**
41
+     * A map of meta keys to data props.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $meta_key_to_props = array(
48
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
49
+        '_wpinv_subscription_id'   => 'subscription_id',
50
+        '_wpinv_taxes'             => 'taxes',
51
+        '_wpinv_fees'              => 'fees',
52
+        '_wpinv_discounts'         => 'discounts',
53
+        '_wpinv_submission_id'     => 'submission_id',
54
+        '_wpinv_payment_form'      => 'payment_form',
55
+        '_wpinv_is_viewed'         => 'is_viewed',
56
+        'wpinv_email_cc'           => 'email_cc',
57
+        'wpinv_template'           => 'template',
58
+        'wpinv_created_via'        => 'created_via',
59
+        '_wpinv_phone'             => 'phone',
60
+        '_wpinv_company_id'        => 'company_id',
61
+    );
62
+
63
+    /**
64
+     * A map of database fields to data props.
65
+     *
66
+     * @since 1.0.19
67
+     *
68
+     * @var array
69
+     */
70
+    protected $database_fields_to_props = array(
71
+        'post_id'            => 'id',
72
+        'number'             => 'number',
73
+        'currency'           => 'currency',
74
+        'key'                => 'key',
75
+        'type'               => 'type',
76
+        'mode'               => 'mode',
77
+        'user_ip'            => 'user_ip',
78
+        'first_name'         => 'first_name',
79
+        'last_name'          => 'last_name',
80
+        'address'            => 'address',
81
+        'city'               => 'city',
82
+        'state'              => 'state',
83
+        'country'            => 'country',
84
+        'zip'                => 'zip',
85
+        'zip'                => 'zip',
86
+        'adddress_confirmed' => 'address_confirmed',
87
+        'gateway'            => 'gateway',
88
+        'transaction_id'     => 'transaction_id',
89
+        'currency'           => 'currency',
90
+        'subtotal'           => 'subtotal',
91
+        'tax'                => 'total_tax',
92
+        'fees_total'         => 'total_fees',
93
+        'discount'           => 'total_discount',
94
+        'total'              => 'total',
95
+        'discount_code'      => 'discount_code',
96
+        'disable_taxes'      => 'disable_taxes',
97
+        'due_date'           => 'due_date',
98
+        'completed_date'     => 'completed_date',
99
+        'company'            => 'company',
100
+        'vat_number'         => 'vat_number',
101
+        'vat_rate'           => 'vat_rate',
102
+    );
103
+
104
+    /*
105 105
 	|--------------------------------------------------------------------------
106 106
 	| CRUD Methods
107 107
 	|--------------------------------------------------------------------------
108 108
 	*/
109 109
 
110
-	/**
111
-	 * Method to create a new invoice in the database.
112
-	 *
113
-	 * @param WPInv_Invoice $invoice Invoice object.
114
-	 */
115
-	public function create( &$invoice ) {
116
-		$invoice->set_version( WPINV_VERSION );
117
-		$invoice->set_date_created( current_time('mysql') );
118
-
119
-		// Create a new post.
120
-		$id = wp_insert_post(
121
-			apply_filters(
122
-				'getpaid_new_invoice_data',
123
-				array(
124
-					'post_date'     => $invoice->get_date_created( 'edit' ),
125
-					'post_type'     => $invoice->get_post_type( 'edit' ),
126
-					'post_status'   => $this->get_post_status( $invoice ),
127
-					'ping_status'   => 'closed',
128
-					'post_author'   => $invoice->get_user_id( 'edit' ),
129
-					'post_title'    => $invoice->get_title( 'edit' ),
130
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
131
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
132
-				)
133
-			),
134
-			true
135
-		);
136
-
137
-		if ( $id && ! is_wp_error( $id ) ) {
138
-
139
-			// Update the new id and regenerate a title.
140
-			$invoice->set_id( $id );
141
-
142
-			$invoice->maybe_set_number();
143
-
144
-			wp_update_post(
145
-				array(
146
-					'ID'         => $invoice->get_id(),
147
-					'post_title' => $invoice->get_number( 'edit' ),
148
-					'post_name'  => $invoice->get_path( 'edit' )
149
-				)
150
-			);
151
-
152
-			// Save special fields and items.
153
-			$this->save_special_fields( $invoice );
154
-			$this->save_items( $invoice );
155
-
156
-			// Update meta data.
157
-			$this->update_post_meta( $invoice );
158
-			$invoice->save_meta_data();
159
-
160
-			// Apply changes.
161
-			$invoice->apply_changes();
162
-			$this->clear_caches( $invoice );
163
-
164
-			// Fires after a new invoice is created.
165
-			do_action( 'getpaid_new_invoice', $invoice );
166
-			return true;
167
-		}
168
-
169
-		if ( is_wp_error( $id ) ) {
170
-			$invoice->last_error = $id->get_error_message();
171
-		}
172
-
173
-		return false;
174
-	}
175
-
176
-	/**
177
-	 * Method to read an invoice from the database.
178
-	 *
179
-	 * @param WPInv_Invoice $invoice Invoice object.
180
-	 *
181
-	 */
182
-	public function read( &$invoice ) {
183
-
184
-		$invoice->set_defaults();
185
-		$invoice_object = get_post( $invoice->get_id() );
186
-
187
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
188
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
189
-			$invoice->set_id( 0 );
190
-			return false;
191
-		}
192
-
193
-		$invoice->set_props(
194
-			array(
195
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
196
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
197
-				'status'        => $invoice_object->post_status,
198
-				'author'        => $invoice_object->post_author,
199
-				'description'   => $invoice_object->post_excerpt,
200
-				'parent_id'     => $invoice_object->post_parent,
201
-				'name'          => $invoice_object->post_title,
202
-				'path'          => $invoice_object->post_name,
203
-				'post_type'     => $invoice_object->post_type,
204
-			)
205
-		);
206
-
207
-		$invoice->set_type( $invoice_object->post_type );
208
-
209
-		$this->read_object_data( $invoice, $invoice_object );
210
-		$this->add_special_fields( $invoice );
211
-		$this->add_items( $invoice );
212
-		$invoice->read_meta_data();
213
-		$invoice->set_object_read( true );
214
-		do_action( 'getpaid_read_invoice', $invoice );
215
-
216
-	}
217
-
218
-	/**
219
-	 * Method to update an invoice in the database.
220
-	 *
221
-	 * @param WPInv_Invoice $invoice Invoice object.
222
-	 */
223
-	public function update( &$invoice ) {
224
-		$invoice->save_meta_data();
225
-		$invoice->set_version( WPINV_VERSION );
226
-
227
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
228
-			$invoice->set_date_created(  current_time('mysql') );
229
-		}
230
-
231
-		// Ensure both the key and number are set.
232
-		$invoice->get_path();
233
-
234
-		// Grab the current status so we can compare.
235
-		$previous_status = get_post_status( $invoice->get_id() );
236
-
237
-		$changes = $invoice->get_changes();
238
-
239
-		// Only update the post when the post data changes.
240
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
241
-			$post_data = array(
242
-				'post_date'         => $invoice->get_date_created( 'edit' ),
243
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
244
-				'post_status'       => $invoice->get_status( 'edit' ),
245
-				'post_title'        => $invoice->get_name( 'edit' ),
246
-				'post_author'       => $invoice->get_user_id( 'edit' ),
247
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
248
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
249
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
250
-				'post_name'         => $invoice->get_path( 'edit' ),
251
-				'post_type'         => $invoice->get_post_type( 'edit' ),
252
-			);
253
-
254
-			/**
255
-			 * When updating this object, to prevent infinite loops, use $wpdb
256
-			 * to update data, since wp_update_post spawns more calls to the
257
-			 * save_post action.
258
-			 *
259
-			 * This ensures hooks are fired by either WP itself (admin screen save),
260
-			 * or an update purely from CRUD.
261
-			 */
262
-			if ( doing_action( 'save_post' ) ) {
263
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
264
-				clean_post_cache( $invoice->get_id() );
265
-			} else {
266
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
267
-			}
268
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
269
-		}
270
-
271
-		// Update meta data.
272
-		$this->update_post_meta( $invoice );
273
-
274
-		// Save special fields and items.
275
-		$this->save_special_fields( $invoice );
276
-		$this->save_items( $invoice );
277
-
278
-		// Apply the changes.
279
-		$invoice->apply_changes();
280
-
281
-		// Clear caches.
282
-		$this->clear_caches( $invoice );
283
-
284
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
285
-		$new_status = $invoice->get_status( 'edit' );
286
-
287
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
288
-			do_action( 'getpaid_new_invoice', $invoice );
289
-		} else {
290
-			do_action( 'getpaid_update_invoice', $invoice );
291
-		}
292
-
293
-	}
294
-
295
-	/*
110
+    /**
111
+     * Method to create a new invoice in the database.
112
+     *
113
+     * @param WPInv_Invoice $invoice Invoice object.
114
+     */
115
+    public function create( &$invoice ) {
116
+        $invoice->set_version( WPINV_VERSION );
117
+        $invoice->set_date_created( current_time('mysql') );
118
+
119
+        // Create a new post.
120
+        $id = wp_insert_post(
121
+            apply_filters(
122
+                'getpaid_new_invoice_data',
123
+                array(
124
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
125
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
126
+                    'post_status'   => $this->get_post_status( $invoice ),
127
+                    'ping_status'   => 'closed',
128
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
129
+                    'post_title'    => $invoice->get_title( 'edit' ),
130
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
131
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
132
+                )
133
+            ),
134
+            true
135
+        );
136
+
137
+        if ( $id && ! is_wp_error( $id ) ) {
138
+
139
+            // Update the new id and regenerate a title.
140
+            $invoice->set_id( $id );
141
+
142
+            $invoice->maybe_set_number();
143
+
144
+            wp_update_post(
145
+                array(
146
+                    'ID'         => $invoice->get_id(),
147
+                    'post_title' => $invoice->get_number( 'edit' ),
148
+                    'post_name'  => $invoice->get_path( 'edit' )
149
+                )
150
+            );
151
+
152
+            // Save special fields and items.
153
+            $this->save_special_fields( $invoice );
154
+            $this->save_items( $invoice );
155
+
156
+            // Update meta data.
157
+            $this->update_post_meta( $invoice );
158
+            $invoice->save_meta_data();
159
+
160
+            // Apply changes.
161
+            $invoice->apply_changes();
162
+            $this->clear_caches( $invoice );
163
+
164
+            // Fires after a new invoice is created.
165
+            do_action( 'getpaid_new_invoice', $invoice );
166
+            return true;
167
+        }
168
+
169
+        if ( is_wp_error( $id ) ) {
170
+            $invoice->last_error = $id->get_error_message();
171
+        }
172
+
173
+        return false;
174
+    }
175
+
176
+    /**
177
+     * Method to read an invoice from the database.
178
+     *
179
+     * @param WPInv_Invoice $invoice Invoice object.
180
+     *
181
+     */
182
+    public function read( &$invoice ) {
183
+
184
+        $invoice->set_defaults();
185
+        $invoice_object = get_post( $invoice->get_id() );
186
+
187
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
188
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
189
+            $invoice->set_id( 0 );
190
+            return false;
191
+        }
192
+
193
+        $invoice->set_props(
194
+            array(
195
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
196
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
197
+                'status'        => $invoice_object->post_status,
198
+                'author'        => $invoice_object->post_author,
199
+                'description'   => $invoice_object->post_excerpt,
200
+                'parent_id'     => $invoice_object->post_parent,
201
+                'name'          => $invoice_object->post_title,
202
+                'path'          => $invoice_object->post_name,
203
+                'post_type'     => $invoice_object->post_type,
204
+            )
205
+        );
206
+
207
+        $invoice->set_type( $invoice_object->post_type );
208
+
209
+        $this->read_object_data( $invoice, $invoice_object );
210
+        $this->add_special_fields( $invoice );
211
+        $this->add_items( $invoice );
212
+        $invoice->read_meta_data();
213
+        $invoice->set_object_read( true );
214
+        do_action( 'getpaid_read_invoice', $invoice );
215
+
216
+    }
217
+
218
+    /**
219
+     * Method to update an invoice in the database.
220
+     *
221
+     * @param WPInv_Invoice $invoice Invoice object.
222
+     */
223
+    public function update( &$invoice ) {
224
+        $invoice->save_meta_data();
225
+        $invoice->set_version( WPINV_VERSION );
226
+
227
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
228
+            $invoice->set_date_created(  current_time('mysql') );
229
+        }
230
+
231
+        // Ensure both the key and number are set.
232
+        $invoice->get_path();
233
+
234
+        // Grab the current status so we can compare.
235
+        $previous_status = get_post_status( $invoice->get_id() );
236
+
237
+        $changes = $invoice->get_changes();
238
+
239
+        // Only update the post when the post data changes.
240
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
241
+            $post_data = array(
242
+                'post_date'         => $invoice->get_date_created( 'edit' ),
243
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
244
+                'post_status'       => $invoice->get_status( 'edit' ),
245
+                'post_title'        => $invoice->get_name( 'edit' ),
246
+                'post_author'       => $invoice->get_user_id( 'edit' ),
247
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
248
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
249
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
250
+                'post_name'         => $invoice->get_path( 'edit' ),
251
+                'post_type'         => $invoice->get_post_type( 'edit' ),
252
+            );
253
+
254
+            /**
255
+             * When updating this object, to prevent infinite loops, use $wpdb
256
+             * to update data, since wp_update_post spawns more calls to the
257
+             * save_post action.
258
+             *
259
+             * This ensures hooks are fired by either WP itself (admin screen save),
260
+             * or an update purely from CRUD.
261
+             */
262
+            if ( doing_action( 'save_post' ) ) {
263
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
264
+                clean_post_cache( $invoice->get_id() );
265
+            } else {
266
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
267
+            }
268
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
269
+        }
270
+
271
+        // Update meta data.
272
+        $this->update_post_meta( $invoice );
273
+
274
+        // Save special fields and items.
275
+        $this->save_special_fields( $invoice );
276
+        $this->save_items( $invoice );
277
+
278
+        // Apply the changes.
279
+        $invoice->apply_changes();
280
+
281
+        // Clear caches.
282
+        $this->clear_caches( $invoice );
283
+
284
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
285
+        $new_status = $invoice->get_status( 'edit' );
286
+
287
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
288
+            do_action( 'getpaid_new_invoice', $invoice );
289
+        } else {
290
+            do_action( 'getpaid_update_invoice', $invoice );
291
+        }
292
+
293
+    }
294
+
295
+    /*
296 296
 	|--------------------------------------------------------------------------
297 297
 	| Additional Methods
298 298
 	|--------------------------------------------------------------------------
299 299
 	*/
300 300
 
301
-	/**
301
+    /**
302 302
      * Retrieves special fields and adds to the invoice.
303
-	 *
304
-	 * @param WPInv_Invoice $invoice Invoice object.
303
+     *
304
+     * @param WPInv_Invoice $invoice Invoice object.
305 305
      */
306 306
     public function add_special_fields( &$invoice ) {
307
-		global $wpdb;
307
+        global $wpdb;
308 308
 
309
-		// Maybe retrieve from the cache.
310
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
309
+        // Maybe retrieve from the cache.
310
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
311 311
 
312
-		// If not found, retrieve from the db.
313
-		if ( false === $data ) {
314
-			$table =  $wpdb->prefix . 'getpaid_invoices';
312
+        // If not found, retrieve from the db.
313
+        if ( false === $data ) {
314
+            $table =  $wpdb->prefix . 'getpaid_invoices';
315 315
 
316
-			$data  = $wpdb->get_row(
317
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
318
-				ARRAY_A
319
-			);
316
+            $data  = $wpdb->get_row(
317
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
318
+                ARRAY_A
319
+            );
320 320
 
321
-			// Update the cache with our data
322
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
321
+            // Update the cache with our data
322
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
323 323
 
324
-		}
324
+        }
325 325
 
326
-		// Abort if the data does not exist.
327
-		if ( empty( $data ) ) {
328
-			$invoice->set_object_read( true );
329
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
330
-			return;
331
-		}
326
+        // Abort if the data does not exist.
327
+        if ( empty( $data ) ) {
328
+            $invoice->set_object_read( true );
329
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
330
+            return;
331
+        }
332 332
 
333
-		$props = array();
333
+        $props = array();
334 334
 
335
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
335
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
336 336
 			
337
-			if ( $db_field == 'post_id' ) {
338
-				continue;
339
-			}
340
-
341
-			$props[ $prop ] = $data[ $db_field ];
342
-		}
343
-
344
-		$invoice->set_props( $props );
345
-
346
-	}
347
-
348
-	/**
349
-	 * Gets a list of special fields that need updated based on change state
350
-	 * or if they are present in the database or not.
351
-	 *
352
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
353
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
-	 */
355
-	protected function get_special_fields_to_update( $invoice ) {
356
-		$fields_to_update = array();
357
-		$changed_props   = $invoice->get_changes();
358
-
359
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
360
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
-			if ( array_key_exists( $prop, $changed_props ) ) {
362
-				$fields_to_update[ $database_field ] = $prop;
363
-			}
364
-		}
365
-
366
-		return $fields_to_update;
367
-	}
368
-
369
-	/**
370
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
-	 *
372
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
-	 * @since 1.0.19
374
-	 */
375
-	protected function update_special_fields( &$invoice ) {
376
-		global $wpdb;
377
-
378
-		$updated_props    = array();
379
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
380
-
381
-		foreach ( $fields_to_update as $database_field => $prop ) {
382
-			$value = $invoice->{"get_$prop"}( 'edit' );
383
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
384
-			$value = is_bool( $value ) ? ( int ) $value : $value;
385
-			$updated_props[ $database_field ] = maybe_serialize( $value );
386
-		}
387
-
388
-		if ( ! empty( $updated_props ) ) {
389
-
390
-			$table = $wpdb->prefix . 'getpaid_invoices';
391
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
394
-
395
-		}
396
-
397
-	}
398
-
399
-	/**
400
-	 * Helper method that inserts special fields to the database.
401
-	 *
402
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
403
-	 * @since 1.0.19
404
-	 */
405
-	protected function insert_special_fields( &$invoice ) {
406
-		global $wpdb;
407
-
408
-		$updated_props   = array();
409
-
410
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
411
-			$value = $invoice->{"get_$prop"}( 'edit' );
412
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
413
-			$value = is_bool( $value ) ? ( int ) $value : $value;
414
-			$updated_props[ $database_field ] = maybe_serialize( $value );
415
-		}
416
-
417
-		$table = $wpdb->prefix . 'getpaid_invoices';
418
-		$wpdb->insert( $table, $updated_props );
419
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
420
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
421
-
422
-	}
423
-
424
-	/**
337
+            if ( $db_field == 'post_id' ) {
338
+                continue;
339
+            }
340
+
341
+            $props[ $prop ] = $data[ $db_field ];
342
+        }
343
+
344
+        $invoice->set_props( $props );
345
+
346
+    }
347
+
348
+    /**
349
+     * Gets a list of special fields that need updated based on change state
350
+     * or if they are present in the database or not.
351
+     *
352
+     * @param  WPInv_Invoice $invoice       The Invoice object.
353
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
+     */
355
+    protected function get_special_fields_to_update( $invoice ) {
356
+        $fields_to_update = array();
357
+        $changed_props   = $invoice->get_changes();
358
+
359
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
360
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
+            if ( array_key_exists( $prop, $changed_props ) ) {
362
+                $fields_to_update[ $database_field ] = $prop;
363
+            }
364
+        }
365
+
366
+        return $fields_to_update;
367
+    }
368
+
369
+    /**
370
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
+     *
372
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
+     * @since 1.0.19
374
+     */
375
+    protected function update_special_fields( &$invoice ) {
376
+        global $wpdb;
377
+
378
+        $updated_props    = array();
379
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
380
+
381
+        foreach ( $fields_to_update as $database_field => $prop ) {
382
+            $value = $invoice->{"get_$prop"}( 'edit' );
383
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
384
+            $value = is_bool( $value ) ? ( int ) $value : $value;
385
+            $updated_props[ $database_field ] = maybe_serialize( $value );
386
+        }
387
+
388
+        if ( ! empty( $updated_props ) ) {
389
+
390
+            $table = $wpdb->prefix . 'getpaid_invoices';
391
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
394
+
395
+        }
396
+
397
+    }
398
+
399
+    /**
400
+     * Helper method that inserts special fields to the database.
401
+     *
402
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
403
+     * @since 1.0.19
404
+     */
405
+    protected function insert_special_fields( &$invoice ) {
406
+        global $wpdb;
407
+
408
+        $updated_props   = array();
409
+
410
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
411
+            $value = $invoice->{"get_$prop"}( 'edit' );
412
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
413
+            $value = is_bool( $value ) ? ( int ) $value : $value;
414
+            $updated_props[ $database_field ] = maybe_serialize( $value );
415
+        }
416
+
417
+        $table = $wpdb->prefix . 'getpaid_invoices';
418
+        $wpdb->insert( $table, $updated_props );
419
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
420
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
421
+
422
+    }
423
+
424
+    /**
425 425
      * Saves all special fields.
426
-	 *
427
-	 * @param WPInv_Invoice $invoice Invoice object.
426
+     *
427
+     * @param WPInv_Invoice $invoice Invoice object.
428 428
      */
429 429
     public function save_special_fields( & $invoice ) {
430
-		global $wpdb;
430
+        global $wpdb;
431 431
 
432
-		// The invoices table.
433
-		$table = $wpdb->prefix . 'getpaid_invoices';
434
-		$id    = (int) $invoice->get_id();
435
-		$invoice->maybe_set_key();
432
+        // The invoices table.
433
+        $table = $wpdb->prefix . 'getpaid_invoices';
434
+        $id    = (int) $invoice->get_id();
435
+        $invoice->maybe_set_key();
436 436
 
437
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
437
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
438 438
 
439
-			$this->update_special_fields( $invoice );
439
+            $this->update_special_fields( $invoice );
440 440
 
441
-		} else {
441
+        } else {
442 442
 
443
-			$this->insert_special_fields( $invoice );
443
+            $this->insert_special_fields( $invoice );
444 444
 
445
-		}
445
+        }
446 446
 
447
-	}
447
+    }
448 448
 
449
-	/**
449
+    /**
450 450
      * Set's up cart details.
451
-	 *
452
-	 * @param WPInv_Invoice $invoice Invoice object.
451
+     *
452
+     * @param WPInv_Invoice $invoice Invoice object.
453 453
      */
454 454
     public function add_items( &$invoice ) {
455
-		global $wpdb;
455
+        global $wpdb;
456 456
 
457
-		// Maybe retrieve from the cache.
458
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
457
+        // Maybe retrieve from the cache.
458
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
459 459
 
460
-		// If not found, retrieve from the db.
461
-		if ( false === $items ) {
462
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
460
+        // If not found, retrieve from the db.
461
+        if ( false === $items ) {
462
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
463 463
 
464
-			$items = $wpdb->get_results(
465
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
466
-			);
464
+            $items = $wpdb->get_results(
465
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
466
+            );
467 467
 
468
-			// Update the cache with our data
469
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
468
+            // Update the cache with our data
469
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
470 470
 
471
-		}
471
+        }
472 472
 
473
-		// Abort if no items found.
473
+        // Abort if no items found.
474 474
         if ( empty( $items ) ) {
475 475
             return;
476
-		}
477
-
478
-		$_items = array();
479
-		foreach ( $items as $item_data ) {
480
-			$item = new GetPaid_Form_Item( $item_data->item_id );
481
-
482
-			// Set item data.
483
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
484
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
485
-			$item->set_name( $item_data->item_name );
486
-			$item->set_description( $item_data->item_description );
487
-			$item->set_price( $item_data->item_price );
488
-			$item->set_quantity( $item_data->quantity );
489
-			$item->set_item_meta( $item_data->meta );
490
-			$_items[] = $item;
491
-		}
492
-
493
-		$invoice->set_items( $_items );
494
-	}
495
-
496
-	/**
476
+        }
477
+
478
+        $_items = array();
479
+        foreach ( $items as $item_data ) {
480
+            $item = new GetPaid_Form_Item( $item_data->item_id );
481
+
482
+            // Set item data.
483
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
484
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
485
+            $item->set_name( $item_data->item_name );
486
+            $item->set_description( $item_data->item_description );
487
+            $item->set_price( $item_data->item_price );
488
+            $item->set_quantity( $item_data->quantity );
489
+            $item->set_item_meta( $item_data->meta );
490
+            $_items[] = $item;
491
+        }
492
+
493
+        $invoice->set_items( $_items );
494
+    }
495
+
496
+    /**
497 497
      * Saves cart details.
498
-	 *
499
-	 * @param WPInv_Invoice $invoice Invoice object.
498
+     *
499
+     * @param WPInv_Invoice $invoice Invoice object.
500 500
      */
501 501
     public function save_items( $invoice ) {
502 502
 
503
-		// Delete previously existing items.
504
-		$this->delete_items( $invoice );
503
+        // Delete previously existing items.
504
+        $this->delete_items( $invoice );
505 505
 
506
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
506
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
507 507
 
508
-		foreach ( $invoice->get_cart_details() as $item_data ) {
509
-			$item_data = array_map( 'maybe_serialize', $item_data );
510
-			$GLOBALS['wpdb']->insert( $table, $item_data );
511
-		}
508
+        foreach ( $invoice->get_cart_details() as $item_data ) {
509
+            $item_data = array_map( 'maybe_serialize', $item_data );
510
+            $GLOBALS['wpdb']->insert( $table, $item_data );
511
+        }
512 512
 
513
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
514
-		do_action( "getpaid_invoice_save_items", $invoice );
513
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
514
+        do_action( "getpaid_invoice_save_items", $invoice );
515 515
 
516
-	}
516
+    }
517 517
 
518
-	/**
518
+    /**
519 519
      * Deletes an invoice's cart details from the database.
520
-	 *
521
-	 * @param WPInv_Invoice $invoice Invoice object.
520
+     *
521
+     * @param WPInv_Invoice $invoice Invoice object.
522 522
      */
523 523
     public function delete_items( $invoice ) {
524
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
525
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
526
-	}
524
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
525
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
526
+    }
527 527
 
528
-	/**
528
+    /**
529 529
      * Deletes an invoice's special fields from the database.
530
-	 *
531
-	 * @param WPInv_Invoice $invoice Invoice object.
530
+     *
531
+     * @param WPInv_Invoice $invoice Invoice object.
532 532
      */
533 533
     public function delete_special_fields( $invoice ) {
534
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
535
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
536
-	}
534
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
535
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
536
+    }
537 537
 	
538
-	/**
539
-	 * Get the status to save to the post object.
540
-	 *
541
-	 *
542
-	 * @since 1.0.19
543
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
544
-	 * @return string
545
-	 */
546
-	protected function get_post_status( $object ) {
547
-		$object_status = $object->get_status( 'edit' );
548
-
549
-		if ( ! $object_status ) {
550
-			$object_status = $object->get_default_status();
551
-		}
552
-
553
-		return $object_status;
554
-	}
538
+    /**
539
+     * Get the status to save to the post object.
540
+     *
541
+     *
542
+     * @since 1.0.19
543
+     * @param  WPInv_Invoice $object GetPaid_Data object.
544
+     * @return string
545
+     */
546
+    protected function get_post_status( $object ) {
547
+        $object_status = $object->get_status( 'edit' );
548
+
549
+        if ( ! $object_status ) {
550
+            $object_status = $object->get_default_status();
551
+        }
552
+
553
+        return $object_status;
554
+    }
555 555
 
556 556
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-profile.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -5,110 +5,110 @@  discard block
 block discarded – undo
5 5
  */
6 6
 
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit; // Exit if accessed directly
8
+    exit; // Exit if accessed directly
9 9
 }
10 10
 
11 11
 if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) :
12 12
 
13
-	/**
14
-	 * GetPaid_Admin_Profile Class.
15
-	 */
16
-	class GetPaid_Admin_Profile {
17
-
18
-		/**
19
-		 * Hook in tabs.
20
-		 */
21
-		public function __construct() {
22
-			add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
-			add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
-
25
-			add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
-			add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
-		}
28
-
29
-		/**
30
-		 * Get Address Fields for the edit user pages.
31
-		 *
32
-		 * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
-		 */
34
-		public function get_customer_meta_fields() {
35
-
36
-			$show_fields = apply_filters(
37
-				'getpaid_customer_meta_fields',
38
-				array(
39
-					'billing'  => array(
40
-						'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
-						'fields' => array(
42
-							'_wpinv_first_name' => array(
43
-								'label'       => __( 'First name', 'invoicing' ),
44
-								'description' => '',
45
-							),
46
-							'_wpinv_last_name'  => array(
47
-								'label'       => __( 'Last name', 'invoicing' ),
48
-								'description' => '',
49
-							),
50
-							'_wpinv_company'    => array(
51
-								'label'       => __( 'Company', 'invoicing' ),
52
-								'description' => '',
53
-							),
54
-							'_wpinv_company_id'    => array(
55
-								'label'       => __( 'Company ID', 'invoicing' ),
56
-								'description' => '',
57
-							),
58
-							'_wpinv_address'  => array(
59
-								'label'       => __( 'Address', 'invoicing' ),
60
-								'description' => '',
61
-							),
62
-							'_wpinv_city'       => array(
63
-								'label'       => __( 'City', 'invoicing' ),
64
-								'description' => '',
65
-							),
66
-							'_wpinv_zip'   => array(
67
-								'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
-								'description' => '',
69
-							),
70
-							'_wpinv_country'    => array(
71
-								'label'       => __( 'Country / Region', 'invoicing' ),
72
-								'description' => '',
73
-								'class'       => 'getpaid_js_field-country',
74
-								'type'        => 'select',
75
-								'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
-							),
77
-							'_wpinv_state'      => array(
78
-								'label'       => __( 'State / County', 'invoicing' ),
79
-								'description' => __( 'State / County or state code', 'invoicing' ),
80
-								'class'       => 'getpaid_js_field-state regular-text',
81
-							),
82
-							'_wpinv_phone'      => array(
83
-								'label'       => __( 'Phone', 'invoicing' ),
84
-								'description' => '',
85
-							),
86
-							'_wpinv_vat_number'      => array(
87
-								'label'       => __( 'VAT Number', 'invoicing' ),
88
-								'description' => '',
89
-							),
90
-						),
91
-					),
92
-				)
93
-			);
94
-			return $show_fields;
95
-		}
96
-
97
-		/**
98
-		 * Show Address Fields on edit user pages.
99
-		 *
100
-		 * @param WP_User $user
101
-		 */
102
-		public function add_customer_meta_fields( $user ) {
103
-
104
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
-				return;
106
-			}
107
-
108
-			$show_fields = $this->get_customer_meta_fields();
109
-
110
-			foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
-				?>
13
+    /**
14
+     * GetPaid_Admin_Profile Class.
15
+     */
16
+    class GetPaid_Admin_Profile {
17
+
18
+        /**
19
+         * Hook in tabs.
20
+         */
21
+        public function __construct() {
22
+            add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
23
+            add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 );
24
+
25
+            add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
26
+            add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
27
+        }
28
+
29
+        /**
30
+         * Get Address Fields for the edit user pages.
31
+         *
32
+         * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned
33
+         */
34
+        public function get_customer_meta_fields() {
35
+
36
+            $show_fields = apply_filters(
37
+                'getpaid_customer_meta_fields',
38
+                array(
39
+                    'billing'  => array(
40
+                        'title'  => __( 'Billing Details (GetPaid)', 'invoicing' ),
41
+                        'fields' => array(
42
+                            '_wpinv_first_name' => array(
43
+                                'label'       => __( 'First name', 'invoicing' ),
44
+                                'description' => '',
45
+                            ),
46
+                            '_wpinv_last_name'  => array(
47
+                                'label'       => __( 'Last name', 'invoicing' ),
48
+                                'description' => '',
49
+                            ),
50
+                            '_wpinv_company'    => array(
51
+                                'label'       => __( 'Company', 'invoicing' ),
52
+                                'description' => '',
53
+                            ),
54
+                            '_wpinv_company_id'    => array(
55
+                                'label'       => __( 'Company ID', 'invoicing' ),
56
+                                'description' => '',
57
+                            ),
58
+                            '_wpinv_address'  => array(
59
+                                'label'       => __( 'Address', 'invoicing' ),
60
+                                'description' => '',
61
+                            ),
62
+                            '_wpinv_city'       => array(
63
+                                'label'       => __( 'City', 'invoicing' ),
64
+                                'description' => '',
65
+                            ),
66
+                            '_wpinv_zip'   => array(
67
+                                'label'       => __( 'Postcode / ZIP', 'invoicing' ),
68
+                                'description' => '',
69
+                            ),
70
+                            '_wpinv_country'    => array(
71
+                                'label'       => __( 'Country / Region', 'invoicing' ),
72
+                                'description' => '',
73
+                                'class'       => 'getpaid_js_field-country',
74
+                                'type'        => 'select',
75
+                                'options'     => array( '' => __( 'Select a country / region&hellip;', 'invoicing' ) ) + wpinv_get_country_list(),
76
+                            ),
77
+                            '_wpinv_state'      => array(
78
+                                'label'       => __( 'State / County', 'invoicing' ),
79
+                                'description' => __( 'State / County or state code', 'invoicing' ),
80
+                                'class'       => 'getpaid_js_field-state regular-text',
81
+                            ),
82
+                            '_wpinv_phone'      => array(
83
+                                'label'       => __( 'Phone', 'invoicing' ),
84
+                                'description' => '',
85
+                            ),
86
+                            '_wpinv_vat_number'      => array(
87
+                                'label'       => __( 'VAT Number', 'invoicing' ),
88
+                                'description' => '',
89
+                            ),
90
+                        ),
91
+                    ),
92
+                )
93
+            );
94
+            return $show_fields;
95
+        }
96
+
97
+        /**
98
+         * Show Address Fields on edit user pages.
99
+         *
100
+         * @param WP_User $user
101
+         */
102
+        public function add_customer_meta_fields( $user ) {
103
+
104
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) {
105
+                return;
106
+            }
107
+
108
+            $show_fields = $this->get_customer_meta_fields();
109
+
110
+            foreach ( $show_fields as $fieldset_key => $fieldset ) :
111
+                ?>
112 112
 				<h2><?php echo $fieldset['title']; ?></h2>
113 113
 				<table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>">
114 114
 					<?php foreach ( $fieldset['fields'] as $key => $field ) : ?>
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 								<?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?>
121 121
 									<select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;">
122 122
 										<?php
123
-											$selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
-										foreach ( $field['options'] as $option_key => $option_value ) :
125
-											?>
123
+                                            $selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
124
+                                        foreach ( $field['options'] as $option_key => $option_value ) :
125
+                                            ?>
126 126
 											<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option>
127 127
 										<?php endforeach; ?>
128 128
 									</select>
@@ -137,52 +137,52 @@  discard block
 block discarded – undo
137 137
 					<?php endforeach; ?>
138 138
 				</table>
139 139
 				<?php
140
-			endforeach;
141
-		}
142
-
143
-		/**
144
-		 * Save Address Fields on edit user pages.
145
-		 *
146
-		 * @param int $user_id User ID of the user being saved
147
-		 */
148
-		public function save_customer_meta_fields( $user_id ) {
149
-			if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
-				return;
151
-			}
152
-
153
-			$save_fields = $this->get_customer_meta_fields();
154
-
155
-			foreach ( $save_fields as $fieldset ) {
156
-
157
-				foreach ( $fieldset['fields'] as $key => $field ) {
158
-
159
-					if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
160
-						update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) );
161
-					} elseif ( isset( $_POST[ $key ] ) ) {
162
-						update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) );
163
-					}
164
-				}
165
-			}
166
-		}
167
-
168
-		/**
169
-		 * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
170
-		 *
171
-		 * @since 3.1.0
172
-		 * @param int    $user_id User ID of the user being edited
173
-		 * @param string $key     Key for user meta field
174
-		 * @return string
175
-		 */
176
-		protected function get_user_meta( $user_id, $key ) {
177
-			$value           = get_user_meta( $user_id, $key, true );
178
-			$existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
179
-			if ( ! $value && in_array( $key, $existing_fields ) ) {
180
-				$value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
181
-			}
182
-
183
-			return $value;
184
-		}
185
-	}
140
+            endforeach;
141
+        }
142
+
143
+        /**
144
+         * Save Address Fields on edit user pages.
145
+         *
146
+         * @param int $user_id User ID of the user being saved
147
+         */
148
+        public function save_customer_meta_fields( $user_id ) {
149
+            if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) {
150
+                return;
151
+            }
152
+
153
+            $save_fields = $this->get_customer_meta_fields();
154
+
155
+            foreach ( $save_fields as $fieldset ) {
156
+
157
+                foreach ( $fieldset['fields'] as $key => $field ) {
158
+
159
+                    if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
160
+                        update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) );
161
+                    } elseif ( isset( $_POST[ $key ] ) ) {
162
+                        update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) );
163
+                    }
164
+                }
165
+            }
166
+        }
167
+
168
+        /**
169
+         * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
170
+         *
171
+         * @since 3.1.0
172
+         * @param int    $user_id User ID of the user being edited
173
+         * @param string $key     Key for user meta field
174
+         * @return string
175
+         */
176
+        protected function get_user_meta( $user_id, $key ) {
177
+            $value           = get_user_meta( $user_id, $key, true );
178
+            $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' );
179
+            if ( ! $value && in_array( $key, $existing_fields ) ) {
180
+                $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true );
181
+            }
182
+
183
+            return $value;
184
+        }
185
+    }
186 186
 
187 187
 endif;
188 188
 
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-helper.php 1 patch
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,372 +11,372 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Helper {
13 13
 
14
-	/**
15
-	 * A component helper for generating a input name.
16
-	 *
17
-	 * @param $text
18
-	 * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
-	 *
20
-	 * @return string
21
-	 */
22
-	public static function name($text,$multiple = false){
23
-		$output = '';
24
-
25
-		if($text){
26
-			$is_multiple = strpos($text, '[') === false && $multiple  ? '[]' : '';
27
-			$output = ' name="'.esc_attr($text).$is_multiple.'" ';
28
-		}
29
-
30
-		return $output;
31
-	}
32
-
33
-	/**
34
-	 * A component helper for generating a item id.
35
-	 *
36
-	 * @param $text string The text to be used as the value.
37
-	 *
38
-	 * @return string The sanitized item.
39
-	 */
40
-	public static function id($text){
41
-		$output = '';
42
-
43
-		if($text){
44
-			$output = ' id="'.sanitize_html_class($text).'" ';
45
-		}
46
-
47
-		return $output;
48
-	}
49
-
50
-	/**
51
-	 * A component helper for generating a item title.
52
-	 *
53
-	 * @param $text string The text to be used as the value.
54
-	 *
55
-	 * @return string The sanitized item.
56
-	 */
57
-	public static function title($text){
58
-		$output = '';
59
-
60
-		if($text){
61
-			$output = ' title="'.esc_attr($text).'" ';
62
-		}
63
-
64
-		return $output;
65
-	}
66
-
67
-	/**
68
-	 * A component helper for generating a item value.
69
-	 *
70
-	 * @param $text string The text to be used as the value.
71
-	 *
72
-	 * @return string The sanitized item.
73
-	 */
74
-	public static function value( $text ) {
75
-		$output = '';
76
-
77
-		if ( $text !== null && $text !== false ) {
78
-			$output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
79
-		}
80
-
81
-		return $output;
82
-	}
83
-
84
-	/**
85
-	 * A component helper for generating a item class attribute.
86
-	 *
87
-	 * @param $text string The text to be used as the value.
88
-	 *
89
-	 * @return string The sanitized item.
90
-	 */
91
-	public static function class_attr($text){
92
-		$output = '';
93
-
94
-		if($text){
95
-			$classes = self::esc_classes($text);
96
-			if(!empty($classes)){
97
-				$output = ' class="'.$classes.'" ';
98
-			}
99
-		}
100
-
101
-		return $output;
102
-	}
103
-
104
-	/**
105
-	 * Escape a string of classes.
106
-	 *
107
-	 * @param $text
108
-	 *
109
-	 * @return string
110
-	 */
111
-	public static function esc_classes($text){
112
-		$output = '';
113
-
114
-		if($text){
115
-			$classes = explode(" ",$text);
116
-			$classes = array_map("trim",$classes);
117
-			$classes = array_map("sanitize_html_class",$classes);
118
-			if(!empty($classes)){
119
-				$output = implode(" ",$classes);
120
-			}
121
-		}
122
-
123
-		return $output;
124
-
125
-	}
126
-
127
-	/**
128
-	 * @param $args
129
-	 *
130
-	 * @return string
131
-	 */
132
-	public static function data_attributes($args){
133
-		$output = '';
134
-
135
-		if(!empty($args)){
136
-
137
-			foreach($args as $key => $val){
138
-				if(substr( $key, 0, 5 ) === "data-"){
139
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
140
-				}
141
-			}
142
-		}
143
-
144
-		return $output;
145
-	}
146
-
147
-	/**
148
-	 * @param $args
149
-	 *
150
-	 * @return string
151
-	 */
152
-	public static function aria_attributes($args){
153
-		$output = '';
154
-
155
-		if(!empty($args)){
156
-
157
-			foreach($args as $key => $val){
158
-				if(substr( $key, 0, 5 ) === "aria-"){
159
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
160
-				}
161
-			}
162
-		}
163
-
164
-		return $output;
165
-	}
166
-
167
-	/**
168
-	 * Build a font awesome icon from a class.
169
-	 *
170
-	 * @param $class
171
-	 * @param bool $space_after
172
-	 * @param array $extra_attributes An array of extra attributes.
173
-	 *
174
-	 * @return string
175
-	 */
176
-	public static function icon($class,$space_after = false, $extra_attributes = array()){
177
-		$output = '';
178
-
179
-		if($class){
180
-			$classes = self::esc_classes($class);
181
-			if(!empty($classes)){
182
-				$output = '<i class="'.$classes.'" ';
183
-				// extra attributes
184
-				if(!empty($extra_attributes)){
185
-					$output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186
-				}
187
-				$output .= '></i>';
188
-				if($space_after){
189
-					$output .= " ";
190
-				}
191
-			}
192
-		}
193
-
194
-		return $output;
195
-	}
196
-
197
-	/**
198
-	 * @param $args
199
-	 *
200
-	 * @return string
201
-	 */
202
-	public static function extra_attributes($args){
203
-		$output = '';
204
-
205
-		if(!empty($args)){
206
-
207
-			if( is_array($args) ){
208
-				foreach($args as $key => $val){
209
-					$output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
210
-				}
211
-			}else{
212
-				$output .= ' '.$args.' ';
213
-			}
214
-
215
-		}
216
-
217
-		return $output;
218
-	}
219
-
220
-	/**
221
-	 * @param $args
222
-	 *
223
-	 * @return string
224
-	 */
225
-	public static function help_text($text){
226
-		$output = '';
227
-
228
-		if($text){
229
-			$output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>';
230
-		}
231
-
232
-
233
-		return $output;
234
-	}
235
-
236
-	/**
237
-	 * Replace element require context with JS.
238
-	 *
239
-	 * @param $input
240
-	 *
241
-	 * @return string|void
242
-	 */
243
-	public static function element_require( $input ) {
244
-
245
-		$input = str_replace( "'", '"', $input );// we only want double quotes
246
-
247
-		$output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
-			"jQuery(form).find('[data-argument=\"",
249
-			"\"]').find('input,select,textarea').val()",
250
-			"\"]').find('input:checked').val()",
251
-		), $input ) );
252
-
253
-		if($output){
254
-			$output = ' data-element-require="'.$output.'" ';
255
-		}
256
-
257
-		return $output;
258
-	}
259
-
260
-	/**
261
-	 * Returns an array of allowed HTML tags and attributes for a given context.
262
-	 *
263
-	 * @since 0.1.41
264
-	 *
265
-	 * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
266
-	 *                              'strip', 'data', 'entities', or the name of a field filter such as
267
-	 *                              'pre_user_description'.
268
-	 * @param array $input Input.
269
-	 * @return array Array of allowed HTML tags and their allowed attributes.
270
-	 */
271
-	public static function kses_allowed_html( $context = 'post', $input = array() ) {
272
-		$allowed_html = wp_kses_allowed_html( $context );
273
-
274
-		if ( is_array( $allowed_html ) ) {
275
-			// <iframe>
276
-			if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
277
-				$allowed_html['iframe']     = array(
278
-					'class'        => true,
279
-					'id'           => true,
280
-					'src'          => true,
281
-					'width'        => true,
282
-					'height'       => true,
283
-					'frameborder'  => true,
284
-					'marginwidth'  => true,
285
-					'marginheight' => true,
286
-					'scrolling'    => true,
287
-					'style'        => true,
288
-					'title'        => true,
289
-					'allow'        => true,
290
-					'allowfullscreen' => true,
291
-					'data-*'       => true,
292
-				);
293
-			}
294
-		}
295
-
296
-		/**
297
-		 * Filters the allowed html tags.
298
-		 *
299
-		 * @since 0.1.41
300
-		 *
301
-		 * @param array[]|string $allowed_html Allowed html tags.
302
-		 * @param @param string|array $context The context for which to retrieve tags.
303
-		 * @param array $input Input field.
304
-		 */
305
-		return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
306
-	}
307
-
308
-	/**
309
-	 * Filters content and keeps only allowable HTML elements.
310
-	 *
311
-	 * This function makes sure that only the allowed HTML element names, attribute
312
-	 * names and attribute values plus only sane HTML entities will occur in
313
-	 * $string. You have to remove any slashes from PHP's magic quotes before you
314
-	 * call this function.
315
-	 *
316
-	 * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
317
-	 * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
318
-	 * covers all common link protocols, except for 'javascript' which should not
319
-	 * be allowed for untrusted users.
320
-	 *
321
-	 * @since 0.1.41
322
-	 *
323
-	 * @param string|array $value Content to filter through kses.
324
-	 * @param array  $input       Input Field.
325
-	 * @return string Filtered content with only allowed HTML elements.
326
-	 */
327
-	public static function _sanitize_html_field( $value, $input = array() ) {
328
-		if ( $value === '' ) {
329
-			return $value;
330
-		}
331
-
332
-		$allowed_html = self::kses_allowed_html( 'post', $input );
333
-
334
-		if ( ! is_array( $allowed_html ) ) {
335
-			$allowed_html = wp_kses_allowed_html( 'post' );
336
-		}
337
-
338
-		$filtered = trim( wp_unslash( $value ) );
339
-		$filtered = wp_kses( $filtered, $allowed_html );
340
-		$filtered = balanceTags( $filtered ); // Balances tags
341
-
342
-		return $filtered;
343
-	}
344
-
345
-	/**
346
-	 * Navigates through an array, object, or scalar, and removes slashes from the values.
347
-	 *
348
-	 * @since 0.1.41
349
-	 *
350
-	 * @param mixed $value The value to be stripped.
351
-	 * @param array  $input Input Field.
352
-	 * @return mixed Stripped value.
353
-	 */
354
-	public static function sanitize_html_field( $value, $input = array() ) {
355
-		$original = $value;
356
-
357
-		if ( is_array( $value ) ) {
358
-			foreach ( $value as $index => $item ) {
359
-				$value[ $index ] = self::_sanitize_html_field( $value, $input );
360
-			}
361
-		} elseif ( is_object( $value ) ) {
362
-			$object_vars = get_object_vars( $value );
363
-
364
-			foreach ( $object_vars as $property_name => $property_value ) {
365
-				$value->$property_name = self::_sanitize_html_field( $property_value, $input );
366
-			}
367
-		} else {
368
-			$value = self::_sanitize_html_field( $value, $input );
369
-		}
370
-
371
-		/**
372
-		 * Filters content and keeps only allowable HTML elements.
373
-		 *
374
-		 * @since 0.1.41
375
-		 *
376
-		 * @param string|array $value Content to filter through kses.
377
-		 * @param string|array $value Original content without filter.
378
-		 * @param array  $input       Input Field.
379
-		 */
380
-		return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
381
-	}
14
+    /**
15
+     * A component helper for generating a input name.
16
+     *
17
+     * @param $text
18
+     * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
+     *
20
+     * @return string
21
+     */
22
+    public static function name($text,$multiple = false){
23
+        $output = '';
24
+
25
+        if($text){
26
+            $is_multiple = strpos($text, '[') === false && $multiple  ? '[]' : '';
27
+            $output = ' name="'.esc_attr($text).$is_multiple.'" ';
28
+        }
29
+
30
+        return $output;
31
+    }
32
+
33
+    /**
34
+     * A component helper for generating a item id.
35
+     *
36
+     * @param $text string The text to be used as the value.
37
+     *
38
+     * @return string The sanitized item.
39
+     */
40
+    public static function id($text){
41
+        $output = '';
42
+
43
+        if($text){
44
+            $output = ' id="'.sanitize_html_class($text).'" ';
45
+        }
46
+
47
+        return $output;
48
+    }
49
+
50
+    /**
51
+     * A component helper for generating a item title.
52
+     *
53
+     * @param $text string The text to be used as the value.
54
+     *
55
+     * @return string The sanitized item.
56
+     */
57
+    public static function title($text){
58
+        $output = '';
59
+
60
+        if($text){
61
+            $output = ' title="'.esc_attr($text).'" ';
62
+        }
63
+
64
+        return $output;
65
+    }
66
+
67
+    /**
68
+     * A component helper for generating a item value.
69
+     *
70
+     * @param $text string The text to be used as the value.
71
+     *
72
+     * @return string The sanitized item.
73
+     */
74
+    public static function value( $text ) {
75
+        $output = '';
76
+
77
+        if ( $text !== null && $text !== false ) {
78
+            $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
79
+        }
80
+
81
+        return $output;
82
+    }
83
+
84
+    /**
85
+     * A component helper for generating a item class attribute.
86
+     *
87
+     * @param $text string The text to be used as the value.
88
+     *
89
+     * @return string The sanitized item.
90
+     */
91
+    public static function class_attr($text){
92
+        $output = '';
93
+
94
+        if($text){
95
+            $classes = self::esc_classes($text);
96
+            if(!empty($classes)){
97
+                $output = ' class="'.$classes.'" ';
98
+            }
99
+        }
100
+
101
+        return $output;
102
+    }
103
+
104
+    /**
105
+     * Escape a string of classes.
106
+     *
107
+     * @param $text
108
+     *
109
+     * @return string
110
+     */
111
+    public static function esc_classes($text){
112
+        $output = '';
113
+
114
+        if($text){
115
+            $classes = explode(" ",$text);
116
+            $classes = array_map("trim",$classes);
117
+            $classes = array_map("sanitize_html_class",$classes);
118
+            if(!empty($classes)){
119
+                $output = implode(" ",$classes);
120
+            }
121
+        }
122
+
123
+        return $output;
124
+
125
+    }
126
+
127
+    /**
128
+     * @param $args
129
+     *
130
+     * @return string
131
+     */
132
+    public static function data_attributes($args){
133
+        $output = '';
134
+
135
+        if(!empty($args)){
136
+
137
+            foreach($args as $key => $val){
138
+                if(substr( $key, 0, 5 ) === "data-"){
139
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
140
+                }
141
+            }
142
+        }
143
+
144
+        return $output;
145
+    }
146
+
147
+    /**
148
+     * @param $args
149
+     *
150
+     * @return string
151
+     */
152
+    public static function aria_attributes($args){
153
+        $output = '';
154
+
155
+        if(!empty($args)){
156
+
157
+            foreach($args as $key => $val){
158
+                if(substr( $key, 0, 5 ) === "aria-"){
159
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
160
+                }
161
+            }
162
+        }
163
+
164
+        return $output;
165
+    }
166
+
167
+    /**
168
+     * Build a font awesome icon from a class.
169
+     *
170
+     * @param $class
171
+     * @param bool $space_after
172
+     * @param array $extra_attributes An array of extra attributes.
173
+     *
174
+     * @return string
175
+     */
176
+    public static function icon($class,$space_after = false, $extra_attributes = array()){
177
+        $output = '';
178
+
179
+        if($class){
180
+            $classes = self::esc_classes($class);
181
+            if(!empty($classes)){
182
+                $output = '<i class="'.$classes.'" ';
183
+                // extra attributes
184
+                if(!empty($extra_attributes)){
185
+                    $output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186
+                }
187
+                $output .= '></i>';
188
+                if($space_after){
189
+                    $output .= " ";
190
+                }
191
+            }
192
+        }
193
+
194
+        return $output;
195
+    }
196
+
197
+    /**
198
+     * @param $args
199
+     *
200
+     * @return string
201
+     */
202
+    public static function extra_attributes($args){
203
+        $output = '';
204
+
205
+        if(!empty($args)){
206
+
207
+            if( is_array($args) ){
208
+                foreach($args as $key => $val){
209
+                    $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" ';
210
+                }
211
+            }else{
212
+                $output .= ' '.$args.' ';
213
+            }
214
+
215
+        }
216
+
217
+        return $output;
218
+    }
219
+
220
+    /**
221
+     * @param $args
222
+     *
223
+     * @return string
224
+     */
225
+    public static function help_text($text){
226
+        $output = '';
227
+
228
+        if($text){
229
+            $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>';
230
+        }
231
+
232
+
233
+        return $output;
234
+    }
235
+
236
+    /**
237
+     * Replace element require context with JS.
238
+     *
239
+     * @param $input
240
+     *
241
+     * @return string|void
242
+     */
243
+    public static function element_require( $input ) {
244
+
245
+        $input = str_replace( "'", '"', $input );// we only want double quotes
246
+
247
+        $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
+            "jQuery(form).find('[data-argument=\"",
249
+            "\"]').find('input,select,textarea').val()",
250
+            "\"]').find('input:checked').val()",
251
+        ), $input ) );
252
+
253
+        if($output){
254
+            $output = ' data-element-require="'.$output.'" ';
255
+        }
256
+
257
+        return $output;
258
+    }
259
+
260
+    /**
261
+     * Returns an array of allowed HTML tags and attributes for a given context.
262
+     *
263
+     * @since 0.1.41
264
+     *
265
+     * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
266
+     *                              'strip', 'data', 'entities', or the name of a field filter such as
267
+     *                              'pre_user_description'.
268
+     * @param array $input Input.
269
+     * @return array Array of allowed HTML tags and their allowed attributes.
270
+     */
271
+    public static function kses_allowed_html( $context = 'post', $input = array() ) {
272
+        $allowed_html = wp_kses_allowed_html( $context );
273
+
274
+        if ( is_array( $allowed_html ) ) {
275
+            // <iframe>
276
+            if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
277
+                $allowed_html['iframe']     = array(
278
+                    'class'        => true,
279
+                    'id'           => true,
280
+                    'src'          => true,
281
+                    'width'        => true,
282
+                    'height'       => true,
283
+                    'frameborder'  => true,
284
+                    'marginwidth'  => true,
285
+                    'marginheight' => true,
286
+                    'scrolling'    => true,
287
+                    'style'        => true,
288
+                    'title'        => true,
289
+                    'allow'        => true,
290
+                    'allowfullscreen' => true,
291
+                    'data-*'       => true,
292
+                );
293
+            }
294
+        }
295
+
296
+        /**
297
+         * Filters the allowed html tags.
298
+         *
299
+         * @since 0.1.41
300
+         *
301
+         * @param array[]|string $allowed_html Allowed html tags.
302
+         * @param @param string|array $context The context for which to retrieve tags.
303
+         * @param array $input Input field.
304
+         */
305
+        return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
306
+    }
307
+
308
+    /**
309
+     * Filters content and keeps only allowable HTML elements.
310
+     *
311
+     * This function makes sure that only the allowed HTML element names, attribute
312
+     * names and attribute values plus only sane HTML entities will occur in
313
+     * $string. You have to remove any slashes from PHP's magic quotes before you
314
+     * call this function.
315
+     *
316
+     * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
317
+     * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
318
+     * covers all common link protocols, except for 'javascript' which should not
319
+     * be allowed for untrusted users.
320
+     *
321
+     * @since 0.1.41
322
+     *
323
+     * @param string|array $value Content to filter through kses.
324
+     * @param array  $input       Input Field.
325
+     * @return string Filtered content with only allowed HTML elements.
326
+     */
327
+    public static function _sanitize_html_field( $value, $input = array() ) {
328
+        if ( $value === '' ) {
329
+            return $value;
330
+        }
331
+
332
+        $allowed_html = self::kses_allowed_html( 'post', $input );
333
+
334
+        if ( ! is_array( $allowed_html ) ) {
335
+            $allowed_html = wp_kses_allowed_html( 'post' );
336
+        }
337
+
338
+        $filtered = trim( wp_unslash( $value ) );
339
+        $filtered = wp_kses( $filtered, $allowed_html );
340
+        $filtered = balanceTags( $filtered ); // Balances tags
341
+
342
+        return $filtered;
343
+    }
344
+
345
+    /**
346
+     * Navigates through an array, object, or scalar, and removes slashes from the values.
347
+     *
348
+     * @since 0.1.41
349
+     *
350
+     * @param mixed $value The value to be stripped.
351
+     * @param array  $input Input Field.
352
+     * @return mixed Stripped value.
353
+     */
354
+    public static function sanitize_html_field( $value, $input = array() ) {
355
+        $original = $value;
356
+
357
+        if ( is_array( $value ) ) {
358
+            foreach ( $value as $index => $item ) {
359
+                $value[ $index ] = self::_sanitize_html_field( $value, $input );
360
+            }
361
+        } elseif ( is_object( $value ) ) {
362
+            $object_vars = get_object_vars( $value );
363
+
364
+            foreach ( $object_vars as $property_name => $property_value ) {
365
+                $value->$property_name = self::_sanitize_html_field( $property_value, $input );
366
+            }
367
+        } else {
368
+            $value = self::_sanitize_html_field( $value, $input );
369
+        }
370
+
371
+        /**
372
+         * Filters content and keeps only allowable HTML elements.
373
+         *
374
+         * @since 0.1.41
375
+         *
376
+         * @param string|array $value Content to filter through kses.
377
+         * @param string|array $value Original content without filter.
378
+         * @param array  $input       Input Field.
379
+         */
380
+        return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
381
+    }
382 382
 }
383 383
\ No newline at end of file
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -12,179 +12,179 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
125
+
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
131
+
132
+        $invoice = $submission->get_invoice();
133 133
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
138 138
 
139
-		return $invoice;
140
-	}
139
+        return $invoice;
140
+    }
141 141
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150 150
 
151
-		$submission = $this->payment_form_submission;
151
+        $submission = $this->payment_form_submission;
152 152
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field('wpi-gateway') );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field('wpi-gateway') );
162 162
 
163
-		$address_confirmed = $submission->get_field( 'confirm-address' );
164
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
163
+        $address_confirmed = $submission->get_field( 'confirm-address' );
164
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
165 165
 
166
-		if ( $submission->has_discount_code() ) {
166
+        if ( $submission->has_discount_code() ) {
167 167
             $invoice->set_discount_code( $submission->get_discount_code() );
168
-		}
169
-
170
-		getpaid_maybe_add_default_address( $invoice );
171
-		return $invoice;
172
-	}
173
-
174
-	/**
175
-	 * Retrieves the submission's customer.
176
-	 *
177
-	 * @return int The customer id.
178
-	 */
179
-	protected function get_submission_customer() {
180
-		$submission = $this->payment_form_submission;
181
-
182
-		// If this is an existing invoice...
183
-		if ( $submission->has_invoice() ) {
184
-			return $submission->get_invoice()->get_user_id();
185
-		}
186
-
187
-		// (Maybe) create the user.
168
+        }
169
+
170
+        getpaid_maybe_add_default_address( $invoice );
171
+        return $invoice;
172
+    }
173
+
174
+    /**
175
+     * Retrieves the submission's customer.
176
+     *
177
+     * @return int The customer id.
178
+     */
179
+    protected function get_submission_customer() {
180
+        $submission = $this->payment_form_submission;
181
+
182
+        // If this is an existing invoice...
183
+        if ( $submission->has_invoice() ) {
184
+            return $submission->get_invoice()->get_user_id();
185
+        }
186
+
187
+        // (Maybe) create the user.
188 188
         $user = get_current_user_id();
189 189
 
190 190
         if ( empty( $user ) ) {
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
         if ( empty( $user ) ) {
195 195
             $user = wpinv_create_user( $submission->get_billing_email() );
196 196
 
197
-			// (Maybe) send new user notification.
198
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
199
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
200
-				wp_send_new_user_notifications( $user, 'user' );
201
-			}
197
+            // (Maybe) send new user notification.
198
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
199
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
200
+                wp_send_new_user_notifications( $user, 'user' );
201
+            }
202 202
 
203 203
         }
204 204
 
@@ -208,34 +208,34 @@  discard block
 block discarded – undo
208 208
 
209 209
         if ( is_numeric( $user ) ) {
210 210
             return $user;
211
-		}
211
+        }
212 212
 
213
-		return $user->ID;
213
+        return $user->ID;
214 214
 
215
-	}
215
+    }
216 216
 
217
-	/**
217
+    /**
218 218
      * Prepares submission data for saving to the database.
219 219
      *
220
-	 * @return array
220
+     * @return array
221 221
      */
222 222
     public function prepare_submission_data_for_saving() {
223 223
 
224
-		$submission = $this->payment_form_submission;
224
+        $submission = $this->payment_form_submission;
225 225
 
226
-		// Prepared submission details.
226
+        // Prepared submission details.
227 227
         $prepared = array(
228
-			'all'  => array(),
229
-			'meta' => array(),
230
-		);
228
+            'all'  => array(),
229
+            'meta' => array(),
230
+        );
231 231
 
232 232
         // Raw submission details.
233
-		$data     = $submission->get_data();
233
+        $data     = $submission->get_data();
234 234
 
235
-		// Loop through the submitted details.
235
+        // Loop through the submitted details.
236 236
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
237 237
 
238
-			// Skip premade fields.
238
+            // Skip premade fields.
239 239
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
240 240
                 continue;
241 241
             }
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
             // Handle misc fields.
249 249
             if ( isset( $data[ $field['id'] ] ) ) {
250 250
 
251
-				if ( $field['type'] == 'checkbox' ) {
252
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
253
-				} else {
254
-					$value = wp_kses_post( $data[ $field['id'] ] );
255
-				}
251
+                if ( $field['type'] == 'checkbox' ) {
252
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
253
+                } else {
254
+                    $value = wp_kses_post( $data[ $field['id'] ] );
255
+                }
256 256
 
257 257
                 $label = $field['id'];
258 258
 
@@ -260,189 +260,189 @@  discard block
 block discarded – undo
260 260
                     $label = $field['label'];
261 261
                 }
262 262
 
263
-				if ( ! empty( $field['add_meta'] ) ) {
264
-					$prepared['meta'][ wpinv_clean( $label ) ] = $value;
265
-				}
266
-				$prepared['all'][ wpinv_clean( $label ) ] = $value;
263
+                if ( ! empty( $field['add_meta'] ) ) {
264
+                    $prepared['meta'][ wpinv_clean( $label ) ] = $value;
265
+                }
266
+                $prepared['all'][ wpinv_clean( $label ) ] = $value;
267 267
 
268 268
             }
269 269
 
270
-		}
270
+        }
271 271
 
272
-		return $prepared;
272
+        return $prepared;
273 273
 
274
-	}
274
+    }
275 275
 
276
-	/**
276
+    /**
277 277
      * Retrieves address details.
278 278
      *
279
-	 * @return array
280
-	 * @param WPInv_Invoice $invoice
281
-	 * @param string $type
279
+     * @return array
280
+     * @param WPInv_Invoice $invoice
281
+     * @param string $type
282 282
      */
283 283
     public function prepare_address_details( $invoice, $type = 'billing' ) {
284 284
 
285
-		$data     = $this->payment_form_submission->get_data();
286
-		$type     = sanitize_key( $type );
287
-		$address  = array();
288
-		$prepared = array();
285
+        $data     = $this->payment_form_submission->get_data();
286
+        $type     = sanitize_key( $type );
287
+        $address  = array();
288
+        $prepared = array();
289 289
 
290
-		if ( ! empty( $data[ $type ] ) ) {
291
-			$address = $data[ $type ];
292
-		}
290
+        if ( ! empty( $data[ $type ] ) ) {
291
+            $address = $data[ $type ];
292
+        }
293 293
 
294
-		// Clean address details.
295
-		foreach ( $address as $key => $value ) {
296
-			$key             = sanitize_key( $key );
297
-			$key             = str_replace( 'wpinv_', '', $key );
298
-			$value           = wpinv_clean( $value );
299
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
300
-		}
294
+        // Clean address details.
295
+        foreach ( $address as $key => $value ) {
296
+            $key             = sanitize_key( $key );
297
+            $key             = str_replace( 'wpinv_', '', $key );
298
+            $value           = wpinv_clean( $value );
299
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
300
+        }
301 301
 
302
-		// Filter address details.
303
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
302
+        // Filter address details.
303
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
304 304
 
305
-		// Remove non-whitelisted values.
306
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
305
+        // Remove non-whitelisted values.
306
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
307 307
 
308
-	}
308
+    }
309 309
 
310
-	/**
310
+    /**
311 311
      * Prepares the billing details.
312 312
      *
313
-	 * @return array
314
-	 * @param WPInv_Invoice $invoice
313
+     * @return array
314
+     * @param WPInv_Invoice $invoice
315 315
      */
316 316
     protected function prepare_billing_info( &$invoice ) {
317 317
 
318
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
318
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
319 319
 
320
-		// Update the invoice with the billing details.
321
-		$invoice->set_props( $billing_address );
320
+        // Update the invoice with the billing details.
321
+        $invoice->set_props( $billing_address );
322 322
 
323
-	}
323
+    }
324 324
 
325
-	/**
325
+    /**
326 326
      * Prepares the shipping details.
327 327
      *
328
-	 * @return array
329
-	 * @param WPInv_Invoice $invoice
328
+     * @return array
329
+     * @param WPInv_Invoice $invoice
330 330
      */
331 331
     protected function prepare_shipping_info( $invoice ) {
332 332
 
333
-		$data = $this->payment_form_submission->get_data();
333
+        $data = $this->payment_form_submission->get_data();
334 334
 
335
-		if ( empty( $data['same-shipping-address'] ) ) {
336
-			return $this->prepare_address_details( $invoice, 'shipping' );
337
-		}
335
+        if ( empty( $data['same-shipping-address'] ) ) {
336
+            return $this->prepare_address_details( $invoice, 'shipping' );
337
+        }
338 338
 
339
-		return $this->prepare_address_details( $invoice, 'billing' );
339
+        return $this->prepare_address_details( $invoice, 'billing' );
340 340
 
341
-	}
341
+    }
342 342
 
343
-	/**
344
-	 * Confirms the submission is valid and send users to the gateway.
345
-	 *
346
-	 * @param WPInv_Invoice $invoice
347
-	 * @param array $prepared_payment_form_data
348
-	 * @param array $shipping
349
-	 */
350
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
343
+    /**
344
+     * Confirms the submission is valid and send users to the gateway.
345
+     *
346
+     * @param WPInv_Invoice $invoice
347
+     * @param array $prepared_payment_form_data
348
+     * @param array $shipping
349
+     */
350
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
351 351
 
352
-		// Ensure the invoice exists.
352
+        // Ensure the invoice exists.
353 353
         if ( ! $invoice->exists() ) {
354 354
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
355 355
         }
356 356
 
357
-		// Save payment form data.
358
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
357
+        // Save payment form data.
358
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
359 359
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
360
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
361
-		if ( ! empty( $prepared_payment_form_data ) ) {
360
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
361
+        if ( ! empty( $prepared_payment_form_data ) ) {
362 362
 
363
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
364
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
365
-			}
363
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
364
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
365
+            }
366 366
 
367
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
368
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
369
-			}
367
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
368
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
369
+            }
370 370
 
371
-		}
371
+        }
372 372
 
373
-		// Save payment form data.
373
+        // Save payment form data.
374 374
         if ( ! empty( $shipping ) ) {
375 375
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
376
-		}
376
+        }
377 377
 
378
-		// Backwards compatibility.
378
+        // Backwards compatibility.
379 379
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
380 380
 
381
-		$this->process_payment( $invoice );
381
+        $this->process_payment( $invoice );
382 382
 
383 383
         // If we are here, there was an error.
384
-		wpinv_send_back_to_checkout( $invoice );
384
+        wpinv_send_back_to_checkout( $invoice );
385 385
 
386
-	}
386
+    }
387 387
 
388
-	/**
389
-	 * Processes the actual payment.
390
-	 *
391
-	 * @param WPInv_Invoice $invoice
392
-	 */
393
-	protected function process_payment( $invoice ) {
388
+    /**
389
+     * Processes the actual payment.
390
+     *
391
+     * @param WPInv_Invoice $invoice
392
+     */
393
+    protected function process_payment( $invoice ) {
394 394
 
395
-		// Clear any checkout errors.
396
-		wpinv_clear_errors();
395
+        // Clear any checkout errors.
396
+        wpinv_clear_errors();
397 397
 
398
-		// No need to send free invoices to the gateway.
399
-		if ( $invoice->is_free() ) {
400
-			$this->process_free_payment( $invoice );
401
-		}
398
+        // No need to send free invoices to the gateway.
399
+        if ( $invoice->is_free() ) {
400
+            $this->process_free_payment( $invoice );
401
+        }
402 402
 
403
-		$submission = $this->payment_form_submission;
403
+        $submission = $this->payment_form_submission;
404 404
 
405
-		// Fires before sending to the gateway.
406
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
405
+        // Fires before sending to the gateway.
406
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
407 407
 
408
-		// Allow the sumission data to be modified before it is sent to the gateway.
409
-		$submission_data    = $submission->get_data();
410
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
411
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
408
+        // Allow the sumission data to be modified before it is sent to the gateway.
409
+        $submission_data    = $submission->get_data();
410
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
411
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
412 412
 
413
-		// Validate the currency.
414
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
415
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
416
-		}
413
+        // Validate the currency.
414
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
415
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
416
+        }
417 417
 
418
-		// Check to see if we have any errors.
419
-		if ( wpinv_get_errors() ) {
420
-			wpinv_send_back_to_checkout( $invoice );
421
-		}
418
+        // Check to see if we have any errors.
419
+        if ( wpinv_get_errors() ) {
420
+            wpinv_send_back_to_checkout( $invoice );
421
+        }
422 422
 
423
-		// Send info to the gateway for payment processing
424
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
423
+        // Send info to the gateway for payment processing
424
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
425 425
 
426
-		// Backwards compatibility.
427
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
426
+        // Backwards compatibility.
427
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
428 428
 
429
-	}
429
+    }
430 430
 
431
-	/**
432
-	 * Marks the invoice as paid in case the checkout is free.
433
-	 *
434
-	 * @param WPInv_Invoice $invoice
435
-	 */
436
-	protected function process_free_payment( $invoice ) {
431
+    /**
432
+     * Marks the invoice as paid in case the checkout is free.
433
+     *
434
+     * @param WPInv_Invoice $invoice
435
+     */
436
+    protected function process_free_payment( $invoice ) {
437 437
 
438
-		$invoice->set_gateway( 'none' );
439
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
440
-		$invoice->mark_paid();
441
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
438
+        $invoice->set_gateway( 'none' );
439
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
440
+        $invoice->mark_paid();
441
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
442 442
 
443
-	}
443
+    }
444 444
 
445
-	/**
445
+    /**
446 446
      * Sends a redrect response to payment details.
447 447
      *
448 448
      */
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +700 added lines, -700 removed lines patch added patch discarded remove patch
@@ -13,703 +13,703 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
-
36
-		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
-
44
-		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
-
49
-		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
-
53
-		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
-
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
-	}
59
-
60
-	/**
61
-	 * Post updated messages.
62
-	 */
63
-	public static function post_updated_messages( $messages ) {
64
-		global $post;
65
-
66
-		$messages['wpi_discount'] = array(
67
-			0   => '',
68
-			1   => __( 'Discount updated.', 'invoicing' ),
69
-			2   => __( 'Custom field updated.', 'invoicing' ),
70
-			3   => __( 'Custom field deleted.', 'invoicing' ),
71
-			4   => __( 'Discount updated.', 'invoicing' ),
72
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6   => __( 'Discount updated.', 'invoicing' ),
74
-			7   => __( 'Discount saved.', 'invoicing' ),
75
-			8   => __( 'Discount submitted.', 'invoicing' ),
76
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10  => __( 'Discount draft updated.', 'invoicing' ),
78
-		);
79
-
80
-		$messages['wpi_payment_form'] = array(
81
-			0   => '',
82
-			1   => __( 'Payment Form updated.', 'invoicing' ),
83
-			2   => __( 'Custom field updated.', 'invoicing' ),
84
-			3   => __( 'Custom field deleted.', 'invoicing' ),
85
-			4   => __( 'Payment Form updated.', 'invoicing' ),
86
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6   => __( 'Payment Form updated.', 'invoicing' ),
88
-			7   => __( 'Payment Form saved.', 'invoicing' ),
89
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
92
-		);
93
-
94
-		return $messages;
95
-
96
-	}
97
-
98
-	/**
99
-	 * Post row actions.
100
-	 */
101
-	public static function post_row_actions( $actions, $post ) {
102
-
103
-		$post = get_post( $post );
104
-
105
-		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
107
-
108
-			if ( $post->ID == wpinv_get_default_payment_form() ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
111
-			}
112
-
113
-			$actions['duplicate'] =  sprintf(
114
-				'<a href="%1$s">%2$s</a>',
115
-				esc_url(
116
-					wp_nonce_url(
117
-						add_query_arg(
118
-							array(
119
-								'getpaid-admin-action' => 'duplicate_form',
120
-								'form_id'              => $post->ID
121
-							)
122
-						),
123
-						'getpaid-nonce',
124
-						'getpaid-nonce'
125
-					)
126
-				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
128
-			);
129
-
130
-		}
131
-
132
-		return $actions;
133
-	}
134
-
135
-	/**
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
19
+
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
22
+
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
+
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+        add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
+        add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
+
36
+        // Items table columns.
37
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
+
44
+        // Payment forms columns.
45
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
+
49
+        // Discount table columns.
50
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
+
53
+        // Deleting posts.
54
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
+
57
+        add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
+    }
59
+
60
+    /**
61
+     * Post updated messages.
62
+     */
63
+    public static function post_updated_messages( $messages ) {
64
+        global $post;
65
+
66
+        $messages['wpi_discount'] = array(
67
+            0   => '',
68
+            1   => __( 'Discount updated.', 'invoicing' ),
69
+            2   => __( 'Custom field updated.', 'invoicing' ),
70
+            3   => __( 'Custom field deleted.', 'invoicing' ),
71
+            4   => __( 'Discount updated.', 'invoicing' ),
72
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
+            6   => __( 'Discount updated.', 'invoicing' ),
74
+            7   => __( 'Discount saved.', 'invoicing' ),
75
+            8   => __( 'Discount submitted.', 'invoicing' ),
76
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
+            10  => __( 'Discount draft updated.', 'invoicing' ),
78
+        );
79
+
80
+        $messages['wpi_payment_form'] = array(
81
+            0   => '',
82
+            1   => __( 'Payment Form updated.', 'invoicing' ),
83
+            2   => __( 'Custom field updated.', 'invoicing' ),
84
+            3   => __( 'Custom field deleted.', 'invoicing' ),
85
+            4   => __( 'Payment Form updated.', 'invoicing' ),
86
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
+            6   => __( 'Payment Form updated.', 'invoicing' ),
88
+            7   => __( 'Payment Form saved.', 'invoicing' ),
89
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
90
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
92
+        );
93
+
94
+        return $messages;
95
+
96
+    }
97
+
98
+    /**
99
+     * Post row actions.
100
+     */
101
+    public static function post_row_actions( $actions, $post ) {
102
+
103
+        $post = get_post( $post );
104
+
105
+        // We do not want to edit the default payment form.
106
+        if ( 'wpi_payment_form' == $post->post_type ) {
107
+
108
+            if ( $post->ID == wpinv_get_default_payment_form() ) {
109
+                unset( $actions['trash'] );
110
+                unset( $actions['inline hide-if-no-js'] );
111
+            }
112
+
113
+            $actions['duplicate'] =  sprintf(
114
+                '<a href="%1$s">%2$s</a>',
115
+                esc_url(
116
+                    wp_nonce_url(
117
+                        add_query_arg(
118
+                            array(
119
+                                'getpaid-admin-action' => 'duplicate_form',
120
+                                'form_id'              => $post->ID
121
+                            )
122
+                        ),
123
+                        'getpaid-nonce',
124
+                        'getpaid-nonce'
125
+                    )
126
+                ),
127
+                esc_html( __( 'Duplicate', 'invoicing' ) )
128
+            );
129
+
130
+        }
131
+
132
+        return $actions;
133
+    }
134
+
135
+    /**
136 136
      * Remove bulk edit option from admin side quote listing
137 137
      *
138 138
      * @since    1.0.0
139 139
      * @param array $actions post actions
140
-	 * @param WP_Post $post
140
+     * @param WP_Post $post
141 141
      * @return array $actions actions without edit option
142 142
      */
143 143
     public static function filter_invoice_row_actions( $actions, $post ) {
144 144
 
145 145
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
146 146
 
147
-			$actions = array();
148
-			$invoice = new WPInv_Invoice( $post );
149
-
150
-			$actions['edit'] =  sprintf(
151
-				'<a href="%1$s">%2$s</a>',
152
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
153
-				esc_html( __( 'Edit', 'invoicing' ) )
154
-			);
155
-
156
-			if ( ! $invoice->is_draft() ) {
157
-
158
-				$actions['view'] =  sprintf(
159
-					'<a href="%1$s">%2$s</a>',
160
-					esc_url( $invoice->get_view_url() ),
161
-					sprintf(
162
-						esc_html( __( 'View %s', 'invoicing' ) ),
163
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
164
-					)
165
-				);
166
-
167
-				$actions['send'] =  sprintf(
168
-					'<a href="%1$s">%2$s</a>',
169
-					esc_url(
170
-						wp_nonce_url(
171
-							add_query_arg(
172
-								array(
173
-									'getpaid-admin-action' => 'send_invoice',
174
-									'invoice_id'           => $invoice->get_id()
175
-								)
176
-							),
177
-							'getpaid-nonce',
178
-							'getpaid-nonce'
179
-						)
180
-					),
181
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
182
-				);
183
-
184
-			}
147
+            $actions = array();
148
+            $invoice = new WPInv_Invoice( $post );
149
+
150
+            $actions['edit'] =  sprintf(
151
+                '<a href="%1$s">%2$s</a>',
152
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
153
+                esc_html( __( 'Edit', 'invoicing' ) )
154
+            );
155
+
156
+            if ( ! $invoice->is_draft() ) {
157
+
158
+                $actions['view'] =  sprintf(
159
+                    '<a href="%1$s">%2$s</a>',
160
+                    esc_url( $invoice->get_view_url() ),
161
+                    sprintf(
162
+                        esc_html( __( 'View %s', 'invoicing' ) ),
163
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
164
+                    )
165
+                );
166
+
167
+                $actions['send'] =  sprintf(
168
+                    '<a href="%1$s">%2$s</a>',
169
+                    esc_url(
170
+                        wp_nonce_url(
171
+                            add_query_arg(
172
+                                array(
173
+                                    'getpaid-admin-action' => 'send_invoice',
174
+                                    'invoice_id'           => $invoice->get_id()
175
+                                )
176
+                            ),
177
+                            'getpaid-nonce',
178
+                            'getpaid-nonce'
179
+                        )
180
+                    ),
181
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
182
+                );
183
+
184
+            }
185 185
 
186 186
         }
187 187
 
188 188
         return $actions;
189
-	}
190
-
191
-	/**
192
-	 * Returns an array of invoice table columns.
193
-	 */
194
-	public static function invoice_columns( $columns ) {
195
-
196
-		$columns = array(
197
-			'cb'                => $columns['cb'],
198
-			'number'            => __( 'Invoice', 'invoicing' ),
199
-			'customer'          => __( 'Customer', 'invoicing' ),
200
-			'invoice_date'      => __( 'Created', 'invoicing' ),
201
-			'payment_date'      => __( 'Completed', 'invoicing' ),
202
-			'amount'            => __( 'Amount', 'invoicing' ),
203
-			'recurring'         => __( 'Recurring', 'invoicing' ),
204
-			'status'            => __( 'Status', 'invoicing' ),
205
-		);
206
-
207
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
208
-	}
209
-
210
-	/**
211
-	 * Displays invoice table columns.
212
-	 */
213
-	public static function display_invoice_columns( $column_name, $post_id ) {
214
-
215
-		$invoice = new WPInv_Invoice( $post_id );
216
-
217
-		switch ( $column_name ) {
218
-
219
-			case 'invoice_date' :
220
-				$date_time = esc_attr( $invoice->get_created_date() );
221
-				$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
222
-				echo "<span title='$date_time'>$date</span>";
223
-				break;
224
-
225
-			case 'payment_date' :
226
-
227
-				if ( $invoice->is_paid() ) {
228
-					$date_time = esc_attr( $invoice->get_completed_date() );
229
-					$date      = getpaid_format_date_value( $date_time, "&mdash;", true );
230
-					echo "<span title='$date_time'>$date</span>";
231
-				} else {
232
-					echo "&mdash;";
233
-				}
189
+    }
190
+
191
+    /**
192
+     * Returns an array of invoice table columns.
193
+     */
194
+    public static function invoice_columns( $columns ) {
195
+
196
+        $columns = array(
197
+            'cb'                => $columns['cb'],
198
+            'number'            => __( 'Invoice', 'invoicing' ),
199
+            'customer'          => __( 'Customer', 'invoicing' ),
200
+            'invoice_date'      => __( 'Created', 'invoicing' ),
201
+            'payment_date'      => __( 'Completed', 'invoicing' ),
202
+            'amount'            => __( 'Amount', 'invoicing' ),
203
+            'recurring'         => __( 'Recurring', 'invoicing' ),
204
+            'status'            => __( 'Status', 'invoicing' ),
205
+        );
206
+
207
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
208
+    }
209
+
210
+    /**
211
+     * Displays invoice table columns.
212
+     */
213
+    public static function display_invoice_columns( $column_name, $post_id ) {
214
+
215
+        $invoice = new WPInv_Invoice( $post_id );
216
+
217
+        switch ( $column_name ) {
218
+
219
+            case 'invoice_date' :
220
+                $date_time = esc_attr( $invoice->get_created_date() );
221
+                $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
222
+                echo "<span title='$date_time'>$date</span>";
223
+                break;
224
+
225
+            case 'payment_date' :
226
+
227
+                if ( $invoice->is_paid() ) {
228
+                    $date_time = esc_attr( $invoice->get_completed_date() );
229
+                    $date      = getpaid_format_date_value( $date_time, "&mdash;", true );
230
+                    echo "<span title='$date_time'>$date</span>";
231
+                } else {
232
+                    echo "&mdash;";
233
+                }
234 234
 				
235
-				break;
235
+                break;
236 236
 
237
-			case 'amount' :
237
+            case 'amount' :
238 238
 
239
-				$amount = $invoice->get_total();
240
-				$formated_amount = wpinv_price( $amount, $invoice->get_currency() );
239
+                $amount = $invoice->get_total();
240
+                $formated_amount = wpinv_price( $amount, $invoice->get_currency() );
241 241
 
242
-				if ( $invoice->is_refunded() ) {
243
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
244
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
245
-				} else {
242
+                if ( $invoice->is_refunded() ) {
243
+                    $refunded_amount = wpinv_price( 0, $invoice->get_currency() );
244
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
245
+                } else {
246 246
 
247
-					$discount = $invoice->get_total_discount();
247
+                    $discount = $invoice->get_total_discount();
248 248
 
249
-					if ( ! empty( $discount ) ) {
250
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
251
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
252
-					} else {
253
-						echo $formated_amount;
254
-					}
249
+                    if ( ! empty( $discount ) ) {
250
+                        $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
251
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
252
+                    } else {
253
+                        echo $formated_amount;
254
+                    }
255 255
 
256
-				}
256
+                }
257 257
 
258
-				break;
258
+                break;
259 259
 
260
-			case 'status' :
261
-				$status       = sanitize_text_field( $invoice->get_status() );
262
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
260
+            case 'status' :
261
+                $status       = sanitize_text_field( $invoice->get_status() );
262
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
263 263
 
264
-				// If it is paid, show the gateway title.
265
-				if ( $invoice->is_paid() ) {
266
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
267
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
264
+                // If it is paid, show the gateway title.
265
+                if ( $invoice->is_paid() ) {
266
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
267
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
268 268
 
269
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
270
-				} else {
271
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
272
-				}
269
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
270
+                } else {
271
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
272
+                }
273 273
 
274
-				// If it is not paid, display the overdue and view status.
275
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
274
+                // If it is not paid, display the overdue and view status.
275
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
276 276
 
277
-					// Invoice view status.
278
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
279
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
280
-					} else {
281
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
282
-					}
277
+                    // Invoice view status.
278
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
279
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
280
+                    } else {
281
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
282
+                    }
283 283
 
284
-					// Display the overview status.
285
-					if ( wpinv_get_option( 'overdue_active' ) ) {
286
-						$due_date = $invoice->get_due_date();
287
-						$fomatted = getpaid_format_date( $due_date );
284
+                    // Display the overview status.
285
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
286
+                        $due_date = $invoice->get_due_date();
287
+                        $fomatted = getpaid_format_date( $due_date );
288 288
 
289
-						if ( ! empty( $fomatted ) ) {
290
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
291
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
292
-						}
293
-					}
289
+                        if ( ! empty( $fomatted ) ) {
290
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
291
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
292
+                        }
293
+                    }
294 294
 
295
-				}
295
+                }
296 296
 
297
-				break;
297
+                break;
298 298
 
299
-			case 'recurring':
299
+            case 'recurring':
300 300
 
301
-				if ( $invoice->is_recurring() ) {
302
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
303
-				} else {
304
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
305
-				}
306
-				break;
301
+                if ( $invoice->is_recurring() ) {
302
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
303
+                } else {
304
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
305
+                }
306
+                break;
307 307
 
308
-			case 'number' :
308
+            case 'number' :
309 309
 
310
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
311
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
312
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
310
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
311
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
312
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
313 313
 
314
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
314
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
315 315
 
316
-				break;
316
+                break;
317 317
 
318
-			case 'customer' :
318
+            case 'customer' :
319 319
 	
320
-				$customer_name = $invoice->get_user_full_name();
320
+                $customer_name = $invoice->get_user_full_name();
321 321
 	
322
-				if ( empty( $customer_name ) ) {
323
-					$customer_name = $invoice->get_email();
324
-				}
322
+                if ( empty( $customer_name ) ) {
323
+                    $customer_name = $invoice->get_email();
324
+                }
325 325
 	
326
-				if ( ! empty( $customer_name ) ) {
327
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
328
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
329
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
330
-				} else {
331
-					echo '<div>&mdash;</div>';
332
-				}
326
+                if ( ! empty( $customer_name ) ) {
327
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
328
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
329
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
330
+                } else {
331
+                    echo '<div>&mdash;</div>';
332
+                }
333 333
 
334
-				break;
334
+                break;
335 335
 
336
-		}
336
+        }
337 337
 
338
-	}
338
+    }
339 339
 
340
-	/**
341
-	 * Displays invoice bulk actions.
342
-	 */
343
-	public static function invoice_bulk_actions( $actions ) {
344
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
345
-		return $actions;
346
-	}
340
+    /**
341
+     * Displays invoice bulk actions.
342
+     */
343
+    public static function invoice_bulk_actions( $actions ) {
344
+        $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
345
+        return $actions;
346
+    }
347 347
 
348
-	/**
349
-	 * Processes invoice bulk actions.
350
-	 */
351
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
348
+    /**
349
+     * Processes invoice bulk actions.
350
+     */
351
+    public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
352 352
 
353
-		if ( $action == 'resend-invoice' ) {
353
+        if ( $action == 'resend-invoice' ) {
354 354
 
355
-			$success = false;
356
-			foreach ( $post_ids as $post_id ) {
357
-				$success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
358
-			}
355
+            $success = false;
356
+            foreach ( $post_ids as $post_id ) {
357
+                $success = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
358
+            }
359 359
 
360
-			if ( $success ) {
361
-				getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) );
362
-			} else {
363
-				getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) );
364
-			}
360
+            if ( $success ) {
361
+                getpaid_admin()->show_success( __( 'Invoices were successfully sent', 'invoicing' ) );
362
+            } else {
363
+                getpaid_admin()->show_error( __( 'Could not send some invoices', 'invoicing' ) );
364
+            }
365 365
 
366
-		}
366
+        }
367 367
 
368
-		return $redirect_url;
368
+        return $redirect_url;
369 369
 
370
-	}
370
+    }
371 371
 
372
-	/**
373
-	 * Returns an array of payment forms table columns.
374
-	 */
375
-	public static function payment_form_columns( $columns ) {
372
+    /**
373
+     * Returns an array of payment forms table columns.
374
+     */
375
+    public static function payment_form_columns( $columns ) {
376 376
 
377
-		$columns = array(
378
-			'cb'                => $columns['cb'],
379
-			'title'             => __( 'Name', 'invoicing' ),
380
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
381
-			'earnings'          => __( 'Revenue', 'invoicing' ),
382
-			'refunds'           => __( 'Refunded', 'invoicing' ),
383
-			'items'             => __( 'Items', 'invoicing' ),
384
-			'date'              => __( 'Date', 'invoicing' ),
385
-		);
377
+        $columns = array(
378
+            'cb'                => $columns['cb'],
379
+            'title'             => __( 'Name', 'invoicing' ),
380
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
381
+            'earnings'          => __( 'Revenue', 'invoicing' ),
382
+            'refunds'           => __( 'Refunded', 'invoicing' ),
383
+            'items'             => __( 'Items', 'invoicing' ),
384
+            'date'              => __( 'Date', 'invoicing' ),
385
+        );
386 386
 
387
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
387
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
388 388
 
389
-	}
389
+    }
390 390
 
391
-	/**
392
-	 * Displays payment form table columns.
393
-	 */
394
-	public static function display_payment_form_columns( $column_name, $post_id ) {
391
+    /**
392
+     * Displays payment form table columns.
393
+     */
394
+    public static function display_payment_form_columns( $column_name, $post_id ) {
395 395
 
396
-		// Retrieve the payment form.
397
-		$form = new GetPaid_Payment_Form( $post_id );
396
+        // Retrieve the payment form.
397
+        $form = new GetPaid_Payment_Form( $post_id );
398 398
 
399
-		switch ( $column_name ) {
399
+        switch ( $column_name ) {
400 400
 
401
-			case 'earnings' :
402
-				echo wpinv_price( $form->get_earned() );
403
-				break;
401
+            case 'earnings' :
402
+                echo wpinv_price( $form->get_earned() );
403
+                break;
404 404
 
405
-			case 'refunds' :
406
-				echo wpinv_price( $form->get_refunded() );
407
-				break;
405
+            case 'refunds' :
406
+                echo wpinv_price( $form->get_refunded() );
407
+                break;
408 408
 
409
-			case 'refunds' :
410
-				echo wpinv_price( $form->get_refunded() );
411
-				break;
409
+            case 'refunds' :
410
+                echo wpinv_price( $form->get_refunded() );
411
+                break;
412 412
 
413
-			case 'shortcode' :
413
+            case 'shortcode' :
414 414
 
415
-				if ( $form->is_default() ) {
416
-					echo '&mdash;';
417
-				} else {
418
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
419
-				}
415
+                if ( $form->is_default() ) {
416
+                    echo '&mdash;';
417
+                } else {
418
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
419
+                }
420 420
 
421
-				break;
421
+                break;
422 422
 
423
-			case 'items' :
423
+            case 'items' :
424 424
 
425
-				$items = $form->get_items();
425
+                $items = $form->get_items();
426 426
 
427
-				if ( $form->is_default() || empty( $items ) ) {
428
-					echo '&mdash;';
429
-					return;
430
-				}
427
+                if ( $form->is_default() || empty( $items ) ) {
428
+                    echo '&mdash;';
429
+                    return;
430
+                }
431 431
 
432
-				$_items = array();
432
+                $_items = array();
433 433
 
434
-				foreach ( $items as $item ) {
435
-					$url = $item->get_edit_url();
434
+                foreach ( $items as $item ) {
435
+                    $url = $item->get_edit_url();
436 436
 
437
-					if ( empty( $url ) ) {
438
-						$_items[] = sanitize_text_field( $item->get_name() );
439
-					} else {
440
-						$_items[] = sprintf(
441
-							'<a href="%s">%s</a>',
442
-							esc_url( $url ),
443
-							sanitize_text_field( $item->get_name() )
444
-						);
445
-					}
437
+                    if ( empty( $url ) ) {
438
+                        $_items[] = sanitize_text_field( $item->get_name() );
439
+                    } else {
440
+                        $_items[] = sprintf(
441
+                            '<a href="%s">%s</a>',
442
+                            esc_url( $url ),
443
+                            sanitize_text_field( $item->get_name() )
444
+                        );
445
+                    }
446 446
 
447
-				}
447
+                }
448 448
 
449
-				echo implode( '<br>', $_items );
449
+                echo implode( '<br>', $_items );
450 450
 
451
-				break;
451
+                break;
452 452
 
453
-		}
453
+        }
454 454
 
455
-	}
455
+    }
456 456
 
457
-	/**
458
-	 * Filters post states.
459
-	 */
460
-	public static function filter_payment_form_state( $post_states, $post ) {
457
+    /**
458
+     * Filters post states.
459
+     */
460
+    public static function filter_payment_form_state( $post_states, $post ) {
461 461
 
462
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
463
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
464
-		}
462
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
463
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
464
+        }
465 465
 	
466
-		return $post_states;
467
-
468
-	}
469
-
470
-	/**
471
-	 * Returns an array of coupon table columns.
472
-	 */
473
-	public static function discount_columns( $columns ) {
474
-
475
-		$columns = array(
476
-			'cb'                => $columns['cb'],
477
-			'title'             => __( 'Name', 'invoicing' ),
478
-			'code'              => __( 'Code', 'invoicing' ),
479
-			'amount'            => __( 'Amount', 'invoicing' ),
480
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
481
-			'start_date'        => __( 'Start Date', 'invoicing' ),
482
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
483
-		);
484
-
485
-		return apply_filters( 'wpi_discount_table_columns', $columns );
486
-	}
487
-
488
-	/**
489
-	 * Filters post states.
490
-	 */
491
-	public static function filter_discount_state( $post_states, $post ) {
492
-
493
-		if ( 'wpi_discount' == $post->post_type ) {
494
-
495
-			$discount = new WPInv_Discount( $post );
496
-
497
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
498
-
499
-			if ( $status != 'publish' ) {
500
-				return array(
501
-					'discount_status' => wpinv_discount_status( $status ),
502
-				);
503
-			}
504
-
505
-			return array();
506
-
507
-		}
508
-
509
-		return $post_states;
510
-
511
-	}
512
-
513
-	/**
514
-	 * Returns an array of items table columns.
515
-	 */
516
-	public static function item_columns( $columns ) {
517
-
518
-		$columns = array(
519
-			'cb'                => $columns['cb'],
520
-			'title'             => __( 'Name', 'invoicing' ),
521
-			'price'             => __( 'Price', 'invoicing' ),
522
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
523
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
524
-			'type'              => __( 'Type', 'invoicing' ),
525
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
526
-		);
527
-
528
-		if ( ! wpinv_use_taxes() ) {
529
-			unset( $columns['vat_rule'] );
530
-			unset( $columns['vat_class'] );
531
-		}
532
-
533
-		return apply_filters( 'wpi_item_table_columns', $columns );
534
-	}
535
-
536
-	/**
537
-	 * Returns an array of sortable items table columns.
538
-	 */
539
-	public static function sortable_item_columns( $columns ) {
540
-
541
-		return array_merge(
542
-			$columns,
543
-			array(
544
-				'price'     => 'price',
545
-				'vat_rule'  => 'vat_rule',
546
-				'vat_class' => 'vat_class',
547
-				'type'      => 'type',
548
-			)
549
-		);
550
-
551
-	}
552
-
553
-	/**
554
-	 * Displays items table columns.
555
-	 */
556
-	public static function display_item_columns( $column_name, $post_id ) {
466
+        return $post_states;
467
+
468
+    }
469
+
470
+    /**
471
+     * Returns an array of coupon table columns.
472
+     */
473
+    public static function discount_columns( $columns ) {
474
+
475
+        $columns = array(
476
+            'cb'                => $columns['cb'],
477
+            'title'             => __( 'Name', 'invoicing' ),
478
+            'code'              => __( 'Code', 'invoicing' ),
479
+            'amount'            => __( 'Amount', 'invoicing' ),
480
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
481
+            'start_date'        => __( 'Start Date', 'invoicing' ),
482
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
483
+        );
484
+
485
+        return apply_filters( 'wpi_discount_table_columns', $columns );
486
+    }
487
+
488
+    /**
489
+     * Filters post states.
490
+     */
491
+    public static function filter_discount_state( $post_states, $post ) {
492
+
493
+        if ( 'wpi_discount' == $post->post_type ) {
494
+
495
+            $discount = new WPInv_Discount( $post );
496
+
497
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
498
+
499
+            if ( $status != 'publish' ) {
500
+                return array(
501
+                    'discount_status' => wpinv_discount_status( $status ),
502
+                );
503
+            }
504
+
505
+            return array();
506
+
507
+        }
508
+
509
+        return $post_states;
510
+
511
+    }
512
+
513
+    /**
514
+     * Returns an array of items table columns.
515
+     */
516
+    public static function item_columns( $columns ) {
517
+
518
+        $columns = array(
519
+            'cb'                => $columns['cb'],
520
+            'title'             => __( 'Name', 'invoicing' ),
521
+            'price'             => __( 'Price', 'invoicing' ),
522
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
523
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
524
+            'type'              => __( 'Type', 'invoicing' ),
525
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
526
+        );
527
+
528
+        if ( ! wpinv_use_taxes() ) {
529
+            unset( $columns['vat_rule'] );
530
+            unset( $columns['vat_class'] );
531
+        }
532
+
533
+        return apply_filters( 'wpi_item_table_columns', $columns );
534
+    }
535
+
536
+    /**
537
+     * Returns an array of sortable items table columns.
538
+     */
539
+    public static function sortable_item_columns( $columns ) {
540
+
541
+        return array_merge(
542
+            $columns,
543
+            array(
544
+                'price'     => 'price',
545
+                'vat_rule'  => 'vat_rule',
546
+                'vat_class' => 'vat_class',
547
+                'type'      => 'type',
548
+            )
549
+        );
550
+
551
+    }
552
+
553
+    /**
554
+     * Displays items table columns.
555
+     */
556
+    public static function display_item_columns( $column_name, $post_id ) {
557 557
  
558
-		$item = new WPInv_Item( $post_id );
558
+        $item = new WPInv_Item( $post_id );
559 559
 
560
-		switch ( $column_name ) {
560
+        switch ( $column_name ) {
561 561
 
562
-			case 'price' :
562
+            case 'price' :
563 563
 
564
-				if ( ! $item->is_recurring() ) {
565
-					echo $item->get_the_price();
566
-					break;
567
-				}
564
+                if ( ! $item->is_recurring() ) {
565
+                    echo $item->get_the_price();
566
+                    break;
567
+                }
568 568
 
569
-				$price = wp_sprintf(
570
-					__( '%s / %s', 'invoicing' ),
571
-					$item->get_the_price(),
572
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
573
-				);
569
+                $price = wp_sprintf(
570
+                    __( '%s / %s', 'invoicing' ),
571
+                    $item->get_the_price(),
572
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
573
+                );
574 574
 
575
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
576
-					echo $price;
577
-					break;
578
-				}
575
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
576
+                    echo $price;
577
+                    break;
578
+                }
579 579
 
580
-				echo $item->get_the_initial_price();
580
+                echo $item->get_the_initial_price();
581 581
 
582
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
583
-				break;
582
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
583
+                break;
584 584
 
585
-			case 'vat_rule' :
586
-				echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
587
-				break;
585
+            case 'vat_rule' :
586
+                echo getpaid_get_tax_rule_label( $item->get_vat_rule() );
587
+                break;
588 588
 
589
-			case 'vat_class' :
590
-				echo getpaid_get_tax_class_label( $item->get_vat_class() );
591
-				break;
589
+            case 'vat_class' :
590
+                echo getpaid_get_tax_class_label( $item->get_vat_class() );
591
+                break;
592 592
 
593
-			case 'shortcode' :
594
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
595
-				break;
593
+            case 'shortcode' :
594
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
595
+                break;
596 596
 
597
-			case 'type' :
598
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
599
-				break;
597
+            case 'type' :
598
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
599
+                break;
600 600
 
601
-		}
601
+        }
602 602
 
603
-	}
603
+    }
604 604
 
605
-	/**
606
-	 * Lets users filter items using taxes.
607
-	 */
608
-	public static function add_item_filters( $post_type ) {
605
+    /**
606
+     * Lets users filter items using taxes.
607
+     */
608
+    public static function add_item_filters( $post_type ) {
609 609
 
610
-		// Abort if we're not dealing with items.
611
-		if ( $post_type != 'wpi_item' ) {
612
-			return;
613
-		}
610
+        // Abort if we're not dealing with items.
611
+        if ( $post_type != 'wpi_item' ) {
612
+            return;
613
+        }
614 614
 
615
-		// Filter by vat rules.
616
-		if ( wpinv_use_taxes() ) {
615
+        // Filter by vat rules.
616
+        if ( wpinv_use_taxes() ) {
617 617
 	
618
-			// Sanitize selected vat rule.
619
-			$vat_rule   = '';
620
-			$vat_rules  = getpaid_get_tax_rules();
621
-			if ( isset( $_GET['vat_rule'] ) ) {
622
-				$vat_rule   =  $_GET['vat_rule'];
623
-			}
624
-
625
-			// Filter by VAT rule.
626
-			echo wpinv_html_select(
627
-				array(
628
-					'options'          => array_merge(
629
-						array(
630
-							'' => __( 'All VAT rules', 'invoicing' )
631
-						),
632
-						$vat_rules
633
-					),
634
-					'name'             => 'vat_rule',
635
-					'id'               => 'vat_rule',
636
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
637
-					'show_option_all'  => false,
638
-					'show_option_none' => false,
639
-				)
640
-			);
641
-
642
-			// Filter by VAT class.
618
+            // Sanitize selected vat rule.
619
+            $vat_rule   = '';
620
+            $vat_rules  = getpaid_get_tax_rules();
621
+            if ( isset( $_GET['vat_rule'] ) ) {
622
+                $vat_rule   =  $_GET['vat_rule'];
623
+            }
624
+
625
+            // Filter by VAT rule.
626
+            echo wpinv_html_select(
627
+                array(
628
+                    'options'          => array_merge(
629
+                        array(
630
+                            '' => __( 'All VAT rules', 'invoicing' )
631
+                        ),
632
+                        $vat_rules
633
+                    ),
634
+                    'name'             => 'vat_rule',
635
+                    'id'               => 'vat_rule',
636
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
637
+                    'show_option_all'  => false,
638
+                    'show_option_none' => false,
639
+                )
640
+            );
641
+
642
+            // Filter by VAT class.
643 643
 	
644
-			// Sanitize selected vat rule.
645
-			$vat_class   = '';
646
-			$vat_classes = getpaid_get_tax_classes();
647
-			if ( isset( $_GET['vat_class'] ) ) {
648
-				$vat_class   =  $_GET['vat_class'];
649
-			}
650
-
651
-			echo wpinv_html_select(
652
-				array(
653
-					'options'          => array_merge(
654
-						array(
655
-							'' => __( 'All VAT classes', 'invoicing' )
656
-						),
657
-						$vat_classes
658
-					),
659
-					'name'             => 'vat_class',
660
-					'id'               => 'vat_class',
661
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
662
-					'show_option_all'  => false,
663
-					'show_option_none' => false,
664
-				)
665
-			);
666
-
667
-		}
668
-
669
-		// Filter by item type.
670
-		$type   = '';
671
-		if ( isset( $_GET['type'] ) ) {
672
-			$type   =  $_GET['type'];
673
-		}
674
-
675
-		echo wpinv_html_select(
676
-			array(
677
-				'options'          => array_merge(
678
-					array(
679
-						'' => __( 'All item types', 'invoicing' )
680
-					),
681
-					wpinv_get_item_types()
682
-				),
683
-				'name'             => 'type',
684
-				'id'               => 'type',
685
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
686
-				'show_option_all'  => false,
687
-				'show_option_none' => false,
688
-			)
689
-		);
690
-
691
-	}
692
-
693
-	/**
694
-	 * Filters the item query.
695
-	 */
696
-	public static function filter_item_query( $query ) {
697
-
698
-		// modify the query only if it admin and main query.
699
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
700
-			return $query;
701
-		}
702
-
703
-		// we want to modify the query for our items.
704
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
705
-			return $query;
706
-		}
707
-
708
-		if ( empty( $query->query_vars['meta_query'] ) ) {
709
-			$query->query_vars['meta_query'] = array();
710
-		}
711
-
712
-		// Filter vat rule type
644
+            // Sanitize selected vat rule.
645
+            $vat_class   = '';
646
+            $vat_classes = getpaid_get_tax_classes();
647
+            if ( isset( $_GET['vat_class'] ) ) {
648
+                $vat_class   =  $_GET['vat_class'];
649
+            }
650
+
651
+            echo wpinv_html_select(
652
+                array(
653
+                    'options'          => array_merge(
654
+                        array(
655
+                            '' => __( 'All VAT classes', 'invoicing' )
656
+                        ),
657
+                        $vat_classes
658
+                    ),
659
+                    'name'             => 'vat_class',
660
+                    'id'               => 'vat_class',
661
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
662
+                    'show_option_all'  => false,
663
+                    'show_option_none' => false,
664
+                )
665
+            );
666
+
667
+        }
668
+
669
+        // Filter by item type.
670
+        $type   = '';
671
+        if ( isset( $_GET['type'] ) ) {
672
+            $type   =  $_GET['type'];
673
+        }
674
+
675
+        echo wpinv_html_select(
676
+            array(
677
+                'options'          => array_merge(
678
+                    array(
679
+                        '' => __( 'All item types', 'invoicing' )
680
+                    ),
681
+                    wpinv_get_item_types()
682
+                ),
683
+                'name'             => 'type',
684
+                'id'               => 'type',
685
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
686
+                'show_option_all'  => false,
687
+                'show_option_none' => false,
688
+            )
689
+        );
690
+
691
+    }
692
+
693
+    /**
694
+     * Filters the item query.
695
+     */
696
+    public static function filter_item_query( $query ) {
697
+
698
+        // modify the query only if it admin and main query.
699
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
700
+            return $query;
701
+        }
702
+
703
+        // we want to modify the query for our items.
704
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){
705
+            return $query;
706
+        }
707
+
708
+        if ( empty( $query->query_vars['meta_query'] ) ) {
709
+            $query->query_vars['meta_query'] = array();
710
+        }
711
+
712
+        // Filter vat rule type
713 713
         if ( ! empty( $_GET['vat_rule'] ) ) {
714 714
             $query->query_vars['meta_query'][] = array(
715 715
                 'key'     => '_wpinv_vat_rule',
@@ -734,97 +734,97 @@  discard block
 block discarded – undo
734 734
                 'value'   => sanitize_text_field( $_GET['type'] ),
735 735
                 'compare' => '='
736 736
             );
737
-		}
738
-
739
-	}
740
-
741
-	/**
742
-	 * Reorders items.
743
-	 */
744
-	public static function reorder_items( $vars ) {
745
-		global $typenow;
746
-
747
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
748
-			return $vars;
749
-		}
750
-
751
-		// By item type.
752
-		if ( 'type' == $vars['orderby'] ) {
753
-			return array_merge(
754
-				$vars,
755
-				array(
756
-					'meta_key' => '_wpinv_type',
757
-					'orderby'  => 'meta_value'
758
-				)
759
-			);
760
-		}
761
-
762
-		// By vat class.
763
-		if ( 'vat_class' == $vars['orderby'] ) {
764
-			return array_merge(
765
-				$vars,
766
-				array(
767
-					'meta_key' => '_wpinv_vat_class',
768
-					'orderby'  => 'meta_value'
769
-				)
770
-			);
771
-		}
772
-
773
-		// By vat rule.
774
-		if ( 'vat_rule' == $vars['orderby'] ) {
775
-			return array_merge(
776
-				$vars,
777
-				array(
778
-					'meta_key' => '_wpinv_vat_rule',
779
-					'orderby'  => 'meta_value'
780
-				)
781
-			);
782
-		}
783
-
784
-		// By price.
785
-		if ( 'price' == $vars['orderby'] ) {
786
-			return array_merge(
787
-				$vars,
788
-				array(
789
-					'meta_key' => '_wpinv_price',
790
-					'orderby'  => 'meta_value_num'
791
-				)
792
-			);
793
-		}
794
-
795
-		return $vars;
796
-
797
-	}
798
-
799
-	/**
800
-	 * Fired when deleting a post.
801
-	 */
802
-	public static function delete_post( $post_id ) {
803
-
804
-		switch ( get_post_type( $post_id ) ) {
805
-
806
-			case 'wpi_item' :
807
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
808
-				break;
809
-
810
-			case 'wpi_payment_form' :
811
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
812
-				break;
813
-
814
-			case 'wpi_discount' :
815
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
816
-				break;
817
-
818
-			case 'wpi_invoice' :
819
-				$invoice = new WPInv_Invoice( $post_id );
820
-				do_action( "getpaid_before_delete_invoice", $invoice );
821
-				$invoice->get_data_store()->delete_items( $invoice );
822
-				$invoice->get_data_store()->delete_special_fields( $invoice );
823
-				break;
824
-		}
825
-	}
826
-
827
-	/**
737
+        }
738
+
739
+    }
740
+
741
+    /**
742
+     * Reorders items.
743
+     */
744
+    public static function reorder_items( $vars ) {
745
+        global $typenow;
746
+
747
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
748
+            return $vars;
749
+        }
750
+
751
+        // By item type.
752
+        if ( 'type' == $vars['orderby'] ) {
753
+            return array_merge(
754
+                $vars,
755
+                array(
756
+                    'meta_key' => '_wpinv_type',
757
+                    'orderby'  => 'meta_value'
758
+                )
759
+            );
760
+        }
761
+
762
+        // By vat class.
763
+        if ( 'vat_class' == $vars['orderby'] ) {
764
+            return array_merge(
765
+                $vars,
766
+                array(
767
+                    'meta_key' => '_wpinv_vat_class',
768
+                    'orderby'  => 'meta_value'
769
+                )
770
+            );
771
+        }
772
+
773
+        // By vat rule.
774
+        if ( 'vat_rule' == $vars['orderby'] ) {
775
+            return array_merge(
776
+                $vars,
777
+                array(
778
+                    'meta_key' => '_wpinv_vat_rule',
779
+                    'orderby'  => 'meta_value'
780
+                )
781
+            );
782
+        }
783
+
784
+        // By price.
785
+        if ( 'price' == $vars['orderby'] ) {
786
+            return array_merge(
787
+                $vars,
788
+                array(
789
+                    'meta_key' => '_wpinv_price',
790
+                    'orderby'  => 'meta_value_num'
791
+                )
792
+            );
793
+        }
794
+
795
+        return $vars;
796
+
797
+    }
798
+
799
+    /**
800
+     * Fired when deleting a post.
801
+     */
802
+    public static function delete_post( $post_id ) {
803
+
804
+        switch ( get_post_type( $post_id ) ) {
805
+
806
+            case 'wpi_item' :
807
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
808
+                break;
809
+
810
+            case 'wpi_payment_form' :
811
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
812
+                break;
813
+
814
+            case 'wpi_discount' :
815
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
816
+                break;
817
+
818
+            case 'wpi_invoice' :
819
+                $invoice = new WPInv_Invoice( $post_id );
820
+                do_action( "getpaid_before_delete_invoice", $invoice );
821
+                $invoice->get_data_store()->delete_items( $invoice );
822
+                $invoice->get_data_store()->delete_special_fields( $invoice );
823
+                break;
824
+        }
825
+    }
826
+
827
+    /**
828 828
      * Add a post display state for special GetPaid pages in the page list table.
829 829
      *
830 830
      * @param array   $post_states An array of post display states.
@@ -838,22 +838,22 @@  discard block
 block discarded – undo
838 838
             $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
839 839
         }
840 840
 
841
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
841
+        foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
842 842
 
843
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
844
-				$post_states["getpaid_{$post_type}_history_page"] = sprintf(
845
-					__( 'GetPaid %s History Page', 'invoicing' ),
846
-					$label
847
-				);
848
-			}
843
+            if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
844
+                $post_states["getpaid_{$post_type}_history_page"] = sprintf(
845
+                    __( 'GetPaid %s History Page', 'invoicing' ),
846
+                    $label
847
+                );
848
+            }
849 849
 
850
-		}
850
+        }
851 851
 		
852
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
852
+        if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
853 853
             $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
854 854
         }
855 855
 
856
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
856
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
857 857
             $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
858 858
         }
859 859
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -12,228 +12,228 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26 26
 
27 27
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
-
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
74
-				continue;
75
-			}
76
-
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
-
80
-		}
81
-
82
-	}
83
-
84
-	/**
85
-	 * Checks if the submission has a digital item.
86
-	 *
87
-	 * @param GetPaid_Payment_Form_Submission $submission
88
-	 * @since 1.0.19
89
-	 * @return bool
90
-	 */
91
-	public function has_digital_item( $submission ) {
92
-
93
-		foreach ( $submission->get_items() as $item ) {
94
-
95
-			if ( 'digital' == $item->get_vat_rule() ) {
96
-				return true;
97
-			}
98
-
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
202 38
             return;
203
-		}
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
+
72
+            if ( ! isset( $this->taxes[ $name ] ) ) {
73
+                $this->taxes[ $name ] = $tax;
74
+                continue;
75
+            }
76
+
77
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
+
80
+        }
81
+
82
+    }
83
+
84
+    /**
85
+     * Checks if the submission has a digital item.
86
+     *
87
+     * @param GetPaid_Payment_Form_Submission $submission
88
+     * @since 1.0.19
89
+     * @return bool
90
+     */
91
+    public function has_digital_item( $submission ) {
92
+
93
+        foreach ( $submission->get_items() as $item ) {
94
+
95
+            if ( 'digital' == $item->get_vat_rule() ) {
96
+                return true;
97
+            }
98
+
99
+        }
204 100
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202
+            return;
203
+        }
204
+
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215 215
 
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
219
+            // Ensure that a vat number has been specified.
220
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) );
221 221
 
222
-		}
222
+        }
223 223
 
224
-		if ( empty( $vat_number ) ) {
225
-			return;
226
-		}
224
+        if ( empty( $vat_number ) ) {
225
+            return;
226
+        }
227 227
 
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
-		}
228
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
+            throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) );
230
+        }
231 231
 
232
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
-			return;
234
-		}
232
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
+            return;
234
+        }
235 235
 
236
-		$this->skip_taxes = true;
237
-	}
236
+        $this->skip_taxes = true;
237
+    }
238 238
 
239 239
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +575 added lines, -575 removed lines patch added patch discarded remove patch
@@ -14,90 +14,90 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29 29
 	
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct(){
38
+     * Class constructor.
39
+     */
40
+    public function __construct(){
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect') );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
66
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
66
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
67 67
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
68
-		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
69
-		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
70
-		add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
71
-		add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
72
-		add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
73
-		add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
74
-		add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
75
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
76
-		do_action( 'getpaid_init_admin_hooks', $this );
77
-
78
-		// Setup/welcome
79
-		if ( ! empty( $_GET['page'] ) ) {
80
-			switch ( $_GET['page'] ) {
81
-				case 'gp-setup' :
82
-					include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
83
-					break;
84
-			}
85
-		}
68
+        add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
69
+        add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
70
+        add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) );
71
+        add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) );
72
+        add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) );
73
+        add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) );
74
+        add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) );
75
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
76
+        do_action( 'getpaid_init_admin_hooks', $this );
77
+
78
+        // Setup/welcome
79
+        if ( ! empty( $_GET['page'] ) ) {
80
+            switch ( $_GET['page'] ) {
81
+                case 'gp-setup' :
82
+                    include_once( dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php' );
83
+                    break;
84
+            }
85
+        }
86 86
 
87 87
     }
88 88
 
89 89
     /**
90
-	 * Register admin scripts
91
-	 *
92
-	 */
93
-	public function enqeue_scripts() {
90
+     * Register admin scripts
91
+     *
92
+     */
93
+    public function enqeue_scripts() {
94 94
         global $current_screen, $pagenow;
95 95
 
96
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
97
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
96
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
97
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
98 98
 
99 99
         if ( ! empty( $current_screen->post_type ) ) {
100
-			$page = $current_screen->post_type;
100
+            $page = $current_screen->post_type;
101 101
         }
102 102
 
103 103
         // General styles.
@@ -118,54 +118,54 @@  discard block
 block discarded – undo
118 118
         }
119 119
 
120 120
         // Payment form scripts.
121
-		if ( 'wpi_payment_form' == $page && $editing ) {
121
+        if ( 'wpi_payment_form' == $page && $editing ) {
122 122
             $this->load_payment_form_scripts();
123 123
         }
124 124
 
125
-		if ( $page == 'wpinv-subscriptions' ) {
126
-			wp_enqueue_script( 'postbox' );
127
-		}
125
+        if ( $page == 'wpinv-subscriptions' ) {
126
+            wp_enqueue_script( 'postbox' );
127
+        }
128 128
 
129 129
     }
130 130
 
131 131
     /**
132
-	 * Returns admin js translations.
133
-	 *
134
-	 */
135
-	protected function get_admin_i18() {
132
+     * Returns admin js translations.
133
+     *
134
+     */
135
+    protected function get_admin_i18() {
136 136
         global $post;
137 137
 
138
-		$date_range = array(
139
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
140
-		);
138
+        $date_range = array(
139
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
140
+        );
141 141
 
142
-		if ( $date_range['period'] == 'custom' ) {
142
+        if ( $date_range['period'] == 'custom' ) {
143 143
 			
144
-			if ( isset( $_GET['from'] ) ) {
145
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
146
-			}
144
+            if ( isset( $_GET['from'] ) ) {
145
+                $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
146
+            }
147 147
 
148
-			if ( isset( $_GET['to'] ) ) {
149
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
150
-			}
148
+            if ( isset( $_GET['to'] ) ) {
149
+                $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
150
+            }
151 151
 
152
-		}
152
+        }
153 153
 
154 154
         $i18n = array(
155 155
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
156 156
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
157
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
158
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
159
-			'rest_root'                 => esc_url_raw( rest_url() ),
160
-			'date_range'                => $date_range,
157
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
158
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
159
+            'rest_root'                 => esc_url_raw( rest_url() ),
160
+            'date_range'                => $date_range,
161 161
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
162 162
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
163 163
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
164 164
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
165 165
             'tax'                       => wpinv_tax_amount(),
166 166
             'discount'                  => 0,
167
-			'currency_symbol'           => wpinv_currency_symbol(),
168
-			'currency'                  => wpinv_get_currency(),
167
+            'currency_symbol'           => wpinv_currency_symbol(),
168
+            'currency'                  => wpinv_get_currency(),
169 169
             'currency_pos'              => wpinv_currency_position(),
170 170
             'thousand_sep'              => wpinv_thousands_separator(),
171 171
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -185,118 +185,118 @@  discard block
 block discarded – undo
185 185
             'item_description'          => __( 'Item Description', 'invoicing' ),
186 186
             'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
187 187
             'discount_description'      => __( 'Discount Description', 'invoicing' ),
188
-			'searching'                 => __( 'Searching', 'invoicing' ),
189
-			'loading'                   => __( 'Loading...', 'invoicing' ),
190
-			'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
191
-			'search_items'              => __( 'Enter item name', 'invoicing' ),
188
+            'searching'                 => __( 'Searching', 'invoicing' ),
189
+            'loading'                   => __( 'Loading...', 'invoicing' ),
190
+            'search_customers'          => __( 'Enter customer name or email', 'invoicing' ),
191
+            'search_items'              => __( 'Enter item name', 'invoicing' ),
192 192
         );
193 193
 
194
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
194
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
195 195
 
196
-			$invoice              = new WPInv_Invoice( $post );
197
-			$i18n['save_invoice'] = sprintf(
198
-				__( 'Save %s', 'invoicing' ),
199
-				ucfirst( $invoice->get_invoice_quote_type() )
200
-			);
196
+            $invoice              = new WPInv_Invoice( $post );
197
+            $i18n['save_invoice'] = sprintf(
198
+                __( 'Save %s', 'invoicing' ),
199
+                ucfirst( $invoice->get_invoice_quote_type() )
200
+            );
201 201
 
202
-			$i18n['invoice_description'] = sprintf(
203
-				__( '%s Description', 'invoicing' ),
204
-				ucfirst( $invoice->get_invoice_quote_type() )
205
-			);
202
+            $i18n['invoice_description'] = sprintf(
203
+                __( '%s Description', 'invoicing' ),
204
+                ucfirst( $invoice->get_invoice_quote_type() )
205
+            );
206 206
 
207
-		}
208
-		return $i18n;
209
-	}
207
+        }
208
+        return $i18n;
209
+    }
210 210
 
211
-	/**
212
-	 * Change the admin footer text on GetPaid admin pages.
213
-	 *
214
-	 * @since  2.0.0
215
-	 * @param  string $footer_text
216
-	 * @return string
217
-	 */
218
-	public function admin_footer_text( $footer_text ) {
219
-		global $current_screen;
211
+    /**
212
+     * Change the admin footer text on GetPaid admin pages.
213
+     *
214
+     * @since  2.0.0
215
+     * @param  string $footer_text
216
+     * @return string
217
+     */
218
+    public function admin_footer_text( $footer_text ) {
219
+        global $current_screen;
220 220
 
221
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
221
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
222 222
 
223 223
         if ( ! empty( $current_screen->post_type ) ) {
224
-			$page = $current_screen->post_type;
224
+            $page = $current_screen->post_type;
225 225
         }
226 226
 
227 227
         // General styles.
228 228
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
229 229
 
230
-			// Change the footer text
231
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
232
-
233
-				$rating_url  = esc_url(
234
-					wp_nonce_url(
235
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
236
-						'getpaid-nonce',
237
-						'getpaid-nonce'
238
-						)
239
-				);
240
-
241
-				$footer_text = sprintf(
242
-					/* translators: %s: five stars */
243
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
244
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
245
-				);
246
-
247
-			} else {
248
-
249
-				$footer_text = sprintf(
250
-					/* translators: %s: GetPaid */
251
-					__( 'Thank you for using %s!', 'invoicing' ),
252
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
253
-				);
254
-
255
-			}
256
-
257
-		}
258
-
259
-		return $footer_text;
260
-	}
261
-
262
-	/**
263
-	 * Redirects to wp.org to rate the plugin.
264
-	 *
265
-	 * @since  2.0.0
266
-	 */
267
-	public function redirect_to_wordpress_rating_page() {
268
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
269
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
270
-		exit;
271
-	}
272
-
273
-    /**
274
-	 * Loads payment form js.
275
-	 *
276
-	 */
277
-	protected function load_payment_form_scripts() {
230
+            // Change the footer text
231
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
232
+
233
+                $rating_url  = esc_url(
234
+                    wp_nonce_url(
235
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
236
+                        'getpaid-nonce',
237
+                        'getpaid-nonce'
238
+                        )
239
+                );
240
+
241
+                $footer_text = sprintf(
242
+                    /* translators: %s: five stars */
243
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
244
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
245
+                );
246
+
247
+            } else {
248
+
249
+                $footer_text = sprintf(
250
+                    /* translators: %s: GetPaid */
251
+                    __( 'Thank you for using %s!', 'invoicing' ),
252
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
253
+                );
254
+
255
+            }
256
+
257
+        }
258
+
259
+        return $footer_text;
260
+    }
261
+
262
+    /**
263
+     * Redirects to wp.org to rate the plugin.
264
+     *
265
+     * @since  2.0.0
266
+     */
267
+    public function redirect_to_wordpress_rating_page() {
268
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
269
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
270
+        exit;
271
+    }
272
+
273
+    /**
274
+     * Loads payment form js.
275
+     *
276
+     */
277
+    protected function load_payment_form_scripts() {
278 278
         global $post;
279 279
 
280 280
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION );
281
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
282
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
281
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
282
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
283 283
 
284
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
285
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
284
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
285
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
286 286
 
287
-		wp_localize_script(
287
+        wp_localize_script(
288 288
             'wpinv-admin-payment-form-script',
289 289
             'wpinvPaymentFormAdmin',
290 290
             array(
291
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
292
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
293
-				'currency'      => wpinv_currency_symbol(),
294
-				'position'      => wpinv_currency_position(),
295
-				'decimals'      => (int) wpinv_decimals(),
296
-				'thousands_sep' => wpinv_thousands_separator(),
297
-				'decimals_sep'  => wpinv_decimal_separator(),
298
-				'form_items'    => gepaid_get_form_items( $post->ID ),
299
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
291
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
292
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
293
+                'currency'      => wpinv_currency_symbol(),
294
+                'position'      => wpinv_currency_position(),
295
+                'decimals'      => (int) wpinv_decimals(),
296
+                'thousands_sep' => wpinv_thousands_separator(),
297
+                'decimals_sep'  => wpinv_decimal_separator(),
298
+                'form_items'    => gepaid_get_form_items( $post->ID ),
299
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
300 300
             )
301 301
         );
302 302
 
@@ -305,20 +305,20 @@  discard block
 block discarded – undo
305 305
     }
306 306
 
307 307
     /**
308
-	 * Add our classes to admin pages.
308
+     * Add our classes to admin pages.
309 309
      *
310 310
      * @param string $classes
311 311
      * @return string
312
-	 *
313
-	 */
312
+     *
313
+     */
314 314
     public function admin_body_class( $classes ) {
315
-		global $pagenow, $post, $current_screen;
315
+        global $pagenow, $post, $current_screen;
316 316
 
317 317
 
318 318
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
319 319
 
320 320
         if ( ! empty( $current_screen->post_type ) ) {
321
-			$page = $current_screen->post_type;
321
+            $page = $current_screen->post_type;
322 322
         }
323 323
 
324 324
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -327,68 +327,68 @@  discard block
 block discarded – undo
327 327
 
328 328
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
329 329
             $classes .= ' wpinv-cpt wpinv';
330
-		}
330
+        }
331 331
 		
332
-		if ( getpaid_is_invoice_post_type( $page ) ) {
332
+        if ( getpaid_is_invoice_post_type( $page ) ) {
333 333
             $classes .= ' getpaid-is-invoice-cpt';
334 334
         }
335 335
 
336
-		return $classes;
336
+        return $classes;
337 337
     }
338 338
 
339 339
     /**
340
-	 * Maybe show the AyeCode Connect Notice.
341
-	 */
342
-	public function init_ayecode_connect_helper(){
340
+     * Maybe show the AyeCode Connect Notice.
341
+     */
342
+    public function init_ayecode_connect_helper(){
343 343
 
344
-		// Register with the deactivation survey class.
345
-		AyeCode_Deactivation_Survey::instance(array(
346
-			'slug'		        => 'invoicing',
347
-			'version'	        => WPINV_VERSION,
348
-			'support_url'       => 'https://wpgetpaid.com/support/',
349
-			'documentation_url' => 'https://docs.wpgetpaid.com/',
350
-			'activated'         => (int) get_option( 'gepaid_installed_on' ),
351
-		));
344
+        // Register with the deactivation survey class.
345
+        AyeCode_Deactivation_Survey::instance(array(
346
+            'slug'		        => 'invoicing',
347
+            'version'	        => WPINV_VERSION,
348
+            'support_url'       => 'https://wpgetpaid.com/support/',
349
+            'documentation_url' => 'https://docs.wpgetpaid.com/',
350
+            'activated'         => (int) get_option( 'gepaid_installed_on' ),
351
+        ));
352 352
 
353 353
         new AyeCode_Connect_Helper(
354 354
             array(
355
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
356
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
357
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
358
-				'connect_button'    => __("Connect Site","invoicing"),
359
-				'connecting_button'    => __("Connecting...","invoicing"),
360
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
361
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
355
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
356
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
357
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
358
+                'connect_button'    => __("Connect Site","invoicing"),
359
+                'connecting_button'    => __("Connecting...","invoicing"),
360
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
361
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
362 362
             ),
363 363
             array( 'wpi-addons' )
364 364
         );
365 365
 
366 366
     }
367 367
 
368
-	/**
369
-	 * Redirect users to settings on activation.
370
-	 *
371
-	 * @return void
372
-	 */
373
-	public function activation_redirect() {
368
+    /**
369
+     * Redirect users to settings on activation.
370
+     *
371
+     * @return void
372
+     */
373
+    public function activation_redirect() {
374 374
 
375
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
375
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
376 376
 
377
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
378
-			return;
379
-		}
377
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
378
+            return;
379
+        }
380 380
 
381
-		// Bail if activating from network, or bulk
382
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
383
-			return;
384
-		}
381
+        // Bail if activating from network, or bulk
382
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
383
+            return;
384
+        }
385 385
 
386
-	    update_option( 'wpinv_redirected_to_settings', 1 );
386
+        update_option( 'wpinv_redirected_to_settings', 1 );
387 387
 
388 388
         wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) );
389 389
         exit;
390 390
 
391
-	}
391
+    }
392 392
 
393 393
     /**
394 394
      * Fires an admin action after verifying that a user can fire them.
@@ -402,498 +402,498 @@  discard block
 block discarded – undo
402 402
 
403 403
     }
404 404
 
405
-	/**
405
+    /**
406 406
      * Sends a payment reminder to a customer.
407
-	 * 
408
-	 * @param array $args
407
+     * 
408
+     * @param array $args
409 409
      */
410 410
     public function duplicate_payment_form( $args ) {
411 411
 
412
-		if ( empty( $args['form_id'] ) ) {
413
-			return;
414
-		}
415
-
416
-		$form = new GetPaid_Payment_Form( $args['form_id'] );
412
+        if ( empty( $args['form_id'] ) ) {
413
+            return;
414
+        }
417 415
 
418
-		if ( ! $form->exists() ) {
419
-			return;
420
-		}
416
+        $form = new GetPaid_Payment_Form( $args['form_id'] );
421 417
 
422
-		$new_form = new GetPaid_Payment_Form();
423
-		$new_form->set_author( $form->get_author( 'edit' ) );
424
-		$new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
425
-		$new_form->set_elements( $form->get_elements( 'edit' ) );
426
-		$new_form->set_items( $form->get_items( 'edit' ) );
427
-		$new_form->save();
418
+        if ( ! $form->exists() ) {
419
+            return;
420
+        }
428 421
 
429
-		if ( $new_form->exists() ) {
430
-			$this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
431
-			$url = get_edit_post_link( $new_form->get_id(), 'edit' );
432
-		} else {
433
-			$this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
434
-			$url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
435
-		}
422
+        $new_form = new GetPaid_Payment_Form();
423
+        $new_form->set_author( $form->get_author( 'edit' ) );
424
+        $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) );
425
+        $new_form->set_elements( $form->get_elements( 'edit' ) );
426
+        $new_form->set_items( $form->get_items( 'edit' ) );
427
+        $new_form->save();
428
+
429
+        if ( $new_form->exists() ) {
430
+            $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) );
431
+            $url = get_edit_post_link( $new_form->get_id(), 'edit' );
432
+        } else {
433
+            $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) );
434
+            $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) );
435
+        }
436 436
 
437
-		wp_redirect( $url );
438
-		exit;
439
-	}
437
+        wp_redirect( $url );
438
+        exit;
439
+    }
440 440
 
441
-	/**
441
+    /**
442 442
      * Sends a payment reminder to a customer.
443
-	 * 
444
-	 * @param array $args
443
+     * 
444
+     * @param array $args
445 445
      */
446 446
     public function send_customer_invoice( $args ) {
447
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
447
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true );
448 448
 
449
-		if ( $sent ) {
450
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
451
-		} else {
452
-			$this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
453
-		}
449
+        if ( $sent ) {
450
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
451
+        } else {
452
+            $this->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
453
+        }
454 454
 
455
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
456
-		exit;
457
-	}
455
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
456
+        exit;
457
+    }
458 458
 
459
-	/**
459
+    /**
460 460
      * Sends a payment reminder to a customer.
461
-	 * 
462
-	 * @param array $args
461
+     * 
462
+     * @param array $args
463 463
      */
464 464
     public function send_customer_payment_reminder( $args ) {
465
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
465
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
466 466
 
467
-		if ( $sent ) {
468
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
469
-		} else {
470
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
471
-		}
467
+        if ( $sent ) {
468
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
469
+        } else {
470
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
471
+        }
472 472
 
473
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
474
-		exit;
475
-	}
473
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
474
+        exit;
475
+    }
476 476
 
477
-	/**
477
+    /**
478 478
      * Resets tax rates.
479
-	 * 
479
+     * 
480 480
      */
481 481
     public function admin_reset_tax_rates() {
482 482
 
483
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
484
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
485
-		exit;
483
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
484
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
485
+        exit;
486 486
 
487
-	}
487
+    }
488 488
 
489
-	/**
489
+    /**
490 490
      * Resets admin pages.
491
-	 * 
491
+     * 
492 492
      */
493 493
     public function admin_create_missing_pages() {
494
-		$installer = new GetPaid_Installer();
495
-		$installer->create_pages();
496
-		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
497
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
498
-		exit;
499
-	}
500
-
501
-	/**
494
+        $installer = new GetPaid_Installer();
495
+        $installer->create_pages();
496
+        $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
497
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
498
+        exit;
499
+    }
500
+
501
+    /**
502 502
      * Creates an missing admin tables.
503
-	 * 
503
+     * 
504 504
      */
505 505
     public function admin_create_missing_tables() {
506
-		global $wpdb;
507
-		$installer = new GetPaid_Installer();
506
+        global $wpdb;
507
+        $installer = new GetPaid_Installer();
508 508
 
509
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
510
-			$installer->create_subscriptions_table();
509
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
510
+            $installer->create_subscriptions_table();
511 511
 
512
-			if ( $wpdb->last_error !== '' ) {
513
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
514
-			}
515
-		}
512
+            if ( $wpdb->last_error !== '' ) {
513
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
514
+            }
515
+        }
516 516
 
517
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
518
-			$installer->create_invoices_table();
517
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
518
+            $installer->create_invoices_table();
519 519
 
520
-			if ( $wpdb->last_error !== '' ) {
521
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
522
-			}
523
-		}
520
+            if ( $wpdb->last_error !== '' ) {
521
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
522
+            }
523
+        }
524 524
 
525
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
526
-			$installer->create_invoice_items_table();
525
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
526
+            $installer->create_invoice_items_table();
527 527
 
528
-			if ( $wpdb->last_error !== '' ) {
529
-				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
530
-			}
531
-		}
528
+            if ( $wpdb->last_error !== '' ) {
529
+                $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
530
+            }
531
+        }
532 532
 
533
-		if ( ! $this->has_notices() ) {
534
-			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
535
-		}
533
+        if ( ! $this->has_notices() ) {
534
+            $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
535
+        }
536 536
 
537
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
538
-		exit;
539
-	}
537
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
538
+        exit;
539
+    }
540 540
 
541
-	/**
541
+    /**
542 542
      * Migrates old invoices to the new database tables.
543
-	 * 
543
+     * 
544 544
      */
545 545
     public function admin_migrate_old_invoices() {
546 546
 
547
-		// Migrate the invoices.
548
-		$installer = new GetPaid_Installer();
549
-		$installer->migrate_old_invoices();
547
+        // Migrate the invoices.
548
+        $installer = new GetPaid_Installer();
549
+        $installer->migrate_old_invoices();
550 550
 
551
-		// Show an admin message.
552
-		$this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
551
+        // Show an admin message.
552
+        $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) );
553 553
 
554
-		// Redirect the admin.
555
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
556
-		exit;
554
+        // Redirect the admin.
555
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
556
+        exit;
557 557
 
558
-	}
558
+    }
559 559
 
560
-	/**
560
+    /**
561 561
      * Download customers.
562
-	 * 
562
+     * 
563 563
      */
564 564
     public function admin_download_customers() {
565
-		global $wpdb;
565
+        global $wpdb;
566 566
 
567
-		$output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
567
+        $output = fopen( 'php://output', 'w' ) or die( __( 'Unsupported server', 'invoicing' ) );
568 568
 
569
-		header( "Content-Type:text/csv" );
570
-		header( "Content-Disposition:attachment;filename=customers.csv" );
569
+        header( "Content-Type:text/csv" );
570
+        header( "Content-Disposition:attachment;filename=customers.csv" );
571 571
 
572
-		$post_types = '';
572
+        $post_types = '';
573 573
 
574
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
575
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
576
-		}
574
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
575
+            $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
576
+        }
577 577
 
578
-		$post_types = rtrim( $post_types, ' OR' );
578
+        $post_types = rtrim( $post_types, ' OR' );
579 579
 
580
-		$customers = $wpdb->get_col(
581
-			$wpdb->prepare(
582
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
583
-			)
584
-		);
580
+        $customers = $wpdb->get_col(
581
+            $wpdb->prepare(
582
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"
583
+            )
584
+        );
585 585
 
586
-		$columns = array(
587
-			'name'     => __( 'Name', 'invoicing' ),
588
-			'email'    => __( 'Email', 'invoicing' ),
589
-			'country'  => __( 'Country', 'invoicing' ),
590
-			'state'    => __( 'State', 'invoicing' ),
591
-			'city'     => __( 'City', 'invoicing' ),
592
-			'zip'      => __( 'ZIP', 'invoicing' ),
593
-			'address'  => __( 'Address', 'invoicing' ),
594
-			'phone'    => __( 'Phone', 'invoicing' ),
595
-			'company'  => __( 'Company', 'invoicing' ),
596
-			'company_id'  => __( 'Company ID', 'invoicing' ),
597
-			'invoices' => __( 'Invoices', 'invoicing' ),
598
-			'total_raw' => __( 'Total Spend', 'invoicing' ),
599
-			'signup'   => __( 'Date created', 'invoicing' ),
600
-		);
586
+        $columns = array(
587
+            'name'     => __( 'Name', 'invoicing' ),
588
+            'email'    => __( 'Email', 'invoicing' ),
589
+            'country'  => __( 'Country', 'invoicing' ),
590
+            'state'    => __( 'State', 'invoicing' ),
591
+            'city'     => __( 'City', 'invoicing' ),
592
+            'zip'      => __( 'ZIP', 'invoicing' ),
593
+            'address'  => __( 'Address', 'invoicing' ),
594
+            'phone'    => __( 'Phone', 'invoicing' ),
595
+            'company'  => __( 'Company', 'invoicing' ),
596
+            'company_id'  => __( 'Company ID', 'invoicing' ),
597
+            'invoices' => __( 'Invoices', 'invoicing' ),
598
+            'total_raw' => __( 'Total Spend', 'invoicing' ),
599
+            'signup'   => __( 'Date created', 'invoicing' ),
600
+        );
601 601
 
602
-		// Output the csv column headers.
603
-		fputcsv( $output, array_values( $columns ) );
602
+        // Output the csv column headers.
603
+        fputcsv( $output, array_values( $columns ) );
604 604
 
605
-		// Loop through
606
-		$table = new WPInv_Customers_Table();
607
-		foreach ( $customers as $customer_id ) {
605
+        // Loop through
606
+        $table = new WPInv_Customers_Table();
607
+        foreach ( $customers as $customer_id ) {
608 608
 
609
-			$user = get_user_by( 'id', $customer_id );
610
-			$row  = array();
611
-			if ( empty( $user ) ) {
612
-				continue;
613
-			}
609
+            $user = get_user_by( 'id', $customer_id );
610
+            $row  = array();
611
+            if ( empty( $user ) ) {
612
+                continue;
613
+            }
614 614
 
615
-			foreach ( array_keys( $columns ) as $column ) {
615
+            foreach ( array_keys( $columns ) as $column ) {
616 616
 
617
-				$method = 'column_' . $column;
617
+                $method = 'column_' . $column;
618 618
 
619
-				if ( 'name' == $column ) {
620
-					$value = sanitize_text_field( $user->display_name );
621
-				} else if( 'email' == $column ) {
622
-					$value = sanitize_email( $user->user_email );
623
-				} else if ( is_callable( array( $table, $method ) ) ) {
624
-					$value = strip_tags( $table->$method( $user ) );
625
-				}
619
+                if ( 'name' == $column ) {
620
+                    $value = sanitize_text_field( $user->display_name );
621
+                } else if( 'email' == $column ) {
622
+                    $value = sanitize_email( $user->user_email );
623
+                } else if ( is_callable( array( $table, $method ) ) ) {
624
+                    $value = strip_tags( $table->$method( $user ) );
625
+                }
626 626
 
627
-				if ( empty( $value ) ) {
628
-					$value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
629
-				}
627
+                if ( empty( $value ) ) {
628
+                    $value = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_' . $column, true ) );
629
+                }
630 630
 
631
-				$row[] = $value;
631
+                $row[] = $value;
632 632
 
633
-			}
633
+            }
634 634
 
635
-			fputcsv( $output, $row );
636
-		}
635
+            fputcsv( $output, $row );
636
+        }
637 637
 
638
-		fclose( $output );
639
-		exit;
638
+        fclose( $output );
639
+        exit;
640 640
 
641
-	}
641
+    }
642 642
 
643
-	/**
643
+    /**
644 644
      * Installs a plugin.
645
-	 *
646
-	 * @param array $data
645
+     *
646
+     * @param array $data
647 647
      */
648 648
     public function admin_install_plugin( $data ) {
649 649
 
650
-		if ( ! empty( $data['plugins'] ) ) {
651
-			include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
652
-			wp_cache_flush();
650
+        if ( ! empty( $data['plugins'] ) ) {
651
+            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
652
+            wp_cache_flush();
653 653
 
654
-			foreach ( $data['plugins'] as $slug => $file ) {
655
-				$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
656
-				$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
657
-				$installed  = $upgrader->install( $plugin_zip );
654
+            foreach ( $data['plugins'] as $slug => $file ) {
655
+                $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' );
656
+                $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
657
+                $installed  = $upgrader->install( $plugin_zip );
658 658
 
659
-				if ( ! is_wp_error( $installed ) && $installed ) {
660
-					activate_plugin( $file, '', false, true );
661
-				} else {
662
-					wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
663
-				}
659
+                if ( ! is_wp_error( $installed ) && $installed ) {
660
+                    activate_plugin( $file, '', false, true );
661
+                } else {
662
+                    wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false );
663
+                }
664 664
 
665
-			}
665
+            }
666 666
 
667
-		}
667
+        }
668 668
 
669
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
670
-		wp_safe_redirect( $redirect );
671
-		exit;
669
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' );
670
+        wp_safe_redirect( $redirect );
671
+        exit;
672 672
 
673
-	}
673
+    }
674 674
 
675
-	/**
675
+    /**
676 676
      * Connects a gateway.
677
-	 *
678
-	 * @param array $data
677
+     *
678
+     * @param array $data
679 679
      */
680 680
     public function admin_connect_gateway( $data ) {
681 681
 
682
-		if ( ! empty( $data['plugin'] ) ) {
682
+        if ( ! empty( $data['plugin'] ) ) {
683 683
 
684
-			$gateway     = sanitize_key( $data['plugin'] );
685
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
684
+            $gateway     = sanitize_key( $data['plugin'] );
685
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
686 686
 
687
-			if ( ! empty( $connect_url ) ) {
688
-				wp_redirect( $connect_url );
689
-				exit;
690
-			}
687
+            if ( ! empty( $connect_url ) ) {
688
+                wp_redirect( $connect_url );
689
+                exit;
690
+            }
691 691
 
692
-			if ( 'stripe' == $data['plugin'] ) {
693
-				require_once ABSPATH . 'wp-admin/includes/plugin.php';
694
-				include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
695
-				wp_cache_flush();
692
+            if ( 'stripe' == $data['plugin'] ) {
693
+                require_once ABSPATH . 'wp-admin/includes/plugin.php';
694
+                include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
695
+                wp_cache_flush();
696 696
 
697
-				if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
698
-					$plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
699
-					$upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
700
-					$upgrader->install( $plugin_zip );
701
-				}
697
+                if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) {
698
+                    $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' );
699
+                    $upgrader   = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
700
+                    $upgrader->install( $plugin_zip );
701
+                }
702 702
 
703
-				activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
704
-			}
703
+                activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true );
704
+            }
705 705
 
706
-			$connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
707
-			if ( ! empty( $connect_url ) ) {
708
-				wp_redirect( $connect_url );
709
-				exit;
710
-			}
706
+            $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data );
707
+            if ( ! empty( $connect_url ) ) {
708
+                wp_redirect( $connect_url );
709
+                exit;
710
+            }
711 711
 
712
-		}
712
+        }
713 713
 
714
-		$redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
715
-		wp_safe_redirect( $redirect );
716
-		exit;
714
+        $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' );
715
+        wp_safe_redirect( $redirect );
716
+        exit;
717 717
 
718
-	}
718
+    }
719 719
 
720
-	/**
720
+    /**
721 721
      * Recalculates discounts.
722
-	 * 
722
+     * 
723 723
      */
724 724
     public function admin_recalculate_discounts() {
725
-		global $wpdb;
725
+        global $wpdb;
726 726
 
727
-		// Fetch all invoices that have discount codes.
728
-		$table    = $wpdb->prefix . 'getpaid_invoices';
729
-		$invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
727
+        // Fetch all invoices that have discount codes.
728
+        $table    = $wpdb->prefix . 'getpaid_invoices';
729
+        $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" );
730 730
 
731
-		foreach ( $invoices as $invoice ) {
731
+        foreach ( $invoices as $invoice ) {
732 732
 
733
-			$invoice = new WPInv_Invoice( $invoice );
733
+            $invoice = new WPInv_Invoice( $invoice );
734 734
 
735
-			if ( ! $invoice->exists() ) {
736
-				continue;
737
-			}
735
+            if ( ! $invoice->exists() ) {
736
+                continue;
737
+            }
738 738
 
739
-			// Abort if the discount does not exist or does not apply here.
740
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
741
-			if ( ! $discount->exists() ) {
742
-				continue;
743
-			}
739
+            // Abort if the discount does not exist or does not apply here.
740
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
741
+            if ( ! $discount->exists() ) {
742
+                continue;
743
+            }
744 744
 
745
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
746
-			$invoice->recalculate_total();
745
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
746
+            $invoice->recalculate_total();
747 747
 
748
-			if ( $invoice->get_total_discount() > 0 ) {
749
-				$invoice->save();
750
-			}
748
+            if ( $invoice->get_total_discount() > 0 ) {
749
+                $invoice->save();
750
+            }
751 751
 
752
-		}
752
+        }
753 753
 
754
-		// Show an admin message.
755
-		$this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
754
+        // Show an admin message.
755
+        $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) );
756 756
 
757
-		// Redirect the admin.
758
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
759
-		exit;
757
+        // Redirect the admin.
758
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
759
+        exit;
760 760
 
761
-	}
761
+    }
762 762
 
763 763
     /**
764
-	 * Returns an array of admin notices.
765
-	 *
766
-	 * @since       1.0.19
764
+     * Returns an array of admin notices.
765
+     *
766
+     * @since       1.0.19
767 767
      * @return array
768
-	 */
769
-	public function get_notices() {
770
-		$notices = get_option( 'wpinv_admin_notices' );
768
+     */
769
+    public function get_notices() {
770
+        $notices = get_option( 'wpinv_admin_notices' );
771 771
         return is_array( $notices ) ? $notices : array();
772
-	}
772
+    }
773 773
 
774
-	/**
775
-	 * Checks if we have any admin notices.
776
-	 *
777
-	 * @since       2.0.4
774
+    /**
775
+     * Checks if we have any admin notices.
776
+     *
777
+     * @since       2.0.4
778 778
      * @return array
779
-	 */
780
-	public function has_notices() {
781
-		return count( $this->get_notices() ) > 0;
782
-	}
783
-
784
-	/**
785
-	 * Clears all admin notices
786
-	 *
787
-	 * @access      public
788
-	 * @since       1.0.19
789
-	 */
790
-	public function clear_notices() {
791
-		delete_option( 'wpinv_admin_notices' );
792
-	}
793
-
794
-	/**
795
-	 * Saves a new admin notice
796
-	 *
797
-	 * @access      public
798
-	 * @since       1.0.19
799
-	 */
800
-	public function save_notice( $type, $message ) {
801
-		$notices = $this->get_notices();
802
-
803
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
804
-			$notices[ $type ] = array();
805
-		}
806
-
807
-		$notices[ $type ][] = $message;
808
-
809
-		update_option( 'wpinv_admin_notices', $notices );
810
-	}
811
-
812
-	/**
813
-	 * Displays a success notice
814
-	 *
815
-	 * @param       string $msg The message to qeue.
816
-	 * @access      public
817
-	 * @since       1.0.19
818
-	 */
819
-	public function show_success( $msg ) {
820
-		$this->save_notice( 'success', $msg );
821
-	}
822
-
823
-	/**
824
-	 * Displays a error notice
825
-	 *
826
-	 * @access      public
827
-	 * @param       string $msg The message to qeue.
828
-	 * @since       1.0.19
829
-	 */
830
-	public function show_error( $msg ) {
831
-		$this->save_notice( 'error', $msg );
832
-	}
833
-
834
-	/**
835
-	 * Displays a warning notice
836
-	 *
837
-	 * @access      public
838
-	 * @param       string $msg The message to qeue.
839
-	 * @since       1.0.19
840
-	 */
841
-	public function show_warning( $msg ) {
842
-		$this->save_notice( 'warning', $msg );
843
-	}
844
-
845
-	/**
846
-	 * Displays a info notice
847
-	 *
848
-	 * @access      public
849
-	 * @param       string $msg The message to qeue.
850
-	 * @since       1.0.19
851
-	 */
852
-	public function show_info( $msg ) {
853
-		$this->save_notice( 'info', $msg );
854
-	}
855
-
856
-	/**
857
-	 * Show notices
858
-	 *
859
-	 * @access      public
860
-	 * @since       1.0.19
861
-	 */
862
-	public function show_notices() {
779
+     */
780
+    public function has_notices() {
781
+        return count( $this->get_notices() ) > 0;
782
+    }
783
+
784
+    /**
785
+     * Clears all admin notices
786
+     *
787
+     * @access      public
788
+     * @since       1.0.19
789
+     */
790
+    public function clear_notices() {
791
+        delete_option( 'wpinv_admin_notices' );
792
+    }
793
+
794
+    /**
795
+     * Saves a new admin notice
796
+     *
797
+     * @access      public
798
+     * @since       1.0.19
799
+     */
800
+    public function save_notice( $type, $message ) {
801
+        $notices = $this->get_notices();
802
+
803
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
804
+            $notices[ $type ] = array();
805
+        }
806
+
807
+        $notices[ $type ][] = $message;
808
+
809
+        update_option( 'wpinv_admin_notices', $notices );
810
+    }
811
+
812
+    /**
813
+     * Displays a success notice
814
+     *
815
+     * @param       string $msg The message to qeue.
816
+     * @access      public
817
+     * @since       1.0.19
818
+     */
819
+    public function show_success( $msg ) {
820
+        $this->save_notice( 'success', $msg );
821
+    }
822
+
823
+    /**
824
+     * Displays a error notice
825
+     *
826
+     * @access      public
827
+     * @param       string $msg The message to qeue.
828
+     * @since       1.0.19
829
+     */
830
+    public function show_error( $msg ) {
831
+        $this->save_notice( 'error', $msg );
832
+    }
833
+
834
+    /**
835
+     * Displays a warning notice
836
+     *
837
+     * @access      public
838
+     * @param       string $msg The message to qeue.
839
+     * @since       1.0.19
840
+     */
841
+    public function show_warning( $msg ) {
842
+        $this->save_notice( 'warning', $msg );
843
+    }
844
+
845
+    /**
846
+     * Displays a info notice
847
+     *
848
+     * @access      public
849
+     * @param       string $msg The message to qeue.
850
+     * @since       1.0.19
851
+     */
852
+    public function show_info( $msg ) {
853
+        $this->save_notice( 'info', $msg );
854
+    }
855
+
856
+    /**
857
+     * Show notices
858
+     *
859
+     * @access      public
860
+     * @since       1.0.19
861
+     */
862
+    public function show_notices() {
863 863
 
864 864
         $notices = $this->get_notices();
865 865
         $this->clear_notices();
866 866
 
867
-		foreach ( $notices as $type => $messages ) {
867
+        foreach ( $notices as $type => $messages ) {
868 868
 
869
-			if ( ! is_array( $messages ) ) {
870
-				continue;
871
-			}
869
+            if ( ! is_array( $messages ) ) {
870
+                continue;
871
+            }
872 872
 
873 873
             $type  = sanitize_key( $type );
874
-			foreach ( $messages as $message ) {
874
+            foreach ( $messages as $message ) {
875 875
                 $message = wp_kses_post( $message );
876
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
876
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
877 877
             }
878 878
 
879 879
         }
880 880
 
881
-		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
882
-
883
-			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
884
-				$url     = wp_nonce_url(
885
-					add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
886
-					'getpaid-nonce',
887
-					'getpaid-nonce'
888
-				);
889
-				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
890
-				$message2 = __( 'Generate Pages', 'invoicing' );
891
-				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
892
-				break;
893
-			}
881
+        foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
882
+
883
+            if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
884
+                $url     = wp_nonce_url(
885
+                    add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
886
+                    'getpaid-nonce',
887
+                    'getpaid-nonce'
888
+                );
889
+                $message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
890
+                $message2 = __( 'Generate Pages', 'invoicing' );
891
+                echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
892
+                break;
893
+            }
894 894
 
895
-		}
895
+        }
896 896
 
897
-	}
897
+    }
898 898
 
899 899
 }
Please login to merge, or discard this patch.