@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | */ |
36 | 36 | protected function inflectModuleVars($vars) |
37 | 37 | { |
38 | - $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
39 | - $vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- |
|
40 | - $vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module |
|
41 | - $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
42 | - $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
38 | + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
39 | + $vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- |
|
40 | + $vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module |
|
41 | + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
42 | + $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
43 | 43 | |
44 | 44 | return $vars; |
45 | 45 | } |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | protected function inflectThemeVars($vars) |
54 | 54 | { |
55 | - $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
56 | - $vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- |
|
57 | - $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme |
|
58 | - $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
59 | - $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
55 | + $vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
|
56 | + $vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- |
|
57 | + $vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme |
|
58 | + $vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
|
59 | + $vars['name'] = ucwords($vars['name']); // make module name camelcased |
|
60 | 60 | |
61 | 61 | return $vars; |
62 | 62 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | */ |
38 | 38 | private function correctPluginName($vars) |
39 | 39 | { |
40 | - $camelCasedName = preg_replace_callback('/(-[a-z])/', function ($matches) { |
|
40 | + $camelCasedName = preg_replace_callback('/(-[a-z])/', function($matches) { |
|
41 | 41 | return strtoupper($matches[0][1]); |
42 | 42 | }, $vars['name']); |
43 | 43 |
@@ -6,8 +6,8 @@ |
||
6 | 6 | } |
7 | 7 | } |
8 | 8 | if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__ . '/../../../autoload.php'))) { |
9 | - die('You must set up the project dependencies, run the following commands:'.PHP_EOL. |
|
10 | - 'curl -s http://getcomposer.org/installer | php'.PHP_EOL. |
|
11 | - 'php composer.phar install'.PHP_EOL); |
|
9 | + die('You must set up the project dependencies, run the following commands:' . PHP_EOL . |
|
10 | + 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . |
|
11 | + 'php composer.phar install' . PHP_EOL); |
|
12 | 12 | } |
13 | 13 | return $loader; |
@@ -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. |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | * @return WP_Font_Awesome_Settings - Main instance. |
86 | 86 | */ |
87 | 87 | public static function instance() { |
88 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
88 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
89 | 89 | self::$instance = new WP_Font_Awesome_Settings; |
90 | 90 | |
91 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
91 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
92 | 92 | |
93 | - if ( is_admin() ) { |
|
94 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
95 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
93 | + if (is_admin()) { |
|
94 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
95 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
96 | 96 | } |
97 | 97 | |
98 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
98 | + do_action('wp_font_awesome_settings_loaded'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return self::$instance; |
@@ -109,30 +109,30 @@ discard block |
||
109 | 109 | public function init() { |
110 | 110 | $this->settings = $this->get_settings(); |
111 | 111 | |
112 | - if ( $this->settings['type'] == 'CSS' ) { |
|
112 | + if ($this->settings['type'] == 'CSS') { |
|
113 | 113 | |
114 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
115 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit; |
|
114 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
115 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); //echo '###';exit; |
|
116 | 116 | } |
117 | 117 | |
118 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
119 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
118 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
119 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | } else { |
123 | 123 | |
124 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
125 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit; |
|
124 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
125 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); //echo '###';exit; |
|
126 | 126 | } |
127 | 127 | |
128 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
129 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
128 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
129 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | // remove font awesome if set to do so |
134 | - if ( $this->settings['dequeue'] == '1' ) { |
|
135 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
134 | + if ($this->settings['dequeue'] == '1') { |
|
135 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | } |
@@ -144,15 +144,15 @@ discard block |
||
144 | 144 | // build url |
145 | 145 | $url = $this->get_url(); |
146 | 146 | |
147 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
148 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
149 | - wp_enqueue_style( 'font-awesome' ); |
|
147 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
148 | + wp_register_style('font-awesome', $url, array(), null); |
|
149 | + wp_enqueue_style('font-awesome'); |
|
150 | 150 | |
151 | - if ( $this->settings['shims'] ) { |
|
152 | - $url = $this->get_url( true ); |
|
153 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
154 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
155 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
151 | + if ($this->settings['shims']) { |
|
152 | + $url = $this->get_url(true); |
|
153 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
154 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
155 | + wp_enqueue_style('font-awesome-shims'); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | // build url |
164 | 164 | $url = $this->get_url(); |
165 | 165 | |
166 | - $deregister_function = 'wp'.'_'.'deregister'.'_'.'script'; |
|
167 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
168 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
169 | - wp_enqueue_script( 'font-awesome' ); |
|
166 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
167 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
168 | + wp_register_script('font-awesome', $url, array(), null); |
|
169 | + wp_enqueue_script('font-awesome'); |
|
170 | 170 | |
171 | - if ( $this->settings['shims'] ) { |
|
172 | - $url = $this->get_url( true ); |
|
173 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
174 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
175 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
171 | + if ($this->settings['shims']) { |
|
172 | + $url = $this->get_url(true); |
|
173 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
174 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
175 | + wp_enqueue_script('font-awesome-shims'); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return string The url to the file. |
185 | 185 | */ |
186 | - public function get_url( $shims = false ) { |
|
186 | + public function get_url($shims = false) { |
|
187 | 187 | $script = $shims ? 'v4-shims' : 'all'; |
188 | 188 | $type = $this->settings['type']; |
189 | 189 | $version = $this->settings['version']; |
190 | 190 | |
191 | 191 | $url = "https://use.fontawesome.com/releases/"; // CDN |
192 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
192 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
193 | 193 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
194 | 194 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
195 | 195 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -208,16 +208,16 @@ discard block |
||
208 | 208 | * |
209 | 209 | * @return string The filtered url. |
210 | 210 | */ |
211 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
211 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
212 | 212 | |
213 | - if ( $_context == 'display' |
|
214 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
215 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
213 | + if ($_context == 'display' |
|
214 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
215 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
216 | 216 | ) {// it's a font-awesome-url (probably) |
217 | 217 | |
218 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
219 | - if ( $this->settings['type'] == 'JS' ) { |
|
220 | - if ( $this->settings['js-pseudo'] ) { |
|
218 | + if (strstr($url, "wpfas=true") !== false) { |
|
219 | + if ($this->settings['type'] == 'JS') { |
|
220 | + if ($this->settings['js-pseudo']) { |
|
221 | 221 | $url .= "' data-search-pseudo-elements defer='defer"; |
222 | 222 | } else { |
223 | 223 | $url .= "' defer='defer"; |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * Register the database settings with WordPress. |
237 | 237 | */ |
238 | 238 | public function register_settings() { |
239 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
239 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
245 | 245 | */ |
246 | 246 | public function menu_item() { |
247 | - $menu_function = 'add'.'_'.'options'.'_'.'page'; // won't pass theme check if function name present in theme |
|
247 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
248 | 248 | call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
249 | 249 | $this, |
250 | 250 | 'settings_page' |
251 | - ) ); |
|
251 | + )); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function get_settings() { |
260 | 260 | |
261 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
261 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
262 | 262 | |
263 | 263 | $defaults = array( |
264 | 264 | 'type' => 'CSS', // type to use, CSS or JS |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
270 | 270 | ); |
271 | 271 | |
272 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
272 | + $settings = wp_parse_args($db_settings, $defaults); |
|
273 | 273 | |
274 | 274 | /** |
275 | 275 | * Filter the Font Awesome settings. |
276 | 276 | * |
277 | 277 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
278 | 278 | */ |
279 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
279 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | * The settings page html output. |
285 | 285 | */ |
286 | 286 | public function settings_page() { |
287 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
288 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
287 | + if (!current_user_can('manage_options')) { |
|
288 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
292 | - if(isset($_REQUEST['force-version-check'])){ |
|
292 | + if (isset($_REQUEST['force-version-check'])) { |
|
293 | 293 | $this->get_latest_version($force_api = true); |
294 | 294 | } |
295 | 295 | ?> |
@@ -297,47 +297,47 @@ discard block |
||
297 | 297 | <h1><?php echo $this->name; ?></h1> |
298 | 298 | <form method="post" action="options.php"> |
299 | 299 | <?php |
300 | - settings_fields( 'wp-font-awesome-settings' ); |
|
301 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
300 | + settings_fields('wp-font-awesome-settings'); |
|
301 | + do_settings_sections('wp-font-awesome-settings'); |
|
302 | 302 | ?> |
303 | 303 | <table class="form-table"> |
304 | 304 | <tr valign="top"> |
305 | - <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
305 | + <th scope="row"><label for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
306 | 306 | <td> |
307 | 307 | <select name="wp-font-awesome-settings[type]" id="wpfas-type"> |
308 | 308 | <option |
309 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
310 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
309 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
310 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
311 | 311 | </select> |
312 | 312 | </td> |
313 | 313 | </tr> |
314 | 314 | |
315 | 315 | <tr valign="top"> |
316 | - <th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
316 | + <th scope="row"><label for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
317 | 317 | <td> |
318 | 318 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
319 | 319 | <option |
320 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
320 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
321 | 321 | </option> |
322 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
322 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
323 | 323 | 5.6.0 |
324 | 324 | </option> |
325 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
325 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
326 | 326 | 5.5.0 |
327 | 327 | </option> |
328 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
328 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
329 | 329 | 5.4.0 |
330 | 330 | </option> |
331 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
331 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
332 | 332 | 5.3.0 |
333 | 333 | </option> |
334 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
334 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
335 | 335 | 5.2.0 |
336 | 336 | </option> |
337 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
337 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
338 | 338 | 5.1.0 |
339 | 339 | </option> |
340 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
340 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
341 | 341 | 4.7.1 (CSS only) |
342 | 342 | </option> |
343 | 343 | </select> |
@@ -345,51 +345,51 @@ discard block |
||
345 | 345 | </tr> |
346 | 346 | |
347 | 347 | <tr valign="top"> |
348 | - <th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
348 | + <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
349 | 349 | <td> |
350 | 350 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
351 | 351 | <option |
352 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
352 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
353 | 353 | <option |
354 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
354 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
355 | 355 | <option |
356 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
356 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
357 | 357 | </select> |
358 | 358 | </td> |
359 | 359 | </tr> |
360 | 360 | |
361 | 361 | <tr valign="top"> |
362 | 362 | <th scope="row"><label |
363 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label></th> |
|
363 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label></th> |
|
364 | 364 | <td> |
365 | 365 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
366 | 366 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
367 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
368 | - <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> |
|
367 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
368 | + <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> |
|
369 | 369 | </td> |
370 | 370 | </tr> |
371 | 371 | |
372 | 372 | <tr valign="top"> |
373 | 373 | <th scope="row"><label |
374 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
374 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
375 | 375 | </th> |
376 | 376 | <td> |
377 | 377 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
378 | 378 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
379 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
379 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
380 | 380 | id="wpfas-js-pseudo"/> |
381 | - <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> |
|
381 | + <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> |
|
382 | 382 | </td> |
383 | 383 | </tr> |
384 | 384 | |
385 | 385 | <tr valign="top"> |
386 | - <th scope="row"><label for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
386 | + <th scope="row"><label for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
387 | 387 | <td> |
388 | 388 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
389 | 389 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
390 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
390 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
391 | 391 | id="wpfas-dequeue"/> |
392 | - <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> |
|
392 | + <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> |
|
393 | 393 | </td> |
394 | 394 | </tr> |
395 | 395 | |
@@ -414,12 +414,12 @@ discard block |
||
414 | 414 | * |
415 | 415 | * @return string Either a valid version number or an empty string. |
416 | 416 | */ |
417 | - public function validate_version_number( $version ) { |
|
417 | + public function validate_version_number($version) { |
|
418 | 418 | |
419 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
419 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
420 | 420 | // valid |
421 | 421 | } else { |
422 | - $version = '';// not validated |
|
422 | + $version = ''; // not validated |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | return $version; |
@@ -437,16 +437,16 @@ discard block |
||
437 | 437 | public function get_latest_version($force_api = false) { |
438 | 438 | $latest_version = $this->latest; |
439 | 439 | |
440 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
440 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
441 | 441 | |
442 | - if ( $cache === false || $force_api) { // its not set |
|
442 | + if ($cache === false || $force_api) { // its not set |
|
443 | 443 | $api_ver = $this->get_latest_version_from_api(); |
444 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
444 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
445 | 445 | $latest_version = $api_ver; |
446 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
446 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
447 | 447 | } |
448 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
449 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
448 | + } elseif ($this->validate_version_number($cache)) { |
|
449 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
450 | 450 | $latest_version = $cache; |
451 | 451 | } |
452 | 452 | } |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | */ |
463 | 463 | public function get_latest_version_from_api() { |
464 | 464 | $version = "0"; |
465 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
466 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
467 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
468 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
465 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
466 | + if (!is_wp_error($response) && is_array($response)) { |
|
467 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
468 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
469 | 469 | $version = $api_response['tag_name']; |
470 | 470 | } |
471 | 471 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | class WPInv_Item { |
6 | 6 | public $ID = 0; |
@@ -47,26 +47,26 @@ discard block |
||
47 | 47 | public $filter; |
48 | 48 | |
49 | 49 | |
50 | - public function __construct( $_id = false, $_args = array() ) { |
|
51 | - $item = WP_Post::get_instance( $_id ); |
|
52 | - return $this->setup_item( $item ); |
|
50 | + public function __construct($_id = false, $_args = array()) { |
|
51 | + $item = WP_Post::get_instance($_id); |
|
52 | + return $this->setup_item($item); |
|
53 | 53 | } |
54 | 54 | |
55 | - private function setup_item( $item ) { |
|
56 | - if( ! is_object( $item ) ) { |
|
55 | + private function setup_item($item) { |
|
56 | + if (!is_object($item)) { |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | - if( ! is_a( $item, 'WP_Post' ) ) { |
|
60 | + if (!is_a($item, 'WP_Post')) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
64 | - if( 'wpi_item' !== $item->post_type ) { |
|
64 | + if ('wpi_item' !== $item->post_type) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | - foreach ( $item as $key => $value ) { |
|
69 | - switch ( $key ) { |
|
68 | + foreach ($item as $key => $value) { |
|
69 | + switch ($key) { |
|
70 | 70 | default: |
71 | 71 | $this->$key = $value; |
72 | 72 | break; |
@@ -76,38 +76,38 @@ discard block |
||
76 | 76 | return true; |
77 | 77 | } |
78 | 78 | |
79 | - public function __get( $key ) { |
|
80 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
81 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
79 | + public function __get($key) { |
|
80 | + if (method_exists($this, 'get_' . $key)) { |
|
81 | + return call_user_func(array($this, 'get_' . $key)); |
|
82 | 82 | } else { |
83 | - return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
83 | + return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - public function create( $data = array(), $wp_error = false ) { |
|
88 | - if ( $this->ID != 0 ) { |
|
87 | + public function create($data = array(), $wp_error = false) { |
|
88 | + if ($this->ID != 0) { |
|
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | 92 | $defaults = array( |
93 | 93 | 'post_type' => 'wpi_item', |
94 | 94 | 'post_status' => 'draft', |
95 | - 'post_title' => __( 'New Invoice Item', 'invoicing' ) |
|
95 | + 'post_title' => __('New Invoice Item', 'invoicing') |
|
96 | 96 | ); |
97 | 97 | |
98 | - $args = wp_parse_args( $data, $defaults ); |
|
98 | + $args = wp_parse_args($data, $defaults); |
|
99 | 99 | |
100 | - do_action( 'wpinv_item_pre_create', $args ); |
|
100 | + do_action('wpinv_item_pre_create', $args); |
|
101 | 101 | |
102 | - $id = wp_insert_post( $args, $wp_error ); |
|
102 | + $id = wp_insert_post($args, $wp_error); |
|
103 | 103 | if ($wp_error && is_wp_error($id)) { |
104 | 104 | return $id; |
105 | 105 | } |
106 | - if ( !$id ) { |
|
106 | + if (!$id) { |
|
107 | 107 | return false; |
108 | 108 | } |
109 | 109 | |
110 | - $item = WP_Post::get_instance( $id ); |
|
110 | + $item = WP_Post::get_instance($id); |
|
111 | 111 | |
112 | 112 | if (!empty($item) && !empty($data['meta'])) { |
113 | 113 | $this->ID = $item->ID; |
@@ -115,47 +115,47 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | // Set custom id if not set. |
118 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
119 | - $this->save_metas( array( 'custom_id' => $id ) ); |
|
118 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
119 | + $this->save_metas(array('custom_id' => $id)); |
|
120 | 120 | } |
121 | 121 | |
122 | - do_action( 'wpinv_item_create', $id, $args ); |
|
122 | + do_action('wpinv_item_create', $id, $args); |
|
123 | 123 | |
124 | - return $this->setup_item( $item ); |
|
124 | + return $this->setup_item($item); |
|
125 | 125 | } |
126 | 126 | |
127 | - public function update( $data = array(), $wp_error = false ) { |
|
128 | - if ( !$this->ID > 0 ) { |
|
127 | + public function update($data = array(), $wp_error = false) { |
|
128 | + if (!$this->ID > 0) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $data['ID'] = $this->ID; |
133 | 133 | |
134 | - do_action( 'wpinv_item_pre_update', $data ); |
|
134 | + do_action('wpinv_item_pre_update', $data); |
|
135 | 135 | |
136 | - $id = wp_update_post( $data, $wp_error ); |
|
136 | + $id = wp_update_post($data, $wp_error); |
|
137 | 137 | if ($wp_error && is_wp_error($id)) { |
138 | 138 | return $id; |
139 | 139 | } |
140 | 140 | |
141 | - if ( !$id ) { |
|
141 | + if (!$id) { |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | - $item = WP_Post::get_instance( $id ); |
|
145 | + $item = WP_Post::get_instance($id); |
|
146 | 146 | if (!empty($item) && !empty($data['meta'])) { |
147 | 147 | $this->ID = $item->ID; |
148 | 148 | $this->save_metas($data['meta']); |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Set custom id if not set. |
152 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
153 | - $this->save_metas( array( 'custom_id' => $id ) ); |
|
152 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
153 | + $this->save_metas(array('custom_id' => $id)); |
|
154 | 154 | } |
155 | 155 | |
156 | - do_action( 'wpinv_item_update', $id, $data ); |
|
156 | + do_action('wpinv_item_update', $id, $data); |
|
157 | 157 | |
158 | - return $this->setup_item( $item ); |
|
158 | + return $this->setup_item($item); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | public function get_ID() { |
@@ -163,120 +163,120 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | public function get_name() { |
166 | - return get_the_title( $this->ID ); |
|
166 | + return get_the_title($this->ID); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | public function get_title() { |
170 | - return get_the_title( $this->ID ); |
|
170 | + return get_the_title($this->ID); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | public function get_status() { |
174 | - return get_post_status( $this->ID ); |
|
174 | + return get_post_status($this->ID); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | public function get_summary() { |
178 | - $post = get_post( $this->ID ); |
|
179 | - return !empty( $post->post_excerpt ) ? $post->post_excerpt : ''; |
|
178 | + $post = get_post($this->ID); |
|
179 | + return !empty($post->post_excerpt) ? $post->post_excerpt : ''; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | public function get_price() { |
183 | - if ( ! isset( $this->price ) ) { |
|
184 | - $this->price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
183 | + if (!isset($this->price)) { |
|
184 | + $this->price = get_post_meta($this->ID, '_wpinv_price', true); |
|
185 | 185 | |
186 | - if ( $this->price ) { |
|
187 | - $this->price = wpinv_sanitize_amount( $this->price ); |
|
186 | + if ($this->price) { |
|
187 | + $this->price = wpinv_sanitize_amount($this->price); |
|
188 | 188 | } else { |
189 | 189 | $this->price = 0; |
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID ); |
|
193 | + return apply_filters('wpinv_get_item_price', $this->price, $this->ID); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | public function get_vat_rule() { |
197 | 197 | global $wpinv_euvat; |
198 | 198 | |
199 | - if( !isset( $this->vat_rule ) ) { |
|
200 | - $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true ); |
|
199 | + if (!isset($this->vat_rule)) { |
|
200 | + $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true); |
|
201 | 201 | |
202 | - if ( empty( $this->vat_rule ) ) { |
|
202 | + if (empty($this->vat_rule)) { |
|
203 | 203 | $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical'; |
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
207 | - return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID ); |
|
207 | + return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | public function get_vat_class() { |
211 | - if( !isset( $this->vat_class ) ) { |
|
212 | - $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true ); |
|
211 | + if (!isset($this->vat_class)) { |
|
212 | + $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true); |
|
213 | 213 | |
214 | - if ( empty( $this->vat_class ) ) { |
|
214 | + if (empty($this->vat_class)) { |
|
215 | 215 | $this->vat_class = '_standard'; |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID ); |
|
219 | + return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | public function get_type() { |
223 | - if( ! isset( $this->type ) ) { |
|
224 | - $this->type = get_post_meta( $this->ID, '_wpinv_type', true ); |
|
223 | + if (!isset($this->type)) { |
|
224 | + $this->type = get_post_meta($this->ID, '_wpinv_type', true); |
|
225 | 225 | |
226 | - if ( empty( $this->type ) ) { |
|
226 | + if (empty($this->type)) { |
|
227 | 227 | $this->type = 'custom'; |
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | - return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID ); |
|
231 | + return apply_filters('wpinv_get_item_type', $this->type, $this->ID); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | public function get_custom_id() { |
235 | - $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true ); |
|
235 | + $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true); |
|
236 | 236 | |
237 | - return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID ); |
|
237 | + return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | public function get_custom_name() { |
241 | - $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true ); |
|
241 | + $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true); |
|
242 | 242 | |
243 | - return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID ); |
|
243 | + return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | public function get_custom_singular_name() { |
247 | - $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true ); |
|
247 | + $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true); |
|
248 | 248 | |
249 | - return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID ); |
|
249 | + return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | public function get_editable() { |
253 | - $editable = get_post_meta( $this->ID, '_wpinv_editable', true ); |
|
253 | + $editable = get_post_meta($this->ID, '_wpinv_editable', true); |
|
254 | 254 | |
255 | - return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID ); |
|
255 | + return apply_filters('wpinv_item_get_editable', $editable, $this->ID); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | public function get_excerpt() { |
259 | - $excerpt = get_the_excerpt( $this->ID ); |
|
259 | + $excerpt = get_the_excerpt($this->ID); |
|
260 | 260 | |
261 | - return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID ); |
|
261 | + return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | public function get_is_recurring() { |
265 | - $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true ); |
|
265 | + $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true); |
|
266 | 266 | |
267 | - return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID ); |
|
267 | + return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID); |
|
268 | 268 | |
269 | 269 | } |
270 | 270 | |
271 | - public function get_recurring_period( $full = false ) { |
|
272 | - $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true ); |
|
271 | + public function get_recurring_period($full = false) { |
|
272 | + $period = get_post_meta($this->ID, '_wpinv_recurring_period', true); |
|
273 | 273 | |
274 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
274 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
275 | 275 | $period = 'D'; |
276 | 276 | } |
277 | 277 | |
278 | - if ( $full ) { |
|
279 | - switch( $period ) { |
|
278 | + if ($full) { |
|
279 | + switch ($period) { |
|
280 | 280 | case 'D': |
281 | 281 | $period = 'day'; |
282 | 282 | break; |
@@ -292,40 +292,40 @@ discard block |
||
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | - return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID ); |
|
295 | + return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | public function get_recurring_interval() { |
299 | - $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true ); |
|
299 | + $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true); |
|
300 | 300 | |
301 | - if ( !$interval > 0 ) { |
|
301 | + if (!$interval > 0) { |
|
302 | 302 | $interval = 1; |
303 | 303 | } |
304 | 304 | |
305 | - return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID ); |
|
305 | + return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | public function get_recurring_limit() { |
309 | - $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true ); |
|
309 | + $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true); |
|
310 | 310 | |
311 | - return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID ); |
|
311 | + return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | public function get_free_trial() { |
315 | - $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true ); |
|
315 | + $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true); |
|
316 | 316 | |
317 | - return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID ); |
|
317 | + return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID); |
|
318 | 318 | } |
319 | 319 | |
320 | - public function get_trial_period( $full = false ) { |
|
321 | - $period = get_post_meta( $this->ID, '_wpinv_trial_period', true ); |
|
320 | + public function get_trial_period($full = false) { |
|
321 | + $period = get_post_meta($this->ID, '_wpinv_trial_period', true); |
|
322 | 322 | |
323 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
323 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
324 | 324 | $period = 'D'; |
325 | 325 | } |
326 | 326 | |
327 | - if ( $full ) { |
|
328 | - switch( $period ) { |
|
327 | + if ($full) { |
|
328 | + switch ($period) { |
|
329 | 329 | case 'D': |
330 | 330 | $period = 'day'; |
331 | 331 | break; |
@@ -341,47 +341,47 @@ discard block |
||
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | - return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID ); |
|
344 | + return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | public function get_trial_interval() { |
348 | - $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) ); |
|
348 | + $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true)); |
|
349 | 349 | |
350 | - if ( !$interval > 0 ) { |
|
350 | + if (!$interval > 0) { |
|
351 | 351 | $interval = 1; |
352 | 352 | } |
353 | 353 | |
354 | - return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID ); |
|
354 | + return apply_filters('wpinv_item_trial_interval', $interval, $this->ID); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | public function get_the_price() { |
358 | - $item_price = wpinv_price( wpinv_format_amount( $this->price ) ); |
|
358 | + $item_price = wpinv_price(wpinv_format_amount($this->price)); |
|
359 | 359 | |
360 | - return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID ); |
|
360 | + return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | public function is_recurring() { |
364 | 364 | $is_recurring = $this->get_is_recurring(); |
365 | 365 | |
366 | - return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID ); |
|
366 | + return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | public function has_free_trial() { |
370 | 370 | $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false; |
371 | 371 | |
372 | - return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID ); |
|
372 | + return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | public function is_free() { |
376 | 376 | $is_free = false; |
377 | 377 | |
378 | - $price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
378 | + $price = get_post_meta($this->ID, '_wpinv_price', true); |
|
379 | 379 | |
380 | - if ( (float)$price == 0 ) { |
|
380 | + if ((float)$price == 0) { |
|
381 | 381 | $is_free = true; |
382 | 382 | } |
383 | 383 | |
384 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID ); |
|
384 | + return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID); |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | |
@@ -390,15 +390,15 @@ discard block |
||
390 | 390 | |
391 | 391 | $is_editable = $editable === 0 || $editable === '0' ? false : true; |
392 | 392 | |
393 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID ); |
|
393 | + return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID); |
|
394 | 394 | } |
395 | 395 | |
396 | - public function save_metas( $metas = array() ) { |
|
397 | - if ( empty( $metas ) ) { |
|
396 | + public function save_metas($metas = array()) { |
|
397 | + if (empty($metas)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $metas as $meta_key => $meta_value ) { |
|
401 | + foreach ($metas as $meta_key => $meta_value) { |
|
402 | 402 | $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key; |
403 | 403 | |
404 | 404 | $this->update_meta($meta_key, $meta_value); |
@@ -407,66 +407,66 @@ discard block |
||
407 | 407 | return true; |
408 | 408 | } |
409 | 409 | |
410 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
411 | - if ( empty( $meta_key ) ) { |
|
410 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
411 | + if (empty($meta_key)) { |
|
412 | 412 | return false; |
413 | 413 | } |
414 | 414 | |
415 | - $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID ); |
|
415 | + $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID); |
|
416 | 416 | |
417 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
417 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
418 | 418 | } |
419 | 419 | |
420 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
420 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
421 | 421 | global $wpi_session; |
422 | 422 | |
423 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
423 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
424 | 424 | |
425 | - if ( ! wpinv_get_cart_contents() ) { |
|
425 | + if (!wpinv_get_cart_contents()) { |
|
426 | 426 | // We can only get item type fees when the cart is empty |
427 | 427 | $type = 'custom'; |
428 | 428 | } |
429 | 429 | |
430 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
431 | - foreach( $fees as $key => $fee ) { |
|
432 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
433 | - unset( $fees[ $key ] ); |
|
430 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
431 | + foreach ($fees as $key => $fee) { |
|
432 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
433 | + unset($fees[$key]); |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
438 | + if (!empty($fees) && !empty($item_id)) { |
|
439 | 439 | // Remove fees that don't belong to the specified Item |
440 | - foreach ( $fees as $key => $fee ) { |
|
441 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
442 | - unset( $fees[ $key ] ); |
|
440 | + foreach ($fees as $key => $fee) { |
|
441 | + if ((int)$item_id !== (int)$fee['custom_id']) { |
|
442 | + unset($fees[$key]); |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | - if ( ! empty( $fees ) ) { |
|
447 | + if (!empty($fees)) { |
|
448 | 448 | // Remove fees that belong to a specific item but are not in the cart |
449 | - foreach( $fees as $key => $fee ) { |
|
450 | - if( empty( $fee['custom_id'] ) ) { |
|
449 | + foreach ($fees as $key => $fee) { |
|
450 | + if (empty($fee['custom_id'])) { |
|
451 | 451 | continue; |
452 | 452 | } |
453 | 453 | |
454 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
455 | - unset( $fees[ $key ] ); |
|
454 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
455 | + unset($fees[$key]); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | - return ! empty( $fees ) ? $fees : array(); |
|
460 | + return !empty($fees) ? $fees : array(); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | public function can_purchase() { |
464 | 464 | $can_purchase = true; |
465 | 465 | |
466 | - if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
466 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
467 | 467 | $can_purchase = false; |
468 | 468 | } |
469 | 469 | |
470 | - return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
470 | + return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
471 | 471 | } |
472 | 472 | } |
@@ -7,201 +7,201 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $is_checkout = is_page( wpinv_get_option( 'checkout_page' ) ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $is_checkout = is_page(wpinv_get_option('checkout_page')); |
|
20 | 20 | |
21 | - if ( !$is_object_set ) { |
|
22 | - unset( $wp_query->queried_object ); |
|
21 | + if (!$is_object_set) { |
|
22 | + unset($wp_query->queried_object); |
|
23 | 23 | } |
24 | 24 | |
25 | - if ( !$is_object_id_set ) { |
|
26 | - unset( $wp_query->queried_object_id ); |
|
25 | + if (!$is_object_id_set) { |
|
26 | + unset($wp_query->queried_object_id); |
|
27 | 27 | } |
28 | 28 | |
29 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
29 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | function wpinv_can_checkout() { |
33 | 33 | $can_checkout = true; // Always true for now |
34 | 34 | |
35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
35 | + return (bool)apply_filters('wpinv_can_checkout', $can_checkout); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function wpinv_get_success_page_uri() { |
39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
40 | - $page_id = absint( $page_id ); |
|
39 | + $page_id = wpinv_get_option('success_page', 0); |
|
40 | + $page_id = absint($page_id); |
|
41 | 41 | |
42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
42 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function wpinv_get_history_page_uri() { |
46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
47 | - $page_id = absint( $page_id ); |
|
46 | + $page_id = wpinv_get_option('invoice_history_page', 0); |
|
47 | + $page_id = absint($page_id); |
|
48 | 48 | |
49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
49 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | function wpinv_is_success_page() { |
53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
53 | + $is_success_page = wpinv_get_option('success_page', false); |
|
54 | + $is_success_page = isset($is_success_page) ? is_page($is_success_page) : false; |
|
55 | 55 | |
56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
56 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_invoice_history_page() { |
60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
61 | - $ret = $ret ? is_page( $ret ) : false; |
|
62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
60 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
61 | + $ret = $ret ? is_page($ret) : false; |
|
62 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | function wpinv_is_subscriptions_history_page() { |
66 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
67 | - $ret = $ret ? is_page( $ret ) : false; |
|
68 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
66 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
67 | + $ret = $ret ? is_page($ret) : false; |
|
68 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
69 | 69 | } |
70 | 70 | |
71 | -function wpinv_send_to_success_page( $args = null ) { |
|
71 | +function wpinv_send_to_success_page($args = null) { |
|
72 | 72 | $redirect = wpinv_get_success_page_uri(); |
73 | 73 | |
74 | - if ( !empty( $args ) ) { |
|
74 | + if (!empty($args)) { |
|
75 | 75 | // Check for backward compatibility |
76 | - if ( is_string( $args ) ) |
|
77 | - $args = str_replace( '?', '', $args ); |
|
76 | + if (is_string($args)) |
|
77 | + $args = str_replace('?', '', $args); |
|
78 | 78 | |
79 | - $args = wp_parse_args( $args ); |
|
79 | + $args = wp_parse_args($args); |
|
80 | 80 | |
81 | - $redirect = add_query_arg( $args, $redirect ); |
|
81 | + $redirect = add_query_arg($args, $redirect); |
|
82 | 82 | } |
83 | 83 | |
84 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
84 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
85 | 85 | |
86 | - $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args ); |
|
87 | - wp_redirect( $redirect ); |
|
86 | + $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args); |
|
87 | + wp_redirect($redirect); |
|
88 | 88 | exit; |
89 | 89 | } |
90 | 90 | |
91 | -function wpinv_send_to_failed_page( $args = null ) { |
|
91 | +function wpinv_send_to_failed_page($args = null) { |
|
92 | 92 | $redirect = wpinv_get_failed_transaction_uri(); |
93 | 93 | |
94 | - if ( !empty( $args ) ) { |
|
94 | + if (!empty($args)) { |
|
95 | 95 | // Check for backward compatibility |
96 | - if ( is_string( $args ) ) |
|
97 | - $args = str_replace( '?', '', $args ); |
|
96 | + if (is_string($args)) |
|
97 | + $args = str_replace('?', '', $args); |
|
98 | 98 | |
99 | - $args = wp_parse_args( $args ); |
|
99 | + $args = wp_parse_args($args); |
|
100 | 100 | |
101 | - $redirect = add_query_arg( $args, $redirect ); |
|
101 | + $redirect = add_query_arg($args, $redirect); |
|
102 | 102 | } |
103 | 103 | |
104 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
104 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
105 | 105 | |
106 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
107 | - wp_redirect( $redirect ); |
|
106 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
107 | + wp_redirect($redirect); |
|
108 | 108 | exit; |
109 | 109 | } |
110 | 110 | |
111 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
111 | +function wpinv_get_checkout_uri($args = array()) { |
|
112 | + $uri = wpinv_get_option('checkout_page', false); |
|
113 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
114 | 114 | |
115 | - if ( !empty( $args ) ) { |
|
115 | + if (!empty($args)) { |
|
116 | 116 | // Check for backward compatibility |
117 | - if ( is_string( $args ) ) |
|
118 | - $args = str_replace( '?', '', $args ); |
|
117 | + if (is_string($args)) |
|
118 | + $args = str_replace('?', '', $args); |
|
119 | 119 | |
120 | - $args = wp_parse_args( $args ); |
|
120 | + $args = wp_parse_args($args); |
|
121 | 121 | |
122 | - $uri = add_query_arg( $args, $uri ); |
|
122 | + $uri = add_query_arg($args, $uri); |
|
123 | 123 | } |
124 | 124 | |
125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
125 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
126 | 126 | |
127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
127 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
128 | 128 | |
129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
129 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
130 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
131 | 131 | } |
132 | 132 | |
133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
133 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_send_back_to_checkout( $args = array() ) { |
|
136 | +function wpinv_send_back_to_checkout($args = array()) { |
|
137 | 137 | $redirect = wpinv_get_checkout_uri(); |
138 | 138 | |
139 | - if ( ! empty( $args ) ) { |
|
139 | + if (!empty($args)) { |
|
140 | 140 | // Check for backward compatibility |
141 | - if ( is_string( $args ) ) |
|
142 | - $args = str_replace( '?', '', $args ); |
|
141 | + if (is_string($args)) |
|
142 | + $args = str_replace('?', '', $args); |
|
143 | 143 | |
144 | - $args = wp_parse_args( $args ); |
|
144 | + $args = wp_parse_args($args); |
|
145 | 145 | |
146 | - $redirect = add_query_arg( $args, $redirect ); |
|
146 | + $redirect = add_query_arg($args, $redirect); |
|
147 | 147 | } |
148 | 148 | |
149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
149 | + wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args)); |
|
150 | 150 | exit; |
151 | 151 | } |
152 | 152 | |
153 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
154 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
155 | - $success_page = get_permalink( $success_page ); |
|
153 | +function wpinv_get_success_page_url($query_string = null) { |
|
154 | + $success_page = wpinv_get_option('success_page', 0); |
|
155 | + $success_page = get_permalink($success_page); |
|
156 | 156 | |
157 | - if ( $query_string ) |
|
157 | + if ($query_string) |
|
158 | 158 | $success_page .= $query_string; |
159 | 159 | |
160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
160 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
161 | 161 | } |
162 | 162 | |
163 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
163 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
164 | + $uri = wpinv_get_option('failure_page', ''); |
|
165 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
166 | 166 | |
167 | - if ( $extras ) |
|
167 | + if ($extras) |
|
168 | 168 | $uri .= $extras; |
169 | 169 | |
170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
170 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_is_failed_transaction_page() { |
174 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
175 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
174 | + $ret = wpinv_get_option('failure_page', false); |
|
175 | + $ret = isset($ret) ? is_page($ret) : false; |
|
176 | 176 | |
177 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
177 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_transaction_query( $type = 'start' ) { |
|
180 | +function wpinv_transaction_query($type = 'start') { |
|
181 | 181 | global $wpdb; |
182 | 182 | |
183 | 183 | $wpdb->hide_errors(); |
184 | 184 | |
185 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
186 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
185 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
186 | + define('WPINV_USE_TRANSACTIONS', true); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
190 | - switch ( $type ) { |
|
189 | + if (WPINV_USE_TRANSACTIONS) { |
|
190 | + switch ($type) { |
|
191 | 191 | case 'commit' : |
192 | - $wpdb->query( 'COMMIT' ); |
|
192 | + $wpdb->query('COMMIT'); |
|
193 | 193 | break; |
194 | 194 | case 'rollback' : |
195 | - $wpdb->query( 'ROLLBACK' ); |
|
195 | + $wpdb->query('ROLLBACK'); |
|
196 | 196 | break; |
197 | 197 | default : |
198 | - $wpdb->query( 'START TRANSACTION' ); |
|
198 | + $wpdb->query('START TRANSACTION'); |
|
199 | 199 | break; |
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | -function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) { |
|
204 | +function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) { |
|
205 | 205 | $default_args = array( |
206 | 206 | 'status' => '', |
207 | 207 | 'user_id' => null, |
@@ -211,63 +211,63 @@ discard block |
||
211 | 211 | 'parent' => 0 |
212 | 212 | ); |
213 | 213 | |
214 | - $args = wp_parse_args( $args, $default_args ); |
|
214 | + $args = wp_parse_args($args, $default_args); |
|
215 | 215 | $invoice_data = array(); |
216 | 216 | |
217 | - if ( $args['invoice_id'] > 0 ) { |
|
218 | - $updating = true; |
|
217 | + if ($args['invoice_id'] > 0) { |
|
218 | + $updating = true; |
|
219 | 219 | $invoice_data['post_type'] = 'wpi_invoice'; |
220 | 220 | $invoice_data['ID'] = $args['invoice_id']; |
221 | 221 | } else { |
222 | 222 | $updating = false; |
223 | 223 | $invoice_data['post_type'] = 'wpi_invoice'; |
224 | - $invoice_data['post_status'] = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' ); |
|
224 | + $invoice_data['post_status'] = apply_filters('wpinv_default_invoice_status', 'wpi-pending'); |
|
225 | 225 | $invoice_data['ping_status'] = 'closed'; |
226 | - $invoice_data['post_author'] = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); |
|
227 | - $invoice_data['post_title'] = wpinv_format_invoice_number( '0' ); |
|
228 | - $invoice_data['post_parent'] = absint( $args['parent'] ); |
|
229 | - if ( !empty( $args['created_date'] ) ) { |
|
226 | + $invoice_data['post_author'] = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id(); |
|
227 | + $invoice_data['post_title'] = wpinv_format_invoice_number('0'); |
|
228 | + $invoice_data['post_parent'] = absint($args['parent']); |
|
229 | + if (!empty($args['created_date'])) { |
|
230 | 230 | $invoice_data['post_date'] = $args['created_date']; |
231 | - $invoice_data['post_date_gmt'] = get_gmt_from_date( $args['created_date'] ); |
|
231 | + $invoice_data['post_date_gmt'] = get_gmt_from_date($args['created_date']); |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - if ( $args['status'] ) { |
|
236 | - if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
237 | - return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) ); |
|
235 | + if ($args['status']) { |
|
236 | + if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) { |
|
237 | + return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status'])); |
|
238 | 238 | } |
239 | - $invoice_data['post_status'] = $args['status']; |
|
239 | + $invoice_data['post_status'] = $args['status']; |
|
240 | 240 | } |
241 | 241 | |
242 | - if ( ! is_null( $args['user_note'] ) ) { |
|
243 | - $invoice_data['post_excerpt'] = $args['user_note']; |
|
242 | + if (!is_null($args['user_note'])) { |
|
243 | + $invoice_data['post_excerpt'] = $args['user_note']; |
|
244 | 244 | } |
245 | 245 | |
246 | - if ( $updating ) { |
|
247 | - $invoice_id = wp_update_post( $invoice_data, true ); |
|
246 | + if ($updating) { |
|
247 | + $invoice_id = wp_update_post($invoice_data, true); |
|
248 | 248 | } else { |
249 | - $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true ); |
|
249 | + $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true); |
|
250 | 250 | } |
251 | 251 | |
252 | - if ( is_wp_error( $invoice_id ) ) { |
|
252 | + if (is_wp_error($invoice_id)) { |
|
253 | 253 | return $wp_error ? $invoice_id : 0; |
254 | 254 | } |
255 | 255 | |
256 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
257 | - |
|
258 | - if ( !$updating ) { |
|
259 | - update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) ); |
|
260 | - update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() ); |
|
261 | - update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) ); |
|
262 | - update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() ); |
|
263 | - update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() ); |
|
264 | - update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) ); |
|
256 | + $invoice = wpinv_get_invoice($invoice_id); |
|
257 | + |
|
258 | + if (!$updating) { |
|
259 | + update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_'))); |
|
260 | + update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency()); |
|
261 | + update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax')); |
|
262 | + update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip()); |
|
263 | + update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent()); |
|
264 | + update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via'])); |
|
265 | 265 | |
266 | 266 | // Add invoice note |
267 | - $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
|
267 | + $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status))); |
|
268 | 268 | } |
269 | 269 | |
270 | - update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION ); |
|
270 | + update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION); |
|
271 | 271 | |
272 | 272 | return $invoice; |
273 | 273 | } |
@@ -275,184 +275,184 @@ discard block |
||
275 | 275 | function wpinv_get_prefix() { |
276 | 276 | $invoice_prefix = 'INV-'; |
277 | 277 | |
278 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
278 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | function wpinv_get_business_logo() { |
282 | - $business_logo = wpinv_get_option( 'logo' ); |
|
283 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
282 | + $business_logo = wpinv_get_option('logo'); |
|
283 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | function wpinv_get_business_name() { |
287 | 287 | $business_name = wpinv_get_option('store_name'); |
288 | - return apply_filters( 'wpinv_get_business_name', $business_name ); |
|
288 | + return apply_filters('wpinv_get_business_name', $business_name); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | function wpinv_get_blogname() { |
292 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
292 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | function wpinv_get_admin_email() { |
296 | - $admin_email = get_option( 'admin_email' ); |
|
297 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
296 | + $admin_email = get_option('admin_email'); |
|
297 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | function wpinv_get_business_website() { |
301 | - $business_website = home_url( '/' ); |
|
302 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
301 | + $business_website = home_url('/'); |
|
302 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
303 | 303 | } |
304 | 304 | |
305 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
305 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
306 | 306 | $terms_text = ''; |
307 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
307 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | function wpinv_get_business_footer() { |
311 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
312 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
313 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
311 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
312 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
313 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | function wpinv_checkout_required_fields() { |
317 | 317 | $required_fields = array(); |
318 | 318 | |
319 | 319 | // Let payment gateways and other extensions determine if address fields should be required |
320 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
320 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
321 | 321 | |
322 | - if ( $require_billing_details ) { |
|
323 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
322 | + if ($require_billing_details) { |
|
323 | + if ((bool)wpinv_get_option('fname_mandatory')) { |
|
324 | 324 | $required_fields['first_name'] = array( |
325 | 325 | 'error_id' => 'invalid_first_name', |
326 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
326 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
327 | 327 | ); |
328 | 328 | } |
329 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
329 | + if ((bool)wpinv_get_option('address_mandatory')) { |
|
330 | 330 | $required_fields['address'] = array( |
331 | 331 | 'error_id' => 'invalid_address', |
332 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
332 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
333 | 333 | ); |
334 | 334 | } |
335 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
335 | + if ((bool)wpinv_get_option('city_mandatory')) { |
|
336 | 336 | $required_fields['city'] = array( |
337 | 337 | 'error_id' => 'invalid_city', |
338 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
338 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
339 | 339 | ); |
340 | 340 | } |
341 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
341 | + if ((bool)wpinv_get_option('state_mandatory')) { |
|
342 | 342 | $required_fields['state'] = array( |
343 | 343 | 'error_id' => 'invalid_state', |
344 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
344 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
345 | 345 | ); |
346 | 346 | } |
347 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
347 | + if ((bool)wpinv_get_option('country_mandatory')) { |
|
348 | 348 | $required_fields['country'] = array( |
349 | 349 | 'error_id' => 'invalid_country', |
350 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
350 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
351 | 351 | ); |
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
355 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | function wpinv_is_ssl_enforced() { |
359 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
360 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
359 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
360 | + return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_user_can_view_invoice( $post ) { |
|
363 | +function wpinv_user_can_view_invoice($post) { |
|
364 | 364 | $allow = false; |
365 | 365 | |
366 | - $post = get_post( $post ); |
|
366 | + $post = get_post($post); |
|
367 | 367 | |
368 | - if ( empty( $post->ID ) ) { |
|
368 | + if (empty($post->ID)) { |
|
369 | 369 | return $allow; |
370 | 370 | } |
371 | 371 | |
372 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
373 | - if ( empty( $invoice->ID ) ) { |
|
372 | + $invoice = wpinv_get_invoice($post->ID); |
|
373 | + if (empty($invoice->ID)) { |
|
374 | 374 | return $allow; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Don't allow trash, draft status |
378 | - if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
379 | - if ( current_user_can( 'manage_options' ) ) { // Admin user |
|
378 | + if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
379 | + if (current_user_can('manage_options')) { // Admin user |
|
380 | 380 | $allow = true; |
381 | 381 | } else { |
382 | - if ( is_user_logged_in() ) { |
|
383 | - if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) { |
|
382 | + if (is_user_logged_in()) { |
|
383 | + if ((int)$invoice->get_user_id() === (int)get_current_user_id()) { |
|
384 | 384 | $allow = true; |
385 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
385 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
386 | 386 | $allow = true; |
387 | 387 | } |
388 | 388 | } else { |
389 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
389 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
390 | 390 | $allow = true; |
391 | 391 | } |
392 | 392 | } |
393 | 393 | } |
394 | 394 | } |
395 | 395 | |
396 | - return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice ); |
|
396 | + return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | function wpinv_schedule_events() { |
400 | 400 | // hourly, daily and twicedaily |
401 | - if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) { |
|
402 | - wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' ); |
|
401 | + if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) { |
|
402 | + wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily'); |
|
403 | 403 | } |
404 | 404 | } |
405 | -add_action( 'wp', 'wpinv_schedule_events' ); |
|
405 | +add_action('wp', 'wpinv_schedule_events'); |
|
406 | 406 | |
407 | 407 | function wpinv_schedule_event_twicedaily() { |
408 | 408 | wpinv_email_payment_reminders(); |
409 | 409 | } |
410 | -add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' ); |
|
410 | +add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily'); |
|
411 | 411 | |
412 | 412 | function wpinv_require_login_to_checkout() { |
413 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
414 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
413 | + $return = wpinv_get_option('login_to_checkout', false); |
|
414 | + return (bool)apply_filters('wpinv_require_login_to_checkout', $return); |
|
415 | 415 | } |
416 | 416 | |
417 | -function wpinv_sequential_number_active( $type = '' ) { |
|
418 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
419 | - if ( null !== $check ) { |
|
417 | +function wpinv_sequential_number_active($type = '') { |
|
418 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
419 | + if (null !== $check) { |
|
420 | 420 | return $check; |
421 | 421 | } |
422 | 422 | |
423 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
423 | + return wpinv_get_option('sequential_invoice_number'); |
|
424 | 424 | } |
425 | 425 | |
426 | -function wpinv_switch_to_locale( $locale = NULL ) { |
|
426 | +function wpinv_switch_to_locale($locale = NULL) { |
|
427 | 427 | global $invoicing, $wpi_switch_locale; |
428 | 428 | |
429 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
430 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
429 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
430 | + $locale = empty($locale) ? get_locale() : $locale; |
|
431 | 431 | |
432 | - switch_to_locale( $locale ); |
|
432 | + switch_to_locale($locale); |
|
433 | 433 | |
434 | 434 | $wpi_switch_locale = $locale; |
435 | 435 | |
436 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
436 | + add_filter('plugin_locale', 'get_locale'); |
|
437 | 437 | |
438 | 438 | $invoicing->load_textdomain(); |
439 | 439 | |
440 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
440 | + do_action('wpinv_switch_to_locale', $locale); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | 444 | function wpinv_restore_locale() { |
445 | 445 | global $invoicing, $wpi_switch_locale; |
446 | 446 | |
447 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
447 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
448 | 448 | restore_previous_locale(); |
449 | 449 | |
450 | 450 | $wpi_switch_locale = NULL; |
451 | 451 | |
452 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
452 | + remove_filter('plugin_locale', 'get_locale'); |
|
453 | 453 | |
454 | 454 | $invoicing->load_textdomain(); |
455 | 455 | |
456 | - do_action( 'wpinv_restore_locale' ); |
|
456 | + do_action('wpinv_restore_locale'); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | \ No newline at end of file |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Admin_Users { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Admin_Users ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Admin_Users)) { |
|
19 | 19 | self::$instance = new WPInv_Admin_Users; |
20 | 20 | } |
21 | 21 | |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | public function __construct() { |
26 | - add_filter( 'manage_users_columns', array( $this, 'wpinv_add_user_column') ); |
|
27 | - add_filter( 'manage_users_custom_column', array( $this, 'wpinv_user_column_content') , 10, 3 ); |
|
26 | + add_filter('manage_users_columns', array($this, 'wpinv_add_user_column')); |
|
27 | + add_filter('manage_users_custom_column', array($this, 'wpinv_user_column_content'), 10, 3); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return mixed |
36 | 36 | */ |
37 | - public function wpinv_add_user_column( $column ) { |
|
38 | - $column['wpinvoicing'] = __('Invoicing','invoicing'); |
|
37 | + public function wpinv_add_user_column($column) { |
|
38 | + $column['wpinvoicing'] = __('Invoicing', 'invoicing'); |
|
39 | 39 | return $column; |
40 | 40 | } |
41 | 41 | |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - function wpinv_user_column_content( $val, $column_name, $user_id ) { |
|
51 | + function wpinv_user_column_content($val, $column_name, $user_id) { |
|
52 | 52 | switch ($column_name) { |
53 | 53 | case 'wpinvoicing' : |
54 | - return $this->get_user_invoices( $user_id ); |
|
54 | + return $this->get_user_invoices($user_id); |
|
55 | 55 | break; |
56 | 56 | default: |
57 | 57 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function get_user_invoices($user_id){ |
|
68 | + public function get_user_invoices($user_id) { |
|
69 | 69 | $output = ''; |
70 | 70 | $wp_query_args = array( |
71 | 71 | 'post_type' => 'wpi_invoice', |
@@ -77,14 +77,14 @@ discard block |
||
77 | 77 | |
78 | 78 | $wp_query_args = apply_filters('wpinv_get_user_invoices_args', $wp_query_args, $user_id); |
79 | 79 | |
80 | - $invoices = new WP_Query( $wp_query_args ); |
|
81 | - $count = absint( $invoices->found_posts ); |
|
80 | + $invoices = new WP_Query($wp_query_args); |
|
81 | + $count = absint($invoices->found_posts); |
|
82 | 82 | |
83 | - if(empty($count)){ |
|
84 | - $output .= __('No Invoice(s)','invoicing'); |
|
85 | - }else{ |
|
86 | - $link_url = admin_url( "edit.php?post_type=wpi_invoice&author=".absint($user_id) ); |
|
87 | - $link_text = sprintf( __('Invoices ( %d )', 'invoicing'), $count ); |
|
83 | + if (empty($count)) { |
|
84 | + $output .= __('No Invoice(s)', 'invoicing'); |
|
85 | + } else { |
|
86 | + $link_url = admin_url("edit.php?post_type=wpi_invoice&author=" . absint($user_id)); |
|
87 | + $link_text = sprintf(__('Invoices ( %d )', 'invoicing'), $count); |
|
88 | 88 | $output .= "<a href='$link_url' >$link_text</a>"; |
89 | 89 | } |
90 | 90 |
@@ -1,47 +1,47 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
8 | -function wpinv_discount_columns( $existing_columns ) { |
|
7 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
8 | +function wpinv_discount_columns($existing_columns) { |
|
9 | 9 | $columns = array(); |
10 | 10 | $columns['cb'] = $existing_columns['cb']; |
11 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
12 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
13 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
14 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
15 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
16 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
17 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
11 | + $columns['name'] = __('Name', 'invoicing'); |
|
12 | + $columns['code'] = __('Code', 'invoicing'); |
|
13 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
14 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
15 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
16 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
17 | + $columns['status'] = __('Status', 'invoicing'); |
|
18 | 18 | |
19 | 19 | return $columns; |
20 | 20 | } |
21 | 21 | |
22 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
23 | -function wpinv_discount_custom_column( $column ) { |
|
22 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
23 | +function wpinv_discount_custom_column($column) { |
|
24 | 24 | global $post; |
25 | 25 | |
26 | 26 | $discount = $post; |
27 | 27 | |
28 | - switch ( $column ) { |
|
28 | + switch ($column) { |
|
29 | 29 | case 'name' : |
30 | - echo get_the_title( $discount->ID ); |
|
30 | + echo get_the_title($discount->ID); |
|
31 | 31 | break; |
32 | 32 | case 'code' : |
33 | - echo wpinv_get_discount_code( $discount->ID ); |
|
33 | + echo wpinv_get_discount_code($discount->ID); |
|
34 | 34 | break; |
35 | 35 | case 'amount' : |
36 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
36 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
37 | 37 | break; |
38 | 38 | case 'usage_limit' : |
39 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
39 | + echo wpinv_get_discount_uses($discount->ID); |
|
40 | 40 | break; |
41 | 41 | case 'usage' : |
42 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
43 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
44 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
42 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
43 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
44 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
45 | 45 | } else { |
46 | 46 | $usage .= ' ∞'; |
47 | 47 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | echo $usage; |
50 | 50 | break; |
51 | 51 | case 'start_date' : |
52 | - if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) { |
|
53 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) ); |
|
52 | + if ($start_date = wpinv_get_discount_start_date($discount->ID)) { |
|
53 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date)); |
|
54 | 54 | } else { |
55 | 55 | $value = '-'; |
56 | 56 | } |
@@ -58,163 +58,163 @@ discard block |
||
58 | 58 | echo $value; |
59 | 59 | break; |
60 | 60 | case 'expiry_date' : |
61 | - if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) { |
|
62 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) ); |
|
61 | + if ($expiration = wpinv_get_discount_expiration($discount->ID)) { |
|
62 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration)); |
|
63 | 63 | } else { |
64 | - $value = __( 'Never', 'invoicing' ); |
|
64 | + $value = __('Never', 'invoicing'); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | echo $value; |
68 | 68 | break; |
69 | 69 | break; |
70 | 70 | case 'description' : |
71 | - echo wp_kses_post( $post->post_excerpt ); |
|
71 | + echo wp_kses_post($post->post_excerpt); |
|
72 | 72 | break; |
73 | 73 | case 'status' : |
74 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
74 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
75 | 75 | |
76 | - echo wpinv_discount_status( $status ); |
|
76 | + echo wpinv_discount_status($status); |
|
77 | 77 | break; |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
82 | -function wpinv_post_row_actions( $actions, $post ) { |
|
83 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
81 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
82 | +function wpinv_post_row_actions($actions, $post) { |
|
83 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
84 | 84 | |
85 | - if ( $post_type == 'wpi_invoice' ) { |
|
85 | + if ($post_type == 'wpi_invoice') { |
|
86 | 86 | $actions = array(); |
87 | 87 | } |
88 | 88 | |
89 | - if ( $post_type == 'wpi_discount' ) { |
|
90 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
89 | + if ($post_type == 'wpi_discount') { |
|
90 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $actions; |
94 | 94 | } |
95 | 95 | |
96 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
97 | - $row_actions = array(); |
|
98 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
99 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
96 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
97 | + $row_actions = array(); |
|
98 | + $edit_link = get_edit_post_link($discount->ID); |
|
99 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
100 | 100 | |
101 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
102 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
103 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
104 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
101 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
102 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
103 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
104 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
105 | 105 | } |
106 | 106 | |
107 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
108 | - if ( isset( $row_actions['delete'] ) ) { |
|
109 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
107 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
108 | + if (isset($row_actions['delete'])) { |
|
109 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
110 | 110 | } |
111 | 111 | } else { |
112 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
112 | + $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
116 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
117 | 117 | |
118 | 118 | return $row_actions; |
119 | 119 | } |
120 | 120 | |
121 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
122 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
123 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
121 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
122 | +function wpinv_table_primary_column($default, $screen_id) { |
|
123 | + if ('edit-wpi_invoice' === $screen_id) { |
|
124 | 124 | return 'name'; |
125 | 125 | } |
126 | 126 | |
127 | 127 | return $default; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
131 | - if ( !$display ) { |
|
130 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
131 | + if (!$display) { |
|
132 | 132 | return array(); |
133 | 133 | } |
134 | 134 | |
135 | 135 | $actions = array( |
136 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
137 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
138 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
136 | + 'activate' => __('Activate', 'invoicing'), |
|
137 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
138 | + 'delete' => __('Delete', 'invoicing'), |
|
139 | 139 | ); |
140 | 140 | $two = ''; |
141 | 141 | $which = 'top'; |
142 | 142 | echo '</div><div class="alignleft actions bulkactions">'; |
143 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
144 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
145 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
143 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
144 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
145 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
146 | 146 | |
147 | - foreach ( $actions as $name => $title ) { |
|
147 | + foreach ($actions as $name => $title) { |
|
148 | 148 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
149 | 149 | |
150 | 150 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
151 | 151 | } |
152 | 152 | echo "</select>"; |
153 | 153 | |
154 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
154 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
155 | 155 | |
156 | 156 | echo '</div><div class="alignleft actions">'; |
157 | 157 | } |
158 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
158 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
159 | 159 | |
160 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
161 | - if ( $post_type == 'wpi_discount' ) { |
|
160 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
161 | + if ($post_type == 'wpi_discount') { |
|
162 | 162 | $disable = true; |
163 | 163 | } |
164 | 164 | |
165 | 165 | return $disable; |
166 | 166 | } |
167 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
167 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
168 | 168 | |
169 | 169 | function wpinv_restrict_manage_posts() { |
170 | 170 | global $typenow; |
171 | 171 | |
172 | - if( 'wpi_discount' == $typenow ) { |
|
172 | + if ('wpi_discount' == $typenow) { |
|
173 | 173 | wpinv_discount_filters(); |
174 | 174 | } |
175 | 175 | } |
176 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
176 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
177 | 177 | |
178 | 178 | function wpinv_discount_filters() { |
179 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
179 | + echo wpinv_discount_bulk_actions(array(), true); |
|
180 | 180 | |
181 | 181 | ?> |
182 | 182 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
183 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
183 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
184 | 184 | <?php |
185 | 185 | $types = wpinv_get_discount_types(); |
186 | 186 | |
187 | - foreach ( $types as $name => $type ) { |
|
188 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
187 | + foreach ($types as $name => $type) { |
|
188 | + echo '<option value="' . esc_attr($name) . '"'; |
|
189 | 189 | |
190 | - if ( isset( $_GET['discount_type'] ) ) |
|
191 | - selected( $name, $_GET['discount_type'] ); |
|
190 | + if (isset($_GET['discount_type'])) |
|
191 | + selected($name, $_GET['discount_type']); |
|
192 | 192 | |
193 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
193 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
194 | 194 | } |
195 | 195 | ?> |
196 | 196 | </select> |
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_request( $vars ) { |
|
200 | +function wpinv_request($vars) { |
|
201 | 201 | global $typenow, $wp_query, $wp_post_statuses; |
202 | 202 | |
203 | - if ( 'wpi_invoice' === $typenow ) { |
|
204 | - if ( !isset( $vars['post_status'] ) ) { |
|
203 | + if ('wpi_invoice' === $typenow) { |
|
204 | + if (!isset($vars['post_status'])) { |
|
205 | 205 | $post_statuses = wpinv_get_invoice_statuses(); |
206 | 206 | |
207 | - foreach ( $post_statuses as $status => $value ) { |
|
208 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
209 | - unset( $post_statuses[ $status ] ); |
|
207 | + foreach ($post_statuses as $status => $value) { |
|
208 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
209 | + unset($post_statuses[$status]); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
213 | + $vars['post_status'] = array_keys($post_statuses); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( isset( $vars['orderby'] ) ) { |
|
217 | - if ( 'amount' == $vars['orderby'] ) { |
|
216 | + if (isset($vars['orderby'])) { |
|
217 | + if ('amount' == $vars['orderby']) { |
|
218 | 218 | $vars = array_merge( |
219 | 219 | $vars, |
220 | 220 | array( |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | 'orderby' => 'meta_value_num' |
223 | 223 | ) |
224 | 224 | ); |
225 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
225 | + } else if ('customer' == $vars['orderby']) { |
|
226 | 226 | $vars = array_merge( |
227 | 227 | $vars, |
228 | 228 | array( |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | 'orderby' => 'meta_value' |
231 | 231 | ) |
232 | 232 | ); |
233 | - } else if ( 'number' == $vars['orderby'] ) { |
|
233 | + } else if ('number' == $vars['orderby']) { |
|
234 | 234 | $vars = array_merge( |
235 | 235 | $vars, |
236 | 236 | array( |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | 'orderby' => 'meta_value' |
239 | 239 | ) |
240 | 240 | ); |
241 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
241 | + } else if ('payment_date' == $vars['orderby']) { |
|
242 | 242 | $vars = array_merge( |
243 | 243 | $vars, |
244 | 244 | array( |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | ); |
249 | 249 | } |
250 | 250 | } |
251 | - } else if ( 'wpi_item' == $typenow ) { |
|
251 | + } else if ('wpi_item' == $typenow) { |
|
252 | 252 | // Check if 'orderby' is set to "price" |
253 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
253 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
254 | 254 | $vars = array_merge( |
255 | 255 | $vars, |
256 | 256 | array( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | } |
262 | 262 | |
263 | 263 | // Check if "orderby" is set to "vat_rule" |
264 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
264 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
265 | 265 | $vars = array_merge( |
266 | 266 | $vars, |
267 | 267 | array( |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | // Check if "orderby" is set to "vat_class" |
275 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
275 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
276 | 276 | $vars = array_merge( |
277 | 277 | $vars, |
278 | 278 | array( |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | // Check if "orderby" is set to "type" |
286 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
286 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
287 | 287 | $vars = array_merge( |
288 | 288 | $vars, |
289 | 289 | array( |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | // Check if "orderby" is set to "recurring" |
297 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
297 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
298 | 298 | $vars = array_merge( |
299 | 299 | $vars, |
300 | 300 | array( |
@@ -304,104 +304,104 @@ discard block |
||
304 | 304 | ); |
305 | 305 | } |
306 | 306 | |
307 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
307 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
308 | 308 | // Filter vat rule type |
309 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
309 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
310 | 310 | $meta_query[] = array( |
311 | 311 | 'key' => '_wpinv_vat_rule', |
312 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
312 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
313 | 313 | 'compare' => '=' |
314 | 314 | ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | // Filter vat class |
318 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
318 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
319 | 319 | $meta_query[] = array( |
320 | 320 | 'key' => '_wpinv_vat_class', |
321 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
321 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
322 | 322 | 'compare' => '=' |
323 | 323 | ); |
324 | 324 | } |
325 | 325 | |
326 | 326 | // Filter item type |
327 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
327 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
328 | 328 | $meta_query[] = array( |
329 | 329 | 'key' => '_wpinv_type', |
330 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
330 | + 'value' => sanitize_text_field($_GET['type']), |
|
331 | 331 | 'compare' => '=' |
332 | 332 | ); |
333 | 333 | } |
334 | 334 | |
335 | - if ( !empty( $meta_query ) ) { |
|
335 | + if (!empty($meta_query)) { |
|
336 | 336 | $vars['meta_query'] = $meta_query; |
337 | 337 | } |
338 | - } else if ( 'wpi_discount' == $typenow ) { |
|
339 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
338 | + } else if ('wpi_discount' == $typenow) { |
|
339 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
340 | 340 | // Filter vat rule type |
341 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
341 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
342 | 342 | $meta_query[] = array( |
343 | 343 | 'key' => '_wpi_discount_type', |
344 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
344 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
345 | 345 | 'compare' => '=' |
346 | 346 | ); |
347 | 347 | } |
348 | 348 | |
349 | - if ( !empty( $meta_query ) ) { |
|
349 | + if (!empty($meta_query)) { |
|
350 | 350 | $vars['meta_query'] = $meta_query; |
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | 354 | return $vars; |
355 | 355 | } |
356 | -add_filter( 'request', 'wpinv_request' ); |
|
356 | +add_filter('request', 'wpinv_request'); |
|
357 | 357 | |
358 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
358 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
359 | 359 | global $pagenow, $typenow; |
360 | 360 | |
361 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
362 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
363 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
361 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
362 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
363 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
364 | 364 | } |
365 | 365 | |
366 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
366 | + if (!wpinv_item_is_editable($post_id)) { |
|
367 | 367 | $classes[] = 'wpi-editable-n'; |
368 | 368 | } |
369 | 369 | } |
370 | 370 | return $classes; |
371 | 371 | } |
372 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
372 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
373 | 373 | |
374 | 374 | function wpinv_check_quick_edit() { |
375 | 375 | global $pagenow, $current_screen, $wpinv_item_screen; |
376 | 376 | |
377 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
378 | - if ( empty( $wpinv_item_screen ) ) { |
|
379 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
377 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
378 | + if (empty($wpinv_item_screen)) { |
|
379 | + if ($current_screen->post_type == 'wpi_item') { |
|
380 | 380 | $wpinv_item_screen = 'y'; |
381 | 381 | } else { |
382 | 382 | $wpinv_item_screen = 'n'; |
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
387 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
388 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
386 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
387 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
388 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | } |
392 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
392 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
393 | 393 | |
394 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
395 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
396 | - unset( $actions['inline hide-if-no-js'] ); |
|
394 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
395 | + if (isset($actions['inline hide-if-no-js'])) { |
|
396 | + unset($actions['inline hide-if-no-js']); |
|
397 | 397 | } |
398 | 398 | |
399 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
400 | - if ( isset( $actions['trash'] ) ) { |
|
401 | - unset( $actions['trash'] ); |
|
399 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
400 | + if (isset($actions['trash'])) { |
|
401 | + unset($actions['trash']); |
|
402 | 402 | } |
403 | - if ( isset( $actions['delete'] ) ) { |
|
404 | - unset( $actions['delete'] ); |
|
403 | + if (isset($actions['delete'])) { |
|
404 | + unset($actions['delete']); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
@@ -418,19 +418,19 @@ discard block |
||
418 | 418 | * @param int $post_parent (default: 0) Parent for the new page |
419 | 419 | * @return int page ID |
420 | 420 | */ |
421 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
421 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
422 | 422 | global $wpdb; |
423 | 423 | |
424 | - $option_value = wpinv_get_option( $option ); |
|
424 | + $option_value = wpinv_get_option($option); |
|
425 | 425 | |
426 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
427 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
426 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
427 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
428 | 428 | // Valid page is already in place |
429 | 429 | return $page_object->ID; |
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
433 | - if(!empty($post_parent)){ |
|
433 | + if (!empty($post_parent)) { |
|
434 | 434 | $page = get_page_by_path($post_parent); |
435 | 435 | if ($page) { |
436 | 436 | $post_parent = $page->ID; |
@@ -439,40 +439,40 @@ discard block |
||
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - if ( strlen( $page_content ) > 0 ) { |
|
442 | + if (strlen($page_content) > 0) { |
|
443 | 443 | // Search for an existing page with the specified page content (typically a shortcode) |
444 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
444 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
445 | 445 | } else { |
446 | 446 | // Search for an existing page with the specified page slug |
447 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
447 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
448 | 448 | } |
449 | 449 | |
450 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
450 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
451 | 451 | |
452 | - if ( $valid_page_found ) { |
|
453 | - if ( $option ) { |
|
454 | - wpinv_update_option( $option, $valid_page_found ); |
|
452 | + if ($valid_page_found) { |
|
453 | + if ($option) { |
|
454 | + wpinv_update_option($option, $valid_page_found); |
|
455 | 455 | } |
456 | 456 | return $valid_page_found; |
457 | 457 | } |
458 | 458 | |
459 | 459 | // Search for a matching valid trashed page |
460 | - if ( strlen( $page_content ) > 0 ) { |
|
460 | + if (strlen($page_content) > 0) { |
|
461 | 461 | // Search for an existing page with the specified page content (typically a shortcode) |
462 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
462 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
463 | 463 | } else { |
464 | 464 | // Search for an existing page with the specified page slug |
465 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
465 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
466 | 466 | } |
467 | 467 | |
468 | - if ( $trashed_page_found ) { |
|
468 | + if ($trashed_page_found) { |
|
469 | 469 | $page_id = $trashed_page_found; |
470 | 470 | $page_data = array( |
471 | 471 | 'ID' => $page_id, |
472 | 472 | 'post_status' => 'publish', |
473 | 473 | 'post_parent' => $post_parent, |
474 | 474 | ); |
475 | - wp_update_post( $page_data ); |
|
475 | + wp_update_post($page_data); |
|
476 | 476 | } else { |
477 | 477 | $page_data = array( |
478 | 478 | 'post_status' => 'publish', |
@@ -484,11 +484,11 @@ discard block |
||
484 | 484 | 'post_parent' => $post_parent, |
485 | 485 | 'comment_status' => 'closed', |
486 | 486 | ); |
487 | - $page_id = wp_insert_post( $page_data ); |
|
487 | + $page_id = wp_insert_post($page_data); |
|
488 | 488 | } |
489 | 489 | |
490 | - if ( $option ) { |
|
491 | - wpinv_update_option( $option, (int)$page_id ); |
|
490 | + if ($option) { |
|
491 | + wpinv_update_option($option, (int)$page_id); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | return $page_id; |
@@ -1,60 +1,60 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
|
5 | +add_filter('wpinv_authorizenet_support_subscription', '__return_true'); |
|
6 | 6 | |
7 | -function wpinv_authorizenet_cc_form( $invoice_id ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
9 | - $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : ''; |
|
7 | +function wpinv_authorizenet_cc_form($invoice_id) { |
|
8 | + $invoice = wpinv_get_invoice($invoice_id); |
|
9 | + $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : ''; |
|
10 | 10 | ?> |
11 | 11 | <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default"> |
12 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div> |
|
12 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div> |
|
13 | 13 | <div class="panel-body"> |
14 | 14 | <div class="form-group required"> |
15 | - <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-5"> |
17 | - <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]"> |
|
17 | + <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]"> |
|
18 | 18 | </div> |
19 | 19 | </div> |
20 | 20 | <div class="form-group required"> |
21 | - <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-5"> |
23 | - <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]"> |
|
23 | + <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]"> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="form-group required"> |
27 | - <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label> |
|
28 | 28 | <div class="col-sm-2"> |
29 | 29 | <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]"> |
30 | - <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
31 | - <option value="<?php echo $value;?>"><?php echo $value;?></option> |
|
30 | + <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
31 | + <option value="<?php echo $value; ?>"><?php echo $value; ?></option> |
|
32 | 32 | <?php } ?> |
33 | 33 | </select> |
34 | 34 | </div> |
35 | 35 | <div class="col-sm-3"> |
36 | 36 | <select class="form-control" name="authorizenet[cc_expire_year]"> |
37 | - <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?> |
|
38 | - <option value="<?php echo $i;?>"><?php echo $i;?></option> |
|
37 | + <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?> |
|
38 | + <option value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div class="form-group required"> |
44 | - <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-5"> |
46 | - <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]""> |
|
46 | + <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]""> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | <?php |
52 | 52 | } |
53 | -add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 ); |
|
53 | +add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1); |
|
54 | 54 | |
55 | -function wpinv_process_authorizenet_payment( $purchase_data ) { |
|
56 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
57 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_process_authorizenet_payment($purchase_data) { |
|
56 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
57 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Collect payment data |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Record the pending payment |
75 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
75 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
76 | 76 | |
77 | - if ( !empty( $invoice ) ) { |
|
78 | - $authorizenet_card = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array(); |
|
77 | + if (!empty($invoice)) { |
|
78 | + $authorizenet_card = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array(); |
|
79 | 79 | $card_defaults = array( |
80 | 80 | 'cc_owner' => $invoice->get_user_full_name(), |
81 | 81 | 'cc_number' => false, |
@@ -83,192 +83,192 @@ discard block |
||
83 | 83 | 'cc_expire_year' => false, |
84 | 84 | 'cc_cvv2' => false, |
85 | 85 | ); |
86 | - $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults ); |
|
86 | + $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults); |
|
87 | 87 | |
88 | - if ( empty( $authorizenet_card['cc_owner'] ) ) { |
|
89 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
88 | + if (empty($authorizenet_card['cc_owner'])) { |
|
89 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
90 | 90 | } |
91 | - if ( empty( $authorizenet_card['cc_number'] ) ) { |
|
92 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
91 | + if (empty($authorizenet_card['cc_number'])) { |
|
92 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
93 | 93 | } |
94 | - if ( empty( $authorizenet_card['cc_expire_month'] ) ) { |
|
95 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
94 | + if (empty($authorizenet_card['cc_expire_month'])) { |
|
95 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
96 | 96 | } |
97 | - if ( empty( $authorizenet_card['cc_expire_year'] ) ) { |
|
98 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
97 | + if (empty($authorizenet_card['cc_expire_year'])) { |
|
98 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
99 | 99 | } |
100 | - if ( empty( $authorizenet_card['cc_cvv2'] ) ) { |
|
101 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
100 | + if (empty($authorizenet_card['cc_cvv2'])) { |
|
101 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $errors = wpinv_get_errors(); |
105 | 105 | |
106 | - if ( empty( $errors ) ) { |
|
106 | + if (empty($errors)) { |
|
107 | 107 | $invoice_id = $invoice->ID; |
108 | 108 | $quantities_enabled = wpinv_item_quantities_enabled(); |
109 | 109 | $use_taxes = wpinv_use_taxes(); |
110 | 110 | |
111 | 111 | $authorizeAIM = wpinv_authorizenet_AIM(); |
112 | - $authorizeAIM->first_name = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 ); |
|
113 | - $authorizeAIM->last_name = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 ); |
|
114 | - $authorizeAIM->company = wpinv_utf8_substr( $invoice->company, 0, 50 ); |
|
115 | - $authorizeAIM->address = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 ); |
|
116 | - $authorizeAIM->city = wpinv_utf8_substr( $invoice->city, 0, 40 ); |
|
117 | - $authorizeAIM->state = wpinv_utf8_substr( $invoice->state, 0, 40 ); |
|
118 | - $authorizeAIM->zip = wpinv_utf8_substr( $invoice->zip, 0, 40 ); |
|
119 | - $authorizeAIM->country = wpinv_utf8_substr( $invoice->country, 0, 60 ); |
|
120 | - $authorizeAIM->phone = wpinv_utf8_substr( $invoice->phone, 0, 25 ); |
|
121 | - $authorizeAIM->email = wpinv_utf8_substr( $invoice->get_email(), 0, 255 ); |
|
122 | - $authorizeAIM->amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
123 | - $authorizeAIM->card_num = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) ); |
|
124 | - $authorizeAIM->exp_date = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] ); |
|
125 | - $authorizeAIM->card_code = sanitize_text_field( $authorizenet_card['cc_cvv2'] ); |
|
112 | + $authorizeAIM->first_name = wpinv_utf8_substr($invoice->get_first_name(), 0, 50); |
|
113 | + $authorizeAIM->last_name = wpinv_utf8_substr($invoice->get_last_name(), 0, 50); |
|
114 | + $authorizeAIM->company = wpinv_utf8_substr($invoice->company, 0, 50); |
|
115 | + $authorizeAIM->address = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60); |
|
116 | + $authorizeAIM->city = wpinv_utf8_substr($invoice->city, 0, 40); |
|
117 | + $authorizeAIM->state = wpinv_utf8_substr($invoice->state, 0, 40); |
|
118 | + $authorizeAIM->zip = wpinv_utf8_substr($invoice->zip, 0, 40); |
|
119 | + $authorizeAIM->country = wpinv_utf8_substr($invoice->country, 0, 60); |
|
120 | + $authorizeAIM->phone = wpinv_utf8_substr($invoice->phone, 0, 25); |
|
121 | + $authorizeAIM->email = wpinv_utf8_substr($invoice->get_email(), 0, 255); |
|
122 | + $authorizeAIM->amount = wpinv_sanitize_amount($invoice->get_total()); |
|
123 | + $authorizeAIM->card_num = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number'])); |
|
124 | + $authorizeAIM->exp_date = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']); |
|
125 | + $authorizeAIM->card_code = sanitize_text_field($authorizenet_card['cc_cvv2']); |
|
126 | 126 | $authorizeAIM->invoice_num = $invoice->ID; |
127 | 127 | |
128 | 128 | $item_desc = array(); |
129 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
130 | - $quantity = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | - $item_name = wpinv_utf8_substr( $item['name'], 0, 31 ); |
|
132 | - $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
129 | + foreach ($invoice->get_cart_details() as $item) { |
|
130 | + $quantity = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | + $item_name = wpinv_utf8_substr($item['name'], 0, 31); |
|
132 | + $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
133 | 133 | |
134 | - $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
134 | + $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
135 | 135 | } |
136 | 136 | |
137 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
137 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
138 | 138 | |
139 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
140 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
139 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
140 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
141 | 141 | |
142 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
142 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $invoice->get_discount() > 0 ) { |
|
146 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
145 | + if ($invoice->get_discount() > 0) { |
|
146 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
147 | 147 | } |
148 | 148 | |
149 | - $item_description = wpinv_utf8_substr( $item_desc, 0, 255 ); |
|
150 | - $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
149 | + $item_description = wpinv_utf8_substr($item_desc, 0, 255); |
|
150 | + $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
151 | 151 | |
152 | - $authorizeAIM->description = wpinv_utf8_substr( $item_description, 0, 255 ); |
|
152 | + $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255); |
|
153 | 153 | |
154 | 154 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
155 | 155 | |
156 | - if ( $is_recurring ) { |
|
156 | + if ($is_recurring) { |
|
157 | 157 | $authorizeAIM->recurring_billing = true; |
158 | 158 | } |
159 | 159 | |
160 | 160 | try { |
161 | 161 | |
162 | - if ( $is_recurring ) { |
|
162 | + if ($is_recurring) { |
|
163 | 163 | $trx_type = wpinv_get_option('authorizenet_transaction_type_recurring', 'authorize_only'); |
164 | - if('authorize_capture' == $trx_type){ |
|
164 | + if ('authorize_capture' == $trx_type) { |
|
165 | 165 | $response = $authorizeAIM->authorizeAndCapture(); |
166 | 166 | } else { |
167 | 167 | $response = $authorizeAIM->authorizeOnly(); |
168 | 168 | } |
169 | 169 | } else { |
170 | 170 | $trx_type = wpinv_get_option('authorizenet_transaction_type', 'authorize_capture'); |
171 | - if('authorize_capture' == $trx_type){ |
|
171 | + if ('authorize_capture' == $trx_type) { |
|
172 | 172 | $response = $authorizeAIM->authorizeAndCapture(); |
173 | 173 | } else { |
174 | 174 | $response = $authorizeAIM->authorizeOnly(); |
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | - if ( $response->approved || $response->held ) { |
|
179 | - if ( $response->approved ) { |
|
180 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
178 | + if ($response->approved || $response->held) { |
|
179 | + if ($response->approved) { |
|
180 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
181 | 181 | } |
182 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
182 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
183 | 183 | |
184 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true ); |
|
185 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true ); |
|
184 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true); |
|
185 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true); |
|
186 | 186 | |
187 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
187 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
188 | 188 | |
189 | 189 | wpinv_clear_errors(); |
190 | 190 | wpinv_empty_cart(); |
191 | 191 | |
192 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
192 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
193 | 193 | } else { |
194 | - if ( !empty( $response->response_reason_text ) ) { |
|
195 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
196 | - } else if ( !empty( $response->error_message ) ) { |
|
197 | - $error = __( $response->error_message, 'invoicing' ); |
|
194 | + if (!empty($response->response_reason_text)) { |
|
195 | + $error = __($response->response_reason_text, 'invoicing'); |
|
196 | + } else if (!empty($response->error_message)) { |
|
197 | + $error = __($response->error_message, 'invoicing'); |
|
198 | 198 | } else { |
199 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
199 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
200 | 200 | } |
201 | 201 | |
202 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
202 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
203 | 203 | |
204 | - wpinv_set_error( 'payment_error', $error ); |
|
205 | - wpinv_record_gateway_error( $error, $response ); |
|
206 | - wpinv_insert_payment_note( $invoice_id, $error, '', '', true ); |
|
204 | + wpinv_set_error('payment_error', $error); |
|
205 | + wpinv_record_gateway_error($error, $response); |
|
206 | + wpinv_insert_payment_note($invoice_id, $error, '', '', true); |
|
207 | 207 | |
208 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
208 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
209 | 209 | } |
210 | - } catch ( AuthorizeNetException $e ) { |
|
211 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
212 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
213 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
210 | + } catch (AuthorizeNetException $e) { |
|
211 | + wpinv_set_error('request_error', $e->getMessage()); |
|
212 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
213 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
214 | 214 | } |
215 | 215 | } else { |
216 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
216 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
217 | 217 | } |
218 | 218 | } else { |
219 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice ); |
|
220 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
219 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice); |
|
220 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
221 | 221 | } |
222 | 222 | } |
223 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
223 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
224 | 224 | |
225 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
226 | - if ( empty( $subscription_id ) ) { |
|
225 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
226 | + if (empty($subscription_id)) { |
|
227 | 227 | return false; |
228 | 228 | } |
229 | 229 | |
230 | 230 | try { |
231 | 231 | $authnetXML = wpinv_authorizenet_XML(); |
232 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
232 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
233 | 233 | return $authnetXML->isSuccessful(); |
234 | - } catch( Exception $e ) { |
|
235 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
234 | + } catch (Exception $e) { |
|
235 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | |
241 | -function wpinv_recurring_cancel_authorizenet_subscription( $subscription, $valid = false ) { |
|
242 | - if ( ! empty( $valid ) && ! empty( $subscription->profile_id ) ) { |
|
243 | - return wpinv_authorizenet_cancel_subscription( $subscription->profile_id ); |
|
241 | +function wpinv_recurring_cancel_authorizenet_subscription($subscription, $valid = false) { |
|
242 | + if (!empty($valid) && !empty($subscription->profile_id)) { |
|
243 | + return wpinv_authorizenet_cancel_subscription($subscription->profile_id); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return false; |
247 | 247 | } |
248 | -add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2 ); |
|
248 | +add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2); |
|
249 | 249 | |
250 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
251 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
252 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
250 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
251 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
252 | + if (empty($authorizenet_md5_hash)) { |
|
253 | 253 | return true; |
254 | 254 | } |
255 | 255 | |
256 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
256 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
257 | 257 | |
258 | - return hash_equals( $compare_md5, $md5_hash ); |
|
258 | + return hash_equals($compare_md5, $md5_hash); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | function wpinv_authorizenet_AIM() { |
262 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
263 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
262 | + if (!class_exists('AuthorizeNetException')) { |
|
263 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
264 | 264 | } |
265 | 265 | |
266 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
266 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
267 | 267 | |
268 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
269 | - $authorizeAIM->setSandbox( true ); |
|
268 | + if (wpinv_is_test_mode('authorizenet')) { |
|
269 | + $authorizeAIM->setSandbox(true); |
|
270 | 270 | } else { |
271 | - $authorizeAIM->setSandbox( false ); |
|
271 | + $authorizeAIM->setSandbox(false); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -277,250 +277,250 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | function wpinv_authorizenet_XML() { |
280 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
281 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
280 | + if (!class_exists('AuthnetXML')) { |
|
281 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
282 | 282 | } |
283 | 283 | |
284 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
284 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet')); |
|
285 | 285 | |
286 | 286 | return $authnetXML; |
287 | 287 | } |
288 | 288 | |
289 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
290 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
289 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
290 | + if (empty($response) || empty($invoice)) { |
|
291 | 291 | return false; |
292 | 292 | } |
293 | 293 | |
294 | - if ( $invoice->is_recurring() && !empty( $response->approved ) ) { |
|
295 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
294 | + if ($invoice->is_recurring() && !empty($response->approved)) { |
|
295 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
296 | 296 | $success = false; |
297 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
297 | + if (wpinv_is_test_mode('authorizenet')) { |
|
298 | 298 | $success = true; |
299 | 299 | } else { |
300 | 300 | $success = $subscription->isSuccessful(); |
301 | 301 | } |
302 | 302 | |
303 | - if ( !empty( $subscription ) && $success ) { |
|
304 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
303 | + if (!empty($subscription) && $success) { |
|
304 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
305 | 305 | |
306 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
306 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
307 | 307 | |
308 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
308 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
309 | 309 | } else { |
310 | - if ( isset( $subscription->messages->message ) ) { |
|
310 | + if (isset($subscription->messages->message)) { |
|
311 | 311 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
312 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
312 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
313 | 313 | } else { |
314 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
315 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
314 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
315 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
316 | 316 | } |
317 | 317 | |
318 | - wpinv_record_gateway_error( $error, $subscription ); |
|
318 | + wpinv_record_gateway_error($error, $subscription); |
|
319 | 319 | |
320 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true ); |
|
320 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
324 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
324 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
325 | 325 | |
326 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
327 | - if ( empty( $invoice ) ) { |
|
326 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
327 | + if (empty($invoice)) { |
|
328 | 328 | return false; |
329 | 329 | } |
330 | 330 | |
331 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
331 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
332 | 332 | |
333 | 333 | try { |
334 | 334 | $authnetXML = wpinv_authorizenet_XML(); |
335 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
336 | - } catch( Exception $e ) { |
|
335 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
336 | + } catch (Exception $e) { |
|
337 | 337 | $authnetXML = array(); |
338 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
338 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $authnetXML; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
345 | - if ( empty( $invoice ) ) { |
|
344 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
345 | + if (empty($invoice)) { |
|
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | |
349 | - $subscription_item = $invoice->get_recurring( true ); |
|
350 | - if ( empty( $subscription_item->ID ) ) { |
|
349 | + $subscription_item = $invoice->get_recurring(true); |
|
350 | + if (empty($subscription_item->ID)) { |
|
351 | 351 | return false; |
352 | 352 | } |
353 | 353 | |
354 | - $item = $invoice->get_recurring( true ); |
|
354 | + $item = $invoice->get_recurring(true); |
|
355 | 355 | |
356 | - if ( empty( $item ) ) { |
|
356 | + if (empty($item)) { |
|
357 | 357 | $name = ''; |
358 | 358 | } |
359 | 359 | |
360 | - if ( !( $name = $item->get_name() ) ) { |
|
360 | + if (!($name = $item->get_name())) { |
|
361 | 361 | $name = $item->post_name; |
362 | 362 | } |
363 | 363 | |
364 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
364 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
365 | 365 | $subscription_name = $invoice->get_subscription_name(); |
366 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
367 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
366 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
367 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
368 | 368 | $interval = $subscription_item->get_recurring_interval(); |
369 | 369 | $period = $subscription_item->get_recurring_period(); |
370 | 370 | $bill_times = (int)$subscription_item->get_recurring_limit(); |
371 | 371 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
372 | 372 | |
373 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
373 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
374 | 374 | $interval = $time_period['interval']; |
375 | 375 | $period = $time_period['period']; |
376 | 376 | |
377 | 377 | $current_tz = date_default_timezone_get(); |
378 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
379 | - $today = date( 'Y-m-d' ); |
|
380 | - date_default_timezone_set( $current_tz ); |
|
378 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
379 | + $today = date('Y-m-d'); |
|
380 | + date_default_timezone_set($current_tz); |
|
381 | 381 | |
382 | 382 | $free_trial = $invoice->is_free_trial(); |
383 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
383 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
384 | 384 | $trial_interval = $subscription_item->get_trial_interval(); |
385 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
385 | + $trial_period = $subscription_item->get_trial_period(true); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | $subscription = array(); |
389 | 389 | $subscription['name'] = $subscription_name; |
390 | 390 | |
391 | 391 | $subscription['paymentSchedule'] = array( |
392 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
392 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
393 | 393 | 'startDate' => $today, |
394 | 394 | 'totalOccurrences' => $bill_times, |
395 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
395 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
396 | 396 | ); |
397 | 397 | |
398 | 398 | $subscription['amount'] = $recurring_amount; |
399 | 399 | $subscription['trialAmount'] = $initial_amount; |
400 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
401 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
402 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
400 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
401 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
402 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
403 | 403 | |
404 | 404 | $subscription['billTo'] = array( |
405 | 405 | 'firstName' => $invoice->get_first_name(), |
406 | 406 | 'lastName' => $invoice->get_last_name(), |
407 | 407 | 'company' => $invoice->company, |
408 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
408 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
409 | 409 | 'city' => $invoice->city, |
410 | 410 | 'state' => $invoice->state, |
411 | 411 | 'zip' => $invoice->zip, |
412 | 412 | 'country' => $invoice->country, |
413 | 413 | ); |
414 | 414 | |
415 | - $params = array( 'subscription' => $subscription ); |
|
415 | + $params = array('subscription' => $subscription); |
|
416 | 416 | |
417 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
417 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
418 | 418 | } |
419 | 419 | |
420 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
421 | - $card_defaults = array( |
|
420 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
421 | + $card_defaults = array( |
|
422 | 422 | 'cc_owner' => null, |
423 | 423 | 'cc_number' => null, |
424 | 424 | 'cc_expire_month' => null, |
425 | 425 | 'cc_expire_year' => null, |
426 | 426 | 'cc_cvv2' => null, |
427 | 427 | ); |
428 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
428 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
429 | 429 | |
430 | 430 | $card_details = array( |
431 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
432 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
433 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
431 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
432 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
433 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
434 | 434 | ); |
435 | 435 | |
436 | 436 | return $card_details; |
437 | 437 | } |
438 | 438 | |
439 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
440 | - $parent_invoice_id = absint( $invoice->ID ); |
|
439 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
440 | + $parent_invoice_id = absint($invoice->ID); |
|
441 | 441 | |
442 | - if( empty( $parent_invoice_id ) ) { |
|
442 | + if (empty($parent_invoice_id)) { |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
447 | - if ( empty( $invoice ) ) { |
|
446 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
447 | + if (empty($invoice)) { |
|
448 | 448 | return; |
449 | 449 | } |
450 | 450 | |
451 | 451 | $subscriptionId = (array)$subscription->subscriptionId; |
452 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
452 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
453 | 453 | |
454 | - $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id ); |
|
454 | + $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id); |
|
455 | 455 | |
456 | - if ( false === $subscription ) { |
|
456 | + if (false === $subscription) { |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Set payment to complete |
461 | - wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' ); |
|
461 | + wpinv_update_payment_status($subscription->parent_payment_id, 'publish'); |
|
462 | 462 | sleep(1); |
463 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true ); |
|
464 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id); |
|
463 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true); |
|
464 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id); |
|
465 | 465 | |
466 | 466 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
467 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
468 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
469 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
467 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
468 | + $created = date_i18n('Y-m-d H:i:s'); |
|
469 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
470 | 470 | |
471 | 471 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
472 | - $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
472 | + $subscription->update(array('profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
476 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
475 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
476 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
477 | 477 | $error = false; |
478 | 478 | |
479 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
479 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
480 | 480 | $error = true; |
481 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
481 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
482 | 482 | } |
483 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
483 | + if (empty($post['authorizenet']['cc_number'])) { |
|
484 | 484 | $error = true; |
485 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
485 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
486 | 486 | } |
487 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
487 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
488 | 488 | $error = true; |
489 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
489 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
490 | 490 | } |
491 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
491 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
492 | 492 | $error = true; |
493 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
493 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
494 | 494 | } |
495 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
495 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
496 | 496 | $error = true; |
497 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
497 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
498 | 498 | } |
499 | 499 | |
500 | - if ( $error ) { |
|
500 | + if ($error) { |
|
501 | 501 | return; |
502 | 502 | } |
503 | 503 | |
504 | 504 | $invoice = wpinv_get_invoice_cart(); |
505 | 505 | |
506 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
507 | - $subscription_item = $invoice->get_recurring( true ); |
|
506 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
507 | + $subscription_item = $invoice->get_recurring(true); |
|
508 | 508 | |
509 | 509 | $interval = $subscription_item->get_recurring_interval(); |
510 | 510 | $period = $subscription_item->get_recurring_period(); |
511 | 511 | |
512 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
513 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
512 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
513 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
518 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
518 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
519 | 519 | |
520 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
521 | - $subscription_interval = absint( $subscription_interval ); |
|
520 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
521 | + $subscription_interval = absint($subscription_interval); |
|
522 | 522 | |
523 | - switch( $subscription_period ) { |
|
523 | + switch ($subscription_period) { |
|
524 | 524 | case 'W': |
525 | 525 | case 'week': |
526 | 526 | case 'weeks': |
@@ -530,14 +530,14 @@ discard block |
||
530 | 530 | case 'M': |
531 | 531 | case 'month': |
532 | 532 | case 'months': |
533 | - if ( $subscription_interval > 12 ) { |
|
533 | + if ($subscription_interval > 12) { |
|
534 | 534 | $subscription_interval = 12; |
535 | 535 | } |
536 | 536 | |
537 | 537 | $interval = $subscription_interval; |
538 | 538 | $period = 'months'; |
539 | 539 | |
540 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
540 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
541 | 541 | $interval = $subscription_interval * 30; |
542 | 542 | $period = 'days'; |
543 | 543 | } |
@@ -554,30 +554,30 @@ discard block |
||
554 | 554 | break; |
555 | 555 | } |
556 | 556 | |
557 | - return compact( 'interval', 'period' ); |
|
557 | + return compact('interval', 'period'); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | function wpinv_authorizenet_process_ipn() { |
561 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
561 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
562 | 562 | return; |
563 | 563 | } |
564 | 564 | |
565 | - $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false; |
|
565 | + $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false; |
|
566 | 566 | |
567 | - if ( $subscription_id ) { |
|
568 | - $response_code = intval( $_POST['x_response_code'] ); |
|
569 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
567 | + if ($subscription_id) { |
|
568 | + $response_code = intval($_POST['x_response_code']); |
|
569 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
570 | 570 | |
571 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
571 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
572 | 572 | |
573 | - if ( !$subscription->id ) { |
|
573 | + if (!$subscription->id) { |
|
574 | 574 | return; |
575 | 575 | } |
576 | 576 | |
577 | - if ( 1 == $response_code ) { |
|
577 | + if (1 == $response_code) { |
|
578 | 578 | // Approved |
579 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
580 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
579 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
580 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
581 | 581 | |
582 | 582 | $args = array( |
583 | 583 | 'amount' => $renewal_amount, |
@@ -585,63 +585,63 @@ discard block |
||
585 | 585 | 'gateway' => 'authorizenet' |
586 | 586 | ); |
587 | 587 | |
588 | - $subscription->add_payment( $args ); |
|
588 | + $subscription->add_payment($args); |
|
589 | 589 | $subscription->renew(); |
590 | 590 | |
591 | - do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription ); |
|
592 | - do_action( 'wpinv_authorizenet_renewal_payment', $subscription ); |
|
593 | - } else if ( 2 == $response_code ) { |
|
591 | + do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription); |
|
592 | + do_action('wpinv_authorizenet_renewal_payment', $subscription); |
|
593 | + } else if (2 == $response_code) { |
|
594 | 594 | // Declined |
595 | 595 | $subscription->failing(); |
596 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
597 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
598 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
596 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
597 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
598 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
599 | 599 | // An expired card |
600 | 600 | $subscription->failing(); |
601 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
602 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
601 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
602 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
603 | 603 | } else { |
604 | 604 | // Other Error |
605 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
605 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | exit; |
609 | 609 | } |
610 | 610 | } |
611 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
611 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
612 | 612 | |
613 | 613 | /** |
614 | 614 | * Retrieve the subscription |
615 | 615 | */ |
616 | -function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) { |
|
617 | - $parent_invoice_id = absint( $invoice_id ); |
|
616 | +function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) { |
|
617 | + $parent_invoice_id = absint($invoice_id); |
|
618 | 618 | |
619 | - if ( empty( $subscription_data ) ) { |
|
619 | + if (empty($subscription_data)) { |
|
620 | 620 | return false; |
621 | 621 | } |
622 | 622 | |
623 | - if ( empty( $parent_invoice_id ) ) { |
|
623 | + if (empty($parent_invoice_id)) { |
|
624 | 624 | return false; |
625 | 625 | } |
626 | 626 | |
627 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
628 | - if ( empty( $invoice ) ) { |
|
627 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
628 | + if (empty($invoice)) { |
|
629 | 629 | return false; |
630 | 630 | } |
631 | 631 | |
632 | 632 | $subscriptionId = (array)$subscription_data->subscriptionId; |
633 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
633 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
634 | 634 | |
635 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
635 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
636 | 636 | |
637 | - if ( ! $subscription || $subscription->id < 1 ) { |
|
637 | + if (!$subscription || $subscription->id < 1) { |
|
638 | 638 | $subs_db = new WPInv_Subscriptions_DB; |
639 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) ); |
|
640 | - $subscription = reset( $subs ); |
|
639 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1)); |
|
640 | + $subscription = reset($subs); |
|
641 | 641 | |
642 | - if ( $subscription && $subscription->id > 0 ) { |
|
642 | + if ($subscription && $subscription->id > 0) { |
|
643 | 643 | // Update the profile ID so it is set for future renewals |
644 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) ); |
|
644 | + $subscription->update(array('profile_id' => sanitize_text_field($subscription_id))); |
|
645 | 645 | } else { |
646 | 646 | // No subscription found with a matching payment ID, bail |
647 | 647 | return false; |
@@ -652,67 +652,67 @@ discard block |
||
652 | 652 | } |
653 | 653 | |
654 | 654 | function wpinv_is_authorizenet_valid_for_use() { |
655 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) ); |
|
655 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR'))); |
|
656 | 656 | } |
657 | -function wpinv_check_authorizenet_currency_support( $gateway_list ) { |
|
658 | - if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) { |
|
659 | - unset( $gateway_list['authorizenet'] ); |
|
657 | +function wpinv_check_authorizenet_currency_support($gateway_list) { |
|
658 | + if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) { |
|
659 | + unset($gateway_list['authorizenet']); |
|
660 | 660 | } |
661 | 661 | return $gateway_list; |
662 | 662 | } |
663 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 ); |
|
663 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1); |
|
664 | 664 | |
665 | -function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
666 | - if ( $transaction_id == $invoice_id ) { |
|
665 | +function wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
666 | + if ($transaction_id == $invoice_id) { |
|
667 | 667 | $link = $transaction_id; |
668 | 668 | } else { |
669 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
669 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
670 | 670 | $mode = $invoice->mode; |
671 | 671 | } else { |
672 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
672 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
676 | 676 | $url .= 'ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=' . $transaction_id; |
677 | 677 | |
678 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
678 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
679 | 679 | } |
680 | 680 | |
681 | - return apply_filters( 'wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice ); |
|
681 | + return apply_filters('wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice); |
|
682 | 682 | } |
683 | -add_filter( 'wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3 ); |
|
683 | +add_filter('wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3); |
|
684 | 684 | |
685 | -function wpinv_authorizenet_transaction_id_link( $transaction_id, $subscription ) { |
|
686 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
687 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
685 | +function wpinv_authorizenet_transaction_id_link($transaction_id, $subscription) { |
|
686 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
687 | + $invoice = wpinv_get_invoice($invoice_id); |
|
688 | 688 | |
689 | - if ( ! empty( $invoice ) ) { |
|
690 | - return wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
689 | + if (!empty($invoice)) { |
|
690 | + return wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
694 | 694 | return $transaction_id; |
695 | 695 | } |
696 | -add_filter( 'wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2 ); |
|
696 | +add_filter('wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2); |
|
697 | 697 | |
698 | -function wpinv_authorizenet_profile_id_link( $profile_id, $subscription ) { |
|
698 | +function wpinv_authorizenet_profile_id_link($profile_id, $subscription) { |
|
699 | 699 | $link = $profile_id; |
700 | 700 | |
701 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
702 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
701 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
702 | + $invoice = wpinv_get_invoice($invoice_id); |
|
703 | 703 | |
704 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
704 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
705 | 705 | $mode = $invoice->mode; |
706 | 706 | } else { |
707 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
707 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
711 | 711 | $url .= 'ui/themes/sandbox/ARB/SubscriptionDetail.aspx?SubscrID=' . $profile_id; |
712 | 712 | |
713 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
713 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
714 | 714 | } |
715 | 715 | |
716 | - return apply_filters( 'wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription ); |
|
716 | + return apply_filters('wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription); |
|
717 | 717 | } |
718 | -add_filter( 'wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2 ); |
|
719 | 718 | \ No newline at end of file |
719 | +add_filter('wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2); |
|
720 | 720 | \ No newline at end of file |