@@ -620,7 +620,7 @@ |
||
620 | 620 | <?php |
621 | 621 | } |
622 | 622 | |
623 | - }else{ |
|
623 | + } else{ |
|
624 | 624 | if ( ! empty( $settings ) ) { |
625 | 625 | if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
626 | 626 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
@@ -13,7 +13,7 @@ discard block |
||
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,345 +21,345 @@ discard block |
||
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 | - * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | - * @since 1.0.15 Font Awesome will now load in the FSE if enable din teh backend. |
|
34 | - * @ver 1.0.15 |
|
35 | - * @todo decide how to implement textdomain |
|
36 | - */ |
|
37 | - class WP_Font_Awesome_Settings { |
|
38 | - |
|
39 | - /** |
|
40 | - * Class version version. |
|
41 | - * |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - public $version = '1.0.15'; |
|
45 | - |
|
46 | - /** |
|
47 | - * Class textdomain. |
|
48 | - * |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - public $textdomain = 'font-awesome-settings'; |
|
52 | - |
|
53 | - /** |
|
54 | - * Latest version of Font Awesome at time of publish published. |
|
55 | - * |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - public $latest = "5.8.2"; |
|
59 | - |
|
60 | - /** |
|
61 | - * The title. |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - public $name = 'Font Awesome'; |
|
66 | - |
|
67 | - /** |
|
68 | - * Holds the settings values. |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - private $settings; |
|
73 | - |
|
74 | - /** |
|
75 | - * WP_Font_Awesome_Settings instance. |
|
76 | - * |
|
77 | - * @access private |
|
78 | - * @since 1.0.0 |
|
79 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
80 | - */ |
|
81 | - private static $instance = null; |
|
82 | - |
|
83 | - /** |
|
84 | - * Main WP_Font_Awesome_Settings Instance. |
|
85 | - * |
|
86 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
87 | - * |
|
88 | - * @since 1.0.0 |
|
89 | - * @static |
|
90 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
91 | - */ |
|
92 | - public static function instance() { |
|
93 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
94 | - self::$instance = new WP_Font_Awesome_Settings; |
|
95 | - |
|
96 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
97 | - |
|
98 | - if ( is_admin() ) { |
|
99 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
100 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
101 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
102 | - } |
|
103 | - |
|
104 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
105 | - } |
|
106 | - |
|
107 | - return self::$instance; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Initiate the settings and add the required action hooks. |
|
112 | - * |
|
113 | - * @since 1.0.8 Settings name wrong - FIXED |
|
114 | - */ |
|
115 | - public function init() { |
|
116 | - $this->settings = $this->get_settings(); |
|
117 | - |
|
118 | - // check if the official plugin is active and use that instead if so. |
|
119 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
120 | - |
|
121 | - if ( $this->settings['type'] == 'CSS' ) { |
|
122 | - |
|
123 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
125 | - } |
|
126 | - |
|
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
128 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
129 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
130 | - } |
|
131 | - |
|
132 | - } else { |
|
133 | - |
|
134 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
135 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
136 | - } |
|
137 | - |
|
138 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
139 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
140 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - // remove font awesome if set to do so |
|
145 | - if ( $this->settings['dequeue'] == '1' ) { |
|
146 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Add FA to the FSE. |
|
154 | - * |
|
155 | - * @param $editor_settings |
|
156 | - * @param $block_editor_context |
|
157 | - * |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
161 | - |
|
162 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
163 | - $url = $this->get_url(); |
|
164 | - $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
165 | - } |
|
166 | - |
|
167 | - return $editor_settings; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Add FA to the FSE. |
|
172 | - * |
|
173 | - * @param $editor_settings |
|
174 | - * @param $block_editor_context |
|
175 | - * |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
179 | - |
|
180 | - $url = $this->get_url(); |
|
181 | - $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
182 | - |
|
183 | - return $editor_settings; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Adds the Font Awesome styles. |
|
188 | - */ |
|
189 | - public function enqueue_style() { |
|
190 | - // build url |
|
191 | - $url = $this->get_url(); |
|
192 | - |
|
193 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
194 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
195 | - wp_enqueue_style( 'font-awesome' ); |
|
196 | - |
|
197 | - // RTL language support CSS. |
|
198 | - if ( is_rtl() ) { |
|
199 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
200 | - } |
|
201 | - |
|
202 | - if ( $this->settings['shims'] ) { |
|
203 | - $url = $this->get_url( true ); |
|
204 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
205 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
206 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Adds the Font Awesome JS. |
|
212 | - */ |
|
213 | - public function enqueue_scripts() { |
|
214 | - // build url |
|
215 | - $url = $this->get_url(); |
|
216 | - |
|
217 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
218 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
219 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
220 | - wp_enqueue_script( 'font-awesome' ); |
|
221 | - |
|
222 | - if ( $this->settings['shims'] ) { |
|
223 | - $url = $this->get_url( true ); |
|
224 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
225 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
226 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Get the url of the Font Awesome files. |
|
232 | - * |
|
233 | - * @param bool $shims If this is a shim file or not. |
|
234 | - * |
|
235 | - * @return string The url to the file. |
|
236 | - */ |
|
237 | - public function get_url( $shims = false ) { |
|
238 | - $script = $shims ? 'v4-shims' : 'all'; |
|
239 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
240 | - $type = $this->settings['type']; |
|
241 | - $version = $this->settings['version']; |
|
242 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
243 | - $url = ''; |
|
244 | - |
|
245 | - if ( $type == 'KIT' && $kit_url ) { |
|
246 | - if ( $shims ) { |
|
247 | - // if its a kit then we don't add shims here |
|
248 | - return ''; |
|
249 | - } |
|
250 | - $url .= $kit_url; // CDN |
|
251 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
252 | - } else { |
|
253 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
254 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
255 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
256 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
257 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
258 | - } |
|
259 | - |
|
260 | - return $url; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
265 | - * |
|
266 | - * 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. |
|
267 | - * |
|
268 | - * @param $url |
|
269 | - * @param $original_url |
|
270 | - * @param $_context |
|
271 | - * |
|
272 | - * @return string The filtered url. |
|
273 | - */ |
|
274 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
275 | - |
|
276 | - if ( $_context == 'display' |
|
277 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
278 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
279 | - ) {// it's a font-awesome-url (probably) |
|
280 | - |
|
281 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
282 | - if ( $this->settings['type'] == 'JS' ) { |
|
283 | - if ( $this->settings['js-pseudo'] ) { |
|
284 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
285 | - } else { |
|
286 | - $url .= "' defer='defer"; |
|
287 | - } |
|
288 | - } |
|
289 | - } else { |
|
290 | - $url = ''; // removing the url removes the file |
|
291 | - } |
|
292 | - |
|
293 | - } |
|
294 | - |
|
295 | - return $url; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Register the database settings with WordPress. |
|
300 | - */ |
|
301 | - public function register_settings() { |
|
302 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Add the WordPress settings menu item. |
|
307 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
308 | - */ |
|
309 | - public function menu_item() { |
|
310 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
311 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
312 | - $this, |
|
313 | - 'settings_page' |
|
314 | - ) ); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Get the current Font Awesome output settings. |
|
319 | - * |
|
320 | - * @return array The array of settings. |
|
321 | - */ |
|
322 | - public function get_settings() { |
|
323 | - |
|
324 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
325 | - |
|
326 | - $defaults = array( |
|
327 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
328 | - 'version' => '', // latest |
|
329 | - 'enqueue' => '', // front and backend |
|
330 | - 'shims' => '0', // default OFF now in 2020 |
|
331 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
332 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
333 | - 'pro' => '0', // if pro CDN url should be used |
|
334 | - 'kit-url' => '', // the kit url |
|
335 | - ); |
|
336 | - |
|
337 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
338 | - |
|
339 | - /** |
|
340 | - * Filter the Font Awesome settings. |
|
341 | - * |
|
342 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
343 | - */ |
|
344 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * The settings page html output. |
|
350 | - */ |
|
351 | - public function settings_page() { |
|
352 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
353 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
354 | - } |
|
355 | - |
|
356 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
357 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
358 | - $this->get_latest_version( $force_api = true ); |
|
359 | - } |
|
360 | - |
|
361 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
362 | - ?> |
|
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 | + * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | + * @since 1.0.15 Font Awesome will now load in the FSE if enable din teh backend. |
|
34 | + * @ver 1.0.15 |
|
35 | + * @todo decide how to implement textdomain |
|
36 | + */ |
|
37 | + class WP_Font_Awesome_Settings { |
|
38 | + |
|
39 | + /** |
|
40 | + * Class version version. |
|
41 | + * |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + public $version = '1.0.15'; |
|
45 | + |
|
46 | + /** |
|
47 | + * Class textdomain. |
|
48 | + * |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + public $textdomain = 'font-awesome-settings'; |
|
52 | + |
|
53 | + /** |
|
54 | + * Latest version of Font Awesome at time of publish published. |
|
55 | + * |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + public $latest = "5.8.2"; |
|
59 | + |
|
60 | + /** |
|
61 | + * The title. |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + public $name = 'Font Awesome'; |
|
66 | + |
|
67 | + /** |
|
68 | + * Holds the settings values. |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + private $settings; |
|
73 | + |
|
74 | + /** |
|
75 | + * WP_Font_Awesome_Settings instance. |
|
76 | + * |
|
77 | + * @access private |
|
78 | + * @since 1.0.0 |
|
79 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
80 | + */ |
|
81 | + private static $instance = null; |
|
82 | + |
|
83 | + /** |
|
84 | + * Main WP_Font_Awesome_Settings Instance. |
|
85 | + * |
|
86 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
87 | + * |
|
88 | + * @since 1.0.0 |
|
89 | + * @static |
|
90 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
91 | + */ |
|
92 | + public static function instance() { |
|
93 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
94 | + self::$instance = new WP_Font_Awesome_Settings; |
|
95 | + |
|
96 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
97 | + |
|
98 | + if ( is_admin() ) { |
|
99 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
100 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
101 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
102 | + } |
|
103 | + |
|
104 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
105 | + } |
|
106 | + |
|
107 | + return self::$instance; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Initiate the settings and add the required action hooks. |
|
112 | + * |
|
113 | + * @since 1.0.8 Settings name wrong - FIXED |
|
114 | + */ |
|
115 | + public function init() { |
|
116 | + $this->settings = $this->get_settings(); |
|
117 | + |
|
118 | + // check if the official plugin is active and use that instead if so. |
|
119 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
120 | + |
|
121 | + if ( $this->settings['type'] == 'CSS' ) { |
|
122 | + |
|
123 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
124 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
125 | + } |
|
126 | + |
|
127 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
128 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
129 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
130 | + } |
|
131 | + |
|
132 | + } else { |
|
133 | + |
|
134 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
135 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
136 | + } |
|
137 | + |
|
138 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
139 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
140 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + // remove font awesome if set to do so |
|
145 | + if ( $this->settings['dequeue'] == '1' ) { |
|
146 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Add FA to the FSE. |
|
154 | + * |
|
155 | + * @param $editor_settings |
|
156 | + * @param $block_editor_context |
|
157 | + * |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
161 | + |
|
162 | + if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
163 | + $url = $this->get_url(); |
|
164 | + $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
165 | + } |
|
166 | + |
|
167 | + return $editor_settings; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Add FA to the FSE. |
|
172 | + * |
|
173 | + * @param $editor_settings |
|
174 | + * @param $block_editor_context |
|
175 | + * |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
179 | + |
|
180 | + $url = $this->get_url(); |
|
181 | + $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
182 | + |
|
183 | + return $editor_settings; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Adds the Font Awesome styles. |
|
188 | + */ |
|
189 | + public function enqueue_style() { |
|
190 | + // build url |
|
191 | + $url = $this->get_url(); |
|
192 | + |
|
193 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
194 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
195 | + wp_enqueue_style( 'font-awesome' ); |
|
196 | + |
|
197 | + // RTL language support CSS. |
|
198 | + if ( is_rtl() ) { |
|
199 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
200 | + } |
|
201 | + |
|
202 | + if ( $this->settings['shims'] ) { |
|
203 | + $url = $this->get_url( true ); |
|
204 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
205 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
206 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Adds the Font Awesome JS. |
|
212 | + */ |
|
213 | + public function enqueue_scripts() { |
|
214 | + // build url |
|
215 | + $url = $this->get_url(); |
|
216 | + |
|
217 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
218 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
219 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
220 | + wp_enqueue_script( 'font-awesome' ); |
|
221 | + |
|
222 | + if ( $this->settings['shims'] ) { |
|
223 | + $url = $this->get_url( true ); |
|
224 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
225 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
226 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Get the url of the Font Awesome files. |
|
232 | + * |
|
233 | + * @param bool $shims If this is a shim file or not. |
|
234 | + * |
|
235 | + * @return string The url to the file. |
|
236 | + */ |
|
237 | + public function get_url( $shims = false ) { |
|
238 | + $script = $shims ? 'v4-shims' : 'all'; |
|
239 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
240 | + $type = $this->settings['type']; |
|
241 | + $version = $this->settings['version']; |
|
242 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
243 | + $url = ''; |
|
244 | + |
|
245 | + if ( $type == 'KIT' && $kit_url ) { |
|
246 | + if ( $shims ) { |
|
247 | + // if its a kit then we don't add shims here |
|
248 | + return ''; |
|
249 | + } |
|
250 | + $url .= $kit_url; // CDN |
|
251 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
252 | + } else { |
|
253 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
254 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
255 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
256 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
257 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
258 | + } |
|
259 | + |
|
260 | + return $url; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
265 | + * |
|
266 | + * 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. |
|
267 | + * |
|
268 | + * @param $url |
|
269 | + * @param $original_url |
|
270 | + * @param $_context |
|
271 | + * |
|
272 | + * @return string The filtered url. |
|
273 | + */ |
|
274 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
275 | + |
|
276 | + if ( $_context == 'display' |
|
277 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
278 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
279 | + ) {// it's a font-awesome-url (probably) |
|
280 | + |
|
281 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
282 | + if ( $this->settings['type'] == 'JS' ) { |
|
283 | + if ( $this->settings['js-pseudo'] ) { |
|
284 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
285 | + } else { |
|
286 | + $url .= "' defer='defer"; |
|
287 | + } |
|
288 | + } |
|
289 | + } else { |
|
290 | + $url = ''; // removing the url removes the file |
|
291 | + } |
|
292 | + |
|
293 | + } |
|
294 | + |
|
295 | + return $url; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Register the database settings with WordPress. |
|
300 | + */ |
|
301 | + public function register_settings() { |
|
302 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Add the WordPress settings menu item. |
|
307 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
308 | + */ |
|
309 | + public function menu_item() { |
|
310 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
311 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
312 | + $this, |
|
313 | + 'settings_page' |
|
314 | + ) ); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Get the current Font Awesome output settings. |
|
319 | + * |
|
320 | + * @return array The array of settings. |
|
321 | + */ |
|
322 | + public function get_settings() { |
|
323 | + |
|
324 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
325 | + |
|
326 | + $defaults = array( |
|
327 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
328 | + 'version' => '', // latest |
|
329 | + 'enqueue' => '', // front and backend |
|
330 | + 'shims' => '0', // default OFF now in 2020 |
|
331 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
332 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
333 | + 'pro' => '0', // if pro CDN url should be used |
|
334 | + 'kit-url' => '', // the kit url |
|
335 | + ); |
|
336 | + |
|
337 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
338 | + |
|
339 | + /** |
|
340 | + * Filter the Font Awesome settings. |
|
341 | + * |
|
342 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
343 | + */ |
|
344 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * The settings page html output. |
|
350 | + */ |
|
351 | + public function settings_page() { |
|
352 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
353 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
354 | + } |
|
355 | + |
|
356 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
357 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
358 | + $this->get_latest_version( $force_api = true ); |
|
359 | + } |
|
360 | + |
|
361 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
362 | + ?> |
|
363 | 363 | <style> |
364 | 364 | .wpfas-kit-show { |
365 | 365 | display: none; |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | <h1><?php echo $this->name; ?></h1> |
378 | 378 | <form method="post" action="options.php" class="fas-settings-form"> |
379 | 379 | <?php |
380 | - settings_fields( 'wp-font-awesome-settings' ); |
|
381 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
382 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
383 | - ?> |
|
380 | + settings_fields( 'wp-font-awesome-settings' ); |
|
381 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
382 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
383 | + ?> |
|
384 | 384 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
385 | 385 | <tr valign="top"> |
386 | 386 | <th scope="row"><label |
@@ -406,12 +406,12 @@ discard block |
||
406 | 406 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
407 | 407 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
408 | 408 | <span><?php |
409 | - echo sprintf( |
|
410 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
411 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
412 | - '</a>' |
|
413 | - ); |
|
414 | - ?></span> |
|
409 | + echo sprintf( |
|
410 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
411 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
412 | + '</a>' |
|
413 | + ); |
|
414 | + ?></span> |
|
415 | 415 | </td> |
416 | 416 | </tr> |
417 | 417 | |
@@ -480,14 +480,14 @@ discard block |
||
480 | 480 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
481 | 481 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
482 | 482 | <span><?php |
483 | - echo sprintf( |
|
484 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
485 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
486 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
487 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
488 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
489 | - ); |
|
490 | - ?></span> |
|
483 | + echo sprintf( |
|
484 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
485 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
486 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
487 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
488 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
489 | + ); |
|
490 | + ?></span> |
|
491 | 491 | </td> |
492 | 492 | </tr> |
493 | 493 | |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | </table> |
532 | 532 | <div class="fas-buttons"> |
533 | 533 | <?php |
534 | - submit_button(); |
|
535 | - ?> |
|
534 | + submit_button(); |
|
535 | + ?> |
|
536 | 536 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
537 | 537 | |
538 | 538 | </div> |
@@ -556,126 +556,126 @@ discard block |
||
556 | 556 | } |
557 | 557 | </style> |
558 | 558 | <?php |
559 | - } |
|
560 | - } |
|
561 | - |
|
562 | - /** |
|
563 | - * Check a version number is valid and if so return it or else return an empty string. |
|
564 | - * |
|
565 | - * @param $version string The version number to check. |
|
566 | - * |
|
567 | - * @since 1.0.6 |
|
568 | - * |
|
569 | - * @return string Either a valid version number or an empty string. |
|
570 | - */ |
|
571 | - public function validate_version_number( $version ) { |
|
572 | - |
|
573 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
574 | - // valid |
|
575 | - } else { |
|
576 | - $version = '';// not validated |
|
577 | - } |
|
578 | - |
|
579 | - return $version; |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * Get the latest version of Font Awesome. |
|
585 | - * |
|
586 | - * 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. |
|
587 | - * |
|
588 | - * @since 1.0.7 |
|
589 | - * @return mixed|string The latest version number found. |
|
590 | - */ |
|
591 | - public function get_latest_version( $force_api = false ) { |
|
592 | - $latest_version = $this->latest; |
|
593 | - |
|
594 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
595 | - |
|
596 | - if ( $cache === false || $force_api ) { // its not set |
|
597 | - $api_ver = $this->get_latest_version_from_api(); |
|
598 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
599 | - $latest_version = $api_ver; |
|
600 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
601 | - } |
|
602 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
603 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
604 | - $latest_version = $cache; |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - return $latest_version; |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * Get the latest Font Awesome version from the github API. |
|
613 | - * |
|
614 | - * @since 1.0.7 |
|
615 | - * @return string The latest version number or `0` on API fail. |
|
616 | - */ |
|
617 | - public function get_latest_version_from_api() { |
|
618 | - $version = "0"; |
|
619 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
620 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
621 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
622 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
623 | - $version = $api_response['tag_name']; |
|
624 | - } |
|
625 | - } |
|
626 | - |
|
627 | - return $version; |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * Inline CSS for RTL language support. |
|
632 | - * |
|
633 | - * @since 1.0.13 |
|
634 | - * @return string Inline CSS. |
|
635 | - */ |
|
636 | - public function rtl_inline_css() { |
|
637 | - $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}'; |
|
638 | - |
|
639 | - return $inline_css; |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * Show any warnings as an admin notice. |
|
644 | - * |
|
645 | - * @return void |
|
646 | - */ |
|
647 | - public function admin_notices(){ |
|
648 | - $settings = $this->settings; |
|
649 | - |
|
650 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
651 | - |
|
652 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
653 | - ?> |
|
559 | + } |
|
560 | + } |
|
561 | + |
|
562 | + /** |
|
563 | + * Check a version number is valid and if so return it or else return an empty string. |
|
564 | + * |
|
565 | + * @param $version string The version number to check. |
|
566 | + * |
|
567 | + * @since 1.0.6 |
|
568 | + * |
|
569 | + * @return string Either a valid version number or an empty string. |
|
570 | + */ |
|
571 | + public function validate_version_number( $version ) { |
|
572 | + |
|
573 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
574 | + // valid |
|
575 | + } else { |
|
576 | + $version = '';// not validated |
|
577 | + } |
|
578 | + |
|
579 | + return $version; |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * Get the latest version of Font Awesome. |
|
585 | + * |
|
586 | + * 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. |
|
587 | + * |
|
588 | + * @since 1.0.7 |
|
589 | + * @return mixed|string The latest version number found. |
|
590 | + */ |
|
591 | + public function get_latest_version( $force_api = false ) { |
|
592 | + $latest_version = $this->latest; |
|
593 | + |
|
594 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
595 | + |
|
596 | + if ( $cache === false || $force_api ) { // its not set |
|
597 | + $api_ver = $this->get_latest_version_from_api(); |
|
598 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
599 | + $latest_version = $api_ver; |
|
600 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
601 | + } |
|
602 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
603 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
604 | + $latest_version = $cache; |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + return $latest_version; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * Get the latest Font Awesome version from the github API. |
|
613 | + * |
|
614 | + * @since 1.0.7 |
|
615 | + * @return string The latest version number or `0` on API fail. |
|
616 | + */ |
|
617 | + public function get_latest_version_from_api() { |
|
618 | + $version = "0"; |
|
619 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
620 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
621 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
622 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
623 | + $version = $api_response['tag_name']; |
|
624 | + } |
|
625 | + } |
|
626 | + |
|
627 | + return $version; |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * Inline CSS for RTL language support. |
|
632 | + * |
|
633 | + * @since 1.0.13 |
|
634 | + * @return string Inline CSS. |
|
635 | + */ |
|
636 | + public function rtl_inline_css() { |
|
637 | + $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}'; |
|
638 | + |
|
639 | + return $inline_css; |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * Show any warnings as an admin notice. |
|
644 | + * |
|
645 | + * @return void |
|
646 | + */ |
|
647 | + public function admin_notices(){ |
|
648 | + $settings = $this->settings; |
|
649 | + |
|
650 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
651 | + |
|
652 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
653 | + ?> |
|
654 | 654 | <div class="notice notice-error is-dismissible"> |
655 | 655 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
656 | 656 | </div> |
657 | 657 | <?php |
658 | - } |
|
658 | + } |
|
659 | 659 | |
660 | - }else{ |
|
661 | - if ( ! empty( $settings ) ) { |
|
662 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
663 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
664 | - ?> |
|
660 | + }else{ |
|
661 | + if ( ! empty( $settings ) ) { |
|
662 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
663 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
664 | + ?> |
|
665 | 665 | <div class="notice notice-error is-dismissible"> |
666 | 666 | <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
667 | 667 | </div> |
668 | 668 | <?php |
669 | - } |
|
670 | - } |
|
671 | - } |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | 672 | |
673 | - } |
|
673 | + } |
|
674 | 674 | |
675 | - } |
|
675 | + } |
|
676 | 676 | |
677 | - /** |
|
678 | - * Run the class if found. |
|
679 | - */ |
|
680 | - WP_Font_Awesome_Settings::instance(); |
|
677 | + /** |
|
678 | + * Run the class if found. |
|
679 | + */ |
|
680 | + WP_Font_Awesome_Settings::instance(); |
|
681 | 681 | } |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | * @return WP_Font_Awesome_Settings - Main instance. |
91 | 91 | */ |
92 | 92 | public static function instance() { |
93 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
93 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
94 | 94 | self::$instance = new WP_Font_Awesome_Settings; |
95 | 95 | |
96 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
96 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
97 | 97 | |
98 | - if ( is_admin() ) { |
|
99 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
100 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
101 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
98 | + if (is_admin()) { |
|
99 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
100 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
101 | + add_action('admin_notices', array(self::$instance, 'admin_notices')); |
|
102 | 102 | } |
103 | 103 | |
104 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
104 | + do_action('wp_font_awesome_settings_loaded'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return self::$instance; |
@@ -116,34 +116,34 @@ discard block |
||
116 | 116 | $this->settings = $this->get_settings(); |
117 | 117 | |
118 | 118 | // check if the official plugin is active and use that instead if so. |
119 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
119 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
120 | 120 | |
121 | - if ( $this->settings['type'] == 'CSS' ) { |
|
121 | + if ($this->settings['type'] == 'CSS') { |
|
122 | 122 | |
123 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
124 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
125 | 125 | } |
126 | 126 | |
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
128 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
129 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
127 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
128 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
129 | + add_filter('block_editor_settings_all', array($this, 'enqueue_editor_styles'), 10, 2); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | } else { |
133 | 133 | |
134 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
135 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
134 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
135 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
136 | 136 | } |
137 | 137 | |
138 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
139 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
140 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
138 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
139 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
140 | + add_filter('block_editor_settings_all', array($this, 'enqueue_editor_scripts'), 10, 2); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | 144 | // remove font awesome if set to do so |
145 | - if ( $this->settings['dequeue'] == '1' ) { |
|
146 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
145 | + if ($this->settings['dequeue'] == '1') { |
|
146 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
160 | + public function enqueue_editor_styles($editor_settings, $block_editor_context) { |
|
161 | 161 | |
162 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
162 | + if (!empty($editor_settings['__unstableResolvedAssets']['styles'])) { |
|
163 | 163 | $url = $this->get_url(); |
164 | 164 | $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
165 | 165 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return array |
177 | 177 | */ |
178 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
178 | + public function enqueue_editor_scripts($editor_settings, $block_editor_context) { |
|
179 | 179 | |
180 | 180 | $url = $this->get_url(); |
181 | 181 | $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
@@ -190,20 +190,20 @@ discard block |
||
190 | 190 | // build url |
191 | 191 | $url = $this->get_url(); |
192 | 192 | |
193 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
194 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
195 | - wp_enqueue_style( 'font-awesome' ); |
|
193 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
194 | + wp_register_style('font-awesome', $url, array(), null); |
|
195 | + wp_enqueue_style('font-awesome'); |
|
196 | 196 | |
197 | 197 | // RTL language support CSS. |
198 | - if ( is_rtl() ) { |
|
199 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
198 | + if (is_rtl()) { |
|
199 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
200 | 200 | } |
201 | 201 | |
202 | - if ( $this->settings['shims'] ) { |
|
203 | - $url = $this->get_url( true ); |
|
204 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
205 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
206 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
202 | + if ($this->settings['shims']) { |
|
203 | + $url = $this->get_url(true); |
|
204 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
205 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
206 | + wp_enqueue_style('font-awesome-shims'); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | $url = $this->get_url(); |
216 | 216 | |
217 | 217 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
218 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
219 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
220 | - wp_enqueue_script( 'font-awesome' ); |
|
221 | - |
|
222 | - if ( $this->settings['shims'] ) { |
|
223 | - $url = $this->get_url( true ); |
|
224 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
225 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
226 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
218 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
219 | + wp_register_script('font-awesome', $url, array(), null); |
|
220 | + wp_enqueue_script('font-awesome'); |
|
221 | + |
|
222 | + if ($this->settings['shims']) { |
|
223 | + $url = $this->get_url(true); |
|
224 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
225 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
226 | + wp_enqueue_script('font-awesome-shims'); |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
@@ -234,16 +234,16 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return string The url to the file. |
236 | 236 | */ |
237 | - public function get_url( $shims = false ) { |
|
237 | + public function get_url($shims = false) { |
|
238 | 238 | $script = $shims ? 'v4-shims' : 'all'; |
239 | 239 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
240 | 240 | $type = $this->settings['type']; |
241 | 241 | $version = $this->settings['version']; |
242 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
242 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
243 | 243 | $url = ''; |
244 | 244 | |
245 | - if ( $type == 'KIT' && $kit_url ) { |
|
246 | - if ( $shims ) { |
|
245 | + if ($type == 'KIT' && $kit_url) { |
|
246 | + if ($shims) { |
|
247 | 247 | // if its a kit then we don't add shims here |
248 | 248 | return ''; |
249 | 249 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $url .= "?wpfas=true"; // set our var so our version is not removed |
252 | 252 | } else { |
253 | 253 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
254 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
254 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
255 | 255 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
256 | 256 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
257 | 257 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -271,16 +271,16 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return string The filtered url. |
273 | 273 | */ |
274 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
274 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
275 | 275 | |
276 | - if ( $_context == 'display' |
|
277 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
278 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
276 | + if ($_context == 'display' |
|
277 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
278 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
279 | 279 | ) {// it's a font-awesome-url (probably) |
280 | 280 | |
281 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
282 | - if ( $this->settings['type'] == 'JS' ) { |
|
283 | - if ( $this->settings['js-pseudo'] ) { |
|
281 | + if (strstr($url, "wpfas=true") !== false) { |
|
282 | + if ($this->settings['type'] == 'JS') { |
|
283 | + if ($this->settings['js-pseudo']) { |
|
284 | 284 | $url .= "' data-search-pseudo-elements defer='defer"; |
285 | 285 | } else { |
286 | 286 | $url .= "' defer='defer"; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * Register the database settings with WordPress. |
300 | 300 | */ |
301 | 301 | public function register_settings() { |
302 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
302 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function menu_item() { |
310 | 310 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
311 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
311 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
312 | 312 | $this, |
313 | 313 | 'settings_page' |
314 | - ) ); |
|
314 | + )); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function get_settings() { |
323 | 323 | |
324 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
324 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
325 | 325 | |
326 | 326 | $defaults = array( |
327 | 327 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -334,14 +334,14 @@ discard block |
||
334 | 334 | 'kit-url' => '', // the kit url |
335 | 335 | ); |
336 | 336 | |
337 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
337 | + $settings = wp_parse_args($db_settings, $defaults); |
|
338 | 338 | |
339 | 339 | /** |
340 | 340 | * Filter the Font Awesome settings. |
341 | 341 | * |
342 | 342 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
343 | 343 | */ |
344 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
344 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | |
@@ -349,16 +349,16 @@ discard block |
||
349 | 349 | * The settings page html output. |
350 | 350 | */ |
351 | 351 | public function settings_page() { |
352 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
353 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
352 | + if (!current_user_can('manage_options')) { |
|
353 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
357 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
358 | - $this->get_latest_version( $force_api = true ); |
|
357 | + if (isset($_REQUEST['force-version-check'])) { |
|
358 | + $this->get_latest_version($force_api = true); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
361 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
362 | 362 | ?> |
363 | 363 | <style> |
364 | 364 | .wpfas-kit-show { |
@@ -377,37 +377,37 @@ discard block |
||
377 | 377 | <h1><?php echo $this->name; ?></h1> |
378 | 378 | <form method="post" action="options.php" class="fas-settings-form"> |
379 | 379 | <?php |
380 | - settings_fields( 'wp-font-awesome-settings' ); |
|
381 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
380 | + settings_fields('wp-font-awesome-settings'); |
|
381 | + do_settings_sections('wp-font-awesome-settings'); |
|
382 | 382 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
383 | 383 | ?> |
384 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
384 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($kit_set); ?>"> |
|
385 | 385 | <tr valign="top"> |
386 | 386 | <th scope="row"><label |
387 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
387 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
388 | 388 | <td> |
389 | 389 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
390 | 390 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
391 | 391 | <option |
392 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
393 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
392 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
393 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
394 | 394 | <option |
395 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
395 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
396 | 396 | </select> |
397 | 397 | </td> |
398 | 398 | </tr> |
399 | 399 | |
400 | 400 | <tr valign="top" class="wpfas-kit-show"> |
401 | 401 | <th scope="row"><label |
402 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
402 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
403 | 403 | <td> |
404 | 404 | <input class="regular-text" id="wpfas-kit-url" type="url" |
405 | 405 | name="wp-font-awesome-settings[kit-url]" |
406 | - value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
|
407 | - placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
406 | + value="<?php echo esc_attr($this->settings['kit-url']); ?>" |
|
407 | + placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
408 | 408 | <span><?php |
409 | 409 | echo sprintf( |
410 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
410 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
411 | 411 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
412 | 412 | '</a>' |
413 | 413 | ); |
@@ -417,40 +417,40 @@ discard block |
||
417 | 417 | |
418 | 418 | <tr valign="top" class="wpfas-kit-hide"> |
419 | 419 | <th scope="row"><label |
420 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
420 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
421 | 421 | <td> |
422 | 422 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
423 | 423 | <option |
424 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
424 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
425 | 425 | </option> |
426 | - <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>> |
|
426 | + <option value="6.1.0" <?php selected($this->settings['version'], '6.1.0'); ?>> |
|
427 | 427 | 6.1.0 |
428 | 428 | </option> |
429 | - <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>> |
|
429 | + <option value="6.0.0" <?php selected($this->settings['version'], '6.0.0'); ?>> |
|
430 | 430 | 6.0.0 |
431 | 431 | </option> |
432 | - <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>> |
|
432 | + <option value="5.15.4" <?php selected($this->settings['version'], '5.15.4'); ?>> |
|
433 | 433 | 5.15.4 |
434 | 434 | </option> |
435 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
435 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
436 | 436 | 5.6.0 |
437 | 437 | </option> |
438 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
438 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
439 | 439 | 5.5.0 |
440 | 440 | </option> |
441 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
441 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
442 | 442 | 5.4.0 |
443 | 443 | </option> |
444 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
444 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
445 | 445 | 5.3.0 |
446 | 446 | </option> |
447 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
447 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
448 | 448 | 5.2.0 |
449 | 449 | </option> |
450 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
450 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
451 | 451 | 5.1.0 |
452 | 452 | </option> |
453 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
453 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
454 | 454 | 4.7.1 (CSS only) |
455 | 455 | </option> |
456 | 456 | </select> |
@@ -459,29 +459,29 @@ discard block |
||
459 | 459 | |
460 | 460 | <tr valign="top"> |
461 | 461 | <th scope="row"><label |
462 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
462 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
463 | 463 | <td> |
464 | 464 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
465 | 465 | <option |
466 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
466 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
467 | 467 | <option |
468 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
468 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
469 | 469 | <option |
470 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
470 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
471 | 471 | </select> |
472 | 472 | </td> |
473 | 473 | </tr> |
474 | 474 | |
475 | 475 | <tr valign="top" class="wpfas-kit-hide"> |
476 | 476 | <th scope="row"><label |
477 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
477 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
478 | 478 | <td> |
479 | 479 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
480 | 480 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
481 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
481 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
482 | 482 | <span><?php |
483 | 483 | echo sprintf( |
484 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
484 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
485 | 485 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
486 | 486 | ' <i class="fas fa-external-link-alt"></i></a>', |
487 | 487 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
@@ -493,38 +493,38 @@ discard block |
||
493 | 493 | |
494 | 494 | <tr valign="top" class="wpfas-kit-hide"> |
495 | 495 | <th scope="row"><label |
496 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
496 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
497 | 497 | </th> |
498 | 498 | <td> |
499 | 499 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
500 | 500 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
501 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
502 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
501 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
502 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
503 | 503 | </td> |
504 | 504 | </tr> |
505 | 505 | |
506 | 506 | <tr valign="top" class="wpfas-kit-hide"> |
507 | 507 | <th scope="row"><label |
508 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
508 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
509 | 509 | </th> |
510 | 510 | <td> |
511 | 511 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
512 | 512 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
513 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
513 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
514 | 514 | id="wpfas-js-pseudo"/> |
515 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
515 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
516 | 516 | </td> |
517 | 517 | </tr> |
518 | 518 | |
519 | 519 | <tr valign="top"> |
520 | 520 | <th scope="row"><label |
521 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
521 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
522 | 522 | <td> |
523 | 523 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
524 | 524 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
525 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
525 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
526 | 526 | id="wpfas-dequeue"/> |
527 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
527 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
528 | 528 | </td> |
529 | 529 | </tr> |
530 | 530 | |
@@ -533,12 +533,12 @@ discard block |
||
533 | 533 | <?php |
534 | 534 | submit_button(); |
535 | 535 | ?> |
536 | - <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
536 | + <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro', 'font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
537 | 537 | |
538 | 538 | </div> |
539 | 539 | </form> |
540 | 540 | |
541 | - <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div> |
|
541 | + <div id="wpfas-version"><?php echo sprintf(__('Version: %s (affiliate links provided)', 'font-awesome-settings'), $this->version); ?></div> |
|
542 | 542 | </div> |
543 | 543 | |
544 | 544 | <style> |
@@ -568,12 +568,12 @@ discard block |
||
568 | 568 | * |
569 | 569 | * @return string Either a valid version number or an empty string. |
570 | 570 | */ |
571 | - public function validate_version_number( $version ) { |
|
571 | + public function validate_version_number($version) { |
|
572 | 572 | |
573 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
573 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
574 | 574 | // valid |
575 | 575 | } else { |
576 | - $version = '';// not validated |
|
576 | + $version = ''; // not validated |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | return $version; |
@@ -588,19 +588,19 @@ discard block |
||
588 | 588 | * @since 1.0.7 |
589 | 589 | * @return mixed|string The latest version number found. |
590 | 590 | */ |
591 | - public function get_latest_version( $force_api = false ) { |
|
591 | + public function get_latest_version($force_api = false) { |
|
592 | 592 | $latest_version = $this->latest; |
593 | 593 | |
594 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
594 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
595 | 595 | |
596 | - if ( $cache === false || $force_api ) { // its not set |
|
596 | + if ($cache === false || $force_api) { // its not set |
|
597 | 597 | $api_ver = $this->get_latest_version_from_api(); |
598 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
598 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
599 | 599 | $latest_version = $api_ver; |
600 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
600 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
601 | 601 | } |
602 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
603 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
602 | + } elseif ($this->validate_version_number($cache)) { |
|
603 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
604 | 604 | $latest_version = $cache; |
605 | 605 | } |
606 | 606 | } |
@@ -616,10 +616,10 @@ discard block |
||
616 | 616 | */ |
617 | 617 | public function get_latest_version_from_api() { |
618 | 618 | $version = "0"; |
619 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
620 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
621 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
622 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
619 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
620 | + if (!is_wp_error($response) && is_array($response)) { |
|
621 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
622 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
623 | 623 | $version = $api_response['tag_name']; |
624 | 624 | } |
625 | 625 | } |
@@ -644,26 +644,26 @@ discard block |
||
644 | 644 | * |
645 | 645 | * @return void |
646 | 646 | */ |
647 | - public function admin_notices(){ |
|
647 | + public function admin_notices() { |
|
648 | 648 | $settings = $this->settings; |
649 | 649 | |
650 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
650 | + if (defined('FONTAWESOME_PLUGIN_FILE')) { |
|
651 | 651 | |
652 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
652 | + if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-font-awesome-settings') { |
|
653 | 653 | ?> |
654 | 654 | <div class="notice notice-error is-dismissible"> |
655 | - <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
|
655 | + <p><?php _e('The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings'); ?></p> |
|
656 | 656 | </div> |
657 | 657 | <?php |
658 | 658 | } |
659 | 659 | |
660 | - }else{ |
|
661 | - if ( ! empty( $settings ) ) { |
|
662 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
660 | + } else { |
|
661 | + if (!empty($settings)) { |
|
662 | + if ($settings['type'] != 'KIT' && $settings['pro'] && ($settings['version'] == '' || version_compare($settings['version'], '6', '>='))) { |
|
663 | 663 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
664 | 664 | ?> |
665 | 665 | <div class="notice notice-error is-dismissible"> |
666 | - <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
|
666 | + <p><?php echo sprintf(__('Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings'), "<a href='" . esc_url_raw($link) . "'>", "</a>"); ?></p> |
|
667 | 667 | </div> |
668 | 668 | <?php |
669 | 669 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
52 | 52 | $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
53 | + $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
54 | 54 | return reset( $matching_group ); |
55 | 55 | } |
56 | 56 | |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | */ |
64 | 64 | function getpaid_get_subscription( $subscription ) { |
65 | 65 | |
66 | - if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
67 | - $subscription = new WPInv_Subscription( $subscription ); |
|
68 | - } |
|
66 | + if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
67 | + $subscription = new WPInv_Subscription( $subscription ); |
|
68 | + } |
|
69 | 69 | |
70 | - return $subscription->exists() ? $subscription : false; |
|
70 | + return $subscription->exists() ? $subscription : false; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -81,28 +81,28 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
83 | 83 | |
84 | - // Do not retrieve all fields if we just want the count. |
|
85 | - if ( 'count' == $return ) { |
|
86 | - $args['fields'] = 'id'; |
|
87 | - $args['number'] = 1; |
|
88 | - } |
|
84 | + // Do not retrieve all fields if we just want the count. |
|
85 | + if ( 'count' == $return ) { |
|
86 | + $args['fields'] = 'id'; |
|
87 | + $args['number'] = 1; |
|
88 | + } |
|
89 | 89 | |
90 | - // Do not count all matches if we just want the results. |
|
91 | - if ( 'results' == $return ) { |
|
92 | - $args['count_total'] = false; |
|
93 | - } |
|
90 | + // Do not count all matches if we just want the results. |
|
91 | + if ( 'results' == $return ) { |
|
92 | + $args['count_total'] = false; |
|
93 | + } |
|
94 | 94 | |
95 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
95 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
96 | 96 | |
97 | - if ( 'results' == $return ) { |
|
98 | - return $query->get_results(); |
|
99 | - } |
|
97 | + if ( 'results' == $return ) { |
|
98 | + return $query->get_results(); |
|
99 | + } |
|
100 | 100 | |
101 | - if ( 'count' == $return ) { |
|
102 | - return $query->get_total(); |
|
103 | - } |
|
101 | + if ( 'count' == $return ) { |
|
102 | + return $query->get_total(); |
|
103 | + } |
|
104 | 104 | |
105 | - return $query; |
|
105 | + return $query; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,18 +112,18 @@ discard block |
||
112 | 112 | */ |
113 | 113 | function getpaid_get_subscription_statuses() { |
114 | 114 | |
115 | - return apply_filters( |
|
116 | - 'getpaid_get_subscription_statuses', |
|
117 | - array( |
|
118 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
119 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
120 | - 'active' => __( 'Active', 'invoicing' ), |
|
121 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
122 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
123 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
124 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
125 | - ) |
|
126 | - ); |
|
115 | + return apply_filters( |
|
116 | + 'getpaid_get_subscription_statuses', |
|
117 | + array( |
|
118 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
119 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
120 | + 'active' => __( 'Active', 'invoicing' ), |
|
121 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
122 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
123 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
124 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
125 | + ) |
|
126 | + ); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * @return string |
134 | 134 | */ |
135 | 135 | function getpaid_get_subscription_status_label( $status ) { |
136 | - $statuses = getpaid_get_subscription_statuses(); |
|
137 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
136 | + $statuses = getpaid_get_subscription_statuses(); |
|
137 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,18 +144,18 @@ discard block |
||
144 | 144 | */ |
145 | 145 | function getpaid_get_subscription_status_classes() { |
146 | 146 | |
147 | - return apply_filters( |
|
148 | - 'getpaid_get_subscription_status_classes', |
|
149 | - array( |
|
150 | - 'pending' => 'badge-dark', |
|
151 | - 'trialling' => 'badge-info', |
|
152 | - 'active' => 'badge-success', |
|
153 | - 'failing' => 'badge-warning', |
|
154 | - 'expired' => 'badge-danger', |
|
155 | - 'completed' => 'badge-primary', |
|
156 | - 'cancelled' => 'badge-secondary', |
|
157 | - ) |
|
158 | - ); |
|
147 | + return apply_filters( |
|
148 | + 'getpaid_get_subscription_status_classes', |
|
149 | + array( |
|
150 | + 'pending' => 'badge-dark', |
|
151 | + 'trialling' => 'badge-info', |
|
152 | + 'active' => 'badge-success', |
|
153 | + 'failing' => 'badge-warning', |
|
154 | + 'expired' => 'badge-danger', |
|
155 | + 'completed' => 'badge-primary', |
|
156 | + 'cancelled' => 'badge-secondary', |
|
157 | + ) |
|
158 | + ); |
|
159 | 159 | |
160 | 160 | } |
161 | 161 | |
@@ -166,15 +166,15 @@ discard block |
||
166 | 166 | */ |
167 | 167 | function getpaid_get_subscription_status_counts( $args = array() ) { |
168 | 168 | |
169 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
170 | - $counts = array(); |
|
169 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
170 | + $counts = array(); |
|
171 | 171 | |
172 | - foreach ( $statuses as $status ) { |
|
173 | - $_args = wp_parse_args( "status=$status", $args ); |
|
174 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
175 | - } |
|
172 | + foreach ( $statuses as $status ) { |
|
173 | + $_args = wp_parse_args( "status=$status", $args ); |
|
174 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
175 | + } |
|
176 | 176 | |
177 | - return $counts; |
|
177 | + return $counts; |
|
178 | 178 | |
179 | 179 | } |
180 | 180 | |
@@ -185,32 +185,32 @@ discard block |
||
185 | 185 | */ |
186 | 186 | function getpaid_get_subscription_periods() { |
187 | 187 | |
188 | - return apply_filters( |
|
189 | - 'getpaid_get_subscription_periods', |
|
190 | - array( |
|
188 | + return apply_filters( |
|
189 | + 'getpaid_get_subscription_periods', |
|
190 | + array( |
|
191 | 191 | |
192 | - 'day' => array( |
|
193 | - 'singular' => __( '%s day', 'invoicing' ), |
|
194 | - 'plural' => __( '%d days', 'invoicing' ), |
|
195 | - ), |
|
192 | + 'day' => array( |
|
193 | + 'singular' => __( '%s day', 'invoicing' ), |
|
194 | + 'plural' => __( '%d days', 'invoicing' ), |
|
195 | + ), |
|
196 | 196 | |
197 | - 'week' => array( |
|
198 | - 'singular' => __( '%s week', 'invoicing' ), |
|
199 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
200 | - ), |
|
197 | + 'week' => array( |
|
198 | + 'singular' => __( '%s week', 'invoicing' ), |
|
199 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
200 | + ), |
|
201 | 201 | |
202 | - 'month' => array( |
|
203 | - 'singular' => __( '%s month', 'invoicing' ), |
|
204 | - 'plural' => __( '%d months', 'invoicing' ), |
|
205 | - ), |
|
202 | + 'month' => array( |
|
203 | + 'singular' => __( '%s month', 'invoicing' ), |
|
204 | + 'plural' => __( '%d months', 'invoicing' ), |
|
205 | + ), |
|
206 | 206 | |
207 | - 'year' => array( |
|
208 | - 'singular' => __( '%s year', 'invoicing' ), |
|
209 | - 'plural' => __( '%d years', 'invoicing' ), |
|
210 | - ), |
|
207 | + 'year' => array( |
|
208 | + 'singular' => __( '%s year', 'invoicing' ), |
|
209 | + 'plural' => __( '%d years', 'invoicing' ), |
|
210 | + ), |
|
211 | 211 | |
212 | - ) |
|
213 | - ); |
|
212 | + ) |
|
213 | + ); |
|
214 | 214 | |
215 | 215 | } |
216 | 216 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @return int |
222 | 222 | */ |
223 | 223 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
224 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
224 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @return string |
232 | 232 | */ |
233 | 233 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
234 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
234 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | * @return string |
243 | 243 | */ |
244 | 244 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
245 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
246 | - return strtolower( sanitize_text_field( $label ) ); |
|
245 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
246 | + return strtolower( sanitize_text_field( $label ) ); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -254,22 +254,22 @@ discard block |
||
254 | 254 | */ |
255 | 255 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
256 | 256 | |
257 | - $periods = getpaid_get_subscription_periods(); |
|
258 | - $period = strtolower( $period ); |
|
257 | + $periods = getpaid_get_subscription_periods(); |
|
258 | + $period = strtolower( $period ); |
|
259 | 259 | |
260 | - if ( isset( $periods[ $period ] ) ) { |
|
261 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
262 | - } |
|
260 | + if ( isset( $periods[ $period ] ) ) { |
|
261 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
262 | + } |
|
263 | 263 | |
264 | - // Backwards compatibility. |
|
265 | - foreach ( $periods as $key => $data ) { |
|
266 | - if ( strpos( $key, $period ) === 0 ) { |
|
267 | - return sprintf( $data['singular'], $singular_prefix ); |
|
268 | - } |
|
269 | - } |
|
264 | + // Backwards compatibility. |
|
265 | + foreach ( $periods as $key => $data ) { |
|
266 | + if ( strpos( $key, $period ) === 0 ) { |
|
267 | + return sprintf( $data['singular'], $singular_prefix ); |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - // Invalid string. |
|
272 | - return ''; |
|
271 | + // Invalid string. |
|
272 | + return ''; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -281,22 +281,22 @@ discard block |
||
281 | 281 | */ |
282 | 282 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
283 | 283 | |
284 | - $periods = getpaid_get_subscription_periods(); |
|
285 | - $period = strtolower( $period ); |
|
284 | + $periods = getpaid_get_subscription_periods(); |
|
285 | + $period = strtolower( $period ); |
|
286 | 286 | |
287 | - if ( isset( $periods[ $period ] ) ) { |
|
288 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
289 | - } |
|
287 | + if ( isset( $periods[ $period ] ) ) { |
|
288 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
289 | + } |
|
290 | 290 | |
291 | - // Backwards compatibility. |
|
292 | - foreach ( $periods as $key => $data ) { |
|
293 | - if ( strpos( $key, $period ) === 0 ) { |
|
294 | - return sprintf( $data['plural'], $interval ); |
|
295 | - } |
|
296 | - } |
|
291 | + // Backwards compatibility. |
|
292 | + foreach ( $periods as $key => $data ) { |
|
293 | + if ( strpos( $key, $period ) === 0 ) { |
|
294 | + return sprintf( $data['plural'], $interval ); |
|
295 | + } |
|
296 | + } |
|
297 | 297 | |
298 | - // Invalid string. |
|
299 | - return ''; |
|
298 | + // Invalid string. |
|
299 | + return ''; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -307,92 +307,92 @@ discard block |
||
307 | 307 | */ |
308 | 308 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
309 | 309 | |
310 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
311 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
312 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
313 | - $bill_times = $subscription->get_bill_times(); |
|
314 | - $bill_times_less = $bill_times - 1; |
|
315 | - |
|
316 | - if ( ! empty( $bill_times ) ) { |
|
317 | - $bill_times = $subscription->get_frequency() * $bill_times; |
|
318 | - $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
319 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
320 | - } |
|
321 | - |
|
322 | - // Trial periods. |
|
323 | - if ( $subscription->has_trial_period() ) { |
|
324 | - |
|
325 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
326 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
327 | - |
|
328 | - if ( empty( $bill_times ) ) { |
|
329 | - |
|
330 | - return sprintf( |
|
331 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
332 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
333 | - $initial, |
|
334 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
335 | - $recurring, |
|
336 | - $period |
|
337 | - ); |
|
338 | - |
|
339 | - } |
|
340 | - |
|
341 | - return sprintf( |
|
342 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
343 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
344 | - $initial, |
|
345 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
346 | - $recurring, |
|
347 | - $period, |
|
348 | - $bill_times |
|
349 | - ); |
|
350 | - |
|
351 | - } |
|
352 | - |
|
353 | - if ( $initial != $recurring ) { |
|
354 | - |
|
355 | - if ( empty( $bill_times ) ) { |
|
356 | - |
|
357 | - return sprintf( |
|
358 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
359 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
360 | - $initial, |
|
361 | - $recurring, |
|
362 | - $period |
|
363 | - ); |
|
364 | - |
|
365 | - } |
|
366 | - |
|
367 | - return sprintf( |
|
368 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
370 | - $initial, |
|
371 | - $recurring, |
|
372 | - $period, |
|
373 | - $bill_times_less |
|
374 | - ); |
|
375 | - |
|
376 | - } |
|
377 | - |
|
378 | - if ( empty( $bill_times ) ) { |
|
379 | - |
|
380 | - return sprintf( |
|
381 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
382 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
383 | - $initial, |
|
384 | - $period |
|
385 | - ); |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - return sprintf( |
|
390 | - // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
391 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
392 | - $bill_times, |
|
393 | - $initial, |
|
394 | - $period |
|
395 | - ); |
|
310 | + $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
311 | + $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
312 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
313 | + $bill_times = $subscription->get_bill_times(); |
|
314 | + $bill_times_less = $bill_times - 1; |
|
315 | + |
|
316 | + if ( ! empty( $bill_times ) ) { |
|
317 | + $bill_times = $subscription->get_frequency() * $bill_times; |
|
318 | + $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
319 | + $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
320 | + } |
|
321 | + |
|
322 | + // Trial periods. |
|
323 | + if ( $subscription->has_trial_period() ) { |
|
324 | + |
|
325 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
326 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
327 | + |
|
328 | + if ( empty( $bill_times ) ) { |
|
329 | + |
|
330 | + return sprintf( |
|
331 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
332 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
333 | + $initial, |
|
334 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
335 | + $recurring, |
|
336 | + $period |
|
337 | + ); |
|
338 | + |
|
339 | + } |
|
340 | + |
|
341 | + return sprintf( |
|
342 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
343 | + _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
344 | + $initial, |
|
345 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
346 | + $recurring, |
|
347 | + $period, |
|
348 | + $bill_times |
|
349 | + ); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + if ( $initial != $recurring ) { |
|
354 | + |
|
355 | + if ( empty( $bill_times ) ) { |
|
356 | + |
|
357 | + return sprintf( |
|
358 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
359 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
360 | + $initial, |
|
361 | + $recurring, |
|
362 | + $period |
|
363 | + ); |
|
364 | + |
|
365 | + } |
|
366 | + |
|
367 | + return sprintf( |
|
368 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
369 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
370 | + $initial, |
|
371 | + $recurring, |
|
372 | + $period, |
|
373 | + $bill_times_less |
|
374 | + ); |
|
375 | + |
|
376 | + } |
|
377 | + |
|
378 | + if ( empty( $bill_times ) ) { |
|
379 | + |
|
380 | + return sprintf( |
|
381 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
382 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
383 | + $initial, |
|
384 | + $period |
|
385 | + ); |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + return sprintf( |
|
390 | + // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
391 | + _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
392 | + $bill_times, |
|
393 | + $initial, |
|
394 | + $period |
|
395 | + ); |
|
396 | 396 | |
397 | 397 | } |
398 | 398 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @return WPInv_Subscription|false |
404 | 404 | */ |
405 | 405 | function getpaid_get_invoice_subscription( $invoice ) { |
406 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
406 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | * @param WPInv_Invoice $invoice |
413 | 413 | */ |
414 | 414 | function getpaid_activate_invoice_subscription( $invoice ) { |
415 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
416 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
417 | - $subscription->activate(); |
|
418 | - } |
|
415 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
416 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
417 | + $subscription->activate(); |
|
418 | + } |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @return WPInv_Subscriptions |
425 | 425 | */ |
426 | 426 | function getpaid_subscriptions() { |
427 | - return getpaid()->get( 'subscriptions' ); |
|
427 | + return getpaid()->get( 'subscriptions' ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -443,15 +443,15 @@ discard block |
||
443 | 443 | return false; |
444 | 444 | } |
445 | 445 | |
446 | - // Fetch the invoice subscription. |
|
447 | - $subscription = getpaid_get_subscriptions( |
|
448 | - array( |
|
449 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
450 | - 'number' => 1, |
|
451 | - ) |
|
452 | - ); |
|
446 | + // Fetch the invoice subscription. |
|
447 | + $subscription = getpaid_get_subscriptions( |
|
448 | + array( |
|
449 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
450 | + 'number' => 1, |
|
451 | + ) |
|
452 | + ); |
|
453 | 453 | |
454 | - return empty( $subscription ) ? false : $subscription[0]; |
|
454 | + return empty( $subscription ) ? false : $subscription[0]; |
|
455 | 455 | |
456 | 456 | } |
457 | 457 | |
@@ -468,48 +468,48 @@ discard block |
||
468 | 468 | */ |
469 | 469 | function getpaid_get_recurring_item_key( $cart_item ) { |
470 | 470 | |
471 | - $cart_key = 'renews_'; |
|
472 | - $interval = $cart_item->get_recurring_interval(); |
|
473 | - $period = $cart_item->get_recurring_period( true ); |
|
474 | - $length = $cart_item->get_recurring_limit() * $interval; |
|
475 | - $trial_period = $cart_item->get_trial_period( true ); |
|
476 | - $trial_length = $cart_item->get_trial_interval(); |
|
477 | - |
|
478 | - // First start with the billing interval and period |
|
479 | - switch ( $interval ) { |
|
480 | - case 1: |
|
481 | - if ( 'day' == $period ) { |
|
482 | - $cart_key .= 'daily'; |
|
483 | - } else { |
|
484 | - $cart_key .= sprintf( '%sly', $period ); |
|
485 | - } |
|
486 | - break; |
|
487 | - case 2: |
|
488 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
489 | - break; |
|
490 | - case 3: |
|
491 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
492 | - break; |
|
493 | - default: |
|
494 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
495 | - break; |
|
496 | - } |
|
497 | - |
|
498 | - // Maybe add the optional maximum billing periods... |
|
499 | - if ( $length > 0 ) { |
|
500 | - $cart_key .= '_for_'; |
|
501 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
502 | - if ( $length > 1 ) { |
|
503 | - $cart_key .= 's'; |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - // And an optional free trial. |
|
508 | - if ( $cart_item->has_free_trial() ) { |
|
509 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
510 | - } |
|
511 | - |
|
512 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
471 | + $cart_key = 'renews_'; |
|
472 | + $interval = $cart_item->get_recurring_interval(); |
|
473 | + $period = $cart_item->get_recurring_period( true ); |
|
474 | + $length = $cart_item->get_recurring_limit() * $interval; |
|
475 | + $trial_period = $cart_item->get_trial_period( true ); |
|
476 | + $trial_length = $cart_item->get_trial_interval(); |
|
477 | + |
|
478 | + // First start with the billing interval and period |
|
479 | + switch ( $interval ) { |
|
480 | + case 1: |
|
481 | + if ( 'day' == $period ) { |
|
482 | + $cart_key .= 'daily'; |
|
483 | + } else { |
|
484 | + $cart_key .= sprintf( '%sly', $period ); |
|
485 | + } |
|
486 | + break; |
|
487 | + case 2: |
|
488 | + $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
489 | + break; |
|
490 | + case 3: |
|
491 | + $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
492 | + break; |
|
493 | + default: |
|
494 | + $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
495 | + break; |
|
496 | + } |
|
497 | + |
|
498 | + // Maybe add the optional maximum billing periods... |
|
499 | + if ( $length > 0 ) { |
|
500 | + $cart_key .= '_for_'; |
|
501 | + $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
502 | + if ( $length > 1 ) { |
|
503 | + $cart_key .= 's'; |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + // And an optional free trial. |
|
508 | + if ( $cart_item->has_free_trial() ) { |
|
509 | + $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
510 | + } |
|
511 | + |
|
512 | + return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -520,16 +520,16 @@ discard block |
||
520 | 520 | */ |
521 | 521 | function getpaid_get_subscription_groups( $invoice ) { |
522 | 522 | |
523 | - // Generate subscription groups. |
|
524 | - $subscription_groups = array(); |
|
525 | - foreach ( $invoice->get_items() as $item ) { |
|
523 | + // Generate subscription groups. |
|
524 | + $subscription_groups = array(); |
|
525 | + foreach ( $invoice->get_items() as $item ) { |
|
526 | 526 | |
527 | - if ( $item->is_recurring() ) { |
|
528 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
529 | - } |
|
527 | + if ( $item->is_recurring() ) { |
|
528 | + $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
529 | + } |
|
530 | 530 | } |
531 | 531 | |
532 | - return $subscription_groups; |
|
532 | + return $subscription_groups; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -543,56 +543,56 @@ discard block |
||
543 | 543 | */ |
544 | 544 | function getpaid_calculate_subscription_totals( $invoice ) { |
545 | 545 | |
546 | - // Generate subscription groups. |
|
547 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
546 | + // Generate subscription groups. |
|
547 | + $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
548 | 548 | |
549 | - // Now let's calculate the totals for each group of subscriptions |
|
550 | - $subscription_totals = array(); |
|
549 | + // Now let's calculate the totals for each group of subscriptions |
|
550 | + $subscription_totals = array(); |
|
551 | 551 | |
552 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
552 | + foreach ( $subscription_groups as $subscription_key => $items ) { |
|
553 | 553 | |
554 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
554 | + if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
555 | 555 | |
556 | - $subscription_totals[ $subscription_key ] = array( |
|
557 | - 'initial_total' => 0, |
|
558 | - 'recurring_total' => 0, |
|
559 | - 'items' => array(), |
|
560 | - 'trialling' => false, |
|
561 | - ); |
|
556 | + $subscription_totals[ $subscription_key ] = array( |
|
557 | + 'initial_total' => 0, |
|
558 | + 'recurring_total' => 0, |
|
559 | + 'items' => array(), |
|
560 | + 'trialling' => false, |
|
561 | + ); |
|
562 | 562 | |
563 | - } |
|
563 | + } |
|
564 | 564 | |
565 | - /** |
|
566 | - * Get the totals of the group. |
|
567 | - * @var GetPaid_Form_Item $item |
|
568 | - */ |
|
569 | - foreach ( $items as $item ) { |
|
565 | + /** |
|
566 | + * Get the totals of the group. |
|
567 | + * @var GetPaid_Form_Item $item |
|
568 | + */ |
|
569 | + foreach ( $items as $item ) { |
|
570 | 570 | |
571 | - $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
572 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
573 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
574 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
575 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
576 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
577 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
571 | + $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
572 | + $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
573 | + $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
574 | + $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
575 | + $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
576 | + $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
577 | + $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
578 | 578 | |
579 | - // Calculate the next renewal date. |
|
580 | - $period = $item->get_recurring_period( true ); |
|
581 | - $interval = $item->get_recurring_interval(); |
|
579 | + // Calculate the next renewal date. |
|
580 | + $period = $item->get_recurring_period( true ); |
|
581 | + $interval = $item->get_recurring_interval(); |
|
582 | 582 | |
583 | - // If the subscription item has a trial period... |
|
584 | - if ( $item->has_free_trial() ) { |
|
585 | - $period = $item->get_trial_period( true ); |
|
586 | - $interval = $item->get_trial_interval(); |
|
587 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
588 | - } |
|
583 | + // If the subscription item has a trial period... |
|
584 | + if ( $item->has_free_trial() ) { |
|
585 | + $period = $item->get_trial_period( true ); |
|
586 | + $interval = $item->get_trial_interval(); |
|
587 | + $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
588 | + } |
|
589 | 589 | |
590 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
590 | + $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
591 | 591 | |
592 | - } |
|
592 | + } |
|
593 | 593 | } |
594 | 594 | |
595 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
595 | + return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,16 +603,16 @@ discard block |
||
603 | 603 | */ |
604 | 604 | function getpaid_should_group_subscriptions( $invoice ) { |
605 | 605 | |
606 | - $recurring_items = 0; |
|
606 | + $recurring_items = 0; |
|
607 | 607 | |
608 | - foreach ( $invoice->get_items() as $item ) { |
|
608 | + foreach ( $invoice->get_items() as $item ) { |
|
609 | 609 | |
610 | - if ( $item->is_recurring() ) { |
|
611 | - $recurring_items ++; |
|
612 | - } |
|
610 | + if ( $item->is_recurring() ) { |
|
611 | + $recurring_items ++; |
|
612 | + } |
|
613 | 613 | } |
614 | 614 | |
615 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
615 | + return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
@@ -623,39 +623,39 @@ discard block |
||
623 | 623 | * @return int |
624 | 624 | */ |
625 | 625 | function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) { |
626 | - global $wpdb; |
|
626 | + global $wpdb; |
|
627 | 627 | |
628 | - $parent_invoice_id = (int) $parent_invoice_id; |
|
628 | + $parent_invoice_id = (int) $parent_invoice_id; |
|
629 | 629 | |
630 | - if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
630 | + if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
631 | 631 | |
632 | - return (int) $wpdb->get_var( |
|
633 | - $wpdb->prepare( |
|
634 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
635 | - $parent_invoice_id, |
|
636 | - $parent_invoice_id |
|
637 | - ) |
|
638 | - ); |
|
632 | + return (int) $wpdb->get_var( |
|
633 | + $wpdb->prepare( |
|
634 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
635 | + $parent_invoice_id, |
|
636 | + $parent_invoice_id |
|
637 | + ) |
|
638 | + ); |
|
639 | 639 | |
640 | - } |
|
640 | + } |
|
641 | 641 | |
642 | - $invoice_ids = $wpdb->get_col( |
|
643 | - $wpdb->prepare( |
|
644 | - "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
645 | - $parent_invoice_id, |
|
646 | - $parent_invoice_id |
|
647 | - ) |
|
648 | - ); |
|
642 | + $invoice_ids = $wpdb->get_col( |
|
643 | + $wpdb->prepare( |
|
644 | + "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
645 | + $parent_invoice_id, |
|
646 | + $parent_invoice_id |
|
647 | + ) |
|
648 | + ); |
|
649 | 649 | |
650 | - $count = 0; |
|
650 | + $count = 0; |
|
651 | 651 | |
652 | - foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
652 | + foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
653 | 653 | |
654 | - if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
655 | - $count ++; |
|
656 | - continue; |
|
657 | - } |
|
654 | + if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
655 | + $count ++; |
|
656 | + continue; |
|
657 | + } |
|
658 | 658 | } |
659 | 659 | |
660 | - return $count; |
|
660 | + return $count; |
|
661 | 661 | } |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | * @return WPInv_Subscription[]|WPInv_Subscription|false |
14 | 14 | * @since 2.3.0 |
15 | 15 | */ |
16 | -function getpaid_get_invoice_subscriptions( $invoice ) { |
|
16 | +function getpaid_get_invoice_subscriptions($invoice) { |
|
17 | 17 | |
18 | 18 | // Retrieve subscription groups. |
19 | - $subscription_ids = wp_list_pluck( getpaid_get_invoice_subscription_groups( $invoice->get_id() ), 'subscription_id' ); |
|
19 | + $subscription_ids = wp_list_pluck(getpaid_get_invoice_subscription_groups($invoice->get_id()), 'subscription_id'); |
|
20 | 20 | |
21 | 21 | // No subscription groups, normal subscription. |
22 | - if ( empty( $subscription_ids ) ) { |
|
23 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
22 | + if (empty($subscription_ids)) { |
|
23 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // Subscription groups. |
27 | - return array_filter( array_map( 'getpaid_get_subscription', $subscription_ids ) ); |
|
27 | + return array_filter(array_map('getpaid_get_subscription', $subscription_ids)); |
|
28 | 28 | |
29 | 29 | } |
30 | 30 | |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * @return array |
36 | 36 | * @since 2.3.0 |
37 | 37 | */ |
38 | -function getpaid_get_invoice_subscription_groups( $invoice_id ) { |
|
39 | - $subscription_groups = get_post_meta( $invoice_id, 'getpaid_subscription_groups', true ); |
|
40 | - return empty( $subscription_groups ) ? array() : $subscription_groups; |
|
38 | +function getpaid_get_invoice_subscription_groups($invoice_id) { |
|
39 | + $subscription_groups = get_post_meta($invoice_id, 'getpaid_subscription_groups', true); |
|
40 | + return empty($subscription_groups) ? array() : $subscription_groups; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | * @return array|false |
49 | 49 | * @since 2.3.0 |
50 | 50 | */ |
51 | -function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
|
52 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
|
53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
54 | - return reset( $matching_group ); |
|
51 | +function getpaid_get_invoice_subscription_group($invoice_id, $subscription_id) { |
|
52 | + $subscription_groups = getpaid_get_invoice_subscription_groups($invoice_id); |
|
53 | + $matching_group = wp_list_filter($subscription_groups, compact('subscription_id')); |
|
54 | + return reset($matching_group); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * @since 2.3.0 |
62 | 62 | * @return WPInv_Subscription|false |
63 | 63 | */ |
64 | -function getpaid_get_subscription( $subscription ) { |
|
64 | +function getpaid_get_subscription($subscription) { |
|
65 | 65 | |
66 | - if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
67 | - $subscription = new WPInv_Subscription( $subscription ); |
|
66 | + if (!is_a($subscription, 'WPInv_Subscription')) { |
|
67 | + $subscription = new WPInv_Subscription($subscription); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | return $subscription->exists() ? $subscription : false; |
@@ -79,26 +79,26 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
81 | 81 | */ |
82 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
82 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
83 | 83 | |
84 | 84 | // Do not retrieve all fields if we just want the count. |
85 | - if ( 'count' == $return ) { |
|
85 | + if ('count' == $return) { |
|
86 | 86 | $args['fields'] = 'id'; |
87 | 87 | $args['number'] = 1; |
88 | 88 | } |
89 | 89 | |
90 | 90 | // Do not count all matches if we just want the results. |
91 | - if ( 'results' == $return ) { |
|
91 | + if ('results' == $return) { |
|
92 | 92 | $args['count_total'] = false; |
93 | 93 | } |
94 | 94 | |
95 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
95 | + $query = new GetPaid_Subscriptions_Query($args); |
|
96 | 96 | |
97 | - if ( 'results' == $return ) { |
|
97 | + if ('results' == $return) { |
|
98 | 98 | return $query->get_results(); |
99 | 99 | } |
100 | 100 | |
101 | - if ( 'count' == $return ) { |
|
101 | + if ('count' == $return) { |
|
102 | 102 | return $query->get_total(); |
103 | 103 | } |
104 | 104 | |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | return apply_filters( |
116 | 116 | 'getpaid_get_subscription_statuses', |
117 | 117 | array( |
118 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
119 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
120 | - 'active' => __( 'Active', 'invoicing' ), |
|
121 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
122 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
123 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
124 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
118 | + 'pending' => __('Pending', 'invoicing'), |
|
119 | + 'trialling' => __('Trialing', 'invoicing'), |
|
120 | + 'active' => __('Active', 'invoicing'), |
|
121 | + 'failing' => __('Failing', 'invoicing'), |
|
122 | + 'expired' => __('Expired', 'invoicing'), |
|
123 | + 'completed' => __('Complete', 'invoicing'), |
|
124 | + 'cancelled' => __('Cancelled', 'invoicing'), |
|
125 | 125 | ) |
126 | 126 | ); |
127 | 127 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return string |
134 | 134 | */ |
135 | -function getpaid_get_subscription_status_label( $status ) { |
|
135 | +function getpaid_get_subscription_status_label($status) { |
|
136 | 136 | $statuses = getpaid_get_subscription_statuses(); |
137 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
137 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status)); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -164,14 +164,14 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return array |
166 | 166 | */ |
167 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
167 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
168 | 168 | |
169 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
169 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
170 | 170 | $counts = array(); |
171 | 171 | |
172 | - foreach ( $statuses as $status ) { |
|
173 | - $_args = wp_parse_args( "status=$status", $args ); |
|
174 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
172 | + foreach ($statuses as $status) { |
|
173 | + $_args = wp_parse_args("status=$status", $args); |
|
174 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | return $counts; |
@@ -190,23 +190,23 @@ discard block |
||
190 | 190 | array( |
191 | 191 | |
192 | 192 | 'day' => array( |
193 | - 'singular' => __( '%s day', 'invoicing' ), |
|
194 | - 'plural' => __( '%d days', 'invoicing' ), |
|
193 | + 'singular' => __('%s day', 'invoicing'), |
|
194 | + 'plural' => __('%d days', 'invoicing'), |
|
195 | 195 | ), |
196 | 196 | |
197 | 197 | 'week' => array( |
198 | - 'singular' => __( '%s week', 'invoicing' ), |
|
199 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
198 | + 'singular' => __('%s week', 'invoicing'), |
|
199 | + 'plural' => __('%d weeks', 'invoicing'), |
|
200 | 200 | ), |
201 | 201 | |
202 | 202 | 'month' => array( |
203 | - 'singular' => __( '%s month', 'invoicing' ), |
|
204 | - 'plural' => __( '%d months', 'invoicing' ), |
|
203 | + 'singular' => __('%s month', 'invoicing'), |
|
204 | + 'plural' => __('%d months', 'invoicing'), |
|
205 | 205 | ), |
206 | 206 | |
207 | 207 | 'year' => array( |
208 | - 'singular' => __( '%s year', 'invoicing' ), |
|
209 | - 'plural' => __( '%d years', 'invoicing' ), |
|
208 | + 'singular' => __('%s year', 'invoicing'), |
|
209 | + 'plural' => __('%d years', 'invoicing'), |
|
210 | 210 | ), |
211 | 211 | |
212 | 212 | ) |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | * @param string $trial_period |
221 | 221 | * @return int |
222 | 222 | */ |
223 | -function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
|
224 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
223 | +function getpaid_get_subscription_trial_period_interval($trial_period) { |
|
224 | + return (int) preg_replace('/[^0-9]/', '', $trial_period); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @param string $trial_period |
231 | 231 | * @return string |
232 | 232 | */ |
233 | -function getpaid_get_subscription_trial_period_period( $trial_period ) { |
|
234 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
233 | +function getpaid_get_subscription_trial_period_period($trial_period) { |
|
234 | + return preg_replace('/[^a-z]/', '', strtolower($trial_period)); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | * @param int $interval |
242 | 242 | * @return string |
243 | 243 | */ |
244 | -function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
|
245 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
246 | - return strtolower( sanitize_text_field( $label ) ); |
|
244 | +function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') { |
|
245 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix); |
|
246 | + return strtolower(sanitize_text_field($label)); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -252,19 +252,19 @@ discard block |
||
252 | 252 | * @param string $period |
253 | 253 | * @return string |
254 | 254 | */ |
255 | -function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
|
255 | +function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') { |
|
256 | 256 | |
257 | 257 | $periods = getpaid_get_subscription_periods(); |
258 | - $period = strtolower( $period ); |
|
258 | + $period = strtolower($period); |
|
259 | 259 | |
260 | - if ( isset( $periods[ $period ] ) ) { |
|
261 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
260 | + if (isset($periods[$period])) { |
|
261 | + return sprintf($periods[$period]['singular'], $singular_prefix); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | // Backwards compatibility. |
265 | - foreach ( $periods as $key => $data ) { |
|
266 | - if ( strpos( $key, $period ) === 0 ) { |
|
267 | - return sprintf( $data['singular'], $singular_prefix ); |
|
265 | + foreach ($periods as $key => $data) { |
|
266 | + if (strpos($key, $period) === 0) { |
|
267 | + return sprintf($data['singular'], $singular_prefix); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
@@ -279,19 +279,19 @@ discard block |
||
279 | 279 | * @param int $interval |
280 | 280 | * @return string |
281 | 281 | */ |
282 | -function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
|
282 | +function getpaid_get_plural_subscription_period_label($period, $interval) { |
|
283 | 283 | |
284 | 284 | $periods = getpaid_get_subscription_periods(); |
285 | - $period = strtolower( $period ); |
|
285 | + $period = strtolower($period); |
|
286 | 286 | |
287 | - if ( isset( $periods[ $period ] ) ) { |
|
288 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
287 | + if (isset($periods[$period])) { |
|
288 | + return sprintf($periods[$period]['plural'], $interval); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // Backwards compatibility. |
292 | - foreach ( $periods as $key => $data ) { |
|
293 | - if ( strpos( $key, $period ) === 0 ) { |
|
294 | - return sprintf( $data['plural'], $interval ); |
|
292 | + foreach ($periods as $key => $data) { |
|
293 | + if (strpos($key, $period) === 0) { |
|
294 | + return sprintf($data['plural'], $interval); |
|
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
@@ -305,33 +305,33 @@ discard block |
||
305 | 305 | * @param WPInv_Subscription $subscription |
306 | 306 | * @return string |
307 | 307 | */ |
308 | -function getpaid_get_formatted_subscription_amount( $subscription ) { |
|
308 | +function getpaid_get_formatted_subscription_amount($subscription) { |
|
309 | 309 | |
310 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
311 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
312 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
310 | + $initial = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
311 | + $recurring = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
312 | + $period = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
313 | 313 | $bill_times = $subscription->get_bill_times(); |
314 | 314 | $bill_times_less = $bill_times - 1; |
315 | 315 | |
316 | - if ( ! empty( $bill_times ) ) { |
|
316 | + if (!empty($bill_times)) { |
|
317 | 317 | $bill_times = $subscription->get_frequency() * $bill_times; |
318 | - $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
319 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
318 | + $bill_times_less = getpaid_get_subscription_period_label($subscription->get_frequency(), $bill_times - $subscription->get_frequency()); |
|
319 | + $bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // Trial periods. |
323 | - if ( $subscription->has_trial_period() ) { |
|
323 | + if ($subscription->has_trial_period()) { |
|
324 | 324 | |
325 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
326 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
325 | + $trial_period = getpaid_get_subscription_trial_period_period($subscription->get_trial_period()); |
|
326 | + $trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period()); |
|
327 | 327 | |
328 | - if ( empty( $bill_times ) ) { |
|
328 | + if (empty($bill_times)) { |
|
329 | 329 | |
330 | 330 | return sprintf( |
331 | 331 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
332 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
332 | + _x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'), |
|
333 | 333 | $initial, |
334 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
334 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
335 | 335 | $recurring, |
336 | 336 | $period |
337 | 337 | ); |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | |
341 | 341 | return sprintf( |
342 | 342 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
343 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
343 | + _x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
344 | 344 | $initial, |
345 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
345 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
346 | 346 | $recurring, |
347 | 347 | $period, |
348 | 348 | $bill_times |
@@ -350,13 +350,13 @@ discard block |
||
350 | 350 | |
351 | 351 | } |
352 | 352 | |
353 | - if ( $initial != $recurring ) { |
|
353 | + if ($initial != $recurring) { |
|
354 | 354 | |
355 | - if ( empty( $bill_times ) ) { |
|
355 | + if (empty($bill_times)) { |
|
356 | 356 | |
357 | 357 | return sprintf( |
358 | 358 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
359 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
359 | + _x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'), |
|
360 | 360 | $initial, |
361 | 361 | $recurring, |
362 | 362 | $period |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | |
367 | 367 | return sprintf( |
368 | 368 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
369 | + _x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'), |
|
370 | 370 | $initial, |
371 | 371 | $recurring, |
372 | 372 | $period, |
@@ -375,11 +375,11 @@ discard block |
||
375 | 375 | |
376 | 376 | } |
377 | 377 | |
378 | - if ( empty( $bill_times ) ) { |
|
378 | + if (empty($bill_times)) { |
|
379 | 379 | |
380 | 380 | return sprintf( |
381 | 381 | // translators: $1: is the recurring amount, $2: is the recurring period |
382 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
382 | + _x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
383 | 383 | $initial, |
384 | 384 | $period |
385 | 385 | ); |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | |
389 | 389 | return sprintf( |
390 | 390 | // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
391 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
391 | + _x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
392 | 392 | $bill_times, |
393 | 393 | $initial, |
394 | 394 | $period |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | * @param WPInv_Invoice $invoice |
403 | 403 | * @return WPInv_Subscription|false |
404 | 404 | */ |
405 | -function getpaid_get_invoice_subscription( $invoice ) { |
|
406 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
405 | +function getpaid_get_invoice_subscription($invoice) { |
|
406 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -411,9 +411,9 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @param WPInv_Invoice $invoice |
413 | 413 | */ |
414 | -function getpaid_activate_invoice_subscription( $invoice ) { |
|
415 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
416 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
414 | +function getpaid_activate_invoice_subscription($invoice) { |
|
415 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
416 | + if (is_a($subscription, 'WPInv_Subscription')) { |
|
417 | 417 | $subscription->activate(); |
418 | 418 | } |
419 | 419 | } |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @return WPInv_Subscriptions |
425 | 425 | */ |
426 | 426 | function getpaid_subscriptions() { |
427 | - return getpaid()->get( 'subscriptions' ); |
|
427 | + return getpaid()->get('subscriptions'); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -433,13 +433,13 @@ discard block |
||
433 | 433 | * @since 2.3.0 |
434 | 434 | * @return WPInv_Subscription|bool |
435 | 435 | */ |
436 | -function wpinv_get_invoice_subscription( $invoice ) { |
|
436 | +function wpinv_get_invoice_subscription($invoice) { |
|
437 | 437 | |
438 | 438 | // Retrieve the invoice. |
439 | - $invoice = new WPInv_Invoice( $invoice ); |
|
439 | + $invoice = new WPInv_Invoice($invoice); |
|
440 | 440 | |
441 | 441 | // Ensure it is a recurring invoice. |
442 | - if ( ! $invoice->is_recurring() ) { |
|
442 | + if (!$invoice->is_recurring()) { |
|
443 | 443 | return false; |
444 | 444 | } |
445 | 445 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | ) |
452 | 452 | ); |
453 | 453 | |
454 | - return empty( $subscription ) ? false : $subscription[0]; |
|
454 | + return empty($subscription) ? false : $subscription[0]; |
|
455 | 455 | |
456 | 456 | } |
457 | 457 | |
@@ -466,50 +466,50 @@ discard block |
||
466 | 466 | * @param GetPaid_Form_Item|WPInv_Item $cart_item |
467 | 467 | * @return string |
468 | 468 | */ |
469 | -function getpaid_get_recurring_item_key( $cart_item ) { |
|
469 | +function getpaid_get_recurring_item_key($cart_item) { |
|
470 | 470 | |
471 | 471 | $cart_key = 'renews_'; |
472 | 472 | $interval = $cart_item->get_recurring_interval(); |
473 | - $period = $cart_item->get_recurring_period( true ); |
|
473 | + $period = $cart_item->get_recurring_period(true); |
|
474 | 474 | $length = $cart_item->get_recurring_limit() * $interval; |
475 | - $trial_period = $cart_item->get_trial_period( true ); |
|
475 | + $trial_period = $cart_item->get_trial_period(true); |
|
476 | 476 | $trial_length = $cart_item->get_trial_interval(); |
477 | 477 | |
478 | 478 | // First start with the billing interval and period |
479 | - switch ( $interval ) { |
|
479 | + switch ($interval) { |
|
480 | 480 | case 1: |
481 | - if ( 'day' == $period ) { |
|
481 | + if ('day' == $period) { |
|
482 | 482 | $cart_key .= 'daily'; |
483 | 483 | } else { |
484 | - $cart_key .= sprintf( '%sly', $period ); |
|
484 | + $cart_key .= sprintf('%sly', $period); |
|
485 | 485 | } |
486 | 486 | break; |
487 | 487 | case 2: |
488 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
488 | + $cart_key .= sprintf('every_2nd_%s', $period); |
|
489 | 489 | break; |
490 | 490 | case 3: |
491 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
491 | + $cart_key .= sprintf('every_3rd_%s', $period); |
|
492 | 492 | break; |
493 | 493 | default: |
494 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
494 | + $cart_key .= sprintf('every_%dth_%s', $interval, $period); |
|
495 | 495 | break; |
496 | 496 | } |
497 | 497 | |
498 | 498 | // Maybe add the optional maximum billing periods... |
499 | - if ( $length > 0 ) { |
|
499 | + if ($length > 0) { |
|
500 | 500 | $cart_key .= '_for_'; |
501 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
502 | - if ( $length > 1 ) { |
|
501 | + $cart_key .= sprintf('%d_%s', $length, $period); |
|
502 | + if ($length > 1) { |
|
503 | 503 | $cart_key .= 's'; |
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | 507 | // And an optional free trial. |
508 | - if ( $cart_item->has_free_trial() ) { |
|
509 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
508 | + if ($cart_item->has_free_trial()) { |
|
509 | + $cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period); |
|
510 | 510 | } |
511 | 511 | |
512 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
512 | + return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -518,14 +518,14 @@ discard block |
||
518 | 518 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
519 | 519 | * @return array |
520 | 520 | */ |
521 | -function getpaid_get_subscription_groups( $invoice ) { |
|
521 | +function getpaid_get_subscription_groups($invoice) { |
|
522 | 522 | |
523 | 523 | // Generate subscription groups. |
524 | 524 | $subscription_groups = array(); |
525 | - foreach ( $invoice->get_items() as $item ) { |
|
525 | + foreach ($invoice->get_items() as $item) { |
|
526 | 526 | |
527 | - if ( $item->is_recurring() ) { |
|
528 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
527 | + if ($item->is_recurring()) { |
|
528 | + $subscription_groups[getpaid_get_recurring_item_key($item)][] = $item; |
|
529 | 529 | } |
530 | 530 | } |
531 | 531 | |
@@ -541,19 +541,19 @@ discard block |
||
541 | 541 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
542 | 542 | * @return array |
543 | 543 | */ |
544 | -function getpaid_calculate_subscription_totals( $invoice ) { |
|
544 | +function getpaid_calculate_subscription_totals($invoice) { |
|
545 | 545 | |
546 | 546 | // Generate subscription groups. |
547 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
547 | + $subscription_groups = getpaid_get_subscription_groups($invoice); |
|
548 | 548 | |
549 | 549 | // Now let's calculate the totals for each group of subscriptions |
550 | 550 | $subscription_totals = array(); |
551 | 551 | |
552 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
552 | + foreach ($subscription_groups as $subscription_key => $items) { |
|
553 | 553 | |
554 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
554 | + if (empty($subscription_totals[$subscription_key])) { |
|
555 | 555 | |
556 | - $subscription_totals[ $subscription_key ] = array( |
|
556 | + $subscription_totals[$subscription_key] = array( |
|
557 | 557 | 'initial_total' => 0, |
558 | 558 | 'recurring_total' => 0, |
559 | 559 | 'items' => array(), |
@@ -566,33 +566,33 @@ discard block |
||
566 | 566 | * Get the totals of the group. |
567 | 567 | * @var GetPaid_Form_Item $item |
568 | 568 | */ |
569 | - foreach ( $items as $item ) { |
|
569 | + foreach ($items as $item) { |
|
570 | 570 | |
571 | - $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
572 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
573 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
574 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
575 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
576 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
577 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
571 | + $subscription_totals[$subscription_key]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
572 | + $subscription_totals[$subscription_key]['item_id'] = $item->get_id(); |
|
573 | + $subscription_totals[$subscription_key]['period'] = $item->get_recurring_period(true); |
|
574 | + $subscription_totals[$subscription_key]['interval'] = $item->get_recurring_interval(); |
|
575 | + $subscription_totals[$subscription_key]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
576 | + $subscription_totals[$subscription_key]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
577 | + $subscription_totals[$subscription_key]['recurring_limit'] = $item->get_recurring_limit(); |
|
578 | 578 | |
579 | 579 | // Calculate the next renewal date. |
580 | - $period = $item->get_recurring_period( true ); |
|
580 | + $period = $item->get_recurring_period(true); |
|
581 | 581 | $interval = $item->get_recurring_interval(); |
582 | 582 | |
583 | 583 | // If the subscription item has a trial period... |
584 | - if ( $item->has_free_trial() ) { |
|
585 | - $period = $item->get_trial_period( true ); |
|
584 | + if ($item->has_free_trial()) { |
|
585 | + $period = $item->get_trial_period(true); |
|
586 | 586 | $interval = $item->get_trial_interval(); |
587 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
587 | + $subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period; |
|
588 | 588 | } |
589 | 589 | |
590 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
590 | + $subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp'))); |
|
591 | 591 | |
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
595 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
595 | + return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -601,18 +601,18 @@ discard block |
||
601 | 601 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
602 | 602 | * @return array |
603 | 603 | */ |
604 | -function getpaid_should_group_subscriptions( $invoice ) { |
|
604 | +function getpaid_should_group_subscriptions($invoice) { |
|
605 | 605 | |
606 | 606 | $recurring_items = 0; |
607 | 607 | |
608 | - foreach ( $invoice->get_items() as $item ) { |
|
608 | + foreach ($invoice->get_items() as $item) { |
|
609 | 609 | |
610 | - if ( $item->is_recurring() ) { |
|
611 | - $recurring_items ++; |
|
610 | + if ($item->is_recurring()) { |
|
611 | + $recurring_items++; |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | |
615 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
615 | + return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
@@ -622,12 +622,12 @@ discard block |
||
622 | 622 | * @param int|false $subscription_id |
623 | 623 | * @return int |
624 | 624 | */ |
625 | -function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) { |
|
625 | +function getpaid_count_subscription_invoices($parent_invoice_id, $subscription_id = false) { |
|
626 | 626 | global $wpdb; |
627 | 627 | |
628 | 628 | $parent_invoice_id = (int) $parent_invoice_id; |
629 | 629 | |
630 | - if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
630 | + if (false === $subscription_id || !(bool) get_post_meta($parent_invoice_id, '_wpinv_subscription_id', true)) { |
|
631 | 631 | |
632 | 632 | return (int) $wpdb->get_var( |
633 | 633 | $wpdb->prepare( |
@@ -649,10 +649,10 @@ discard block |
||
649 | 649 | |
650 | 650 | $count = 0; |
651 | 651 | |
652 | - foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
652 | + foreach (wp_parse_id_list($invoice_ids) as $invoice_id) { |
|
653 | 653 | |
654 | - if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
655 | - $count ++; |
|
654 | + if ($invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta($invoice_id, '_wpinv_subscription_id', true)) { |
|
655 | + $count++; |
|
656 | 656 | continue; |
657 | 657 | } |
658 | 658 | } |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
62 | - 'page' => 1, |
|
63 | - 'exclude' => array(), |
|
64 | - 'orderby' => 'date', |
|
65 | - 'order' => 'DESC', |
|
66 | - 'type' => wpinv_item_types(), |
|
67 | - 'meta_query' => array(), |
|
68 | - 'return' => 'objects', |
|
69 | - 'paginate' => false, |
|
60 | + 'status' => array( 'publish' ), |
|
61 | + 'limit' => get_option( 'posts_per_page' ), |
|
62 | + 'page' => 1, |
|
63 | + 'exclude' => array(), |
|
64 | + 'orderby' => 'date', |
|
65 | + 'order' => 'DESC', |
|
66 | + 'type' => wpinv_item_types(), |
|
67 | + 'meta_query' => array(), |
|
68 | + 'return' => 'objects', |
|
69 | + 'paginate' => false, |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | |
207 | 207 | function wpinv_get_item_types() { |
208 | 208 | $item_types = array( |
209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
211 | - ); |
|
209 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
211 | + ); |
|
212 | 212 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
213 | 213 | } |
214 | 214 | |
@@ -249,17 +249,17 @@ discard block |
||
249 | 249 | function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
250 | 250 | if ( $post_ids ) { |
251 | 251 | $args = array( |
252 | - 'post_type' => 'wpi_item', |
|
253 | - 'orderby' => 'rand', |
|
254 | - 'post_count' => $num, |
|
255 | - 'fields' => 'ids', |
|
256 | - ); |
|
252 | + 'post_type' => 'wpi_item', |
|
253 | + 'orderby' => 'rand', |
|
254 | + 'post_count' => $num, |
|
255 | + 'fields' => 'ids', |
|
256 | + ); |
|
257 | 257 | } else { |
258 | 258 | $args = array( |
259 | - 'post_type' => 'wpi_item', |
|
260 | - 'orderby' => 'rand', |
|
261 | - 'post_count' => $num, |
|
262 | - ); |
|
259 | + 'post_type' => 'wpi_item', |
|
260 | + 'orderby' => 'rand', |
|
261 | + 'post_count' => $num, |
|
262 | + ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $args = apply_filters( 'wpinv_get_random_items', $args ); |
@@ -427,10 +427,10 @@ discard block |
||
427 | 427 | $bill_times_less = $bill_times - 1; |
428 | 428 | |
429 | 429 | if ( ! empty( $bill_times ) ) { |
430 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
430 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
431 | 431 | $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
432 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
433 | - } |
|
432 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
433 | + } |
|
434 | 434 | |
435 | 435 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
436 | 436 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param int the item ID to retrieve. |
15 | 15 | * @return WPInv_Item|false |
16 | 16 | */ |
17 | -function wpinv_get_item_by_id( $id ) { |
|
18 | - $item = wpinv_get_item( $id ); |
|
19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
17 | +function wpinv_get_item_by_id($id) { |
|
18 | + $item = wpinv_get_item($id); |
|
19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return WPInv_Item|false |
26 | 26 | */ |
27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
28 | 28 | |
29 | - if ( 'id' == strtolower( $field ) ) { |
|
30 | - return wpinv_get_item_by_id( $field ); |
|
29 | + if ('id' == strtolower($field)) { |
|
30 | + return wpinv_get_item_by_id($field); |
|
31 | 31 | } |
32 | 32 | |
33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
34 | - return empty( $id ) ? false : wpinv_get_item( $id ); |
|
33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
34 | + return empty($id) ? false : wpinv_get_item($id); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | * @param int|WPInv_Item the item to retrieve. |
42 | 42 | * @return WPInv_Item|false |
43 | 43 | */ |
44 | -function wpinv_get_item( $item = 0 ) { |
|
44 | +function wpinv_get_item($item = 0) { |
|
45 | 45 | |
46 | - if ( empty( $item ) ) { |
|
46 | + if (empty($item)) { |
|
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | |
50 | - $item = new WPInv_Item( $item ); |
|
50 | + $item = new WPInv_Item($item); |
|
51 | 51 | return $item->exists() ? $item : false; |
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | -function wpinv_get_all_items( $args = array() ) { |
|
55 | +function wpinv_get_all_items($args = array()) { |
|
56 | 56 | |
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
60 | + 'status' => array('publish'), |
|
61 | + 'limit' => get_option('posts_per_page'), |
|
62 | 62 | 'page' => 1, |
63 | 63 | 'exclude' => array(), |
64 | 64 | 'orderby' => 'date', |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'fields' => 'ids', |
79 | 79 | 'orderby' => $args['orderby'], |
80 | 80 | 'order' => $args['order'], |
81 | - 'paged' => absint( $args['page'] ), |
|
81 | + 'paged' => absint($args['page']), |
|
82 | 82 | ); |
83 | 83 | |
84 | - if ( ! empty( $args['exclude'] ) ) { |
|
85 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
84 | + if (!empty($args['exclude'])) { |
|
85 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( ! $args['paginate'] ) { |
|
88 | + if (!$args['paginate']) { |
|
89 | 89 | $wp_query_args['no_found_rows'] = true; |
90 | 90 | } |
91 | 91 | |
92 | - if ( ! empty( $args['search'] ) ) { |
|
92 | + if (!empty($args['search'])) { |
|
93 | 93 | $wp_query_args['s'] = $args['search']; |
94 | 94 | } |
95 | 95 | |
96 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
97 | - $types = wpinv_parse_list( $args['type'] ); |
|
96 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
97 | + $types = wpinv_parse_list($args['type']); |
|
98 | 98 | $wp_query_args['meta_query'][] = array( |
99 | 99 | 'key' => '_wpinv_type', |
100 | - 'value' => implode( ',', $types ), |
|
100 | + 'value' => implode(',', $types), |
|
101 | 101 | 'compare' => 'IN', |
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args ); |
|
105 | + $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
|
106 | 106 | |
107 | 107 | // Get results. |
108 | - $items = new WP_Query( $wp_query_args ); |
|
108 | + $items = new WP_Query($wp_query_args); |
|
109 | 109 | |
110 | - if ( 'objects' === $args['return'] ) { |
|
111 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
112 | - } elseif ( 'self' === $args['return'] ) { |
|
110 | + if ('objects' === $args['return']) { |
|
111 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
112 | + } elseif ('self' === $args['return']) { |
|
113 | 113 | return $items; |
114 | 114 | } else { |
115 | 115 | $return = $items->posts; |
116 | 116 | } |
117 | 117 | |
118 | - if ( $args['paginate'] ) { |
|
118 | + if ($args['paginate']) { |
|
119 | 119 | return (object) array( |
120 | 120 | 'items' => $return, |
121 | 121 | 'total' => $items->found_posts, |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
131 | - if ( empty( $item_id ) ) { |
|
130 | +function wpinv_is_free_item($item_id = 0) { |
|
131 | + if (empty($item_id)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - $item = new WPInv_Item( $item_id ); |
|
135 | + $item = new WPInv_Item($item_id); |
|
136 | 136 | |
137 | 137 | return $item->is_free(); |
138 | 138 | } |
@@ -142,21 +142,21 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
144 | 144 | */ |
145 | -function wpinv_item_is_editable( $item = 0 ) { |
|
145 | +function wpinv_item_is_editable($item = 0) { |
|
146 | 146 | |
147 | 147 | // Fetch the item. |
148 | - $item = new WPInv_Item( $item ); |
|
148 | + $item = new WPInv_Item($item); |
|
149 | 149 | |
150 | 150 | // Check if it is editable. |
151 | 151 | return $item->is_editable(); |
152 | 152 | } |
153 | 153 | |
154 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
155 | - if ( empty( $item_id ) ) { |
|
154 | +function wpinv_get_item_price($item_id = 0) { |
|
155 | + if (empty($item_id)) { |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
159 | - $item = new WPInv_Item( $item_id ); |
|
159 | + $item = new WPInv_Item($item_id); |
|
160 | 160 | |
161 | 161 | return $item->get_price(); |
162 | 162 | } |
@@ -166,88 +166,88 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @param WPInv_Item|int $item |
168 | 168 | */ |
169 | -function wpinv_is_recurring_item( $item = 0 ) { |
|
170 | - $item = new WPInv_Item( $item ); |
|
169 | +function wpinv_is_recurring_item($item = 0) { |
|
170 | + $item = new WPInv_Item($item); |
|
171 | 171 | return $item->is_recurring(); |
172 | 172 | } |
173 | 173 | |
174 | -function wpinv_item_price( $item_id = 0 ) { |
|
175 | - if ( empty( $item_id ) ) { |
|
174 | +function wpinv_item_price($item_id = 0) { |
|
175 | + if (empty($item_id)) { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $price = wpinv_get_item_price( $item_id ); |
|
180 | - $price = wpinv_price( $price ); |
|
179 | + $price = wpinv_get_item_price($item_id); |
|
180 | + $price = wpinv_price($price); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
182 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
183 | 183 | } |
184 | 184 | |
185 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
186 | - if ( is_null( $amount_override ) ) { |
|
187 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
185 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
186 | + if (is_null($amount_override)) { |
|
187 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
188 | 188 | } else { |
189 | 189 | $original_price = $amount_override; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $price = $original_price; |
193 | 193 | |
194 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
194 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
198 | - if ( empty( $item_id ) ) { |
|
197 | +function wpinv_item_custom_singular_name($item_id) { |
|
198 | + if (empty($item_id)) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | 201 | |
202 | - $item = new WPInv_Item( $item_id ); |
|
202 | + $item = new WPInv_Item($item_id); |
|
203 | 203 | |
204 | 204 | return $item->get_custom_singular_name(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | function wpinv_get_item_types() { |
208 | 208 | $item_types = array( |
209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
209 | + 'custom' => __('Standard', 'invoicing'), |
|
210 | + 'fee' => __('Fee', 'invoicing'), |
|
211 | 211 | ); |
212 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
212 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | function wpinv_item_types() { |
216 | 216 | $item_types = wpinv_get_item_types(); |
217 | 217 | |
218 | - return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
218 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
219 | 219 | } |
220 | 220 | |
221 | -function wpinv_get_item_type( $item_id ) { |
|
222 | - if ( empty( $item_id ) ) { |
|
221 | +function wpinv_get_item_type($item_id) { |
|
222 | + if (empty($item_id)) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | |
226 | - $item = new WPInv_Item( $item_id ); |
|
226 | + $item = new WPInv_Item($item_id); |
|
227 | 227 | |
228 | 228 | return $item->get_type(); |
229 | 229 | } |
230 | 230 | |
231 | -function wpinv_item_type( $item_id ) { |
|
231 | +function wpinv_item_type($item_id) { |
|
232 | 232 | $item_types = wpinv_get_item_types(); |
233 | 233 | |
234 | - $item_type = wpinv_get_item_type( $item_id ); |
|
234 | + $item_type = wpinv_get_item_type($item_id); |
|
235 | 235 | |
236 | - if ( empty( $item_type ) ) { |
|
236 | + if (empty($item_type)) { |
|
237 | 237 | $item_type = '-'; |
238 | 238 | } |
239 | 239 | |
240 | - $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' ); |
|
240 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
241 | 241 | |
242 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
242 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
243 | 243 | } |
244 | 244 | |
245 | -function wpinv_get_random_item( $post_ids = true ) { |
|
246 | - wpinv_get_random_items( 1, $post_ids ); |
|
245 | +function wpinv_get_random_item($post_ids = true) { |
|
246 | + wpinv_get_random_items(1, $post_ids); |
|
247 | 247 | } |
248 | 248 | |
249 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
250 | - if ( $post_ids ) { |
|
249 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
250 | + if ($post_ids) { |
|
251 | 251 | $args = array( |
252 | 252 | 'post_type' => 'wpi_item', |
253 | 253 | 'orderby' => 'rand', |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | ); |
263 | 263 | } |
264 | 264 | |
265 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
265 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
266 | 266 | |
267 | - return get_posts( $args ); |
|
267 | + return get_posts($args); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | * @param WPInv_Item|int $item |
274 | 274 | * @param bool $html |
275 | 275 | */ |
276 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
276 | +function wpinv_get_item_suffix($item, $html = true) { |
|
277 | 277 | |
278 | - $item = new WPInv_Item( $item ); |
|
279 | - $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : ''; |
|
280 | - $suffix = $html ? $suffix : wp_strip_all_tags( $suffix ); |
|
278 | + $item = new WPInv_Item($item); |
|
279 | + $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : ''; |
|
280 | + $suffix = $html ? $suffix : wp_strip_all_tags($suffix); |
|
281 | 281 | |
282 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
282 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | * @param WPInv_Item|int $item |
289 | 289 | * @param bool $force_delete |
290 | 290 | */ |
291 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
292 | - $item = new WPInv_Item( $item ); |
|
293 | - $item->delete( $force_delete ); |
|
291 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
292 | + $item = new WPInv_Item($item); |
|
293 | + $item->delete($force_delete); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -329,44 +329,44 @@ discard block |
||
329 | 329 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
330 | 330 | * @return bool|WP_Error|WPInv_Item |
331 | 331 | */ |
332 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
332 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
333 | 333 | |
334 | 334 | // Prepare the item. |
335 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
336 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
337 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
335 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
336 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
337 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
338 | 338 | |
339 | - if ( ! empty( $item ) ) { |
|
339 | + if (!empty($item)) { |
|
340 | 340 | $args['ID'] = $item->get_id(); |
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Do we have an item? |
345 | - if ( ! empty( $args['ID'] ) ) { |
|
346 | - $item = new WPInv_Item( $args['ID'] ); |
|
345 | + if (!empty($args['ID'])) { |
|
346 | + $item = new WPInv_Item($args['ID']); |
|
347 | 347 | } else { |
348 | 348 | $item = new WPInv_Item(); |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Do we have an error? |
352 | - if ( ! empty( $item->last_error ) ) { |
|
353 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
352 | + if (!empty($item->last_error)) { |
|
353 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Update item props. |
357 | - $item->set_props( $args ); |
|
357 | + $item->set_props($args); |
|
358 | 358 | |
359 | 359 | // Save the item. |
360 | 360 | $item->save(); |
361 | 361 | |
362 | 362 | // Do we have an error? |
363 | - if ( ! empty( $item->last_error ) ) { |
|
364 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
363 | + if (!empty($item->last_error)) { |
|
364 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | // Was the item saved? |
368 | - if ( ! $item->get_id() ) { |
|
369 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
368 | + if (!$item->get_id()) { |
|
369 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $item; |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @see wpinv_create_item() |
380 | 380 | */ |
381 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
382 | - return wpinv_create_item( $args, $wp_error ); |
|
381 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
382 | + return wpinv_create_item($args, $wp_error); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Sanitizes a recurring period |
387 | 387 | */ |
388 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
388 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
389 | 389 | |
390 | 390 | $periods = array( |
391 | 391 | 'D' => 'day', |
@@ -394,16 +394,16 @@ discard block |
||
394 | 394 | 'Y' => 'year', |
395 | 395 | ); |
396 | 396 | |
397 | - if ( ! isset( $periods[ $period ] ) ) { |
|
397 | + if (!isset($periods[$period])) { |
|
398 | 398 | $period = 'D'; |
399 | 399 | } |
400 | 400 | |
401 | - return $full ? $periods[ $period ] : $period; |
|
401 | + return $full ? $periods[$period] : $period; |
|
402 | 402 | |
403 | 403 | } |
404 | 404 | |
405 | -function wpinv_item_max_buyable_quantity( $item_id ) { |
|
406 | - return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id ); |
|
405 | +function wpinv_item_max_buyable_quantity($item_id) { |
|
406 | + return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -411,47 +411,47 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @param WPInv_Item|GetPaid_Form_Item $item |
413 | 413 | */ |
414 | -function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
|
414 | +function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) { |
|
415 | 415 | |
416 | 416 | // Abort if it is not recurring. |
417 | - if ( ! $item->is_recurring() ) { |
|
417 | + if (!$item->is_recurring()) { |
|
418 | 418 | return ''; |
419 | 419 | } |
420 | 420 | |
421 | - $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
|
422 | - $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
|
423 | - $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
|
421 | + $initial_price = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price; |
|
422 | + $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price; |
|
423 | + $period = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), ''); |
|
424 | 424 | $initial_class = 'getpaid-item-initial-price'; |
425 | 425 | $recurring_class = 'getpaid-item-recurring-price'; |
426 | 426 | $bill_times = $item->get_recurring_limit(); |
427 | 427 | $bill_times_less = $bill_times - 1; |
428 | 428 | |
429 | - if ( ! empty( $bill_times ) ) { |
|
429 | + if (!empty($bill_times)) { |
|
430 | 430 | $bill_times = $item->get_recurring_interval() * $bill_times; |
431 | - $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
|
432 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
431 | + $bill_times_less = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times - $item->get_recurring_interval()); |
|
432 | + $bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times); |
|
433 | 433 | } |
434 | 434 | |
435 | - if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
|
436 | - $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
|
437 | - $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
|
435 | + if ($item instanceof GetPaid_Form_Item && false === $_initial_price) { |
|
436 | + $initial_price = wpinv_price($item->get_sub_total(), $currency); |
|
437 | + $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency); |
|
438 | 438 | } |
439 | 439 | |
440 | - if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
|
441 | - return __( 'Free forever', 'invoicing' ); |
|
440 | + if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) { |
|
441 | + return __('Free forever', 'invoicing'); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | // For free trial items. |
445 | - if ( $item->has_free_trial() ) { |
|
446 | - $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
|
445 | + if ($item->has_free_trial()) { |
|
446 | + $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval()); |
|
447 | 447 | |
448 | - if ( wpinv_price( 0, $currency ) == $initial_price ) { |
|
448 | + if (wpinv_price(0, $currency) == $initial_price) { |
|
449 | 449 | |
450 | - if ( empty( $bill_times ) ) { |
|
450 | + if (empty($bill_times)) { |
|
451 | 451 | |
452 | 452 | return sprintf( |
453 | 453 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
454 | - _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
|
454 | + _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'), |
|
455 | 455 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
456 | 456 | "<span class='$recurring_class'>$recurring_price</span>", |
457 | 457 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | |
462 | 462 | return sprintf( |
463 | 463 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
464 | - _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
464 | + _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
465 | 465 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
466 | 466 | "<span class='$recurring_class'>$recurring_price</span>", |
467 | 467 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -470,11 +470,11 @@ discard block |
||
470 | 470 | |
471 | 471 | } |
472 | 472 | |
473 | - if ( empty( $bill_times ) ) { |
|
473 | + if (empty($bill_times)) { |
|
474 | 474 | |
475 | 475 | return sprintf( |
476 | 476 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
477 | - _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
|
477 | + _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'), |
|
478 | 478 | "<span class='$initial_class'>$initial_price</span>", |
479 | 479 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
480 | 480 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | |
486 | 486 | return sprintf( |
487 | 487 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
488 | - _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
|
488 | + _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'), |
|
489 | 489 | "<span class='$initial_class'>$initial_price</span>", |
490 | 490 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
491 | 491 | "<span class='$recurring_class'>$recurring_price</span>", |
@@ -495,13 +495,13 @@ discard block |
||
495 | 495 | |
496 | 496 | } |
497 | 497 | |
498 | - if ( $initial_price == $recurring_price ) { |
|
498 | + if ($initial_price == $recurring_price) { |
|
499 | 499 | |
500 | - if ( empty( $bill_times ) ) { |
|
500 | + if (empty($bill_times)) { |
|
501 | 501 | |
502 | 502 | return sprintf( |
503 | 503 | // translators: $1: is the recurring price, $2: is the susbcription period |
504 | - _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
504 | + _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
505 | 505 | "<span class='$recurring_class'>$recurring_price</span>", |
506 | 506 | "<span class='getpaid-item-recurring-period'>$period</span>" |
507 | 507 | ); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | |
511 | 511 | return sprintf( |
512 | 512 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
513 | - _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
513 | + _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
514 | 514 | "<span class='$recurring_class'>$recurring_price</span>", |
515 | 515 | "<span class='getpaid-item-recurring-period'>$period</span>", |
516 | 516 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | |
519 | 519 | } |
520 | 520 | |
521 | - if ( $initial_price == wpinv_price( 0, $currency ) ) { |
|
521 | + if ($initial_price == wpinv_price(0, $currency)) { |
|
522 | 522 | |
523 | - if ( empty( $bill_times ) ) { |
|
523 | + if (empty($bill_times)) { |
|
524 | 524 | |
525 | 525 | return sprintf( |
526 | 526 | // translators: $1: is the recurring period, $2: is the recurring price |
527 | - _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
|
527 | + _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'), |
|
528 | 528 | "<span class='getpaid-item-recurring-period'>$period</span>", |
529 | 529 | "<span class='$recurring_class'>$recurring_price</span>" |
530 | 530 | ); |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | |
534 | 534 | return sprintf( |
535 | 535 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
536 | - _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
|
536 | + _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'), |
|
537 | 537 | "<span class='getpaid-item-recurring-period'>$period</span>", |
538 | 538 | "<span class='$recurring_class'>$recurring_price</span>", |
539 | 539 | "<span class='getpaid-item-recurring-bill-times'>$bill_times_less</span>" |
@@ -541,11 +541,11 @@ discard block |
||
541 | 541 | |
542 | 542 | } |
543 | 543 | |
544 | - if ( empty( $bill_times ) ) { |
|
544 | + if (empty($bill_times)) { |
|
545 | 545 | |
546 | 546 | return sprintf( |
547 | 547 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
548 | - _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
|
548 | + _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'), |
|
549 | 549 | "<span class='$initial_class'>$initial_price</span>", |
550 | 550 | "<span class='$recurring_class'>$recurring_price</span>", |
551 | 551 | "<span class='getpaid-item-recurring-period'>$period</span>" |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | |
556 | 556 | return sprintf( |
557 | 557 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
558 | - _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
|
558 | + _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'), |
|
559 | 559 | "<span class='$initial_class'>$initial_price</span>", |
560 | 560 | "<span class='$recurring_class'>$recurring_price</span>", |
561 | 561 | "<span class='getpaid-item-recurring-period'>$period</span>", |
@@ -7,35 +7,35 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | $value = $query_value; |
13 | 13 | $class = ''; |
14 | 14 | |
15 | -if ( ! empty( $form->invoice ) ) { |
|
16 | - $value = sanitize_email( $form->invoice->get_email() ); |
|
17 | -} elseif ( is_user_logged_in() ) { |
|
15 | +if (!empty($form->invoice)) { |
|
16 | + $value = sanitize_email($form->invoice->get_email()); |
|
17 | +} elseif (is_user_logged_in()) { |
|
18 | 18 | $user = wp_get_current_user(); |
19 | - $value = sanitize_email( $user->user_email ); |
|
19 | + $value = sanitize_email($user->user_email); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( ! empty( $value ) && ! empty( $hide_billing_email ) ) { |
|
22 | +if (!empty($value) && !empty($hide_billing_email)) { |
|
23 | 23 | $class = 'd-none'; |
24 | 24 | } |
25 | 25 | |
26 | -do_action( 'getpaid_before_payment_form_billing_email', $form ); |
|
26 | +do_action('getpaid_before_payment_form_billing_email', $form); |
|
27 | 27 | |
28 | -echo "<span class='" . esc_attr( $class ) . "'>"; |
|
28 | +echo "<span class='" . esc_attr($class) . "'>"; |
|
29 | 29 | |
30 | 30 | aui()->input( |
31 | 31 | array( |
32 | 32 | 'name' => 'billing_email', |
33 | - 'id' => esc_attr( $element_id ), |
|
34 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
35 | - 'required' => ! empty( $required ), |
|
36 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ) . '<span class="text-danger"> *</span>', |
|
33 | + 'id' => esc_attr($element_id), |
|
34 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
35 | + 'required' => !empty($required), |
|
36 | + 'label' => empty($label) ? '' : wp_kses_post($label) . '<span class="text-danger"> *</span>', |
|
37 | 37 | 'label_type' => 'vertical', |
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
38 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
39 | 39 | 'type' => 'email', |
40 | 40 | 'value' => $value, |
41 | 41 | 'class' => 'wpinv_billing_email getpaid-refresh-on-change', |
@@ -48,4 +48,4 @@ discard block |
||
48 | 48 | |
49 | 49 | echo '</span>'; |
50 | 50 | |
51 | -do_action( 'getpaid_after_payment_form_billing_email', $form ); |
|
51 | +do_action('getpaid_after_payment_form_billing_email', $form); |
@@ -12,59 +12,59 @@ |
||
12 | 12 | $label = empty( $label ) ? '' : wp_kses_post( $label ); |
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | if ( ! empty( $required ) ) { |
15 | - $label .= "<span class='text-danger'> *</span>"; |
|
15 | + $label .= "<span class='text-danger'> *</span>"; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | $disable_dates = array(); |
19 | 19 | |
20 | 20 | if ( ! empty( $disabled_dates ) ) { |
21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
21 | + $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | + $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | + $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
24 | 24 | |
25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
25 | + foreach ( $disabled_dates as $disabled_date ) { |
|
26 | 26 | |
27 | - $disabled_date = trim( $disabled_date ); |
|
27 | + $disabled_date = trim( $disabled_date ); |
|
28 | 28 | |
29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | - $disable_dates[] = $disabled_date; |
|
31 | - continue; |
|
32 | - } |
|
29 | + if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | + $disable_dates[] = $disabled_date; |
|
31 | + continue; |
|
32 | + } |
|
33 | 33 | |
34 | - $disabled_date = explode( '|', $disabled_date ); |
|
35 | - $disable_dates[] = array( |
|
36 | - 'from' => trim( $disabled_date[0] ), |
|
37 | - 'to' => trim( $disabled_date[1] ), |
|
38 | - ); |
|
34 | + $disabled_date = explode( '|', $disabled_date ); |
|
35 | + $disable_dates[] = array( |
|
36 | + 'from' => trim( $disabled_date[0] ), |
|
37 | + 'to' => trim( $disabled_date[1] ), |
|
38 | + ); |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | $options = array( |
44 | - 'data-default-date' => empty( $default_date ) ? false : $default_date, |
|
45 | - 'data-min-date' => empty( $min_date ) ? false : $min_date, |
|
46 | - 'data-max-date' => empty( $max_date ) ? false : $max_date, |
|
47 | - 'data-mode' => empty( $mode ) ? 'single' : $mode, |
|
48 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
49 | - 'data-date-format' => 'Y-m-d', |
|
50 | - 'data-alt-input' => 'true', |
|
51 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
52 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
44 | + 'data-default-date' => empty( $default_date ) ? false : $default_date, |
|
45 | + 'data-min-date' => empty( $min_date ) ? false : $min_date, |
|
46 | + 'data-max-date' => empty( $max_date ) ? false : $max_date, |
|
47 | + 'data-mode' => empty( $mode ) ? 'single' : $mode, |
|
48 | + 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
49 | + 'data-date-format' => 'Y-m-d', |
|
50 | + 'data-alt-input' => 'true', |
|
51 | + 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
52 | + 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
53 | 53 | ); |
54 | 54 | |
55 | 55 | aui()->input( |
56 | - array( |
|
57 | - 'name' => esc_attr( $id ), |
|
58 | - 'id' => esc_attr( $element_id ), |
|
59 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
60 | - 'required' => ! empty( $required ), |
|
61 | - 'label' => $label, |
|
62 | - 'label_type' => 'vertical', |
|
63 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
64 | - 'type' => 'datepicker', |
|
65 | - 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
66 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
67 | - 'value' => $query_value, |
|
68 | - ), |
|
69 | - true |
|
56 | + array( |
|
57 | + 'name' => esc_attr( $id ), |
|
58 | + 'id' => esc_attr( $element_id ), |
|
59 | + 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
60 | + 'required' => ! empty( $required ), |
|
61 | + 'label' => $label, |
|
62 | + 'label_type' => 'vertical', |
|
63 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
64 | + 'type' => 'datepicker', |
|
65 | + 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
66 | + 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
67 | + 'value' => $query_value, |
|
68 | + ), |
|
69 | + true |
|
70 | 70 | ); |
@@ -7,63 +7,63 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
14 | -if ( ! empty( $required ) ) { |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
14 | +if (!empty($required)) { |
|
15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | $disable_dates = array(); |
19 | 19 | |
20 | -if ( ! empty( $disabled_dates ) ) { |
|
21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
20 | +if (!empty($disabled_dates)) { |
|
21 | + $disabled_dates = preg_replace('/\s+/', '', $disabled_dates); |
|
22 | + $disabled_dates = str_ireplace('today', current_time('Y-m-d'), $disabled_dates); |
|
23 | + $disabled_dates = array_filter(explode(',', $disabled_dates)); |
|
24 | 24 | |
25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
25 | + foreach ($disabled_dates as $disabled_date) { |
|
26 | 26 | |
27 | - $disabled_date = trim( $disabled_date ); |
|
27 | + $disabled_date = trim($disabled_date); |
|
28 | 28 | |
29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
29 | + if (false === strpos($disabled_date, '|')) { |
|
30 | 30 | $disable_dates[] = $disabled_date; |
31 | 31 | continue; |
32 | 32 | } |
33 | 33 | |
34 | - $disabled_date = explode( '|', $disabled_date ); |
|
34 | + $disabled_date = explode('|', $disabled_date); |
|
35 | 35 | $disable_dates[] = array( |
36 | - 'from' => trim( $disabled_date[0] ), |
|
37 | - 'to' => trim( $disabled_date[1] ), |
|
36 | + 'from' => trim($disabled_date[0]), |
|
37 | + 'to' => trim($disabled_date[1]), |
|
38 | 38 | ); |
39 | 39 | |
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | 43 | $options = array( |
44 | - 'data-default-date' => empty( $default_date ) ? false : $default_date, |
|
45 | - 'data-min-date' => empty( $min_date ) ? false : $min_date, |
|
46 | - 'data-max-date' => empty( $max_date ) ? false : $max_date, |
|
47 | - 'data-mode' => empty( $mode ) ? 'single' : $mode, |
|
48 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
44 | + 'data-default-date' => empty($default_date) ? false : $default_date, |
|
45 | + 'data-min-date' => empty($min_date) ? false : $min_date, |
|
46 | + 'data-max-date' => empty($max_date) ? false : $max_date, |
|
47 | + 'data-mode' => empty($mode) ? 'single' : $mode, |
|
48 | + 'data-alt-format' => get_option('date_format', 'F j, Y'), |
|
49 | 49 | 'data-date-format' => 'Y-m-d', |
50 | 50 | 'data-alt-input' => 'true', |
51 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
52 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
51 | + 'data-disable_alt' => empty($disabled_dates) ? false : wp_json_encode($disable_dates), |
|
52 | + 'data-disable_days_alt' => empty($disable_days) ? false : wp_json_encode(wp_parse_id_list($disable_days)), |
|
53 | 53 | ); |
54 | 54 | |
55 | 55 | aui()->input( |
56 | 56 | array( |
57 | - 'name' => esc_attr( $id ), |
|
58 | - 'id' => esc_attr( $element_id ), |
|
59 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
60 | - 'required' => ! empty( $required ), |
|
57 | + 'name' => esc_attr($id), |
|
58 | + 'id' => esc_attr($element_id), |
|
59 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
60 | + 'required' => !empty($required), |
|
61 | 61 | 'label' => $label, |
62 | 62 | 'label_type' => 'vertical', |
63 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
63 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
64 | 64 | 'type' => 'datepicker', |
65 | 65 | 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
66 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
66 | + 'extra_attributes' => array_filter(apply_filters('getpaid_date_field_attributes', $options)), |
|
67 | 67 | 'value' => $query_value, |
68 | 68 | ), |
69 | 69 | true |
@@ -12,184 +12,184 @@ discard block |
||
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 | - wp_send_json_error( __( '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 | + wp_send_json_error( __( '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 | + } |
|
133 | 117 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
138 | 125 | |
139 | - return $invoice; |
|
140 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
141 | 131 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
132 | + $invoice = $submission->get_invoice(); |
|
150 | 133 | |
151 | - $submission = $this->payment_form_submission; |
|
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 | + } |
|
152 | 138 | |
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() ) ); |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
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() ) ); |
|
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' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | if ( empty( $user ) ) { |
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | + $name = implode( '', array_filter( $name ) ); |
|
202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
203 | 203 | |
204 | - // (Maybe) send new user notification. |
|
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
208 | - } |
|
209 | - } |
|
204 | + // (Maybe) send new user notification. |
|
205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | 211 | if ( is_wp_error( $user ) ) { |
212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | |
215 | 215 | if ( is_numeric( $user ) ) { |
216 | 216 | return $user; |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - return $user->ID; |
|
219 | + return $user->ID; |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Prepares submission data for saving to the database. |
225 | 225 | * |
226 | - * @return array |
|
226 | + * @return array |
|
227 | 227 | */ |
228 | 228 | public function prepare_submission_data_for_saving() { |
229 | 229 | |
230 | - $submission = $this->payment_form_submission; |
|
230 | + $submission = $this->payment_form_submission; |
|
231 | 231 | |
232 | - // Prepared submission details. |
|
232 | + // Prepared submission details. |
|
233 | 233 | $prepared = array( |
234 | - 'all' => array(), |
|
235 | - 'meta' => array(), |
|
236 | - ); |
|
234 | + 'all' => array(), |
|
235 | + 'meta' => array(), |
|
236 | + ); |
|
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | - // Loop through the submitted details. |
|
241 | + // Loop through the submitted details. |
|
242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
243 | 243 | |
244 | - // Skip premade fields. |
|
244 | + // Skip premade fields. |
|
245 | 245 | if ( ! empty( $field['premade'] ) ) { |
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | - // Ensure address is provided. |
|
250 | - if ( $field['type'] == 'address' ) { |
|
249 | + // Ensure address is provided. |
|
250 | + if ( $field['type'] == 'address' ) { |
|
251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ( $field['fields'] as $address_field ) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
266 | 266 | // Handle misc fields. |
267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
268 | 268 | |
269 | - // Uploads. |
|
270 | - if ( $field['type'] === 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
269 | + // Uploads. |
|
270 | + if ( $field['type'] === 'file_upload' ) { |
|
271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | - } |
|
273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | + } |
|
276 | 276 | |
277 | - $value = array(); |
|
277 | + $value = array(); |
|
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | - $value[] = sprintf( |
|
281 | - '<a href="%s" target="_blank">%s</a>', |
|
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
284 | - ); |
|
285 | - } |
|
279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + $value[] = sprintf( |
|
281 | + '<a href="%s" target="_blank">%s</a>', |
|
282 | + esc_url_raw( $url ), |
|
283 | + esc_html( $name ) |
|
284 | + ); |
|
285 | + } |
|
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode( ' | ', $value ); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] === 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | - } else { |
|
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | - } |
|
289 | + } elseif ( $field['type'] === 'checkbox' ) { |
|
290 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | + } else { |
|
292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
@@ -298,188 +298,188 @@ discard block |
||
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | - } |
|
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | + } |
|
304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | 305 | |
306 | 306 | } |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | - return $prepared; |
|
309 | + return $prepared; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Retrieves address details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
318 | - * @param string $type |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | + * @param string $type |
|
319 | 319 | */ |
320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
321 | 321 | |
322 | - $data = $this->payment_form_submission->get_data(); |
|
323 | - $type = sanitize_key( $type ); |
|
324 | - $address = array(); |
|
325 | - $prepared = array(); |
|
322 | + $data = $this->payment_form_submission->get_data(); |
|
323 | + $type = sanitize_key( $type ); |
|
324 | + $address = array(); |
|
325 | + $prepared = array(); |
|
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
329 | - } |
|
327 | + if ( ! empty( $data[ $type ] ) ) { |
|
328 | + $address = $data[ $type ]; |
|
329 | + } |
|
330 | 330 | |
331 | - // Clean address details. |
|
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | - } |
|
331 | + // Clean address details. |
|
332 | + foreach ( $address as $key => $value ) { |
|
333 | + $key = sanitize_key( $key ); |
|
334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
335 | + $value = wpinv_clean( $value ); |
|
336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | + } |
|
338 | 338 | |
339 | - // Filter address details. |
|
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
339 | + // Filter address details. |
|
340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | 341 | |
342 | - // Remove non-whitelisted values. |
|
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
342 | + // Remove non-whitelisted values. |
|
343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
347 | + /** |
|
348 | 348 | * Prepares the billing details. |
349 | 349 | * |
350 | - * @return array |
|
351 | - * @param WPInv_Invoice $invoice |
|
350 | + * @return array |
|
351 | + * @param WPInv_Invoice $invoice |
|
352 | 352 | */ |
353 | 353 | protected function prepare_billing_info( &$invoice ) { |
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | 356 | |
357 | - // Update the invoice with the billing details. |
|
358 | - $invoice->set_props( $billing_address ); |
|
357 | + // Update the invoice with the billing details. |
|
358 | + $invoice->set_props( $billing_address ); |
|
359 | 359 | |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
362 | + /** |
|
363 | 363 | * Prepares the shipping details. |
364 | 364 | * |
365 | - * @return array |
|
366 | - * @param WPInv_Invoice $invoice |
|
365 | + * @return array |
|
366 | + * @param WPInv_Invoice $invoice |
|
367 | 367 | */ |
368 | 368 | protected function prepare_shipping_info( $invoice ) { |
369 | 369 | |
370 | - $data = $this->payment_form_submission->get_data(); |
|
370 | + $data = $this->payment_form_submission->get_data(); |
|
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | - } |
|
372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + } |
|
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | 377 | |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Confirms the submission is valid and send users to the gateway. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice |
|
384 | - * @param array $prepared_payment_form_data |
|
385 | - * @param array $shipping |
|
386 | - */ |
|
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
380 | + /** |
|
381 | + * Confirms the submission is valid and send users to the gateway. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice |
|
384 | + * @param array $prepared_payment_form_data |
|
385 | + * @param array $shipping |
|
386 | + */ |
|
387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | 388 | |
389 | - // Ensure the invoice exists. |
|
389 | + // Ensure the invoice exists. |
|
390 | 390 | if ( ! $invoice->exists() ) { |
391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
392 | 392 | } |
393 | 393 | |
394 | - // Save payment form data. |
|
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
394 | + // Save payment form data. |
|
395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | - } |
|
400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + } |
|
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | - } |
|
404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + } |
|
407 | 407 | } |
408 | 408 | |
409 | - // Save payment form data. |
|
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
409 | + // Save payment form data. |
|
410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | 411 | if ( ! empty( $shipping ) ) { |
412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - // Backwards compatibility. |
|
415 | + // Backwards compatibility. |
|
416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment( $invoice ); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout( $invoice ); |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Processes the actual payment. |
|
427 | - * |
|
428 | - * @param WPInv_Invoice $invoice |
|
429 | - */ |
|
430 | - protected function process_payment( $invoice ) { |
|
425 | + /** |
|
426 | + * Processes the actual payment. |
|
427 | + * |
|
428 | + * @param WPInv_Invoice $invoice |
|
429 | + */ |
|
430 | + protected function process_payment( $invoice ) { |
|
431 | 431 | |
432 | - // Clear any checkout errors. |
|
433 | - wpinv_clear_errors(); |
|
432 | + // Clear any checkout errors. |
|
433 | + wpinv_clear_errors(); |
|
434 | 434 | |
435 | - // No need to send free invoices to the gateway. |
|
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
438 | - } |
|
435 | + // No need to send free invoices to the gateway. |
|
436 | + if ( $invoice->is_free() ) { |
|
437 | + $this->process_free_payment( $invoice ); |
|
438 | + } |
|
439 | 439 | |
440 | - $submission = $this->payment_form_submission; |
|
440 | + $submission = $this->payment_form_submission; |
|
441 | 441 | |
442 | - // Fires before sending to the gateway. |
|
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
442 | + // Fires before sending to the gateway. |
|
443 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
444 | 444 | |
445 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | - $submission_data = $submission->get_data(); |
|
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
445 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
446 | + $submission_data = $submission->get_data(); |
|
447 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
449 | 449 | |
450 | - // Validate the currency. |
|
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
453 | - } |
|
450 | + // Validate the currency. |
|
451 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
453 | + } |
|
454 | 454 | |
455 | - // Check to see if we have any errors. |
|
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
458 | - } |
|
455 | + // Check to see if we have any errors. |
|
456 | + if ( wpinv_get_errors() ) { |
|
457 | + wpinv_send_back_to_checkout( $invoice ); |
|
458 | + } |
|
459 | 459 | |
460 | - // Send info to the gateway for payment processing |
|
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
460 | + // Send info to the gateway for payment processing |
|
461 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
462 | 462 | |
463 | - // Backwards compatibility. |
|
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
463 | + // Backwards compatibility. |
|
464 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | - /** |
|
469 | - * Marks the invoice as paid in case the checkout is free. |
|
470 | - * |
|
471 | - * @param WPInv_Invoice $invoice |
|
472 | - */ |
|
473 | - protected function process_free_payment( $invoice ) { |
|
468 | + /** |
|
469 | + * Marks the invoice as paid in case the checkout is free. |
|
470 | + * |
|
471 | + * @param WPInv_Invoice $invoice |
|
472 | + */ |
|
473 | + protected function process_free_payment( $invoice ) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | - $invoice->mark_paid(); |
|
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
475 | + $invoice->set_gateway( 'none' ); |
|
476 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
477 | + $invoice->mark_paid(); |
|
478 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
479 | 479 | |
480 | - } |
|
480 | + } |
|
481 | 481 | |
482 | - /** |
|
482 | + /** |
|
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 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 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 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' ) ); |
|
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 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 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' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 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 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
163 | - |
|
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
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 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
159 | + $invoice->set_taxes($submission->get_taxes()); |
|
160 | + $invoice->set_discounts($submission->get_discounts()); |
|
161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
162 | + $invoice->set_currency($submission->get_currency()); |
|
163 | + |
|
164 | + if ($submission->has_shipping()) { |
|
165 | + $invoice->set_shipping($submission->get_shipping()); |
|
166 | 166 | } |
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
169 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
171 | + if ($submission->has_discount_code()) { |
|
172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
173 | 173 | } |
174 | 174 | |
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
175 | + getpaid_maybe_add_default_address($invoice); |
|
176 | 176 | return $invoice; |
177 | 177 | } |
178 | 178 | |
@@ -185,34 +185,34 @@ discard block |
||
185 | 185 | $submission = $this->payment_form_submission; |
186 | 186 | |
187 | 187 | // If this is an existing invoice... |
188 | - if ( $submission->has_invoice() ) { |
|
188 | + if ($submission->has_invoice()) { |
|
189 | 189 | return $submission->get_invoice()->get_user_id(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | // (Maybe) create the user. |
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $user ) ) { |
|
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
202 | - $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
|
199 | + if (empty($user)) { |
|
200 | + $name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing')); |
|
201 | + $name = implode('', array_filter($name)); |
|
202 | + $user = wpinv_create_user($submission->get_billing_email(), $name); |
|
203 | 203 | |
204 | 204 | // (Maybe) send new user notification. |
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
205 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
206 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
207 | + wp_send_new_user_notifications($user, 'user'); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_wp_error( $user ) ) { |
|
212 | - wp_send_json_error( $user->get_error_message() ); |
|
211 | + if (is_wp_error($user)) { |
|
212 | + wp_send_json_error($user->get_error_message()); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( is_numeric( $user ) ) { |
|
215 | + if (is_numeric($user)) { |
|
216 | 216 | return $user; |
217 | 217 | } |
218 | 218 | |
@@ -236,72 +236,72 @@ discard block |
||
236 | 236 | ); |
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | 241 | // Loop through the submitted details. |
242 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
242 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
243 | 243 | |
244 | 244 | // Skip premade fields. |
245 | - if ( ! empty( $field['premade'] ) ) { |
|
245 | + if (!empty($field['premade'])) { |
|
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | 249 | // Ensure address is provided. |
250 | - if ( $field['type'] == 'address' ) { |
|
251 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
250 | + if ($field['type'] == 'address') { |
|
251 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ($field['fields'] as $address_field) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
255 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { |
|
256 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
263 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
262 | + if (!$submission->is_required_field_set($field)) { |
|
263 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // Handle misc fields. |
267 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
267 | + if (isset($data[$field['id']])) { |
|
268 | 268 | |
269 | 269 | // Uploads. |
270 | - if ( $field['type'] === 'file_upload' ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + if ($field['type'] === 'file_upload') { |
|
271 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
273 | + if (count($data[$field['id']]) > $max_file_num) { |
|
274 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $value = array(); |
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
279 | + foreach ($data[$field['id']] as $url => $name) { |
|
280 | 280 | $value[] = sprintf( |
281 | 281 | '<a href="%s" target="_blank">%s</a>', |
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
282 | + esc_url_raw($url), |
|
283 | + esc_html($name) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode(' | ', $value); |
|
288 | 288 | |
289 | - } elseif ( $field['type'] === 'checkbox' ) { |
|
290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
289 | + } elseif ($field['type'] === 'checkbox') { |
|
290 | + $value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
291 | 291 | } else { |
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
292 | + $value = wp_kses_post($data[$field['id']]); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
297 | - if ( isset( $field['label'] ) ) { |
|
297 | + if (isset($field['label'])) { |
|
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if (!empty($field['add_meta'])) { |
|
302 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
303 | 303 | } |
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | } |
@@ -317,30 +317,30 @@ discard block |
||
317 | 317 | * @param WPInv_Invoice $invoice |
318 | 318 | * @param string $type |
319 | 319 | */ |
320 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
320 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
321 | 321 | |
322 | 322 | $data = $this->payment_form_submission->get_data(); |
323 | - $type = sanitize_key( $type ); |
|
323 | + $type = sanitize_key($type); |
|
324 | 324 | $address = array(); |
325 | 325 | $prepared = array(); |
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
327 | + if (!empty($data[$type])) { |
|
328 | + $address = $data[$type]; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | // Clean address details. |
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
332 | + foreach ($address as $key => $value) { |
|
333 | + $key = sanitize_key($key); |
|
334 | + $key = str_replace('wpinv_', '', $key); |
|
335 | + $value = wpinv_clean($value); |
|
336 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Filter address details. |
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
340 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
341 | 341 | |
342 | 342 | // Remove non-whitelisted values. |
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
343 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | * @return array |
351 | 351 | * @param WPInv_Invoice $invoice |
352 | 352 | */ |
353 | - protected function prepare_billing_info( &$invoice ) { |
|
353 | + protected function prepare_billing_info(&$invoice) { |
|
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
356 | 356 | |
357 | 357 | // Update the invoice with the billing details. |
358 | - $invoice->set_props( $billing_address ); |
|
358 | + $invoice->set_props($billing_address); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
@@ -365,15 +365,15 @@ discard block |
||
365 | 365 | * @return array |
366 | 366 | * @param WPInv_Invoice $invoice |
367 | 367 | */ |
368 | - protected function prepare_shipping_info( $invoice ) { |
|
368 | + protected function prepare_shipping_info($invoice) { |
|
369 | 369 | |
370 | 370 | $data = $this->payment_form_submission->get_data(); |
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
372 | + if (empty($data['same-shipping-address'])) { |
|
373 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
374 | 374 | } |
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details($invoice, 'billing'); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -384,41 +384,41 @@ discard block |
||
384 | 384 | * @param array $prepared_payment_form_data |
385 | 385 | * @param array $shipping |
386 | 386 | */ |
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
387 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
388 | 388 | |
389 | 389 | // Ensure the invoice exists. |
390 | - if ( ! $invoice->exists() ) { |
|
391 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
390 | + if (!$invoice->exists()) { |
|
391 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Save payment form data. |
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
395 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
396 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
397 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
398 | + if (!empty($prepared_payment_form_data)) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
400 | + if (!empty($prepared_payment_form_data['all'])) { |
|
401 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
402 | 402 | } |
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
404 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
405 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Save payment form data. |
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | - if ( ! empty( $shipping ) ) { |
|
412 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
410 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
411 | + if (!empty($shipping)) { |
|
412 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // Backwards compatibility. |
416 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
416 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
417 | 417 | |
418 | - $this->process_payment( $invoice ); |
|
418 | + $this->process_payment($invoice); |
|
419 | 419 | |
420 | 420 | // If we are here, there was an error. |
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
421 | + wpinv_send_back_to_checkout($invoice); |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
@@ -427,41 +427,41 @@ discard block |
||
427 | 427 | * |
428 | 428 | * @param WPInv_Invoice $invoice |
429 | 429 | */ |
430 | - protected function process_payment( $invoice ) { |
|
430 | + protected function process_payment($invoice) { |
|
431 | 431 | |
432 | 432 | // Clear any checkout errors. |
433 | 433 | wpinv_clear_errors(); |
434 | 434 | |
435 | 435 | // No need to send free invoices to the gateway. |
436 | - if ( $invoice->is_free() ) { |
|
437 | - $this->process_free_payment( $invoice ); |
|
436 | + if ($invoice->is_free()) { |
|
437 | + $this->process_free_payment($invoice); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | $submission = $this->payment_form_submission; |
441 | 441 | |
442 | 442 | // Fires before sending to the gateway. |
443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
443 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
444 | 444 | |
445 | 445 | // Allow the sumission data to be modified before it is sent to the gateway. |
446 | 446 | $submission_data = $submission->get_data(); |
447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
447 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
448 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
449 | 449 | |
450 | 450 | // Validate the currency. |
451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
452 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
451 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
452 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | // Check to see if we have any errors. |
456 | - if ( wpinv_get_errors() ) { |
|
457 | - wpinv_send_back_to_checkout( $invoice ); |
|
456 | + if (wpinv_get_errors()) { |
|
457 | + wpinv_send_back_to_checkout($invoice); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | // Send info to the gateway for payment processing |
461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
461 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
462 | 462 | |
463 | 463 | // Backwards compatibility. |
464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
464 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
465 | 465 | |
466 | 466 | } |
467 | 467 | |
@@ -470,12 +470,12 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @param WPInv_Invoice $invoice |
472 | 472 | */ |
473 | - protected function process_free_payment( $invoice ) { |
|
473 | + protected function process_free_payment($invoice) { |
|
474 | 474 | |
475 | - $invoice->set_gateway( 'none' ); |
|
476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
475 | + $invoice->set_gateway('none'); |
|
476 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
477 | 477 | $invoice->mark_paid(); |
478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
478 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
479 | 479 | |
480 | 480 | } |
481 | 481 | |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | * Sends a redrect response to payment details. |
484 | 484 | * |
485 | 485 | */ |
486 | - public function send_redirect_response( $url ) { |
|
487 | - $url = urlencode( $url ); |
|
488 | - wp_send_json_success( $url ); |
|
486 | + public function send_redirect_response($url) { |
|
487 | + $url = urlencode($url); |
|
488 | + wp_send_json_success($url); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | } |
@@ -14,636 +14,636 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
133 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
134 | - |
|
135 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
133 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
134 | + |
|
135 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
136 | 136 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
137 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
138 | - |
|
139 | - // Fires after registering actions. |
|
140 | - do_action( 'wpinv_actions', $this ); |
|
141 | - do_action( 'getpaid_actions', $this ); |
|
142 | - |
|
143 | - } |
|
144 | - |
|
145 | - public function plugins_loaded() { |
|
146 | - /* Internationalize the text strings used. */ |
|
147 | - $this->load_textdomain(); |
|
148 | - |
|
149 | - do_action( 'wpinv_loaded' ); |
|
150 | - |
|
151 | - // Fix oxygen page builder conflict |
|
152 | - if ( function_exists( 'ct_css_output' ) ) { |
|
153 | - wpinv_oxygen_fix_conflict(); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Load Localisation files. |
|
159 | - * |
|
160 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
161 | - * |
|
162 | - * Locales found in: |
|
163 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
164 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
165 | - * |
|
166 | - * @since 1.0.0 |
|
167 | - */ |
|
168 | - public function load_textdomain() { |
|
169 | - |
|
170 | - load_plugin_textdomain( |
|
171 | - 'invoicing', |
|
172 | - false, |
|
173 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
174 | - ); |
|
175 | - |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Include required core files used in admin and on the frontend. |
|
180 | - */ |
|
181 | - public function includes() { |
|
182 | - |
|
183 | - // Start with the settings. |
|
184 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
185 | - |
|
186 | - // Packages/libraries. |
|
187 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
188 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
189 | - |
|
190 | - // Load functions. |
|
191 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
192 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
193 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
194 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
195 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
205 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
206 | - |
|
207 | - // Register autoloader. |
|
208 | - try { |
|
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | - } |
|
213 | - |
|
214 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
215 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
216 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
217 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
218 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
235 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
236 | - |
|
237 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
238 | - GetPaid_Post_Types_Admin::init(); |
|
239 | - |
|
240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
241 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
242 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
243 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
246 | - // load the user class only on the users.php page |
|
247 | - global $pagenow; |
|
248 | - if ( $pagenow == 'users.php' ) { |
|
249 | - new WPInv_Admin_Users(); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - // Register cli commands |
|
254 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
255 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
256 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
257 | - } |
|
258 | - |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Class autoloader |
|
263 | - * |
|
264 | - * @param string $class_name The name of the class to load. |
|
265 | - * @access public |
|
266 | - * @since 1.0.19 |
|
267 | - * @return void |
|
268 | - */ |
|
269 | - public function autoload( $class_name ) { |
|
270 | - |
|
271 | - // Normalize the class name... |
|
272 | - $class_name = strtolower( $class_name ); |
|
273 | - |
|
274 | - // ... and make sure it is our class. |
|
275 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
276 | - return; |
|
277 | - } |
|
278 | - |
|
279 | - // Next, prepare the file name from the class. |
|
280 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
281 | - |
|
282 | - // Base path of the classes. |
|
283 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
284 | - |
|
285 | - // And an array of possible locations in order of importance. |
|
286 | - $locations = array( |
|
287 | - "$plugin_path/includes", |
|
288 | - "$plugin_path/includes/data-stores", |
|
289 | - "$plugin_path/includes/gateways", |
|
290 | - "$plugin_path/includes/payments", |
|
291 | - "$plugin_path/includes/geolocation", |
|
292 | - "$plugin_path/includes/reports", |
|
293 | - "$plugin_path/includes/api", |
|
294 | - "$plugin_path/includes/admin", |
|
295 | - "$plugin_path/includes/admin/meta-boxes", |
|
296 | - ); |
|
297 | - |
|
298 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
299 | - |
|
300 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
301 | - include trailingslashit( $location ) . $file_name; |
|
302 | - break; |
|
303 | - } |
|
137 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
138 | + |
|
139 | + // Fires after registering actions. |
|
140 | + do_action( 'wpinv_actions', $this ); |
|
141 | + do_action( 'getpaid_actions', $this ); |
|
142 | + |
|
143 | + } |
|
144 | + |
|
145 | + public function plugins_loaded() { |
|
146 | + /* Internationalize the text strings used. */ |
|
147 | + $this->load_textdomain(); |
|
148 | + |
|
149 | + do_action( 'wpinv_loaded' ); |
|
150 | + |
|
151 | + // Fix oxygen page builder conflict |
|
152 | + if ( function_exists( 'ct_css_output' ) ) { |
|
153 | + wpinv_oxygen_fix_conflict(); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Load Localisation files. |
|
159 | + * |
|
160 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
161 | + * |
|
162 | + * Locales found in: |
|
163 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
164 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
165 | + * |
|
166 | + * @since 1.0.0 |
|
167 | + */ |
|
168 | + public function load_textdomain() { |
|
169 | + |
|
170 | + load_plugin_textdomain( |
|
171 | + 'invoicing', |
|
172 | + false, |
|
173 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
174 | + ); |
|
175 | + |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Include required core files used in admin and on the frontend. |
|
180 | + */ |
|
181 | + public function includes() { |
|
182 | + |
|
183 | + // Start with the settings. |
|
184 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
185 | + |
|
186 | + // Packages/libraries. |
|
187 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
188 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
189 | + |
|
190 | + // Load functions. |
|
191 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
192 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
193 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
194 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
195 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
205 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
206 | + |
|
207 | + // Register autoloader. |
|
208 | + try { |
|
209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | + } catch ( Exception $e ) { |
|
211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | + } |
|
213 | + |
|
214 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
215 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
216 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
217 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
218 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
235 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
236 | + |
|
237 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
238 | + GetPaid_Post_Types_Admin::init(); |
|
239 | + |
|
240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
241 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
242 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
243 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
246 | + // load the user class only on the users.php page |
|
247 | + global $pagenow; |
|
248 | + if ( $pagenow == 'users.php' ) { |
|
249 | + new WPInv_Admin_Users(); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + // Register cli commands |
|
254 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
255 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
256 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
257 | + } |
|
258 | + |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Class autoloader |
|
263 | + * |
|
264 | + * @param string $class_name The name of the class to load. |
|
265 | + * @access public |
|
266 | + * @since 1.0.19 |
|
267 | + * @return void |
|
268 | + */ |
|
269 | + public function autoload( $class_name ) { |
|
270 | + |
|
271 | + // Normalize the class name... |
|
272 | + $class_name = strtolower( $class_name ); |
|
273 | + |
|
274 | + // ... and make sure it is our class. |
|
275 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
276 | + return; |
|
277 | + } |
|
278 | + |
|
279 | + // Next, prepare the file name from the class. |
|
280 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
281 | + |
|
282 | + // Base path of the classes. |
|
283 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
284 | + |
|
285 | + // And an array of possible locations in order of importance. |
|
286 | + $locations = array( |
|
287 | + "$plugin_path/includes", |
|
288 | + "$plugin_path/includes/data-stores", |
|
289 | + "$plugin_path/includes/gateways", |
|
290 | + "$plugin_path/includes/payments", |
|
291 | + "$plugin_path/includes/geolocation", |
|
292 | + "$plugin_path/includes/reports", |
|
293 | + "$plugin_path/includes/api", |
|
294 | + "$plugin_path/includes/admin", |
|
295 | + "$plugin_path/includes/admin/meta-boxes", |
|
296 | + ); |
|
297 | + |
|
298 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
299 | + |
|
300 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
301 | + include trailingslashit( $location ) . $file_name; |
|
302 | + break; |
|
303 | + } |
|
304 | 304 | } |
305 | 305 | |
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Inits hooks etc. |
|
310 | - */ |
|
311 | - public function init() { |
|
312 | - |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | - GetPaid_Installer::rename_gateways_label(); |
|
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | - } |
|
339 | - |
|
340 | - // Fires after getpaid inits. |
|
341 | - do_action( 'getpaid_init', $this ); |
|
342 | - |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Checks if this is an IPN request and processes it. |
|
347 | - */ |
|
348 | - public function maybe_process_ipn() { |
|
349 | - |
|
350 | - // Ensure that this is an IPN request. |
|
351 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
352 | - return; |
|
353 | - } |
|
354 | - |
|
355 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
356 | - |
|
357 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
358 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
359 | - exit; |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - public function enqueue_scripts() { |
|
364 | - |
|
365 | - // Fires before adding scripts. |
|
366 | - do_action( 'getpaid_enqueue_scripts' ); |
|
367 | - |
|
368 | - $localize = array(); |
|
369 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
370 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
371 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
372 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
373 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
374 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
377 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
378 | - |
|
379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | - |
|
381 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
382 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
383 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
384 | - } |
|
385 | - |
|
386 | - public function wpinv_actions() { |
|
387 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
388 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
389 | - } |
|
390 | - |
|
391 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
392 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Inits hooks etc. |
|
310 | + */ |
|
311 | + public function init() { |
|
312 | + |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | + GetPaid_Installer::rename_gateways_label(); |
|
337 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | + } |
|
339 | + |
|
340 | + // Fires after getpaid inits. |
|
341 | + do_action( 'getpaid_init', $this ); |
|
342 | + |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Checks if this is an IPN request and processes it. |
|
347 | + */ |
|
348 | + public function maybe_process_ipn() { |
|
349 | + |
|
350 | + // Ensure that this is an IPN request. |
|
351 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
352 | + return; |
|
353 | + } |
|
354 | + |
|
355 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
356 | + |
|
357 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
358 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
359 | + exit; |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + public function enqueue_scripts() { |
|
364 | + |
|
365 | + // Fires before adding scripts. |
|
366 | + do_action( 'getpaid_enqueue_scripts' ); |
|
367 | + |
|
368 | + $localize = array(); |
|
369 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
370 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
371 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
372 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
373 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
374 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
375 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
377 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
378 | + |
|
379 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | + |
|
381 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
382 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
383 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
384 | + } |
|
385 | + |
|
386 | + public function wpinv_actions() { |
|
387 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
388 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
389 | + } |
|
390 | + |
|
391 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
392 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | 397 | * Fires an action after verifying that a user can fire them. |
398 | - * |
|
399 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
400 | - * current user owns the invoice/subscription. |
|
398 | + * |
|
399 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
400 | + * current user owns the invoice/subscription. |
|
401 | 401 | */ |
402 | 402 | public function maybe_do_authenticated_action() { |
403 | 403 | |
404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | 405 | |
406 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
407 | - $data = wp_unslash( $_REQUEST ); |
|
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | - } |
|
406 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
407 | + $data = wp_unslash( $_REQUEST ); |
|
408 | + if ( is_user_logged_in() ) { |
|
409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | + } |
|
411 | 411 | |
412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
413 | 413 | |
414 | - } |
|
414 | + } |
|
415 | 415 | |
416 | 416 | } |
417 | 417 | |
418 | - public function pre_get_posts( $wp_query ) { |
|
419 | - |
|
420 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
421 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
422 | - } |
|
423 | - |
|
424 | - return $wp_query; |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Register widgets |
|
429 | - * |
|
430 | - */ |
|
431 | - public function register_widgets() { |
|
432 | - global $pagenow; |
|
433 | - |
|
434 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
435 | - // So we disable our widgets when editing a page with UX Builder. |
|
436 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
437 | - return; |
|
438 | - } |
|
439 | - |
|
440 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
441 | - |
|
442 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
443 | - // don't initiate in these conditions. |
|
444 | - } else { |
|
445 | - |
|
446 | - // Only load allowed widgets. |
|
447 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
448 | - $widgets = apply_filters( |
|
449 | - 'getpaid_widget_classes', |
|
450 | - array( |
|
451 | - 'WPInv_Checkout_Widget', |
|
452 | - 'WPInv_History_Widget', |
|
453 | - 'WPInv_Receipt_Widget', |
|
454 | - 'WPInv_Subscriptions_Widget', |
|
455 | - 'WPInv_Buy_Item_Widget', |
|
456 | - 'WPInv_Messages_Widget', |
|
457 | - 'WPInv_GetPaid_Widget', |
|
458 | - 'WPInv_Invoice_Widget', |
|
459 | - ) |
|
460 | - ); |
|
461 | - |
|
462 | - // For each widget... |
|
463 | - foreach ( $widgets as $widget ) { |
|
464 | - |
|
465 | - // Abort early if it is excluded for this page. |
|
466 | - if ( in_array( $widget, $exclude ) ) { |
|
467 | - continue; |
|
468 | - } |
|
469 | - |
|
470 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
471 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
472 | - register_widget( $widget ); |
|
473 | - } else { |
|
474 | - new $widget(); |
|
475 | - } |
|
418 | + public function pre_get_posts( $wp_query ) { |
|
419 | + |
|
420 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
421 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
422 | + } |
|
423 | + |
|
424 | + return $wp_query; |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Register widgets |
|
429 | + * |
|
430 | + */ |
|
431 | + public function register_widgets() { |
|
432 | + global $pagenow; |
|
433 | + |
|
434 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
435 | + // So we disable our widgets when editing a page with UX Builder. |
|
436 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
437 | + return; |
|
438 | + } |
|
439 | + |
|
440 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
441 | + |
|
442 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
443 | + // don't initiate in these conditions. |
|
444 | + } else { |
|
445 | + |
|
446 | + // Only load allowed widgets. |
|
447 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
448 | + $widgets = apply_filters( |
|
449 | + 'getpaid_widget_classes', |
|
450 | + array( |
|
451 | + 'WPInv_Checkout_Widget', |
|
452 | + 'WPInv_History_Widget', |
|
453 | + 'WPInv_Receipt_Widget', |
|
454 | + 'WPInv_Subscriptions_Widget', |
|
455 | + 'WPInv_Buy_Item_Widget', |
|
456 | + 'WPInv_Messages_Widget', |
|
457 | + 'WPInv_GetPaid_Widget', |
|
458 | + 'WPInv_Invoice_Widget', |
|
459 | + ) |
|
460 | + ); |
|
461 | + |
|
462 | + // For each widget... |
|
463 | + foreach ( $widgets as $widget ) { |
|
464 | + |
|
465 | + // Abort early if it is excluded for this page. |
|
466 | + if ( in_array( $widget, $exclude ) ) { |
|
467 | + continue; |
|
468 | + } |
|
469 | + |
|
470 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
471 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
472 | + register_widget( $widget ); |
|
473 | + } else { |
|
474 | + new $widget(); |
|
475 | + } |
|
476 | 476 | } |
477 | 477 | } |
478 | 478 | |
479 | - } |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Upgrades the database. |
|
483 | + * |
|
484 | + * @since 2.0.2 |
|
485 | + */ |
|
486 | + public function maybe_upgrade_database() { |
|
487 | + |
|
488 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
489 | + |
|
490 | + if ( $wpi_version == WPINV_VERSION ) { |
|
491 | + return; |
|
492 | + } |
|
480 | 493 | |
481 | - /** |
|
482 | - * Upgrades the database. |
|
483 | - * |
|
484 | - * @since 2.0.2 |
|
485 | - */ |
|
486 | - public function maybe_upgrade_database() { |
|
494 | + $installer = new GetPaid_Installer(); |
|
487 | 495 | |
488 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
496 | + if ( empty( $wpi_version ) ) { |
|
497 | + return $installer->upgrade_db( 0 ); |
|
498 | + } |
|
489 | 499 | |
490 | - if ( $wpi_version == WPINV_VERSION ) { |
|
491 | - return; |
|
492 | - } |
|
500 | + $upgrades = array( |
|
501 | + '0.0.5' => '004', |
|
502 | + '1.0.3' => '102', |
|
503 | + '2.0.0' => '118', |
|
504 | + '2.0.8' => '207', |
|
505 | + '2.6.16' => '2615', |
|
506 | + ); |
|
493 | 507 | |
494 | - $installer = new GetPaid_Installer(); |
|
508 | + foreach ( $upgrades as $key => $method ) { |
|
509 | + |
|
510 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
511 | + return $installer->upgrade_db( $method ); |
|
512 | + } |
|
513 | + } |
|
514 | + |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Flushes the permalinks if needed. |
|
519 | + * |
|
520 | + * @since 2.0.8 |
|
521 | + */ |
|
522 | + public function maybe_flush_permalinks() { |
|
495 | 523 | |
496 | - if ( empty( $wpi_version ) ) { |
|
497 | - return $installer->upgrade_db( 0 ); |
|
498 | - } |
|
524 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
499 | 525 | |
500 | - $upgrades = array( |
|
501 | - '0.0.5' => '004', |
|
502 | - '1.0.3' => '102', |
|
503 | - '2.0.0' => '118', |
|
504 | - '2.0.8' => '207', |
|
505 | - '2.6.16' => '2615', |
|
506 | - ); |
|
507 | - |
|
508 | - foreach ( $upgrades as $key => $method ) { |
|
509 | - |
|
510 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
511 | - return $installer->upgrade_db( $method ); |
|
512 | - } |
|
513 | - } |
|
514 | - |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Flushes the permalinks if needed. |
|
519 | - * |
|
520 | - * @since 2.0.8 |
|
521 | - */ |
|
522 | - public function maybe_flush_permalinks() { |
|
523 | - |
|
524 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
525 | - |
|
526 | - if ( ! empty( $flush ) ) { |
|
527 | - flush_rewrite_rules(); |
|
528 | - delete_option( 'wpinv_flush_permalinks' ); |
|
529 | - } |
|
530 | - |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Remove our pages from yoast sitemaps. |
|
535 | - * |
|
536 | - * @since 1.0.19 |
|
537 | - * @param int[] $excluded_posts_ids |
|
538 | - */ |
|
539 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
540 | - |
|
541 | - // Ensure that we have an array. |
|
542 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
543 | - $excluded_posts_ids = array(); |
|
544 | - } |
|
545 | - |
|
546 | - // Prepare our pages. |
|
547 | - $our_pages = array(); |
|
548 | - |
|
549 | - // Checkout page. |
|
550 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
551 | - |
|
552 | - // Success page. |
|
553 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
554 | - |
|
555 | - // Failure page. |
|
556 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
557 | - |
|
558 | - // History page. |
|
559 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
560 | - |
|
561 | - // Subscriptions page. |
|
562 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
563 | - |
|
564 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
565 | - |
|
566 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
567 | - return array_unique( $excluded_posts_ids ); |
|
568 | - |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Remove our pages from yoast sitemaps. |
|
573 | - * |
|
574 | - * @since 1.0.19 |
|
575 | - * @param string[] $post_types |
|
576 | - */ |
|
577 | - public function exclude_invoicing_post_types( $post_types ) { |
|
578 | - |
|
579 | - // Ensure that we have an array. |
|
580 | - if ( ! is_array( $post_types ) ) { |
|
581 | - $post_types = array(); |
|
582 | - } |
|
583 | - |
|
584 | - // Remove our post types. |
|
585 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Displays additional footer code. |
|
590 | - * |
|
591 | - * @since 2.0.0 |
|
592 | - */ |
|
593 | - public function wp_footer() { |
|
594 | - wpinv_get_template( 'frontend-footer.php' ); |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Displays additional header code. |
|
599 | - * |
|
600 | - * @since 2.0.0 |
|
601 | - */ |
|
602 | - public function wp_head() { |
|
603 | - wpinv_get_template( 'frontend-head.php' ); |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Custom query vars. |
|
608 | - * |
|
609 | - */ |
|
610 | - public function custom_query_vars( $vars ) { |
|
526 | + if ( ! empty( $flush ) ) { |
|
527 | + flush_rewrite_rules(); |
|
528 | + delete_option( 'wpinv_flush_permalinks' ); |
|
529 | + } |
|
530 | + |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Remove our pages from yoast sitemaps. |
|
535 | + * |
|
536 | + * @since 1.0.19 |
|
537 | + * @param int[] $excluded_posts_ids |
|
538 | + */ |
|
539 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
540 | + |
|
541 | + // Ensure that we have an array. |
|
542 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
543 | + $excluded_posts_ids = array(); |
|
544 | + } |
|
545 | + |
|
546 | + // Prepare our pages. |
|
547 | + $our_pages = array(); |
|
548 | + |
|
549 | + // Checkout page. |
|
550 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
551 | + |
|
552 | + // Success page. |
|
553 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
554 | + |
|
555 | + // Failure page. |
|
556 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
557 | + |
|
558 | + // History page. |
|
559 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
560 | + |
|
561 | + // Subscriptions page. |
|
562 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
563 | + |
|
564 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
565 | + |
|
566 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
567 | + return array_unique( $excluded_posts_ids ); |
|
568 | + |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Remove our pages from yoast sitemaps. |
|
573 | + * |
|
574 | + * @since 1.0.19 |
|
575 | + * @param string[] $post_types |
|
576 | + */ |
|
577 | + public function exclude_invoicing_post_types( $post_types ) { |
|
578 | + |
|
579 | + // Ensure that we have an array. |
|
580 | + if ( ! is_array( $post_types ) ) { |
|
581 | + $post_types = array(); |
|
582 | + } |
|
583 | + |
|
584 | + // Remove our post types. |
|
585 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Displays additional footer code. |
|
590 | + * |
|
591 | + * @since 2.0.0 |
|
592 | + */ |
|
593 | + public function wp_footer() { |
|
594 | + wpinv_get_template( 'frontend-footer.php' ); |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Displays additional header code. |
|
599 | + * |
|
600 | + * @since 2.0.0 |
|
601 | + */ |
|
602 | + public function wp_head() { |
|
603 | + wpinv_get_template( 'frontend-head.php' ); |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Custom query vars. |
|
608 | + * |
|
609 | + */ |
|
610 | + public function custom_query_vars( $vars ) { |
|
611 | 611 | $vars[] = 'getpaid-ipn'; |
612 | 612 | return $vars; |
613 | - } |
|
613 | + } |
|
614 | 614 | |
615 | - /** |
|
616 | - * Add rewrite tags and rules. |
|
617 | - * |
|
618 | - */ |
|
619 | - public function add_rewrite_rule() { |
|
615 | + /** |
|
616 | + * Add rewrite tags and rules. |
|
617 | + * |
|
618 | + */ |
|
619 | + public function add_rewrite_rule() { |
|
620 | 620 | $tag = 'getpaid-ipn'; |
621 | 621 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
622 | 622 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
623 | - } |
|
623 | + } |
|
624 | 624 | |
625 | - /** |
|
626 | - * Processes non-query string ipns. |
|
627 | - * |
|
628 | - */ |
|
629 | - public function maybe_process_new_ipn( $query ) { |
|
625 | + /** |
|
626 | + * Processes non-query string ipns. |
|
627 | + * |
|
628 | + */ |
|
629 | + public function maybe_process_new_ipn( $query ) { |
|
630 | 630 | |
631 | 631 | if ( is_admin() || ! $query->is_main_query() ) { |
632 | 632 | return; |
633 | 633 | } |
634 | 634 | |
635 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
635 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
636 | 636 | |
637 | 637 | if ( ! empty( $gateway ) ) { |
638 | 638 | |
639 | - $gateway = sanitize_text_field( $gateway ); |
|
640 | - nocache_headers(); |
|
641 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
642 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
643 | - exit; |
|
639 | + $gateway = sanitize_text_field( $gateway ); |
|
640 | + nocache_headers(); |
|
641 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
642 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
643 | + exit; |
|
644 | 644 | |
645 | 645 | } |
646 | 646 | |
647 | - } |
|
647 | + } |
|
648 | 648 | |
649 | 649 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,28 +117,28 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
133 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
134 | - |
|
135 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
136 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
137 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
128 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
129 | + add_action('wp_head', array($this, 'wp_head')); |
|
130 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
131 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
132 | + add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types')); |
|
133 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
134 | + |
|
135 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
136 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
137 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
138 | 138 | |
139 | 139 | // Fires after registering actions. |
140 | - do_action( 'wpinv_actions', $this ); |
|
141 | - do_action( 'getpaid_actions', $this ); |
|
140 | + do_action('wpinv_actions', $this); |
|
141 | + do_action('getpaid_actions', $this); |
|
142 | 142 | |
143 | 143 | } |
144 | 144 | |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | /* Internationalize the text strings used. */ |
147 | 147 | $this->load_textdomain(); |
148 | 148 | |
149 | - do_action( 'wpinv_loaded' ); |
|
149 | + do_action('wpinv_loaded'); |
|
150 | 150 | |
151 | 151 | // Fix oxygen page builder conflict |
152 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + if (function_exists('ct_css_output')) { |
|
153 | 153 | wpinv_oxygen_fix_conflict(); |
154 | 154 | } |
155 | 155 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | load_plugin_textdomain( |
171 | 171 | 'invoicing', |
172 | 172 | false, |
173 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | + plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/' |
|
174 | 174 | ); |
175 | 175 | |
176 | 176 | } |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | |
207 | 207 | // Register autoloader. |
208 | 208 | try { |
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
209 | + spl_autoload_register(array($this, 'autoload'), true); |
|
210 | + } catch (Exception $e) { |
|
211 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
235 | 235 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
236 | 236 | |
237 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
238 | 238 | GetPaid_Post_Types_Admin::init(); |
239 | 239 | |
240 | 240 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -245,15 +245,15 @@ discard block |
||
245 | 245 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
246 | 246 | // load the user class only on the users.php page |
247 | 247 | global $pagenow; |
248 | - if ( $pagenow == 'users.php' ) { |
|
248 | + if ($pagenow == 'users.php') { |
|
249 | 249 | new WPInv_Admin_Users(); |
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
253 | 253 | // Register cli commands |
254 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + if (defined('WP_CLI') && WP_CLI) { |
|
255 | 255 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
256 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | } |
@@ -266,21 +266,21 @@ discard block |
||
266 | 266 | * @since 1.0.19 |
267 | 267 | * @return void |
268 | 268 | */ |
269 | - public function autoload( $class_name ) { |
|
269 | + public function autoload($class_name) { |
|
270 | 270 | |
271 | 271 | // Normalize the class name... |
272 | - $class_name = strtolower( $class_name ); |
|
272 | + $class_name = strtolower($class_name); |
|
273 | 273 | |
274 | 274 | // ... and make sure it is our class. |
275 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
276 | 276 | return; |
277 | 277 | } |
278 | 278 | |
279 | 279 | // Next, prepare the file name from the class. |
280 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
281 | 281 | |
282 | 282 | // Base path of the classes. |
283 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
284 | 284 | |
285 | 285 | // And an array of possible locations in order of importance. |
286 | 286 | $locations = array( |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | "$plugin_path/includes/admin/meta-boxes", |
296 | 296 | ); |
297 | 297 | |
298 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
299 | 299 | |
300 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
301 | - include trailingslashit( $location ) . $file_name; |
|
300 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
301 | + include trailingslashit($location) . $file_name; |
|
302 | 302 | break; |
303 | 303 | } |
304 | 304 | } |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | public function init() { |
312 | 312 | |
313 | 313 | // Fires before getpaid inits. |
314 | - do_action( 'before_getpaid_init', $this ); |
|
314 | + do_action('before_getpaid_init', $this); |
|
315 | 315 | |
316 | 316 | // Maybe upgrade. |
317 | 317 | $this->maybe_upgrade_database(); |
@@ -328,17 +328,17 @@ discard block |
||
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
331 | + foreach ($gateways as $id => $class) { |
|
332 | + $this->gateways[$id] = new $class(); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
336 | 336 | GetPaid_Installer::rename_gateways_label(); |
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // Fires after getpaid inits. |
341 | - do_action( 'getpaid_init', $this ); |
|
341 | + do_action('getpaid_init', $this); |
|
342 | 342 | |
343 | 343 | } |
344 | 344 | |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | public function maybe_process_ipn() { |
349 | 349 | |
350 | 350 | // Ensure that this is an IPN request. |
351 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
355 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
355 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
356 | 356 | |
357 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
358 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
358 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
359 | 359 | exit; |
360 | 360 | |
361 | 361 | } |
@@ -363,33 +363,33 @@ discard block |
||
363 | 363 | public function enqueue_scripts() { |
364 | 364 | |
365 | 365 | // Fires before adding scripts. |
366 | - do_action( 'getpaid_enqueue_scripts' ); |
|
366 | + do_action('getpaid_enqueue_scripts'); |
|
367 | 367 | |
368 | 368 | $localize = array(); |
369 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
370 | 370 | $localize['thousands'] = wpinv_thousands_separator(); |
371 | 371 | $localize['decimals'] = wpinv_decimal_separator(); |
372 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
373 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
372 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
373 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
374 | 374 | $localize['UseTaxes'] = wpinv_use_taxes(); |
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
377 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
375 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
376 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
377 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
378 | 378 | |
379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
380 | 380 | |
381 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
382 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
383 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
381 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
382 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true); |
|
383 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | public function wpinv_actions() { |
387 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
388 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
387 | + if (isset($_REQUEST['wpi_action'])) { |
|
388 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
389 | 389 | } |
390 | 390 | |
391 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
392 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
391 | + if (defined('WP_ALL_IMPORT_ROOT_DIR')) { |
|
392 | + include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
393 | 393 | } |
394 | 394 | } |
395 | 395 | |
@@ -401,24 +401,24 @@ discard block |
||
401 | 401 | */ |
402 | 402 | public function maybe_do_authenticated_action() { |
403 | 403 | |
404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
405 | 405 | |
406 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
407 | - $data = wp_unslash( $_REQUEST ); |
|
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
406 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
407 | + $data = wp_unslash($_REQUEST); |
|
408 | + if (is_user_logged_in()) { |
|
409 | + do_action("getpaid_authenticated_action_$key", $data); |
|
410 | 410 | } |
411 | 411 | |
412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
413 | 413 | |
414 | 414 | } |
415 | 415 | |
416 | 416 | } |
417 | 417 | |
418 | - public function pre_get_posts( $wp_query ) { |
|
418 | + public function pre_get_posts($wp_query) { |
|
419 | 419 | |
420 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
421 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
420 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
421 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | return $wp_query; |
@@ -433,18 +433,18 @@ discard block |
||
433 | 433 | |
434 | 434 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
435 | 435 | // So we disable our widgets when editing a page with UX Builder. |
436 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
436 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
440 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
440 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
441 | 441 | |
442 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
442 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
443 | 443 | // don't initiate in these conditions. |
444 | 444 | } else { |
445 | 445 | |
446 | 446 | // Only load allowed widgets. |
447 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
447 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
448 | 448 | $widgets = apply_filters( |
449 | 449 | 'getpaid_widget_classes', |
450 | 450 | array( |
@@ -460,16 +460,16 @@ discard block |
||
460 | 460 | ); |
461 | 461 | |
462 | 462 | // For each widget... |
463 | - foreach ( $widgets as $widget ) { |
|
463 | + foreach ($widgets as $widget) { |
|
464 | 464 | |
465 | 465 | // Abort early if it is excluded for this page. |
466 | - if ( in_array( $widget, $exclude ) ) { |
|
466 | + if (in_array($widget, $exclude)) { |
|
467 | 467 | continue; |
468 | 468 | } |
469 | 469 | |
470 | 470 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
471 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
472 | - register_widget( $widget ); |
|
471 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
472 | + register_widget($widget); |
|
473 | 473 | } else { |
474 | 474 | new $widget(); |
475 | 475 | } |
@@ -485,19 +485,19 @@ discard block |
||
485 | 485 | */ |
486 | 486 | public function maybe_upgrade_database() { |
487 | 487 | |
488 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
488 | + $wpi_version = get_option('wpinv_version', 0); |
|
489 | 489 | |
490 | - if ( $wpi_version == WPINV_VERSION ) { |
|
490 | + if ($wpi_version == WPINV_VERSION) { |
|
491 | 491 | return; |
492 | 492 | } |
493 | 493 | |
494 | 494 | $installer = new GetPaid_Installer(); |
495 | 495 | |
496 | - if ( empty( $wpi_version ) ) { |
|
497 | - return $installer->upgrade_db( 0 ); |
|
496 | + if (empty($wpi_version)) { |
|
497 | + return $installer->upgrade_db(0); |
|
498 | 498 | } |
499 | 499 | |
500 | - $upgrades = array( |
|
500 | + $upgrades = array( |
|
501 | 501 | '0.0.5' => '004', |
502 | 502 | '1.0.3' => '102', |
503 | 503 | '2.0.0' => '118', |
@@ -505,10 +505,10 @@ discard block |
||
505 | 505 | '2.6.16' => '2615', |
506 | 506 | ); |
507 | 507 | |
508 | - foreach ( $upgrades as $key => $method ) { |
|
508 | + foreach ($upgrades as $key => $method) { |
|
509 | 509 | |
510 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
511 | - return $installer->upgrade_db( $method ); |
|
510 | + if (version_compare($wpi_version, $key, '<')) { |
|
511 | + return $installer->upgrade_db($method); |
|
512 | 512 | } |
513 | 513 | } |
514 | 514 | |
@@ -521,11 +521,11 @@ discard block |
||
521 | 521 | */ |
522 | 522 | public function maybe_flush_permalinks() { |
523 | 523 | |
524 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
524 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
525 | 525 | |
526 | - if ( ! empty( $flush ) ) { |
|
526 | + if (!empty($flush)) { |
|
527 | 527 | flush_rewrite_rules(); |
528 | - delete_option( 'wpinv_flush_permalinks' ); |
|
528 | + delete_option('wpinv_flush_permalinks'); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | } |
@@ -536,10 +536,10 @@ discard block |
||
536 | 536 | * @since 1.0.19 |
537 | 537 | * @param int[] $excluded_posts_ids |
538 | 538 | */ |
539 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
539 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
540 | 540 | |
541 | 541 | // Ensure that we have an array. |
542 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
542 | + if (!is_array($excluded_posts_ids)) { |
|
543 | 543 | $excluded_posts_ids = array(); |
544 | 544 | } |
545 | 545 | |
@@ -547,24 +547,24 @@ discard block |
||
547 | 547 | $our_pages = array(); |
548 | 548 | |
549 | 549 | // Checkout page. |
550 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
550 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
551 | 551 | |
552 | 552 | // Success page. |
553 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
553 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
554 | 554 | |
555 | 555 | // Failure page. |
556 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
556 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
557 | 557 | |
558 | 558 | // History page. |
559 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
559 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
560 | 560 | |
561 | 561 | // Subscriptions page. |
562 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
562 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
563 | 563 | |
564 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
564 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
565 | 565 | |
566 | 566 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
567 | - return array_unique( $excluded_posts_ids ); |
|
567 | + return array_unique($excluded_posts_ids); |
|
568 | 568 | |
569 | 569 | } |
570 | 570 | |
@@ -574,15 +574,15 @@ discard block |
||
574 | 574 | * @since 1.0.19 |
575 | 575 | * @param string[] $post_types |
576 | 576 | */ |
577 | - public function exclude_invoicing_post_types( $post_types ) { |
|
577 | + public function exclude_invoicing_post_types($post_types) { |
|
578 | 578 | |
579 | 579 | // Ensure that we have an array. |
580 | - if ( ! is_array( $post_types ) ) { |
|
580 | + if (!is_array($post_types)) { |
|
581 | 581 | $post_types = array(); |
582 | 582 | } |
583 | 583 | |
584 | 584 | // Remove our post types. |
585 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
585 | + return array_diff($post_types, array_keys(getpaid_get_invoice_post_types())); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | * @since 2.0.0 |
592 | 592 | */ |
593 | 593 | public function wp_footer() { |
594 | - wpinv_get_template( 'frontend-footer.php' ); |
|
594 | + wpinv_get_template('frontend-footer.php'); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -600,14 +600,14 @@ discard block |
||
600 | 600 | * @since 2.0.0 |
601 | 601 | */ |
602 | 602 | public function wp_head() { |
603 | - wpinv_get_template( 'frontend-head.php' ); |
|
603 | + wpinv_get_template('frontend-head.php'); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
607 | 607 | * Custom query vars. |
608 | 608 | * |
609 | 609 | */ |
610 | - public function custom_query_vars( $vars ) { |
|
610 | + public function custom_query_vars($vars) { |
|
611 | 611 | $vars[] = 'getpaid-ipn'; |
612 | 612 | return $vars; |
613 | 613 | } |
@@ -618,28 +618,28 @@ discard block |
||
618 | 618 | */ |
619 | 619 | public function add_rewrite_rule() { |
620 | 620 | $tag = 'getpaid-ipn'; |
621 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
622 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
621 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
622 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
626 | 626 | * Processes non-query string ipns. |
627 | 627 | * |
628 | 628 | */ |
629 | - public function maybe_process_new_ipn( $query ) { |
|
629 | + public function maybe_process_new_ipn($query) { |
|
630 | 630 | |
631 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
631 | + if (is_admin() || !$query->is_main_query()) { |
|
632 | 632 | return; |
633 | 633 | } |
634 | 634 | |
635 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
635 | + $gateway = get_query_var('getpaid-ipn'); |
|
636 | 636 | |
637 | - if ( ! empty( $gateway ) ) { |
|
637 | + if (!empty($gateway)) { |
|
638 | 638 | |
639 | - $gateway = sanitize_text_field( $gateway ); |
|
639 | + $gateway = sanitize_text_field($gateway); |
|
640 | 640 | nocache_headers(); |
641 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
642 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
641 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
642 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
643 | 643 | exit; |
644 | 644 | |
645 | 645 | } |
@@ -20,237 +20,237 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
52 | - |
|
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $method ) ) { |
|
58 | - $this->$method(); |
|
59 | - } |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Do a fresh install. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function upgrade_from_0() { |
|
68 | - $this->create_subscriptions_table(); |
|
69 | - $this->create_invoices_table(); |
|
70 | - $this->create_invoice_items_table(); |
|
71 | - |
|
72 | - // Save default tax rates. |
|
73 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Upgrade to 0.0.5 |
|
78 | - * |
|
79 | - */ |
|
80 | - public function upgrade_from_004() { |
|
81 | - global $wpdb; |
|
82 | - |
|
83 | - // Invoices. |
|
84 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | - if ( ! empty( $results ) ) { |
|
86 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | - |
|
88 | - // Clean post cache |
|
89 | - foreach ( $results as $row ) { |
|
90 | - clean_post_cache( $row->ID ); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - // Item meta key changes |
|
95 | - $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
96 | - $results = $wpdb->get_results( $query ); |
|
97 | - |
|
98 | - if ( ! empty( $results ) ) { |
|
99 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
100 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
101 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
102 | - |
|
103 | - foreach ( $results as $row ) { |
|
104 | - clean_post_cache( $row->post_id ); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - $this->upgrade_from_102(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Upgrade to 1.0.3 |
|
113 | - * |
|
114 | - */ |
|
115 | - public function upgrade_from_102() { |
|
116 | - $this->create_subscriptions_table(); |
|
117 | - $this->upgrade_from_118(); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Upgrade to version 2.0.0. |
|
122 | - * |
|
123 | - */ |
|
124 | - public function upgrade_from_118() { |
|
125 | - $this->create_invoices_table(); |
|
126 | - $this->create_invoice_items_table(); |
|
127 | - $this->migrate_old_invoices(); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Upgrade to version 2.0.8. |
|
132 | - * |
|
133 | - */ |
|
134 | - public function upgrade_from_207() { |
|
135 | - global $wpdb; |
|
136 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
137 | - $this->upgrade_from_2615(); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Upgrade to version 2.6.16. |
|
142 | - * |
|
143 | - */ |
|
144 | - public function upgrade_from_2615() { |
|
145 | - global $wpdb; |
|
146 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
147 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Give administrators the capability to manage GetPaid. |
|
152 | - * |
|
153 | - */ |
|
154 | - public function add_capabilities() { |
|
155 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Retreives GetPaid pages. |
|
160 | - * |
|
161 | - */ |
|
162 | - public static function get_pages() { |
|
163 | - |
|
164 | - return apply_filters( |
|
165 | - 'wpinv_create_pages', |
|
166 | - array( |
|
167 | - |
|
168 | - // Checkout page. |
|
169 | - 'checkout_page' => array( |
|
170 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
171 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
172 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + $installed = get_option( 'gepaid_installed_on' ); |
|
52 | + |
|
53 | + if ( empty( $installed ) ) { |
|
54 | + update_option( 'gepaid_installed_on', time() ); |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $method ) ) { |
|
58 | + $this->$method(); |
|
59 | + } |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Do a fresh install. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function upgrade_from_0() { |
|
68 | + $this->create_subscriptions_table(); |
|
69 | + $this->create_invoices_table(); |
|
70 | + $this->create_invoice_items_table(); |
|
71 | + |
|
72 | + // Save default tax rates. |
|
73 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Upgrade to 0.0.5 |
|
78 | + * |
|
79 | + */ |
|
80 | + public function upgrade_from_004() { |
|
81 | + global $wpdb; |
|
82 | + |
|
83 | + // Invoices. |
|
84 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | + if ( ! empty( $results ) ) { |
|
86 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | + |
|
88 | + // Clean post cache |
|
89 | + foreach ( $results as $row ) { |
|
90 | + clean_post_cache( $row->ID ); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + // Item meta key changes |
|
95 | + $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
96 | + $results = $wpdb->get_results( $query ); |
|
97 | + |
|
98 | + if ( ! empty( $results ) ) { |
|
99 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
100 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
101 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
102 | + |
|
103 | + foreach ( $results as $row ) { |
|
104 | + clean_post_cache( $row->post_id ); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + $this->upgrade_from_102(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Upgrade to 1.0.3 |
|
113 | + * |
|
114 | + */ |
|
115 | + public function upgrade_from_102() { |
|
116 | + $this->create_subscriptions_table(); |
|
117 | + $this->upgrade_from_118(); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Upgrade to version 2.0.0. |
|
122 | + * |
|
123 | + */ |
|
124 | + public function upgrade_from_118() { |
|
125 | + $this->create_invoices_table(); |
|
126 | + $this->create_invoice_items_table(); |
|
127 | + $this->migrate_old_invoices(); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Upgrade to version 2.0.8. |
|
132 | + * |
|
133 | + */ |
|
134 | + public function upgrade_from_207() { |
|
135 | + global $wpdb; |
|
136 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
137 | + $this->upgrade_from_2615(); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Upgrade to version 2.6.16. |
|
142 | + * |
|
143 | + */ |
|
144 | + public function upgrade_from_2615() { |
|
145 | + global $wpdb; |
|
146 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
147 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Give administrators the capability to manage GetPaid. |
|
152 | + * |
|
153 | + */ |
|
154 | + public function add_capabilities() { |
|
155 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Retreives GetPaid pages. |
|
160 | + * |
|
161 | + */ |
|
162 | + public static function get_pages() { |
|
163 | + |
|
164 | + return apply_filters( |
|
165 | + 'wpinv_create_pages', |
|
166 | + array( |
|
167 | + |
|
168 | + // Checkout page. |
|
169 | + 'checkout_page' => array( |
|
170 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
171 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
172 | + 'content' => ' |
|
173 | 173 | <!-- wp:shortcode --> |
174 | 174 | [wpinv_checkout] |
175 | 175 | <!-- /wp:shortcode --> |
176 | 176 | ', |
177 | - 'parent' => '', |
|
178 | - ), |
|
179 | - |
|
180 | - // Invoice history page. |
|
181 | - 'invoice_history_page' => array( |
|
182 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
183 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
184 | - 'content' => ' |
|
177 | + 'parent' => '', |
|
178 | + ), |
|
179 | + |
|
180 | + // Invoice history page. |
|
181 | + 'invoice_history_page' => array( |
|
182 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
183 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
184 | + 'content' => ' |
|
185 | 185 | <!-- wp:shortcode --> |
186 | 186 | [wpinv_history] |
187 | 187 | <!-- /wp:shortcode --> |
188 | 188 | ', |
189 | - 'parent' => '', |
|
190 | - ), |
|
191 | - |
|
192 | - // Success page content. |
|
193 | - 'success_page' => array( |
|
194 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
195 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
196 | - 'content' => ' |
|
189 | + 'parent' => '', |
|
190 | + ), |
|
191 | + |
|
192 | + // Success page content. |
|
193 | + 'success_page' => array( |
|
194 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
195 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
196 | + 'content' => ' |
|
197 | 197 | <!-- wp:shortcode --> |
198 | 198 | [wpinv_receipt] |
199 | 199 | <!-- /wp:shortcode --> |
200 | 200 | ', |
201 | - 'parent' => 'gp-checkout', |
|
202 | - ), |
|
203 | - |
|
204 | - // Failure page content. |
|
205 | - 'failure_page' => array( |
|
206 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
207 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
208 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
209 | - 'parent' => 'gp-checkout', |
|
210 | - ), |
|
211 | - |
|
212 | - // Subscriptions history page. |
|
213 | - 'invoice_subscription_page' => array( |
|
214 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
215 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
216 | - 'content' => ' |
|
201 | + 'parent' => 'gp-checkout', |
|
202 | + ), |
|
203 | + |
|
204 | + // Failure page content. |
|
205 | + 'failure_page' => array( |
|
206 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
207 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
208 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
209 | + 'parent' => 'gp-checkout', |
|
210 | + ), |
|
211 | + |
|
212 | + // Subscriptions history page. |
|
213 | + 'invoice_subscription_page' => array( |
|
214 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
215 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
216 | + 'content' => ' |
|
217 | 217 | <!-- wp:shortcode --> |
218 | 218 | [wpinv_subscriptions] |
219 | 219 | <!-- /wp:shortcode --> |
220 | 220 | ', |
221 | - 'parent' => '', |
|
222 | - ), |
|
221 | + 'parent' => '', |
|
222 | + ), |
|
223 | 223 | |
224 | - ) |
|
225 | - ); |
|
224 | + ) |
|
225 | + ); |
|
226 | 226 | |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Re-create GetPaid pages. |
|
231 | - * |
|
232 | - */ |
|
233 | - public function create_pages() { |
|
229 | + /** |
|
230 | + * Re-create GetPaid pages. |
|
231 | + * |
|
232 | + */ |
|
233 | + public function create_pages() { |
|
234 | 234 | |
235 | - foreach ( self::get_pages() as $key => $page ) { |
|
236 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
237 | - } |
|
235 | + foreach ( self::get_pages() as $key => $page ) { |
|
236 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
237 | + } |
|
238 | 238 | |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Create subscriptions table. |
|
243 | - * |
|
244 | - */ |
|
245 | - public function create_subscriptions_table() { |
|
241 | + /** |
|
242 | + * Create subscriptions table. |
|
243 | + * |
|
244 | + */ |
|
245 | + public function create_subscriptions_table() { |
|
246 | 246 | |
247 | - global $wpdb; |
|
247 | + global $wpdb; |
|
248 | 248 | |
249 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
249 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
250 | 250 | |
251 | - // Create tables. |
|
252 | - $charset_collate = $wpdb->get_charset_collate(); |
|
253 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
251 | + // Create tables. |
|
252 | + $charset_collate = $wpdb->get_charset_collate(); |
|
253 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
254 | 254 | id bigint(20) unsigned NOT NULL auto_increment, |
255 | 255 | customer_id bigint(20) NOT NULL, |
256 | 256 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -273,22 +273,22 @@ discard block |
||
273 | 273 | KEY customer_and_status (customer_id, status) |
274 | 274 | ) $charset_collate;"; |
275 | 275 | |
276 | - dbDelta( $sql ); |
|
276 | + dbDelta( $sql ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Create invoices table. |
|
282 | - * |
|
283 | - */ |
|
284 | - public function create_invoices_table() { |
|
285 | - global $wpdb; |
|
280 | + /** |
|
281 | + * Create invoices table. |
|
282 | + * |
|
283 | + */ |
|
284 | + public function create_invoices_table() { |
|
285 | + global $wpdb; |
|
286 | 286 | |
287 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
287 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
288 | 288 | |
289 | - // Create tables. |
|
290 | - $charset_collate = $wpdb->get_charset_collate(); |
|
291 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
289 | + // Create tables. |
|
290 | + $charset_collate = $wpdb->get_charset_collate(); |
|
291 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
292 | 292 | post_id BIGINT(20) NOT NULL, |
293 | 293 | `number` VARCHAR(100), |
294 | 294 | `key` VARCHAR(100), |
@@ -324,22 +324,22 @@ discard block |
||
324 | 324 | KEY `key` (`key`) |
325 | 325 | ) $charset_collate;"; |
326 | 326 | |
327 | - dbDelta( $sql ); |
|
327 | + dbDelta( $sql ); |
|
328 | 328 | |
329 | - } |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * Create invoice items table. |
|
333 | - * |
|
334 | - */ |
|
335 | - public function create_invoice_items_table() { |
|
336 | - global $wpdb; |
|
331 | + /** |
|
332 | + * Create invoice items table. |
|
333 | + * |
|
334 | + */ |
|
335 | + public function create_invoice_items_table() { |
|
336 | + global $wpdb; |
|
337 | 337 | |
338 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
338 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
339 | 339 | |
340 | - // Create tables. |
|
341 | - $charset_collate = $wpdb->get_charset_collate(); |
|
342 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
340 | + // Create tables. |
|
341 | + $charset_collate = $wpdb->get_charset_collate(); |
|
342 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
343 | 343 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
344 | 344 | post_id BIGINT(20) NOT NULL, |
345 | 345 | item_id BIGINT(20) NOT NULL, |
@@ -361,159 +361,159 @@ discard block |
||
361 | 361 | KEY post_id (post_id) |
362 | 362 | ) $charset_collate;"; |
363 | 363 | |
364 | - dbDelta( $sql ); |
|
365 | - |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Migrates old invoices to new invoices. |
|
370 | - * |
|
371 | - */ |
|
372 | - public function migrate_old_invoices() { |
|
373 | - global $wpdb; |
|
374 | - |
|
375 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
376 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
377 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
378 | - $invoices = array_unique( |
|
379 | - get_posts( |
|
380 | - array( |
|
381 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
382 | - 'posts_per_page' => -1, |
|
383 | - 'fields' => 'ids', |
|
384 | - 'post_status' => array_keys( get_post_stati() ), |
|
385 | - 'exclude' => (array) $migrated, |
|
386 | - ) |
|
387 | - ) |
|
388 | - ); |
|
389 | - |
|
390 | - // Abort if we do not have any invoices. |
|
391 | - if ( empty( $invoices ) ) { |
|
392 | - return; |
|
393 | - } |
|
394 | - |
|
395 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
396 | - |
|
397 | - $invoice_rows = array(); |
|
398 | - foreach ( $invoices as $invoice ) { |
|
399 | - |
|
400 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
401 | - |
|
402 | - if ( empty( $invoice->ID ) ) { |
|
403 | - return; |
|
404 | - } |
|
405 | - |
|
406 | - $fields = array( |
|
407 | - 'post_id' => $invoice->ID, |
|
408 | - 'number' => $invoice->get_number(), |
|
409 | - 'key' => $invoice->get_key(), |
|
410 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
411 | - 'mode' => $invoice->mode, |
|
412 | - 'user_ip' => $invoice->get_ip(), |
|
413 | - 'first_name' => $invoice->get_first_name(), |
|
414 | - 'last_name' => $invoice->get_last_name(), |
|
415 | - 'address' => $invoice->get_address(), |
|
416 | - 'city' => $invoice->city, |
|
417 | - 'state' => $invoice->state, |
|
418 | - 'country' => $invoice->country, |
|
419 | - 'zip' => $invoice->zip, |
|
420 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
421 | - 'gateway' => $invoice->get_gateway(), |
|
422 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
423 | - 'currency' => $invoice->get_currency(), |
|
424 | - 'subtotal' => $invoice->get_subtotal(), |
|
425 | - 'tax' => $invoice->get_tax(), |
|
426 | - 'fees_total' => $invoice->get_fees_total(), |
|
427 | - 'total' => $invoice->get_total(), |
|
428 | - 'discount' => $invoice->get_discount(), |
|
429 | - 'discount_code' => $invoice->get_discount_code(), |
|
430 | - 'disable_taxes' => $invoice->disable_taxes, |
|
431 | - 'due_date' => $invoice->get_due_date(), |
|
432 | - 'completed_date' => $invoice->get_completed_date(), |
|
433 | - 'company' => $invoice->company, |
|
434 | - 'vat_number' => $invoice->vat_number, |
|
435 | - 'vat_rate' => $invoice->vat_rate, |
|
436 | - 'custom_meta' => $invoice->payment_meta, |
|
437 | - ); |
|
438 | - |
|
439 | - foreach ( $fields as $key => $val ) { |
|
440 | - if ( is_null( $val ) ) { |
|
441 | - $val = ''; |
|
442 | - } |
|
443 | - $val = maybe_serialize( $val ); |
|
444 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
445 | - } |
|
446 | - |
|
447 | - $fields = implode( ', ', $fields ); |
|
448 | - $invoice_rows[] = "($fields)"; |
|
449 | - |
|
450 | - $item_rows = array(); |
|
451 | - $item_columns = array(); |
|
452 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
453 | - $fields = array( |
|
454 | - 'post_id' => $invoice->ID, |
|
455 | - 'item_id' => $details['id'], |
|
456 | - 'item_name' => $details['name'], |
|
457 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
458 | - 'vat_rate' => $details['vat_rate'], |
|
459 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
460 | - 'tax' => $details['tax'], |
|
461 | - 'item_price' => $details['item_price'], |
|
462 | - 'custom_price' => $details['custom_price'], |
|
463 | - 'quantity' => $details['quantity'], |
|
464 | - 'discount' => $details['discount'], |
|
465 | - 'subtotal' => $details['subtotal'], |
|
466 | - 'price' => $details['price'], |
|
467 | - 'meta' => $details['meta'], |
|
468 | - 'fees' => $details['fees'], |
|
469 | - ); |
|
470 | - |
|
471 | - $item_columns = array_keys( $fields ); |
|
472 | - |
|
473 | - foreach ( $fields as $key => $val ) { |
|
474 | - if ( is_null( $val ) ) { |
|
475 | - $val = ''; |
|
476 | - } |
|
477 | - $val = maybe_serialize( $val ); |
|
478 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
479 | - } |
|
480 | - |
|
481 | - $fields = implode( ', ', $fields ); |
|
482 | - $item_rows[] = "($fields)"; |
|
483 | - } |
|
484 | - |
|
485 | - $item_rows = implode( ', ', $item_rows ); |
|
486 | - $item_columns = implode( ', ', $item_columns ); |
|
487 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
488 | - } |
|
489 | - |
|
490 | - if ( empty( $invoice_rows ) ) { |
|
491 | - return; |
|
492 | - } |
|
493 | - |
|
494 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
495 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
496 | - |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Migrates old invoices to new invoices. |
|
501 | - * |
|
502 | - */ |
|
503 | - public static function rename_gateways_label() { |
|
504 | - global $wpdb; |
|
505 | - |
|
506 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
507 | - |
|
508 | - $wpdb->update( |
|
509 | - $wpdb->prefix . 'getpaid_invoices', |
|
510 | - array( 'gateway' => $gateway ), |
|
511 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
512 | - '%s', |
|
513 | - '%s' |
|
514 | - ); |
|
515 | - |
|
516 | - } |
|
517 | - } |
|
364 | + dbDelta( $sql ); |
|
365 | + |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Migrates old invoices to new invoices. |
|
370 | + * |
|
371 | + */ |
|
372 | + public function migrate_old_invoices() { |
|
373 | + global $wpdb; |
|
374 | + |
|
375 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
376 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
377 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
378 | + $invoices = array_unique( |
|
379 | + get_posts( |
|
380 | + array( |
|
381 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
382 | + 'posts_per_page' => -1, |
|
383 | + 'fields' => 'ids', |
|
384 | + 'post_status' => array_keys( get_post_stati() ), |
|
385 | + 'exclude' => (array) $migrated, |
|
386 | + ) |
|
387 | + ) |
|
388 | + ); |
|
389 | + |
|
390 | + // Abort if we do not have any invoices. |
|
391 | + if ( empty( $invoices ) ) { |
|
392 | + return; |
|
393 | + } |
|
394 | + |
|
395 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
396 | + |
|
397 | + $invoice_rows = array(); |
|
398 | + foreach ( $invoices as $invoice ) { |
|
399 | + |
|
400 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
401 | + |
|
402 | + if ( empty( $invoice->ID ) ) { |
|
403 | + return; |
|
404 | + } |
|
405 | + |
|
406 | + $fields = array( |
|
407 | + 'post_id' => $invoice->ID, |
|
408 | + 'number' => $invoice->get_number(), |
|
409 | + 'key' => $invoice->get_key(), |
|
410 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
411 | + 'mode' => $invoice->mode, |
|
412 | + 'user_ip' => $invoice->get_ip(), |
|
413 | + 'first_name' => $invoice->get_first_name(), |
|
414 | + 'last_name' => $invoice->get_last_name(), |
|
415 | + 'address' => $invoice->get_address(), |
|
416 | + 'city' => $invoice->city, |
|
417 | + 'state' => $invoice->state, |
|
418 | + 'country' => $invoice->country, |
|
419 | + 'zip' => $invoice->zip, |
|
420 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
421 | + 'gateway' => $invoice->get_gateway(), |
|
422 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
423 | + 'currency' => $invoice->get_currency(), |
|
424 | + 'subtotal' => $invoice->get_subtotal(), |
|
425 | + 'tax' => $invoice->get_tax(), |
|
426 | + 'fees_total' => $invoice->get_fees_total(), |
|
427 | + 'total' => $invoice->get_total(), |
|
428 | + 'discount' => $invoice->get_discount(), |
|
429 | + 'discount_code' => $invoice->get_discount_code(), |
|
430 | + 'disable_taxes' => $invoice->disable_taxes, |
|
431 | + 'due_date' => $invoice->get_due_date(), |
|
432 | + 'completed_date' => $invoice->get_completed_date(), |
|
433 | + 'company' => $invoice->company, |
|
434 | + 'vat_number' => $invoice->vat_number, |
|
435 | + 'vat_rate' => $invoice->vat_rate, |
|
436 | + 'custom_meta' => $invoice->payment_meta, |
|
437 | + ); |
|
438 | + |
|
439 | + foreach ( $fields as $key => $val ) { |
|
440 | + if ( is_null( $val ) ) { |
|
441 | + $val = ''; |
|
442 | + } |
|
443 | + $val = maybe_serialize( $val ); |
|
444 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
445 | + } |
|
446 | + |
|
447 | + $fields = implode( ', ', $fields ); |
|
448 | + $invoice_rows[] = "($fields)"; |
|
449 | + |
|
450 | + $item_rows = array(); |
|
451 | + $item_columns = array(); |
|
452 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
453 | + $fields = array( |
|
454 | + 'post_id' => $invoice->ID, |
|
455 | + 'item_id' => $details['id'], |
|
456 | + 'item_name' => $details['name'], |
|
457 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
458 | + 'vat_rate' => $details['vat_rate'], |
|
459 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
460 | + 'tax' => $details['tax'], |
|
461 | + 'item_price' => $details['item_price'], |
|
462 | + 'custom_price' => $details['custom_price'], |
|
463 | + 'quantity' => $details['quantity'], |
|
464 | + 'discount' => $details['discount'], |
|
465 | + 'subtotal' => $details['subtotal'], |
|
466 | + 'price' => $details['price'], |
|
467 | + 'meta' => $details['meta'], |
|
468 | + 'fees' => $details['fees'], |
|
469 | + ); |
|
470 | + |
|
471 | + $item_columns = array_keys( $fields ); |
|
472 | + |
|
473 | + foreach ( $fields as $key => $val ) { |
|
474 | + if ( is_null( $val ) ) { |
|
475 | + $val = ''; |
|
476 | + } |
|
477 | + $val = maybe_serialize( $val ); |
|
478 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
479 | + } |
|
480 | + |
|
481 | + $fields = implode( ', ', $fields ); |
|
482 | + $item_rows[] = "($fields)"; |
|
483 | + } |
|
484 | + |
|
485 | + $item_rows = implode( ', ', $item_rows ); |
|
486 | + $item_columns = implode( ', ', $item_columns ); |
|
487 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
488 | + } |
|
489 | + |
|
490 | + if ( empty( $invoice_rows ) ) { |
|
491 | + return; |
|
492 | + } |
|
493 | + |
|
494 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
495 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
496 | + |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Migrates old invoices to new invoices. |
|
501 | + * |
|
502 | + */ |
|
503 | + public static function rename_gateways_label() { |
|
504 | + global $wpdb; |
|
505 | + |
|
506 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
507 | + |
|
508 | + $wpdb->update( |
|
509 | + $wpdb->prefix . 'getpaid_invoices', |
|
510 | + array( 'gateway' => $gateway ), |
|
511 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
512 | + '%s', |
|
513 | + '%s' |
|
514 | + ); |
|
515 | + |
|
516 | + } |
|
517 | + } |
|
518 | 518 | |
519 | 519 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.0.2 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * The main installer/updater class. |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param string $upgrade_from The current invoicing version. |
27 | 27 | */ |
28 | - public function upgrade_db( $upgrade_from ) { |
|
28 | + public function upgrade_db($upgrade_from) { |
|
29 | 29 | |
30 | 30 | // Save the current invoicing version. |
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
31 | + update_option('wpinv_version', WPINV_VERSION); |
|
32 | 32 | |
33 | 33 | // Setup the invoice Custom Post Type. |
34 | 34 | GetPaid_Post_Types::register_post_types(); |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | // Create any missing database tables. |
49 | 49 | $method = "upgrade_from_$upgrade_from"; |
50 | 50 | |
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
51 | + $installed = get_option('gepaid_installed_on'); |
|
52 | 52 | |
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
53 | + if (empty($installed)) { |
|
54 | + update_option('gepaid_installed_on', time()); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $method ) ) { |
|
57 | + if (method_exists($this, $method)) { |
|
58 | 58 | $this->$method(); |
59 | 59 | } |
60 | 60 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $this->create_invoice_items_table(); |
71 | 71 | |
72 | 72 | // Save default tax rates. |
73 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
73 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -81,27 +81,27 @@ discard block |
||
81 | 81 | global $wpdb; |
82 | 82 | |
83 | 83 | // Invoices. |
84 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | - if ( ! empty( $results ) ) { |
|
86 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
84 | + $results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
85 | + if (!empty($results)) { |
|
86 | + $wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
87 | 87 | |
88 | 88 | // Clean post cache |
89 | - foreach ( $results as $row ) { |
|
90 | - clean_post_cache( $row->ID ); |
|
89 | + foreach ($results as $row) { |
|
90 | + clean_post_cache($row->ID); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | // Item meta key changes |
95 | 95 | $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
96 | - $results = $wpdb->get_results( $query ); |
|
96 | + $results = $wpdb->get_results($query); |
|
97 | 97 | |
98 | - if ( ! empty( $results ) ) { |
|
99 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
100 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
101 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
98 | + if (!empty($results)) { |
|
99 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
100 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
101 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
102 | 102 | |
103 | - foreach ( $results as $row ) { |
|
104 | - clean_post_cache( $row->post_id ); |
|
103 | + foreach ($results as $row) { |
|
104 | + clean_post_cache($row->post_id); |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function upgrade_from_207() { |
135 | 135 | global $wpdb; |
136 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
136 | + $wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);"); |
|
137 | 137 | $this->upgrade_from_2615(); |
138 | 138 | } |
139 | 139 | |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function upgrade_from_2615() { |
145 | 145 | global $wpdb; |
146 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
147 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
146 | + $wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';"); |
|
147 | + $wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';"); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * |
153 | 153 | */ |
154 | 154 | public function add_capabilities() { |
155 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
155 | + $GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing'); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | |
168 | 168 | // Checkout page. |
169 | 169 | 'checkout_page' => array( |
170 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
171 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
170 | + 'name' => _x('gp-checkout', 'Page slug', 'invoicing'), |
|
171 | + 'title' => _x('Checkout', 'Page title', 'invoicing'), |
|
172 | 172 | 'content' => ' |
173 | 173 | <!-- wp:shortcode --> |
174 | 174 | [wpinv_checkout] |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | |
180 | 180 | // Invoice history page. |
181 | 181 | 'invoice_history_page' => array( |
182 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
183 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
182 | + 'name' => _x('gp-invoices', 'Page slug', 'invoicing'), |
|
183 | + 'title' => _x('My Invoices', 'Page title', 'invoicing'), |
|
184 | 184 | 'content' => ' |
185 | 185 | <!-- wp:shortcode --> |
186 | 186 | [wpinv_history] |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | |
192 | 192 | // Success page content. |
193 | 193 | 'success_page' => array( |
194 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
195 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
194 | + 'name' => _x('gp-receipt', 'Page slug', 'invoicing'), |
|
195 | + 'title' => _x('Payment Confirmation', 'Page title', 'invoicing'), |
|
196 | 196 | 'content' => ' |
197 | 197 | <!-- wp:shortcode --> |
198 | 198 | [wpinv_receipt] |
@@ -203,16 +203,16 @@ discard block |
||
203 | 203 | |
204 | 204 | // Failure page content. |
205 | 205 | 'failure_page' => array( |
206 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
207 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
208 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
206 | + 'name' => _x('gp-transaction-failed', 'Page slug', 'invoicing'), |
|
207 | + 'title' => _x('Transaction Failed', 'Page title', 'invoicing'), |
|
208 | + 'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'), |
|
209 | 209 | 'parent' => 'gp-checkout', |
210 | 210 | ), |
211 | 211 | |
212 | 212 | // Subscriptions history page. |
213 | 213 | 'invoice_subscription_page' => array( |
214 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
215 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
214 | + 'name' => _x('gp-subscriptions', 'Page slug', 'invoicing'), |
|
215 | + 'title' => _x('My Subscriptions', 'Page title', 'invoicing'), |
|
216 | 216 | 'content' => ' |
217 | 217 | <!-- wp:shortcode --> |
218 | 218 | [wpinv_subscriptions] |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function create_pages() { |
234 | 234 | |
235 | - foreach ( self::get_pages() as $key => $page ) { |
|
236 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
235 | + foreach (self::get_pages() as $key => $page) { |
|
236 | + wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | KEY customer_and_status (customer_id, status) |
274 | 274 | ) $charset_collate;"; |
275 | 275 | |
276 | - dbDelta( $sql ); |
|
276 | + dbDelta($sql); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | KEY `key` (`key`) |
325 | 325 | ) $charset_collate;"; |
326 | 326 | |
327 | - dbDelta( $sql ); |
|
327 | + dbDelta($sql); |
|
328 | 328 | |
329 | 329 | } |
330 | 330 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | KEY post_id (post_id) |
362 | 362 | ) $charset_collate;"; |
363 | 363 | |
364 | - dbDelta( $sql ); |
|
364 | + dbDelta($sql); |
|
365 | 365 | |
366 | 366 | } |
367 | 367 | |
@@ -374,32 +374,32 @@ discard block |
||
374 | 374 | |
375 | 375 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
376 | 376 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
377 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
377 | + $migrated = $wpdb->get_col("SELECT post_id FROM $invoices_table"); |
|
378 | 378 | $invoices = array_unique( |
379 | 379 | get_posts( |
380 | 380 | array( |
381 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
381 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
382 | 382 | 'posts_per_page' => -1, |
383 | 383 | 'fields' => 'ids', |
384 | - 'post_status' => array_keys( get_post_stati() ), |
|
384 | + 'post_status' => array_keys(get_post_stati()), |
|
385 | 385 | 'exclude' => (array) $migrated, |
386 | 386 | ) |
387 | 387 | ) |
388 | 388 | ); |
389 | 389 | |
390 | 390 | // Abort if we do not have any invoices. |
391 | - if ( empty( $invoices ) ) { |
|
391 | + if (empty($invoices)) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | 395 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
396 | 396 | |
397 | 397 | $invoice_rows = array(); |
398 | - foreach ( $invoices as $invoice ) { |
|
398 | + foreach ($invoices as $invoice) { |
|
399 | 399 | |
400 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
400 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
401 | 401 | |
402 | - if ( empty( $invoice->ID ) ) { |
|
402 | + if (empty($invoice->ID)) { |
|
403 | 403 | return; |
404 | 404 | } |
405 | 405 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | 'post_id' => $invoice->ID, |
408 | 408 | 'number' => $invoice->get_number(), |
409 | 409 | 'key' => $invoice->get_key(), |
410 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
410 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
411 | 411 | 'mode' => $invoice->mode, |
412 | 412 | 'user_ip' => $invoice->get_ip(), |
413 | 413 | 'first_name' => $invoice->get_first_name(), |
@@ -436,27 +436,27 @@ discard block |
||
436 | 436 | 'custom_meta' => $invoice->payment_meta, |
437 | 437 | ); |
438 | 438 | |
439 | - foreach ( $fields as $key => $val ) { |
|
440 | - if ( is_null( $val ) ) { |
|
439 | + foreach ($fields as $key => $val) { |
|
440 | + if (is_null($val)) { |
|
441 | 441 | $val = ''; |
442 | 442 | } |
443 | - $val = maybe_serialize( $val ); |
|
444 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
443 | + $val = maybe_serialize($val); |
|
444 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
445 | 445 | } |
446 | 446 | |
447 | - $fields = implode( ', ', $fields ); |
|
447 | + $fields = implode(', ', $fields); |
|
448 | 448 | $invoice_rows[] = "($fields)"; |
449 | 449 | |
450 | 450 | $item_rows = array(); |
451 | 451 | $item_columns = array(); |
452 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
452 | + foreach ($invoice->get_cart_details() as $details) { |
|
453 | 453 | $fields = array( |
454 | 454 | 'post_id' => $invoice->ID, |
455 | 455 | 'item_id' => $details['id'], |
456 | 456 | 'item_name' => $details['name'], |
457 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
457 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
458 | 458 | 'vat_rate' => $details['vat_rate'], |
459 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
459 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
460 | 460 | 'tax' => $details['tax'], |
461 | 461 | 'item_price' => $details['item_price'], |
462 | 462 | 'custom_price' => $details['custom_price'], |
@@ -468,31 +468,31 @@ discard block |
||
468 | 468 | 'fees' => $details['fees'], |
469 | 469 | ); |
470 | 470 | |
471 | - $item_columns = array_keys( $fields ); |
|
471 | + $item_columns = array_keys($fields); |
|
472 | 472 | |
473 | - foreach ( $fields as $key => $val ) { |
|
474 | - if ( is_null( $val ) ) { |
|
473 | + foreach ($fields as $key => $val) { |
|
474 | + if (is_null($val)) { |
|
475 | 475 | $val = ''; |
476 | 476 | } |
477 | - $val = maybe_serialize( $val ); |
|
478 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
477 | + $val = maybe_serialize($val); |
|
478 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
479 | 479 | } |
480 | 480 | |
481 | - $fields = implode( ', ', $fields ); |
|
481 | + $fields = implode(', ', $fields); |
|
482 | 482 | $item_rows[] = "($fields)"; |
483 | 483 | } |
484 | 484 | |
485 | - $item_rows = implode( ', ', $item_rows ); |
|
486 | - $item_columns = implode( ', ', $item_columns ); |
|
487 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
485 | + $item_rows = implode(', ', $item_rows); |
|
486 | + $item_columns = implode(', ', $item_columns); |
|
487 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
488 | 488 | } |
489 | 489 | |
490 | - if ( empty( $invoice_rows ) ) { |
|
490 | + if (empty($invoice_rows)) { |
|
491 | 491 | return; |
492 | 492 | } |
493 | 493 | |
494 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
495 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
494 | + $invoice_rows = implode(', ', $invoice_rows); |
|
495 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
496 | 496 | |
497 | 497 | } |
498 | 498 | |
@@ -503,12 +503,12 @@ discard block |
||
503 | 503 | public static function rename_gateways_label() { |
504 | 504 | global $wpdb; |
505 | 505 | |
506 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
506 | + foreach (array_keys(wpinv_get_payment_gateways()) as $gateway) { |
|
507 | 507 | |
508 | 508 | $wpdb->update( |
509 | 509 | $wpdb->prefix . 'getpaid_invoices', |
510 | - array( 'gateway' => $gateway ), |
|
511 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
510 | + array('gateway' => $gateway), |
|
511 | + array('gateway' => wpinv_get_gateway_admin_label($gateway)), |
|
512 | 512 | '%s', |
513 | 513 | '%s' |
514 | 514 | ); |
@@ -14,92 +14,92 @@ discard block |
||
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; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
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 | + |
|
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' ), 9 ); |
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_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | - 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_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
68 | 68 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
77 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
78 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
79 | - |
|
80 | - // Setup/welcome |
|
81 | - if ( ! empty( $_GET['page'] ) ) { |
|
82 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
83 | - case 'gp-setup': |
|
84 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
85 | - break; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Register admin scripts |
|
93 | - * |
|
94 | - */ |
|
95 | - public function enqeue_scripts() { |
|
69 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
76 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
77 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
78 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
79 | + |
|
80 | + // Setup/welcome |
|
81 | + if ( ! empty( $_GET['page'] ) ) { |
|
82 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
83 | + case 'gp-setup': |
|
84 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
85 | + break; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Register admin scripts |
|
93 | + * |
|
94 | + */ |
|
95 | + public function enqeue_scripts() { |
|
96 | 96 | global $current_screen, $pagenow; |
97 | 97 | |
98 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
99 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
98 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
99 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
100 | 100 | |
101 | 101 | if ( ! empty( $current_screen->post_type ) ) { |
102 | - $page = $current_screen->post_type; |
|
102 | + $page = $current_screen->post_type; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | // General styles. |
@@ -120,53 +120,53 @@ discard block |
||
120 | 120 | } |
121 | 121 | |
122 | 122 | // Payment form scripts. |
123 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
123 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
124 | 124 | $this->load_payment_form_scripts(); |
125 | 125 | } |
126 | 126 | |
127 | - if ( $page == 'wpinv-subscriptions' ) { |
|
128 | - wp_enqueue_script( 'postbox' ); |
|
129 | - } |
|
127 | + if ( $page == 'wpinv-subscriptions' ) { |
|
128 | + wp_enqueue_script( 'postbox' ); |
|
129 | + } |
|
130 | 130 | |
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | - * Returns admin js translations. |
|
135 | - * |
|
136 | - */ |
|
137 | - protected function get_admin_i18() { |
|
134 | + * Returns admin js translations. |
|
135 | + * |
|
136 | + */ |
|
137 | + protected function get_admin_i18() { |
|
138 | 138 | global $post; |
139 | 139 | |
140 | - $date_range = array( |
|
141 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
142 | - ); |
|
140 | + $date_range = array( |
|
141 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
142 | + ); |
|
143 | 143 | |
144 | - if ( $date_range['period'] == 'custom' ) { |
|
144 | + if ( $date_range['period'] == 'custom' ) { |
|
145 | 145 | |
146 | - if ( isset( $_GET['from'] ) ) { |
|
147 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
148 | - } |
|
146 | + if ( isset( $_GET['from'] ) ) { |
|
147 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
148 | + } |
|
149 | 149 | |
150 | - if ( isset( $_GET['to'] ) ) { |
|
151 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
152 | - } |
|
150 | + if ( isset( $_GET['to'] ) ) { |
|
151 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
152 | + } |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | $i18n = array( |
156 | 156 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
157 | 157 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
158 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
159 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
160 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
161 | - 'date_range' => $date_range, |
|
158 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
159 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
160 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
161 | + 'date_range' => $date_range, |
|
162 | 162 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
163 | 163 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
164 | 164 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
165 | 165 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
166 | 166 | 'tax' => wpinv_tax_amount(), |
167 | 167 | 'discount' => 0, |
168 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
169 | - 'currency' => wpinv_get_currency(), |
|
168 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
169 | + 'currency' => wpinv_get_currency(), |
|
170 | 170 | 'currency_pos' => wpinv_currency_position(), |
171 | 171 | 'thousand_sep' => wpinv_thousands_separator(), |
172 | 172 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -186,118 +186,118 @@ discard block |
||
186 | 186 | 'item_description' => __( 'Item Description', 'invoicing' ), |
187 | 187 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
188 | 188 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
189 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
190 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
191 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
192 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
193 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
189 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
190 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
191 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
192 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
193 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
194 | 194 | ); |
195 | 195 | |
196 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
196 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
197 | 197 | |
198 | - $invoice = new WPInv_Invoice( $post ); |
|
199 | - $i18n['save_invoice'] = sprintf( |
|
200 | - __( 'Save %s', 'invoicing' ), |
|
201 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
202 | - ); |
|
198 | + $invoice = new WPInv_Invoice( $post ); |
|
199 | + $i18n['save_invoice'] = sprintf( |
|
200 | + __( 'Save %s', 'invoicing' ), |
|
201 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
202 | + ); |
|
203 | 203 | |
204 | - $i18n['invoice_description'] = sprintf( |
|
205 | - __( '%s Description', 'invoicing' ), |
|
206 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
207 | - ); |
|
204 | + $i18n['invoice_description'] = sprintf( |
|
205 | + __( '%s Description', 'invoicing' ), |
|
206 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
207 | + ); |
|
208 | 208 | |
209 | - } |
|
210 | - return $i18n; |
|
211 | - } |
|
209 | + } |
|
210 | + return $i18n; |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * Change the admin footer text on GetPaid admin pages. |
|
215 | - * |
|
216 | - * @since 2.0.0 |
|
217 | - * @param string $footer_text |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public function admin_footer_text( $footer_text ) { |
|
221 | - global $current_screen; |
|
213 | + /** |
|
214 | + * Change the admin footer text on GetPaid admin pages. |
|
215 | + * |
|
216 | + * @since 2.0.0 |
|
217 | + * @param string $footer_text |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public function admin_footer_text( $footer_text ) { |
|
221 | + global $current_screen; |
|
222 | 222 | |
223 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
223 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
224 | 224 | |
225 | 225 | if ( ! empty( $current_screen->post_type ) ) { |
226 | - $page = $current_screen->post_type; |
|
226 | + $page = $current_screen->post_type; |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // General styles. |
230 | 230 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
231 | 231 | |
232 | - // Change the footer text |
|
233 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
232 | + // Change the footer text |
|
233 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
234 | 234 | |
235 | - $rating_url = esc_url( |
|
236 | - wp_nonce_url( |
|
237 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
238 | - 'getpaid-nonce', |
|
239 | - 'getpaid-nonce' |
|
235 | + $rating_url = esc_url( |
|
236 | + wp_nonce_url( |
|
237 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
238 | + 'getpaid-nonce', |
|
239 | + 'getpaid-nonce' |
|
240 | 240 | ) |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - $footer_text = sprintf( |
|
244 | - /* translators: %s: five stars */ |
|
245 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
246 | - "<a href='$rating_url'>★★★★★</a>" |
|
247 | - ); |
|
243 | + $footer_text = sprintf( |
|
244 | + /* translators: %s: five stars */ |
|
245 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
246 | + "<a href='$rating_url'>★★★★★</a>" |
|
247 | + ); |
|
248 | 248 | |
249 | - } else { |
|
249 | + } else { |
|
250 | 250 | |
251 | - $footer_text = sprintf( |
|
252 | - /* translators: %s: GetPaid */ |
|
253 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
254 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
255 | - ); |
|
251 | + $footer_text = sprintf( |
|
252 | + /* translators: %s: GetPaid */ |
|
253 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
254 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
255 | + ); |
|
256 | 256 | |
257 | - } |
|
257 | + } |
|
258 | 258 | } |
259 | 259 | |
260 | - return $footer_text; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Redirects to wp.org to rate the plugin. |
|
265 | - * |
|
266 | - * @since 2.0.0 |
|
267 | - */ |
|
268 | - public function redirect_to_wordpress_rating_page() { |
|
269 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
270 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
271 | - exit; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Loads payment form js. |
|
276 | - * |
|
277 | - */ |
|
278 | - protected function load_payment_form_scripts() { |
|
260 | + return $footer_text; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Redirects to wp.org to rate the plugin. |
|
265 | + * |
|
266 | + * @since 2.0.0 |
|
267 | + */ |
|
268 | + public function redirect_to_wordpress_rating_page() { |
|
269 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
270 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
271 | + exit; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Loads payment form js. |
|
276 | + * |
|
277 | + */ |
|
278 | + protected function load_payment_form_scripts() { |
|
279 | 279 | global $post; |
280 | 280 | |
281 | 281 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
282 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
283 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
282 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
283 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
284 | 284 | |
285 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
286 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
285 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
286 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
287 | 287 | |
288 | - wp_localize_script( |
|
288 | + wp_localize_script( |
|
289 | 289 | 'wpinv-admin-payment-form-script', |
290 | 290 | 'wpinvPaymentFormAdmin', |
291 | 291 | array( |
292 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
293 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
294 | - 'currency' => wpinv_currency_symbol(), |
|
295 | - 'position' => wpinv_currency_position(), |
|
296 | - 'decimals' => (int) wpinv_decimals(), |
|
297 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
298 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
299 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
300 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
292 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
293 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
294 | + 'currency' => wpinv_currency_symbol(), |
|
295 | + 'position' => wpinv_currency_position(), |
|
296 | + 'decimals' => (int) wpinv_decimals(), |
|
297 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
298 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
299 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
300 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
301 | 301 | ) |
302 | 302 | ); |
303 | 303 | |
@@ -306,19 +306,19 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * Add our classes to admin pages. |
|
309 | + * Add our classes to admin pages. |
|
310 | 310 | * |
311 | 311 | * @param string $classes |
312 | 312 | * @return string |
313 | - * |
|
314 | - */ |
|
313 | + * |
|
314 | + */ |
|
315 | 315 | public function admin_body_class( $classes ) { |
316 | - global $pagenow, $post, $current_screen; |
|
316 | + global $pagenow, $post, $current_screen; |
|
317 | 317 | |
318 | 318 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_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,70 +327,70 @@ discard block |
||
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( |
|
344 | + // Register with the deactivation survey class. |
|
345 | + AyeCode_Deactivation_Survey::instance( |
|
346 | 346 | array( |
347 | - 'slug' => 'invoicing', |
|
348 | - 'version' => WPINV_VERSION, |
|
349 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
350 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
351 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
347 | + 'slug' => 'invoicing', |
|
348 | + 'version' => WPINV_VERSION, |
|
349 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
350 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
351 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
352 | 352 | ) |
353 | 353 | ); |
354 | 354 | |
355 | 355 | new AyeCode_Connect_Helper( |
356 | 356 | array( |
357 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
358 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
359 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
360 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
361 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
362 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
363 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
357 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
358 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
359 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
360 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
361 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
362 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
363 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
364 | 364 | ), |
365 | 365 | array( 'wpi-addons' ) |
366 | 366 | ); |
367 | 367 | |
368 | 368 | } |
369 | 369 | |
370 | - /** |
|
371 | - * Redirect users to settings on activation. |
|
372 | - * |
|
373 | - * @return void |
|
374 | - */ |
|
375 | - public function activation_redirect() { |
|
370 | + /** |
|
371 | + * Redirect users to settings on activation. |
|
372 | + * |
|
373 | + * @return void |
|
374 | + */ |
|
375 | + public function activation_redirect() { |
|
376 | 376 | |
377 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
377 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | 378 | |
379 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
380 | - return; |
|
381 | - } |
|
379 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | 382 | |
383 | - // Bail if activating from network, or bulk |
|
384 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
385 | - return; |
|
386 | - } |
|
383 | + // Bail if activating from network, or bulk |
|
384 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
385 | + return; |
|
386 | + } |
|
387 | 387 | |
388 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
388 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | 389 | |
390 | 390 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
391 | 391 | exit; |
392 | 392 | |
393 | - } |
|
393 | + } |
|
394 | 394 | |
395 | 395 | /** |
396 | 396 | * Fires an admin action after verifying that a user can fire them. |
@@ -404,535 +404,535 @@ discard block |
||
404 | 404 | |
405 | 405 | } |
406 | 406 | |
407 | - /** |
|
407 | + /** |
|
408 | 408 | * Duplicate invoice. |
409 | - * |
|
410 | - * @param array $args |
|
409 | + * |
|
410 | + * @param array $args |
|
411 | 411 | */ |
412 | 412 | public function duplicate_invoice( $args ) { |
413 | 413 | |
414 | - if ( empty( $args['invoice_id'] ) ) { |
|
415 | - return; |
|
416 | - } |
|
414 | + if ( empty( $args['invoice_id'] ) ) { |
|
415 | + return; |
|
416 | + } |
|
417 | 417 | |
418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
418 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | 419 | |
420 | - if ( ! $invoice->exists() ) { |
|
421 | - return; |
|
422 | - } |
|
420 | + if ( ! $invoice->exists() ) { |
|
421 | + return; |
|
422 | + } |
|
423 | 423 | |
424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
425 | - $new_invoice->save(); |
|
424 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
425 | + $new_invoice->save(); |
|
426 | 426 | |
427 | - if ( $new_invoice->exists() ) { |
|
427 | + if ( $new_invoice->exists() ) { |
|
428 | 428 | |
429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
429 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
430 | 430 | |
431 | - wp_safe_redirect( |
|
432 | - add_query_arg( |
|
433 | - array( |
|
434 | - 'action' => 'edit', |
|
435 | - 'post' => $new_invoice->get_id(), |
|
436 | - ), |
|
437 | - admin_url( 'post.php' ) |
|
438 | - ) |
|
439 | - ); |
|
440 | - exit; |
|
431 | + wp_safe_redirect( |
|
432 | + add_query_arg( |
|
433 | + array( |
|
434 | + 'action' => 'edit', |
|
435 | + 'post' => $new_invoice->get_id(), |
|
436 | + ), |
|
437 | + admin_url( 'post.php' ) |
|
438 | + ) |
|
439 | + ); |
|
440 | + exit; |
|
441 | 441 | |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
444 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - /** |
|
448 | + /** |
|
449 | 449 | * Sends a payment reminder to a customer. |
450 | - * |
|
451 | - * @param array $args |
|
450 | + * |
|
451 | + * @param array $args |
|
452 | 452 | */ |
453 | 453 | public function duplicate_payment_form( $args ) { |
454 | 454 | |
455 | - if ( empty( $args['form_id'] ) ) { |
|
456 | - return; |
|
457 | - } |
|
458 | - |
|
459 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
455 | + if ( empty( $args['form_id'] ) ) { |
|
456 | + return; |
|
457 | + } |
|
460 | 458 | |
461 | - if ( ! $form->exists() ) { |
|
462 | - return; |
|
463 | - } |
|
459 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
464 | 460 | |
465 | - $new_form = new GetPaid_Payment_Form(); |
|
466 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
467 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
468 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
469 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
470 | - $new_form->save(); |
|
461 | + if ( ! $form->exists() ) { |
|
462 | + return; |
|
463 | + } |
|
471 | 464 | |
472 | - if ( $new_form->exists() ) { |
|
473 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
474 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
475 | - } else { |
|
476 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
477 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
478 | - } |
|
465 | + $new_form = new GetPaid_Payment_Form(); |
|
466 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
467 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
468 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
469 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
470 | + $new_form->save(); |
|
471 | + |
|
472 | + if ( $new_form->exists() ) { |
|
473 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
474 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
475 | + } else { |
|
476 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
477 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
478 | + } |
|
479 | 479 | |
480 | - wp_redirect( $url ); |
|
481 | - exit; |
|
482 | - } |
|
480 | + wp_redirect( $url ); |
|
481 | + exit; |
|
482 | + } |
|
483 | 483 | |
484 | - /** |
|
484 | + /** |
|
485 | 485 | * Sends a payment reminder to a customer. |
486 | - * |
|
487 | - * @param array $args |
|
486 | + * |
|
487 | + * @param array $args |
|
488 | 488 | */ |
489 | 489 | public function send_customer_invoice( $args ) { |
490 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
491 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
492 | - exit; |
|
493 | - } |
|
490 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
491 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
492 | + exit; |
|
493 | + } |
|
494 | 494 | |
495 | - /** |
|
495 | + /** |
|
496 | 496 | * Sends a payment reminder to a customer. |
497 | - * |
|
498 | - * @param array $args |
|
497 | + * |
|
498 | + * @param array $args |
|
499 | 499 | */ |
500 | 500 | public function send_customer_payment_reminder( $args ) { |
501 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
501 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
502 | 502 | |
503 | - if ( $sent ) { |
|
504 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
505 | - } else { |
|
506 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
507 | - } |
|
503 | + if ( $sent ) { |
|
504 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
505 | + } else { |
|
506 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
507 | + } |
|
508 | 508 | |
509 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
510 | - exit; |
|
511 | - } |
|
509 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
510 | + exit; |
|
511 | + } |
|
512 | 512 | |
513 | - /** |
|
513 | + /** |
|
514 | 514 | * Resets tax rates. |
515 | - * |
|
515 | + * |
|
516 | 516 | */ |
517 | 517 | public function admin_reset_tax_rates() { |
518 | 518 | |
519 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
520 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
521 | - exit; |
|
519 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
520 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
521 | + exit; |
|
522 | 522 | |
523 | - } |
|
523 | + } |
|
524 | 524 | |
525 | - /** |
|
525 | + /** |
|
526 | 526 | * Resets admin pages. |
527 | - * |
|
527 | + * |
|
528 | 528 | */ |
529 | 529 | public function admin_create_missing_pages() { |
530 | - $installer = new GetPaid_Installer(); |
|
531 | - $installer->create_pages(); |
|
532 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
533 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
534 | - exit; |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Refreshes the permalinks. |
|
539 | - */ |
|
540 | - public function admin_refresh_permalinks() { |
|
541 | - flush_rewrite_rules(); |
|
542 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
543 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
544 | - exit; |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
530 | + $installer = new GetPaid_Installer(); |
|
531 | + $installer->create_pages(); |
|
532 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
533 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
534 | + exit; |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Refreshes the permalinks. |
|
539 | + */ |
|
540 | + public function admin_refresh_permalinks() { |
|
541 | + flush_rewrite_rules(); |
|
542 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
543 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
544 | + exit; |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | 548 | * Creates an missing admin tables. |
549 | - * |
|
549 | + * |
|
550 | 550 | */ |
551 | 551 | public function admin_create_missing_tables() { |
552 | - global $wpdb; |
|
553 | - $installer = new GetPaid_Installer(); |
|
552 | + global $wpdb; |
|
553 | + $installer = new GetPaid_Installer(); |
|
554 | 554 | |
555 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
556 | - $installer->create_subscriptions_table(); |
|
555 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
556 | + $installer->create_subscriptions_table(); |
|
557 | 557 | |
558 | - if ( $wpdb->last_error !== '' ) { |
|
559 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
560 | - } |
|
561 | - } |
|
558 | + if ( $wpdb->last_error !== '' ) { |
|
559 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
560 | + } |
|
561 | + } |
|
562 | 562 | |
563 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
564 | - $installer->create_invoices_table(); |
|
563 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
564 | + $installer->create_invoices_table(); |
|
565 | 565 | |
566 | - if ( '' !== $wpdb->last_error ) { |
|
567 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
568 | - } |
|
569 | - } |
|
566 | + if ( '' !== $wpdb->last_error ) { |
|
567 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
568 | + } |
|
569 | + } |
|
570 | 570 | |
571 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
572 | - $installer->create_invoice_items_table(); |
|
571 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
572 | + $installer->create_invoice_items_table(); |
|
573 | 573 | |
574 | - if ( '' !== $wpdb->last_error ) { |
|
575 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
576 | - } |
|
577 | - } |
|
574 | + if ( '' !== $wpdb->last_error ) { |
|
575 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
576 | + } |
|
577 | + } |
|
578 | 578 | |
579 | - if ( ! $this->has_notices() ) { |
|
580 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
581 | - } |
|
579 | + if ( ! $this->has_notices() ) { |
|
580 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
581 | + } |
|
582 | 582 | |
583 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
584 | - exit; |
|
585 | - } |
|
583 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
584 | + exit; |
|
585 | + } |
|
586 | 586 | |
587 | - /** |
|
587 | + /** |
|
588 | 588 | * Migrates old invoices to the new database tables. |
589 | - * |
|
589 | + * |
|
590 | 590 | */ |
591 | 591 | public function admin_migrate_old_invoices() { |
592 | 592 | |
593 | - // Migrate the invoices. |
|
594 | - $installer = new GetPaid_Installer(); |
|
595 | - $installer->migrate_old_invoices(); |
|
593 | + // Migrate the invoices. |
|
594 | + $installer = new GetPaid_Installer(); |
|
595 | + $installer->migrate_old_invoices(); |
|
596 | 596 | |
597 | - // Show an admin message. |
|
598 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
597 | + // Show an admin message. |
|
598 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
599 | 599 | |
600 | - // Redirect the admin. |
|
601 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
602 | - exit; |
|
600 | + // Redirect the admin. |
|
601 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
602 | + exit; |
|
603 | 603 | |
604 | - } |
|
604 | + } |
|
605 | 605 | |
606 | - /** |
|
606 | + /** |
|
607 | 607 | * Download customers. |
608 | - * |
|
608 | + * |
|
609 | 609 | */ |
610 | 610 | public function admin_download_customers() { |
611 | - global $wpdb; |
|
612 | - |
|
613 | - $output = fopen( 'php://output', 'w' ); |
|
614 | - |
|
615 | - if ( false === $output ) { |
|
616 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
617 | - } |
|
611 | + global $wpdb; |
|
618 | 612 | |
619 | - header( 'Content-Type:text/csv' ); |
|
620 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
613 | + $output = fopen( 'php://output', 'w' ); |
|
621 | 614 | |
622 | - $post_types = ''; |
|
615 | + if ( false === $output ) { |
|
616 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
617 | + } |
|
623 | 618 | |
624 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
625 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
626 | - } |
|
619 | + header( 'Content-Type:text/csv' ); |
|
620 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
627 | 621 | |
628 | - $post_types = rtrim( $post_types, ' OR' ); |
|
622 | + $post_types = ''; |
|
629 | 623 | |
630 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
624 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
625 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
626 | + } |
|
631 | 627 | |
632 | - $columns = array( |
|
633 | - 'name' => __( 'Name', 'invoicing' ), |
|
634 | - 'email' => __( 'Email', 'invoicing' ), |
|
635 | - 'country' => __( 'Country', 'invoicing' ), |
|
636 | - 'state' => __( 'State', 'invoicing' ), |
|
637 | - 'city' => __( 'City', 'invoicing' ), |
|
638 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
639 | - 'address' => __( 'Address', 'invoicing' ), |
|
640 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
641 | - 'company' => __( 'Company', 'invoicing' ), |
|
642 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
643 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
644 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
645 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
646 | - ); |
|
628 | + $post_types = rtrim( $post_types, ' OR' ); |
|
629 | + |
|
630 | + $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
631 | + |
|
632 | + $columns = array( |
|
633 | + 'name' => __( 'Name', 'invoicing' ), |
|
634 | + 'email' => __( 'Email', 'invoicing' ), |
|
635 | + 'country' => __( 'Country', 'invoicing' ), |
|
636 | + 'state' => __( 'State', 'invoicing' ), |
|
637 | + 'city' => __( 'City', 'invoicing' ), |
|
638 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
639 | + 'address' => __( 'Address', 'invoicing' ), |
|
640 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
641 | + 'company' => __( 'Company', 'invoicing' ), |
|
642 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
643 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
644 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
645 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
646 | + ); |
|
647 | 647 | |
648 | - // Output the csv column headers. |
|
649 | - fputcsv( $output, array_values( $columns ) ); |
|
648 | + // Output the csv column headers. |
|
649 | + fputcsv( $output, array_values( $columns ) ); |
|
650 | 650 | |
651 | - // Loop through |
|
652 | - $table = new WPInv_Customers_Table(); |
|
653 | - foreach ( $customers as $customer_id ) { |
|
651 | + // Loop through |
|
652 | + $table = new WPInv_Customers_Table(); |
|
653 | + foreach ( $customers as $customer_id ) { |
|
654 | 654 | |
655 | - $user = get_user_by( 'id', $customer_id ); |
|
656 | - $row = array(); |
|
657 | - if ( empty( $user ) ) { |
|
658 | - continue; |
|
659 | - } |
|
655 | + $user = get_user_by( 'id', $customer_id ); |
|
656 | + $row = array(); |
|
657 | + if ( empty( $user ) ) { |
|
658 | + continue; |
|
659 | + } |
|
660 | 660 | |
661 | - foreach ( array_keys( $columns ) as $column ) { |
|
661 | + foreach ( array_keys( $columns ) as $column ) { |
|
662 | 662 | |
663 | - $method = 'column_' . $column; |
|
663 | + $method = 'column_' . $column; |
|
664 | 664 | |
665 | - if ( 'name' == $column ) { |
|
666 | - $value = esc_html( $user->display_name ); |
|
667 | - } elseif ( 'email' == $column ) { |
|
668 | - $value = sanitize_email( $user->user_email ); |
|
669 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
670 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
671 | - } |
|
665 | + if ( 'name' == $column ) { |
|
666 | + $value = esc_html( $user->display_name ); |
|
667 | + } elseif ( 'email' == $column ) { |
|
668 | + $value = sanitize_email( $user->user_email ); |
|
669 | + } elseif ( is_callable( array( $table, $method ) ) ) { |
|
670 | + $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
671 | + } |
|
672 | 672 | |
673 | - if ( empty( $value ) ) { |
|
674 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
675 | - } |
|
673 | + if ( empty( $value ) ) { |
|
674 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
675 | + } |
|
676 | 676 | |
677 | - $row[] = $value; |
|
677 | + $row[] = $value; |
|
678 | 678 | |
679 | - } |
|
679 | + } |
|
680 | 680 | |
681 | - fputcsv( $output, $row ); |
|
682 | - } |
|
681 | + fputcsv( $output, $row ); |
|
682 | + } |
|
683 | 683 | |
684 | - fclose( $output ); |
|
685 | - exit; |
|
684 | + fclose( $output ); |
|
685 | + exit; |
|
686 | 686 | |
687 | - } |
|
687 | + } |
|
688 | 688 | |
689 | - /** |
|
689 | + /** |
|
690 | 690 | * Installs a plugin. |
691 | - * |
|
692 | - * @param array $data |
|
691 | + * |
|
692 | + * @param array $data |
|
693 | 693 | */ |
694 | 694 | public function admin_install_plugin( $data ) { |
695 | 695 | |
696 | - if ( ! empty( $data['plugins'] ) ) { |
|
697 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
698 | - wp_cache_flush(); |
|
696 | + if ( ! empty( $data['plugins'] ) ) { |
|
697 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
698 | + wp_cache_flush(); |
|
699 | 699 | |
700 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
701 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
702 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
703 | - $installed = $upgrader->install( $plugin_zip ); |
|
700 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
701 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
702 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
703 | + $installed = $upgrader->install( $plugin_zip ); |
|
704 | 704 | |
705 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
706 | - activate_plugin( $file, '', false, true ); |
|
707 | - } else { |
|
708 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
709 | - } |
|
705 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
706 | + activate_plugin( $file, '', false, true ); |
|
707 | + } else { |
|
708 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
709 | + } |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
714 | - wp_safe_redirect( $redirect ); |
|
715 | - exit; |
|
713 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
714 | + wp_safe_redirect( $redirect ); |
|
715 | + exit; |
|
716 | 716 | |
717 | - } |
|
717 | + } |
|
718 | 718 | |
719 | - /** |
|
719 | + /** |
|
720 | 720 | * Connects a gateway. |
721 | - * |
|
722 | - * @param array $data |
|
721 | + * |
|
722 | + * @param array $data |
|
723 | 723 | */ |
724 | 724 | public function admin_connect_gateway( $data ) { |
725 | 725 | |
726 | - if ( ! empty( $data['plugin'] ) ) { |
|
726 | + if ( ! empty( $data['plugin'] ) ) { |
|
727 | 727 | |
728 | - $gateway = sanitize_key( $data['plugin'] ); |
|
729 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
728 | + $gateway = sanitize_key( $data['plugin'] ); |
|
729 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
730 | 730 | |
731 | - if ( ! empty( $connect_url ) ) { |
|
732 | - wp_redirect( $connect_url ); |
|
733 | - exit; |
|
734 | - } |
|
731 | + if ( ! empty( $connect_url ) ) { |
|
732 | + wp_redirect( $connect_url ); |
|
733 | + exit; |
|
734 | + } |
|
735 | 735 | |
736 | - if ( 'stripe' == $data['plugin'] ) { |
|
737 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
738 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
739 | - wp_cache_flush(); |
|
736 | + if ( 'stripe' == $data['plugin'] ) { |
|
737 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
738 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
739 | + wp_cache_flush(); |
|
740 | 740 | |
741 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
742 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
743 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
744 | - $upgrader->install( $plugin_zip ); |
|
745 | - } |
|
741 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
742 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
743 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
744 | + $upgrader->install( $plugin_zip ); |
|
745 | + } |
|
746 | 746 | |
747 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
748 | - } |
|
747 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
748 | + } |
|
749 | 749 | |
750 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
751 | - if ( ! empty( $connect_url ) ) { |
|
752 | - wp_redirect( $connect_url ); |
|
753 | - exit; |
|
754 | - } |
|
750 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
751 | + if ( ! empty( $connect_url ) ) { |
|
752 | + wp_redirect( $connect_url ); |
|
753 | + exit; |
|
754 | + } |
|
755 | 755 | } |
756 | 756 | |
757 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
758 | - wp_safe_redirect( $redirect ); |
|
759 | - exit; |
|
757 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
758 | + wp_safe_redirect( $redirect ); |
|
759 | + exit; |
|
760 | 760 | |
761 | - } |
|
761 | + } |
|
762 | 762 | |
763 | - /** |
|
763 | + /** |
|
764 | 764 | * Recalculates discounts. |
765 | - * |
|
765 | + * |
|
766 | 766 | */ |
767 | 767 | public function admin_recalculate_discounts() { |
768 | - global $wpdb; |
|
768 | + global $wpdb; |
|
769 | 769 | |
770 | - // Fetch all invoices that have discount codes. |
|
771 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
772 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
770 | + // Fetch all invoices that have discount codes. |
|
771 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
772 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
773 | 773 | |
774 | - foreach ( $invoices as $invoice ) { |
|
774 | + foreach ( $invoices as $invoice ) { |
|
775 | 775 | |
776 | - $invoice = new WPInv_Invoice( $invoice ); |
|
776 | + $invoice = new WPInv_Invoice( $invoice ); |
|
777 | 777 | |
778 | - if ( ! $invoice->exists() ) { |
|
779 | - continue; |
|
780 | - } |
|
778 | + if ( ! $invoice->exists() ) { |
|
779 | + continue; |
|
780 | + } |
|
781 | 781 | |
782 | - // Abort if the discount does not exist or does not apply here. |
|
783 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
784 | - if ( ! $discount->exists() ) { |
|
785 | - continue; |
|
786 | - } |
|
782 | + // Abort if the discount does not exist or does not apply here. |
|
783 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
784 | + if ( ! $discount->exists() ) { |
|
785 | + continue; |
|
786 | + } |
|
787 | 787 | |
788 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
789 | - $invoice->recalculate_total(); |
|
788 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
789 | + $invoice->recalculate_total(); |
|
790 | 790 | |
791 | - if ( $invoice->get_total_discount() > 0 ) { |
|
792 | - $invoice->save(); |
|
793 | - } |
|
791 | + if ( $invoice->get_total_discount() > 0 ) { |
|
792 | + $invoice->save(); |
|
793 | + } |
|
794 | 794 | } |
795 | 795 | |
796 | - // Show an admin message. |
|
797 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
796 | + // Show an admin message. |
|
797 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
798 | 798 | |
799 | - // Redirect the admin. |
|
800 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
801 | - exit; |
|
799 | + // Redirect the admin. |
|
800 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
801 | + exit; |
|
802 | 802 | |
803 | - } |
|
803 | + } |
|
804 | 804 | |
805 | 805 | /** |
806 | - * Returns an array of admin notices. |
|
807 | - * |
|
808 | - * @since 1.0.19 |
|
806 | + * Returns an array of admin notices. |
|
807 | + * |
|
808 | + * @since 1.0.19 |
|
809 | 809 | * @return array |
810 | - */ |
|
811 | - public function get_notices() { |
|
812 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
810 | + */ |
|
811 | + public function get_notices() { |
|
812 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
813 | 813 | return is_array( $notices ) ? $notices : array(); |
814 | - } |
|
814 | + } |
|
815 | 815 | |
816 | - /** |
|
817 | - * Checks if we have any admin notices. |
|
818 | - * |
|
819 | - * @since 2.0.4 |
|
816 | + /** |
|
817 | + * Checks if we have any admin notices. |
|
818 | + * |
|
819 | + * @since 2.0.4 |
|
820 | 820 | * @return array |
821 | - */ |
|
822 | - public function has_notices() { |
|
823 | - return count( $this->get_notices() ) > 0; |
|
824 | - } |
|
825 | - |
|
826 | - /** |
|
827 | - * Clears all admin notices |
|
828 | - * |
|
829 | - * @access public |
|
830 | - * @since 1.0.19 |
|
831 | - */ |
|
832 | - public function clear_notices() { |
|
833 | - delete_option( 'wpinv_admin_notices' ); |
|
834 | - } |
|
835 | - |
|
836 | - /** |
|
837 | - * Saves a new admin notice |
|
838 | - * |
|
839 | - * @access public |
|
840 | - * @since 1.0.19 |
|
841 | - */ |
|
842 | - public function save_notice( $type, $message ) { |
|
843 | - $notices = $this->get_notices(); |
|
844 | - |
|
845 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
846 | - $notices[ $type ] = array(); |
|
847 | - } |
|
848 | - |
|
849 | - $notices[ $type ][] = $message; |
|
850 | - |
|
851 | - update_option( 'wpinv_admin_notices', $notices ); |
|
852 | - } |
|
853 | - |
|
854 | - /** |
|
855 | - * Displays a success notice |
|
856 | - * |
|
857 | - * @param string $msg The message to qeue. |
|
858 | - * @access public |
|
859 | - * @since 1.0.19 |
|
860 | - */ |
|
861 | - public function show_success( $msg ) { |
|
862 | - $this->save_notice( 'success', $msg ); |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Displays a error notice |
|
867 | - * |
|
868 | - * @access public |
|
869 | - * @param string $msg The message to qeue. |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function show_error( $msg ) { |
|
873 | - $this->save_notice( 'error', $msg ); |
|
874 | - } |
|
875 | - |
|
876 | - /** |
|
877 | - * Displays a warning notice |
|
878 | - * |
|
879 | - * @access public |
|
880 | - * @param string $msg The message to qeue. |
|
881 | - * @since 1.0.19 |
|
882 | - */ |
|
883 | - public function show_warning( $msg ) { |
|
884 | - $this->save_notice( 'warning', $msg ); |
|
885 | - } |
|
886 | - |
|
887 | - /** |
|
888 | - * Displays a info notice |
|
889 | - * |
|
890 | - * @access public |
|
891 | - * @param string $msg The message to qeue. |
|
892 | - * @since 1.0.19 |
|
893 | - */ |
|
894 | - public function show_info( $msg ) { |
|
895 | - $this->save_notice( 'info', $msg ); |
|
896 | - } |
|
897 | - |
|
898 | - /** |
|
899 | - * Show notices |
|
900 | - * |
|
901 | - * @access public |
|
902 | - * @since 1.0.19 |
|
903 | - */ |
|
904 | - public function show_notices() { |
|
821 | + */ |
|
822 | + public function has_notices() { |
|
823 | + return count( $this->get_notices() ) > 0; |
|
824 | + } |
|
825 | + |
|
826 | + /** |
|
827 | + * Clears all admin notices |
|
828 | + * |
|
829 | + * @access public |
|
830 | + * @since 1.0.19 |
|
831 | + */ |
|
832 | + public function clear_notices() { |
|
833 | + delete_option( 'wpinv_admin_notices' ); |
|
834 | + } |
|
835 | + |
|
836 | + /** |
|
837 | + * Saves a new admin notice |
|
838 | + * |
|
839 | + * @access public |
|
840 | + * @since 1.0.19 |
|
841 | + */ |
|
842 | + public function save_notice( $type, $message ) { |
|
843 | + $notices = $this->get_notices(); |
|
844 | + |
|
845 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
846 | + $notices[ $type ] = array(); |
|
847 | + } |
|
848 | + |
|
849 | + $notices[ $type ][] = $message; |
|
850 | + |
|
851 | + update_option( 'wpinv_admin_notices', $notices ); |
|
852 | + } |
|
853 | + |
|
854 | + /** |
|
855 | + * Displays a success notice |
|
856 | + * |
|
857 | + * @param string $msg The message to qeue. |
|
858 | + * @access public |
|
859 | + * @since 1.0.19 |
|
860 | + */ |
|
861 | + public function show_success( $msg ) { |
|
862 | + $this->save_notice( 'success', $msg ); |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Displays a error notice |
|
867 | + * |
|
868 | + * @access public |
|
869 | + * @param string $msg The message to qeue. |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function show_error( $msg ) { |
|
873 | + $this->save_notice( 'error', $msg ); |
|
874 | + } |
|
875 | + |
|
876 | + /** |
|
877 | + * Displays a warning notice |
|
878 | + * |
|
879 | + * @access public |
|
880 | + * @param string $msg The message to qeue. |
|
881 | + * @since 1.0.19 |
|
882 | + */ |
|
883 | + public function show_warning( $msg ) { |
|
884 | + $this->save_notice( 'warning', $msg ); |
|
885 | + } |
|
886 | + |
|
887 | + /** |
|
888 | + * Displays a info notice |
|
889 | + * |
|
890 | + * @access public |
|
891 | + * @param string $msg The message to qeue. |
|
892 | + * @since 1.0.19 |
|
893 | + */ |
|
894 | + public function show_info( $msg ) { |
|
895 | + $this->save_notice( 'info', $msg ); |
|
896 | + } |
|
897 | + |
|
898 | + /** |
|
899 | + * Show notices |
|
900 | + * |
|
901 | + * @access public |
|
902 | + * @since 1.0.19 |
|
903 | + */ |
|
904 | + public function show_notices() { |
|
905 | 905 | |
906 | 906 | $notices = $this->get_notices(); |
907 | 907 | $this->clear_notices(); |
908 | 908 | |
909 | - foreach ( $notices as $type => $messages ) { |
|
909 | + foreach ( $notices as $type => $messages ) { |
|
910 | 910 | |
911 | - if ( ! is_array( $messages ) ) { |
|
912 | - continue; |
|
913 | - } |
|
911 | + if ( ! is_array( $messages ) ) { |
|
912 | + continue; |
|
913 | + } |
|
914 | 914 | |
915 | 915 | $type = esc_attr( $type ); |
916 | - foreach ( $messages as $message ) { |
|
917 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
916 | + foreach ( $messages as $message ) { |
|
917 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
918 | 918 | } |
919 | 919 | } |
920 | 920 | |
921 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
922 | - |
|
923 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
924 | - $url = wp_nonce_url( |
|
925 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
926 | - 'getpaid-nonce', |
|
927 | - 'getpaid-nonce' |
|
928 | - ); |
|
929 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
930 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
931 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
932 | - break; |
|
933 | - } |
|
921 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
922 | + |
|
923 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
924 | + $url = wp_nonce_url( |
|
925 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
926 | + 'getpaid-nonce', |
|
927 | + 'getpaid-nonce' |
|
928 | + ); |
|
929 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
930 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
931 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
932 | + break; |
|
933 | + } |
|
934 | 934 | } |
935 | 935 | |
936 | - } |
|
936 | + } |
|
937 | 937 | |
938 | 938 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The main admin class. |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct() { |
41 | 41 | |
42 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
42 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
43 | + $this->admin_url = plugins_url('/', __FILE__); |
|
44 | 44 | $this->reports = new GetPaid_Reports(); |
45 | 45 | |
46 | - if ( is_admin() ) { |
|
46 | + if (is_admin()) { |
|
47 | 47 | $this->init_admin_hooks(); |
48 | 48 | } |
49 | 49 | |
@@ -54,34 +54,34 @@ discard block |
||
54 | 54 | * |
55 | 55 | */ |
56 | 56 | private function init_admin_hooks() { |
57 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
|
58 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
59 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
60 | - add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
|
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_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
77 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
78 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'), 9); |
|
58 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
59 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
60 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
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_duplicate_invoice', array($this, 'duplicate_invoice')); |
|
66 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
67 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
68 | + add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates')); |
|
69 | + add_action('getpaid_authenticated_admin_action_create_missing_pages', array($this, 'admin_create_missing_pages')); |
|
70 | + add_action('getpaid_authenticated_admin_action_refresh_permalinks', array($this, 'admin_refresh_permalinks')); |
|
71 | + add_action('getpaid_authenticated_admin_action_create_missing_tables', array($this, 'admin_create_missing_tables')); |
|
72 | + add_action('getpaid_authenticated_admin_action_migrate_old_invoices', array($this, 'admin_migrate_old_invoices')); |
|
73 | + add_action('getpaid_authenticated_admin_action_download_customers', array($this, 'admin_download_customers')); |
|
74 | + add_action('getpaid_authenticated_admin_action_recalculate_discounts', array($this, 'admin_recalculate_discounts')); |
|
75 | + add_action('getpaid_authenticated_admin_action_install_plugin', array($this, 'admin_install_plugin')); |
|
76 | + add_action('getpaid_authenticated_admin_action_connect_gateway', array($this, 'admin_connect_gateway')); |
|
77 | + add_filter('admin_footer_text', array($this, 'admin_footer_text')); |
|
78 | + do_action('getpaid_init_admin_hooks', $this); |
|
79 | 79 | |
80 | 80 | // Setup/welcome |
81 | - if ( ! empty( $_GET['page'] ) ) { |
|
82 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
81 | + if (!empty($_GET['page'])) { |
|
82 | + switch (sanitize_text_field($_GET['page'])) { |
|
83 | 83 | case 'gp-setup': |
84 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
84 | + include_once dirname(__FILE__) . '/class-getpaid-admin-setup-wizard.php'; |
|
85 | 85 | break; |
86 | 86 | } |
87 | 87 | } |
@@ -95,37 +95,37 @@ discard block |
||
95 | 95 | public function enqeue_scripts() { |
96 | 96 | global $current_screen, $pagenow; |
97 | 97 | |
98 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
98 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
99 | 99 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
100 | 100 | |
101 | - if ( ! empty( $current_screen->post_type ) ) { |
|
101 | + if (!empty($current_screen->post_type)) { |
|
102 | 102 | $page = $current_screen->post_type; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // General styles. |
106 | - if ( false !== stripos( $page, 'wpi' ) || false !== stripos( $page, 'getpaid' ) || 'gp-setup' == $page || false !== stripos( $page, 'geodir-tickets' ) ) { |
|
106 | + if (false !== stripos($page, 'wpi') || false !== stripos($page, 'getpaid') || 'gp-setup' == $page || false !== stripos($page, 'geodir-tickets')) { |
|
107 | 107 | |
108 | 108 | // Styles. |
109 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
110 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
111 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
109 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
110 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
111 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
112 | 112 | |
113 | 113 | // Scripts. |
114 | - wp_enqueue_script( 'select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
114 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
115 | 115 | |
116 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
117 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'wp-color-picker', 'jquery-ui-tooltip' ), $version ); |
|
118 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
116 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
117 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'wp-color-picker', 'jquery-ui-tooltip'), $version); |
|
118 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
119 | 119 | |
120 | 120 | } |
121 | 121 | |
122 | 122 | // Payment form scripts. |
123 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
123 | + if ('wpi_payment_form' == $page && $editing) { |
|
124 | 124 | $this->load_payment_form_scripts(); |
125 | 125 | } |
126 | 126 | |
127 | - if ( $page == 'wpinv-subscriptions' ) { |
|
128 | - wp_enqueue_script( 'postbox' ); |
|
127 | + if ($page == 'wpinv-subscriptions') { |
|
128 | + wp_enqueue_script('postbox'); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | } |
@@ -138,31 +138,31 @@ discard block |
||
138 | 138 | global $post; |
139 | 139 | |
140 | 140 | $date_range = array( |
141 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
141 | + 'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days', |
|
142 | 142 | ); |
143 | 143 | |
144 | - if ( $date_range['period'] == 'custom' ) { |
|
144 | + if ($date_range['period'] == 'custom') { |
|
145 | 145 | |
146 | - if ( isset( $_GET['from'] ) ) { |
|
147 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
146 | + if (isset($_GET['from'])) { |
|
147 | + $date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS); |
|
148 | 148 | } |
149 | 149 | |
150 | - if ( isset( $_GET['to'] ) ) { |
|
151 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
150 | + if (isset($_GET['to'])) { |
|
151 | + $date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | 155 | $i18n = array( |
156 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
157 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
158 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
159 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
160 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
156 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
157 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
158 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
159 | + 'rest_nonce' => wp_create_nonce('wp_rest'), |
|
160 | + 'rest_root' => esc_url_raw(rest_url()), |
|
161 | 161 | 'date_range' => $date_range, |
162 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
163 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
164 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
165 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
162 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
163 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
164 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
165 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
166 | 166 | 'tax' => wpinv_tax_amount(), |
167 | 167 | 'discount' => 0, |
168 | 168 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -171,39 +171,39 @@ discard block |
||
171 | 171 | 'thousand_sep' => wpinv_thousands_separator(), |
172 | 172 | 'decimal_sep' => wpinv_decimal_separator(), |
173 | 173 | 'decimals' => wpinv_decimals(), |
174 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
175 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
176 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
177 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
178 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
179 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
180 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
181 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
182 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
183 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
184 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
185 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
186 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
187 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
188 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
189 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
190 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
191 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
192 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
193 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
174 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
175 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
176 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
177 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
178 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
179 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
180 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
181 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
182 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
183 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
184 | + 'action_edit' => __('Edit', 'invoicing'), |
|
185 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
186 | + 'item_description' => __('Item Description', 'invoicing'), |
|
187 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
188 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
189 | + 'searching' => __('Searching', 'invoicing'), |
|
190 | + 'loading' => __('Loading...', 'invoicing'), |
|
191 | + 'search_customers' => __('Enter customer name or email', 'invoicing'), |
|
192 | + 'search_items' => __('Enter item name', 'invoicing'), |
|
193 | + 'graphs' => array_merge(array('refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax'), array_keys(wpinv_get_report_graphs())), |
|
194 | 194 | ); |
195 | 195 | |
196 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
196 | + if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) { |
|
197 | 197 | |
198 | - $invoice = new WPInv_Invoice( $post ); |
|
198 | + $invoice = new WPInv_Invoice($post); |
|
199 | 199 | $i18n['save_invoice'] = sprintf( |
200 | - __( 'Save %s', 'invoicing' ), |
|
201 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
200 | + __('Save %s', 'invoicing'), |
|
201 | + ucfirst($invoice->get_invoice_quote_type()) |
|
202 | 202 | ); |
203 | 203 | |
204 | 204 | $i18n['invoice_description'] = sprintf( |
205 | - __( '%s Description', 'invoicing' ), |
|
206 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
205 | + __('%s Description', 'invoicing'), |
|
206 | + ucfirst($invoice->get_invoice_quote_type()) |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | } |
@@ -217,24 +217,24 @@ discard block |
||
217 | 217 | * @param string $footer_text |
218 | 218 | * @return string |
219 | 219 | */ |
220 | - public function admin_footer_text( $footer_text ) { |
|
220 | + public function admin_footer_text($footer_text) { |
|
221 | 221 | global $current_screen; |
222 | 222 | |
223 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
223 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
224 | 224 | |
225 | - if ( ! empty( $current_screen->post_type ) ) { |
|
225 | + if (!empty($current_screen->post_type)) { |
|
226 | 226 | $page = $current_screen->post_type; |
227 | 227 | } |
228 | 228 | |
229 | 229 | // General styles. |
230 | - if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
|
230 | + if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) { |
|
231 | 231 | |
232 | 232 | // Change the footer text |
233 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
233 | + if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) { |
|
234 | 234 | |
235 | - $rating_url = esc_url( |
|
235 | + $rating_url = esc_url( |
|
236 | 236 | wp_nonce_url( |
237 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
237 | + admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'), |
|
238 | 238 | 'getpaid-nonce', |
239 | 239 | 'getpaid-nonce' |
240 | 240 | ) |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $footer_text = sprintf( |
244 | 244 | /* translators: %s: five stars */ |
245 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
245 | + __('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'), |
|
246 | 246 | "<a href='$rating_url'>★★★★★</a>" |
247 | 247 | ); |
248 | 248 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | |
251 | 251 | $footer_text = sprintf( |
252 | 252 | /* translators: %s: GetPaid */ |
253 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
253 | + __('Thank you for using %s!', 'invoicing'), |
|
254 | 254 | "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
255 | 255 | ); |
256 | 256 | |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @since 2.0.0 |
267 | 267 | */ |
268 | 268 | public function redirect_to_wordpress_rating_page() { |
269 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
270 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
269 | + update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1); |
|
270 | + wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post'); |
|
271 | 271 | exit; |
272 | 272 | } |
273 | 273 | |
@@ -278,30 +278,30 @@ discard block |
||
278 | 278 | protected function load_payment_form_scripts() { |
279 | 279 | global $post; |
280 | 280 | |
281 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
|
282 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
283 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
281 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION); |
|
282 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
283 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
284 | 284 | |
285 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
286 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
285 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
286 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable', 'wp-hooks'), $version); |
|
287 | 287 | |
288 | 288 | wp_localize_script( |
289 | 289 | 'wpinv-admin-payment-form-script', |
290 | 290 | 'wpinvPaymentFormAdmin', |
291 | 291 | array( |
292 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
293 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
292 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
293 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
294 | 294 | 'currency' => wpinv_currency_symbol(), |
295 | 295 | 'position' => wpinv_currency_position(), |
296 | 296 | 'decimals' => (int) wpinv_decimals(), |
297 | 297 | 'thousands_sep' => wpinv_thousands_separator(), |
298 | 298 | 'decimals_sep' => wpinv_decimal_separator(), |
299 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
299 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
300 | 300 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
301 | 301 | ) |
302 | 302 | ); |
303 | 303 | |
304 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
304 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | |
@@ -312,24 +312,24 @@ discard block |
||
312 | 312 | * @return string |
313 | 313 | * |
314 | 314 | */ |
315 | - public function admin_body_class( $classes ) { |
|
315 | + public function admin_body_class($classes) { |
|
316 | 316 | global $pagenow, $post, $current_screen; |
317 | 317 | |
318 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
318 | + $page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
|
319 | 319 | |
320 | - if ( ! empty( $current_screen->post_type ) ) { |
|
320 | + if (!empty($current_screen->post_type)) { |
|
321 | 321 | $page = $current_screen->post_type; |
322 | 322 | } |
323 | 323 | |
324 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
325 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
324 | + if (false !== stripos($page, 'wpi')) { |
|
325 | + $classes .= ' wpi-' . sanitize_key($page); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
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 | |
@@ -348,21 +348,21 @@ discard block |
||
348 | 348 | 'version' => WPINV_VERSION, |
349 | 349 | 'support_url' => 'https://wpgetpaid.com/support/', |
350 | 350 | 'documentation_url' => 'https://docs.wpgetpaid.com/', |
351 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
351 | + 'activated' => (int) get_option('gepaid_installed_on'), |
|
352 | 352 | ) |
353 | 353 | ); |
354 | 354 | |
355 | 355 | new AyeCode_Connect_Helper( |
356 | 356 | array( |
357 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
358 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
359 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
360 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
361 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
362 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
363 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
357 | + 'connect_title' => __('WP Invoicing - an AyeCode product!', 'invoicing'), |
|
358 | + 'connect_external' => __('Please confirm you wish to connect your site?', 'invoicing'), |
|
359 | + 'connect' => sprintf(__('<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing'), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>'), |
|
360 | + 'connect_button' => __('Connect Site', 'invoicing'), |
|
361 | + 'connecting_button' => __('Connecting...', 'invoicing'), |
|
362 | + 'error_localhost' => __('This service will only work with a live domain, not a localhost.', 'invoicing'), |
|
363 | + 'error' => __('Something went wrong, please refresh and try again.', 'invoicing'), |
|
364 | 364 | ), |
365 | - array( 'wpi-addons' ) |
|
365 | + array('wpi-addons') |
|
366 | 366 | ); |
367 | 367 | |
368 | 368 | } |
@@ -374,20 +374,20 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function activation_redirect() { |
376 | 376 | |
377 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
377 | + $redirected = get_option('wpinv_redirected_to_settings'); |
|
378 | 378 | |
379 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
379 | + if (!empty($redirected) || wp_doing_ajax() || !current_user_can('manage_options')) { |
|
380 | 380 | return; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // Bail if activating from network, or bulk |
384 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
384 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
385 | 385 | return; |
386 | 386 | } |
387 | 387 | |
388 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
388 | + update_option('wpinv_redirected_to_settings', 1); |
|
389 | 389 | |
390 | - wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
|
390 | + wp_safe_redirect(admin_url('index.php?page=gp-setup')); |
|
391 | 391 | exit; |
392 | 392 | |
393 | 393 | } |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | */ |
398 | 398 | public function maybe_do_admin_action() { |
399 | 399 | |
400 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
401 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
402 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
400 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
401 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
402 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | } |
@@ -409,24 +409,24 @@ discard block |
||
409 | 409 | * |
410 | 410 | * @param array $args |
411 | 411 | */ |
412 | - public function duplicate_invoice( $args ) { |
|
412 | + public function duplicate_invoice($args) { |
|
413 | 413 | |
414 | - if ( empty( $args['invoice_id'] ) ) { |
|
414 | + if (empty($args['invoice_id'])) { |
|
415 | 415 | return; |
416 | 416 | } |
417 | 417 | |
418 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
418 | + $invoice = new WPInv_Invoice((int) $args['invoice_id']); |
|
419 | 419 | |
420 | - if ( ! $invoice->exists() ) { |
|
420 | + if (!$invoice->exists()) { |
|
421 | 421 | return; |
422 | 422 | } |
423 | 423 | |
424 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
424 | + $new_invoice = getpaid_duplicate_invoice($invoice); |
|
425 | 425 | $new_invoice->save(); |
426 | 426 | |
427 | - if ( $new_invoice->exists() ) { |
|
427 | + if ($new_invoice->exists()) { |
|
428 | 428 | |
429 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
429 | + getpaid_admin()->show_success(__('Invoice duplicated successfully.', 'newsletter-optin-box')); |
|
430 | 430 | |
431 | 431 | wp_safe_redirect( |
432 | 432 | add_query_arg( |
@@ -434,14 +434,14 @@ discard block |
||
434 | 434 | 'action' => 'edit', |
435 | 435 | 'post' => $new_invoice->get_id(), |
436 | 436 | ), |
437 | - admin_url( 'post.php' ) |
|
437 | + admin_url('post.php') |
|
438 | 438 | ) |
439 | 439 | ); |
440 | 440 | exit; |
441 | 441 | |
442 | 442 | } |
443 | 443 | |
444 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
444 | + getpaid_admin()->show_error(__('There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box')); |
|
445 | 445 | |
446 | 446 | } |
447 | 447 | |
@@ -450,34 +450,34 @@ discard block |
||
450 | 450 | * |
451 | 451 | * @param array $args |
452 | 452 | */ |
453 | - public function duplicate_payment_form( $args ) { |
|
453 | + public function duplicate_payment_form($args) { |
|
454 | 454 | |
455 | - if ( empty( $args['form_id'] ) ) { |
|
455 | + if (empty($args['form_id'])) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | |
459 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
459 | + $form = new GetPaid_Payment_Form((int) $args['form_id']); |
|
460 | 460 | |
461 | - if ( ! $form->exists() ) { |
|
461 | + if (!$form->exists()) { |
|
462 | 462 | return; |
463 | 463 | } |
464 | 464 | |
465 | 465 | $new_form = new GetPaid_Payment_Form(); |
466 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
467 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
468 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
469 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
466 | + $new_form->set_author($form->get_author('edit')); |
|
467 | + $new_form->set_name($form->get_name('edit') . __('(copy)', 'invoicing')); |
|
468 | + $new_form->set_elements($form->get_elements('edit')); |
|
469 | + $new_form->set_items($form->get_items('edit')); |
|
470 | 470 | $new_form->save(); |
471 | 471 | |
472 | - if ( $new_form->exists() ) { |
|
473 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
474 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
472 | + if ($new_form->exists()) { |
|
473 | + $this->show_success(__('Form duplicated successfully', 'invoicing')); |
|
474 | + $url = get_edit_post_link($new_form->get_id(), 'edit'); |
|
475 | 475 | } else { |
476 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
477 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
476 | + $this->show_error(__('Unable to duplicate form', 'invoicing')); |
|
477 | + $url = remove_query_arg(array('getpaid-admin-action', 'form_id', 'getpaid-nonce')); |
|
478 | 478 | } |
479 | 479 | |
480 | - wp_redirect( $url ); |
|
480 | + wp_redirect($url); |
|
481 | 481 | exit; |
482 | 482 | } |
483 | 483 | |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * |
487 | 487 | * @param array $args |
488 | 488 | */ |
489 | - public function send_customer_invoice( $args ) { |
|
490 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
491 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
489 | + public function send_customer_invoice($args) { |
|
490 | + getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']), true); |
|
491 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
492 | 492 | exit; |
493 | 493 | } |
494 | 494 | |
@@ -497,16 +497,16 @@ discard block |
||
497 | 497 | * |
498 | 498 | * @param array $args |
499 | 499 | */ |
500 | - public function send_customer_payment_reminder( $args ) { |
|
501 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
500 | + public function send_customer_payment_reminder($args) { |
|
501 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
502 | 502 | |
503 | - if ( $sent ) { |
|
504 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
503 | + if ($sent) { |
|
504 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
505 | 505 | } else { |
506 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
506 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
507 | 507 | } |
508 | 508 | |
509 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
509 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
510 | 510 | exit; |
511 | 511 | } |
512 | 512 | |
@@ -516,8 +516,8 @@ discard block |
||
516 | 516 | */ |
517 | 517 | public function admin_reset_tax_rates() { |
518 | 518 | |
519 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
520 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
519 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
520 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
521 | 521 | exit; |
522 | 522 | |
523 | 523 | } |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | public function admin_create_missing_pages() { |
530 | 530 | $installer = new GetPaid_Installer(); |
531 | 531 | $installer->create_pages(); |
532 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
533 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
532 | + $this->show_success(__('GetPaid pages updated.', 'invoicing')); |
|
533 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
534 | 534 | exit; |
535 | 535 | } |
536 | 536 | |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public function admin_refresh_permalinks() { |
541 | 541 | flush_rewrite_rules(); |
542 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
543 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
542 | + $this->show_success(__('Permalinks refreshed.', 'invoicing')); |
|
543 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
544 | 544 | exit; |
545 | 545 | } |
546 | 546 | |
@@ -552,35 +552,35 @@ discard block |
||
552 | 552 | global $wpdb; |
553 | 553 | $installer = new GetPaid_Installer(); |
554 | 554 | |
555 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
555 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'") != $wpdb->prefix . 'wpinv_subscriptions') { |
|
556 | 556 | $installer->create_subscriptions_table(); |
557 | 557 | |
558 | - if ( $wpdb->last_error !== '' ) { |
|
559 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
558 | + if ($wpdb->last_error !== '') { |
|
559 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
563 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") != $wpdb->prefix . 'getpaid_invoices') { |
|
564 | 564 | $installer->create_invoices_table(); |
565 | 565 | |
566 | - if ( '' !== $wpdb->last_error ) { |
|
567 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
566 | + if ('' !== $wpdb->last_error) { |
|
567 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
571 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'") != $wpdb->prefix . 'getpaid_invoice_items') { |
|
572 | 572 | $installer->create_invoice_items_table(); |
573 | 573 | |
574 | - if ( '' !== $wpdb->last_error ) { |
|
575 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
574 | + if ('' !== $wpdb->last_error) { |
|
575 | + $this->show_error(__('Your GetPaid tables have been updated:', 'invoicing') . ' ' . $wpdb->last_error); |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 | |
579 | - if ( ! $this->has_notices() ) { |
|
580 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
579 | + if (!$this->has_notices()) { |
|
580 | + $this->show_success(__('Your GetPaid tables have been updated.', 'invoicing')); |
|
581 | 581 | } |
582 | 582 | |
583 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
583 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
584 | 584 | exit; |
585 | 585 | } |
586 | 586 | |
@@ -595,10 +595,10 @@ discard block |
||
595 | 595 | $installer->migrate_old_invoices(); |
596 | 596 | |
597 | 597 | // Show an admin message. |
598 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
598 | + $this->show_success(__('Your invoices have been migrated.', 'invoicing')); |
|
599 | 599 | |
600 | 600 | // Redirect the admin. |
601 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
601 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
602 | 602 | exit; |
603 | 603 | |
604 | 604 | } |
@@ -610,78 +610,78 @@ discard block |
||
610 | 610 | public function admin_download_customers() { |
611 | 611 | global $wpdb; |
612 | 612 | |
613 | - $output = fopen( 'php://output', 'w' ); |
|
613 | + $output = fopen('php://output', 'w'); |
|
614 | 614 | |
615 | - if ( false === $output ) { |
|
616 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
615 | + if (false === $output) { |
|
616 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
617 | 617 | } |
618 | 618 | |
619 | - header( 'Content-Type:text/csv' ); |
|
620 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
619 | + header('Content-Type:text/csv'); |
|
620 | + header('Content-Disposition:attachment;filename=customers.csv'); |
|
621 | 621 | |
622 | 622 | $post_types = ''; |
623 | 623 | |
624 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
625 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
624 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
625 | + $post_types .= $wpdb->prepare('post_type=%s OR ', $post_type); |
|
626 | 626 | } |
627 | 627 | |
628 | - $post_types = rtrim( $post_types, ' OR' ); |
|
628 | + $post_types = rtrim($post_types, ' OR'); |
|
629 | 629 | |
630 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
630 | + $customers = $wpdb->get_col("SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types"); |
|
631 | 631 | |
632 | 632 | $columns = array( |
633 | - 'name' => __( 'Name', 'invoicing' ), |
|
634 | - 'email' => __( 'Email', 'invoicing' ), |
|
635 | - 'country' => __( 'Country', 'invoicing' ), |
|
636 | - 'state' => __( 'State', 'invoicing' ), |
|
637 | - 'city' => __( 'City', 'invoicing' ), |
|
638 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
639 | - 'address' => __( 'Address', 'invoicing' ), |
|
640 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
641 | - 'company' => __( 'Company', 'invoicing' ), |
|
642 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
643 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
644 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
645 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
633 | + 'name' => __('Name', 'invoicing'), |
|
634 | + 'email' => __('Email', 'invoicing'), |
|
635 | + 'country' => __('Country', 'invoicing'), |
|
636 | + 'state' => __('State', 'invoicing'), |
|
637 | + 'city' => __('City', 'invoicing'), |
|
638 | + 'zip' => __('ZIP', 'invoicing'), |
|
639 | + 'address' => __('Address', 'invoicing'), |
|
640 | + 'phone' => __('Phone', 'invoicing'), |
|
641 | + 'company' => __('Company', 'invoicing'), |
|
642 | + 'company_id' => __('Company ID', 'invoicing'), |
|
643 | + 'invoices' => __('Invoices', 'invoicing'), |
|
644 | + 'total_raw' => __('Total Spend', 'invoicing'), |
|
645 | + 'signup' => __('Date created', 'invoicing'), |
|
646 | 646 | ); |
647 | 647 | |
648 | 648 | // Output the csv column headers. |
649 | - fputcsv( $output, array_values( $columns ) ); |
|
649 | + fputcsv($output, array_values($columns)); |
|
650 | 650 | |
651 | 651 | // Loop through |
652 | 652 | $table = new WPInv_Customers_Table(); |
653 | - foreach ( $customers as $customer_id ) { |
|
653 | + foreach ($customers as $customer_id) { |
|
654 | 654 | |
655 | - $user = get_user_by( 'id', $customer_id ); |
|
655 | + $user = get_user_by('id', $customer_id); |
|
656 | 656 | $row = array(); |
657 | - if ( empty( $user ) ) { |
|
657 | + if (empty($user)) { |
|
658 | 658 | continue; |
659 | 659 | } |
660 | 660 | |
661 | - foreach ( array_keys( $columns ) as $column ) { |
|
661 | + foreach (array_keys($columns) as $column) { |
|
662 | 662 | |
663 | 663 | $method = 'column_' . $column; |
664 | 664 | |
665 | - if ( 'name' == $column ) { |
|
666 | - $value = esc_html( $user->display_name ); |
|
667 | - } elseif ( 'email' == $column ) { |
|
668 | - $value = sanitize_email( $user->user_email ); |
|
669 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
670 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
665 | + if ('name' == $column) { |
|
666 | + $value = esc_html($user->display_name); |
|
667 | + } elseif ('email' == $column) { |
|
668 | + $value = sanitize_email($user->user_email); |
|
669 | + } elseif (is_callable(array($table, $method))) { |
|
670 | + $value = wp_strip_all_tags($table->$method($user)); |
|
671 | 671 | } |
672 | 672 | |
673 | - if ( empty( $value ) ) { |
|
674 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
673 | + if (empty($value)) { |
|
674 | + $value = esc_html(get_user_meta($user->ID, '_wpinv_' . $column, true)); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | $row[] = $value; |
678 | 678 | |
679 | 679 | } |
680 | 680 | |
681 | - fputcsv( $output, $row ); |
|
681 | + fputcsv($output, $row); |
|
682 | 682 | } |
683 | 683 | |
684 | - fclose( $output ); |
|
684 | + fclose($output); |
|
685 | 685 | exit; |
686 | 686 | |
687 | 687 | } |
@@ -691,27 +691,27 @@ discard block |
||
691 | 691 | * |
692 | 692 | * @param array $data |
693 | 693 | */ |
694 | - public function admin_install_plugin( $data ) { |
|
694 | + public function admin_install_plugin($data) { |
|
695 | 695 | |
696 | - if ( ! empty( $data['plugins'] ) ) { |
|
696 | + if (!empty($data['plugins'])) { |
|
697 | 697 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
698 | 698 | wp_cache_flush(); |
699 | 699 | |
700 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
701 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
702 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
703 | - $installed = $upgrader->install( $plugin_zip ); |
|
700 | + foreach ($data['plugins'] as $slug => $file) { |
|
701 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip'); |
|
702 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
703 | + $installed = $upgrader->install($plugin_zip); |
|
704 | 704 | |
705 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
706 | - activate_plugin( $file, '', false, true ); |
|
705 | + if (!is_wp_error($installed) && $installed) { |
|
706 | + activate_plugin($file, '', false, true); |
|
707 | 707 | } else { |
708 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
708 | + wpinv_error_log($upgrader->skin->get_upgrade_messages(), false); |
|
709 | 709 | } |
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
714 | - wp_safe_redirect( $redirect ); |
|
713 | + $redirect = isset($data['redirect']) ? esc_url_raw($data['redirect']) : admin_url('plugins.php'); |
|
714 | + wp_safe_redirect($redirect); |
|
715 | 715 | exit; |
716 | 716 | |
717 | 717 | } |
@@ -721,41 +721,41 @@ discard block |
||
721 | 721 | * |
722 | 722 | * @param array $data |
723 | 723 | */ |
724 | - public function admin_connect_gateway( $data ) { |
|
724 | + public function admin_connect_gateway($data) { |
|
725 | 725 | |
726 | - if ( ! empty( $data['plugin'] ) ) { |
|
726 | + if (!empty($data['plugin'])) { |
|
727 | 727 | |
728 | - $gateway = sanitize_key( $data['plugin'] ); |
|
729 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
728 | + $gateway = sanitize_key($data['plugin']); |
|
729 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
730 | 730 | |
731 | - if ( ! empty( $connect_url ) ) { |
|
732 | - wp_redirect( $connect_url ); |
|
731 | + if (!empty($connect_url)) { |
|
732 | + wp_redirect($connect_url); |
|
733 | 733 | exit; |
734 | 734 | } |
735 | 735 | |
736 | - if ( 'stripe' == $data['plugin'] ) { |
|
736 | + if ('stripe' == $data['plugin']) { |
|
737 | 737 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
738 | 738 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
739 | 739 | wp_cache_flush(); |
740 | 740 | |
741 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
742 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
743 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
744 | - $upgrader->install( $plugin_zip ); |
|
741 | + if (!array_key_exists('getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins())) { |
|
742 | + $plugin_zip = esc_url('https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip'); |
|
743 | + $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin()); |
|
744 | + $upgrader->install($plugin_zip); |
|
745 | 745 | } |
746 | 746 | |
747 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
747 | + activate_plugin('getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true); |
|
748 | 748 | } |
749 | 749 | |
750 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
751 | - if ( ! empty( $connect_url ) ) { |
|
752 | - wp_redirect( $connect_url ); |
|
750 | + $connect_url = apply_filters("getpaid_get_{$gateway}_connect_url", false, $data); |
|
751 | + if (!empty($connect_url)) { |
|
752 | + wp_redirect($connect_url); |
|
753 | 753 | exit; |
754 | 754 | } |
755 | 755 | } |
756 | 756 | |
757 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
758 | - wp_safe_redirect( $redirect ); |
|
757 | + $redirect = isset($data['redirect']) ? esc_url_raw(urldecode($data['redirect'])) : admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
|
758 | + wp_safe_redirect($redirect); |
|
759 | 759 | exit; |
760 | 760 | |
761 | 761 | } |
@@ -769,35 +769,35 @@ discard block |
||
769 | 769 | |
770 | 770 | // Fetch all invoices that have discount codes. |
771 | 771 | $table = $wpdb->prefix . 'getpaid_invoices'; |
772 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
772 | + $invoices = $wpdb->get_col("SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''"); |
|
773 | 773 | |
774 | - foreach ( $invoices as $invoice ) { |
|
774 | + foreach ($invoices as $invoice) { |
|
775 | 775 | |
776 | - $invoice = new WPInv_Invoice( $invoice ); |
|
776 | + $invoice = new WPInv_Invoice($invoice); |
|
777 | 777 | |
778 | - if ( ! $invoice->exists() ) { |
|
778 | + if (!$invoice->exists()) { |
|
779 | 779 | continue; |
780 | 780 | } |
781 | 781 | |
782 | 782 | // Abort if the discount does not exist or does not apply here. |
783 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
784 | - if ( ! $discount->exists() ) { |
|
783 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
784 | + if (!$discount->exists()) { |
|
785 | 785 | continue; |
786 | 786 | } |
787 | 787 | |
788 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
788 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
789 | 789 | $invoice->recalculate_total(); |
790 | 790 | |
791 | - if ( $invoice->get_total_discount() > 0 ) { |
|
791 | + if ($invoice->get_total_discount() > 0) { |
|
792 | 792 | $invoice->save(); |
793 | 793 | } |
794 | 794 | } |
795 | 795 | |
796 | 796 | // Show an admin message. |
797 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
797 | + $this->show_success(__('Discounts have been recalculated.', 'invoicing')); |
|
798 | 798 | |
799 | 799 | // Redirect the admin. |
800 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
800 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce'))); |
|
801 | 801 | exit; |
802 | 802 | |
803 | 803 | } |
@@ -809,8 +809,8 @@ discard block |
||
809 | 809 | * @return array |
810 | 810 | */ |
811 | 811 | public function get_notices() { |
812 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
813 | - return is_array( $notices ) ? $notices : array(); |
|
812 | + $notices = get_option('wpinv_admin_notices'); |
|
813 | + return is_array($notices) ? $notices : array(); |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | /** |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | * @return array |
821 | 821 | */ |
822 | 822 | public function has_notices() { |
823 | - return count( $this->get_notices() ) > 0; |
|
823 | + return count($this->get_notices()) > 0; |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | * @since 1.0.19 |
831 | 831 | */ |
832 | 832 | public function clear_notices() { |
833 | - delete_option( 'wpinv_admin_notices' ); |
|
833 | + delete_option('wpinv_admin_notices'); |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | /** |
@@ -839,16 +839,16 @@ discard block |
||
839 | 839 | * @access public |
840 | 840 | * @since 1.0.19 |
841 | 841 | */ |
842 | - public function save_notice( $type, $message ) { |
|
842 | + public function save_notice($type, $message) { |
|
843 | 843 | $notices = $this->get_notices(); |
844 | 844 | |
845 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
846 | - $notices[ $type ] = array(); |
|
845 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
846 | + $notices[$type] = array(); |
|
847 | 847 | } |
848 | 848 | |
849 | - $notices[ $type ][] = $message; |
|
849 | + $notices[$type][] = $message; |
|
850 | 850 | |
851 | - update_option( 'wpinv_admin_notices', $notices ); |
|
851 | + update_option('wpinv_admin_notices', $notices); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -858,8 +858,8 @@ discard block |
||
858 | 858 | * @access public |
859 | 859 | * @since 1.0.19 |
860 | 860 | */ |
861 | - public function show_success( $msg ) { |
|
862 | - $this->save_notice( 'success', $msg ); |
|
861 | + public function show_success($msg) { |
|
862 | + $this->save_notice('success', $msg); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
@@ -869,8 +869,8 @@ discard block |
||
869 | 869 | * @param string $msg The message to qeue. |
870 | 870 | * @since 1.0.19 |
871 | 871 | */ |
872 | - public function show_error( $msg ) { |
|
873 | - $this->save_notice( 'error', $msg ); |
|
872 | + public function show_error($msg) { |
|
873 | + $this->save_notice('error', $msg); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @param string $msg The message to qeue. |
881 | 881 | * @since 1.0.19 |
882 | 882 | */ |
883 | - public function show_warning( $msg ) { |
|
884 | - $this->save_notice( 'warning', $msg ); |
|
883 | + public function show_warning($msg) { |
|
884 | + $this->save_notice('warning', $msg); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
@@ -891,8 +891,8 @@ discard block |
||
891 | 891 | * @param string $msg The message to qeue. |
892 | 892 | * @since 1.0.19 |
893 | 893 | */ |
894 | - public function show_info( $msg ) { |
|
895 | - $this->save_notice( 'info', $msg ); |
|
894 | + public function show_info($msg) { |
|
895 | + $this->save_notice('info', $msg); |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | /** |
@@ -906,29 +906,29 @@ discard block |
||
906 | 906 | $notices = $this->get_notices(); |
907 | 907 | $this->clear_notices(); |
908 | 908 | |
909 | - foreach ( $notices as $type => $messages ) { |
|
909 | + foreach ($notices as $type => $messages) { |
|
910 | 910 | |
911 | - if ( ! is_array( $messages ) ) { |
|
911 | + if (!is_array($messages)) { |
|
912 | 912 | continue; |
913 | 913 | } |
914 | 914 | |
915 | - $type = esc_attr( $type ); |
|
916 | - foreach ( $messages as $message ) { |
|
917 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
915 | + $type = esc_attr($type); |
|
916 | + foreach ($messages as $message) { |
|
917 | + echo wp_kses_post("<div class='notice notice-$type is-dismissible'><p>$message</p></div>"); |
|
918 | 918 | } |
919 | 919 | } |
920 | 920 | |
921 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
921 | + foreach (array('checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page') as $page) { |
|
922 | 922 | |
923 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
924 | - $url = wp_nonce_url( |
|
925 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
923 | + if (!is_numeric(wpinv_get_option($page, false))) { |
|
924 | + $url = wp_nonce_url( |
|
925 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
926 | 926 | 'getpaid-nonce', |
927 | 927 | 'getpaid-nonce' |
928 | 928 | ); |
929 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
930 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
931 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
929 | + $message = __('Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing'); |
|
930 | + $message2 = __('Generate Pages', 'invoicing'); |
|
931 | + echo wp_kses_post("<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"); |
|
932 | 932 | break; |
933 | 933 | } |
934 | 934 | } |