@@ -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_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -31,31 +31,31 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | public function define_constants() { |
34 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
35 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
34 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
35 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | private function actions() { |
39 | 39 | /* Internationalize the text strings used. */ |
40 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
40 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
41 | 41 | |
42 | 42 | /* Perform actions on admin initialization. */ |
43 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
44 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
45 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
43 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
44 | + add_action('init', array(&$this, 'init'), 3); |
|
45 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
47 | 47 | |
48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
48 | + if (class_exists('BuddyPress')) { |
|
49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
50 | 50 | } |
51 | 51 | |
52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
53 | 53 | |
54 | - if ( is_admin() ) { |
|
55 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
56 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
54 | + if (is_admin()) { |
|
55 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
56 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
57 | 57 | } else { |
58 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
58 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
67 | 67 | */ |
68 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
68 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
69 | 69 | |
70 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
70 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | public function plugins_loaded() { |
74 | 74 | /* Internationalize the text strings used. */ |
75 | 75 | $this->load_textdomain(); |
76 | 76 | |
77 | - do_action( 'wpinv_loaded' ); |
|
77 | + do_action('wpinv_loaded'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,209 +82,209 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @since 1.0 |
84 | 84 | */ |
85 | - public function load_textdomain( $locale = NULL ) { |
|
86 | - if ( empty( $locale ) ) { |
|
87 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
85 | + public function load_textdomain($locale = NULL) { |
|
86 | + if (empty($locale)) { |
|
87 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
88 | 88 | } |
89 | 89 | |
90 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
90 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
91 | 91 | |
92 | - unload_textdomain( 'invoicing' ); |
|
93 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
94 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
92 | + unload_textdomain('invoicing'); |
|
93 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
94 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Define language constants. |
98 | 98 | */ |
99 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
99 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function includes() { |
103 | 103 | global $wpinv_options; |
104 | 104 | |
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
106 | 106 | $wpinv_options = wpinv_get_settings(); |
107 | 107 | |
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
132 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
133 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
135 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
136 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
137 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
138 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
132 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
133 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
135 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
136 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
137 | + if (!class_exists('WPInv_EUVat')) { |
|
138 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
139 | 139 | } |
140 | 140 | |
141 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
142 | - if ( !empty( $gateways ) ) { |
|
143 | - foreach ( $gateways as $gateway ) { |
|
144 | - if ( $gateway == 'manual' ) { |
|
141 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
142 | + if (!empty($gateways)) { |
|
143 | + foreach ($gateways as $gateway) { |
|
144 | + if ($gateway == 'manual') { |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | |
148 | 148 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
149 | 149 | |
150 | - if ( file_exists( $gateway_file ) ) { |
|
151 | - require_once( $gateway_file ); |
|
150 | + if (file_exists($gateway_file)) { |
|
151 | + require_once($gateway_file); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | } |
155 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
155 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
156 | 156 | |
157 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
158 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
159 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
160 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
157 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
158 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
159 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
160 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
161 | 161 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
162 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
163 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
164 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
165 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
166 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
162 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
163 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
164 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
165 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
166 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
167 | 167 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
168 | 168 | } |
169 | 169 | |
170 | 170 | // include css inliner |
171 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
172 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
171 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
172 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
173 | 173 | } |
174 | 174 | |
175 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | public function init() { |
179 | 179 | } |
180 | 180 | |
181 | 181 | public function admin_init() { |
182 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
182 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
183 | 183 | } |
184 | 184 | |
185 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
185 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | public function activation_redirect() { |
189 | 189 | // Bail if no activation redirect |
190 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
190 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Delete the redirect transient |
195 | - delete_transient( '_wpinv_activation_redirect' ); |
|
195 | + delete_transient('_wpinv_activation_redirect'); |
|
196 | 196 | |
197 | 197 | // Bail if activating from network, or bulk |
198 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
198 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | |
202 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
202 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
203 | 203 | exit; |
204 | 204 | } |
205 | 205 | |
206 | 206 | public function enqueue_scripts() { |
207 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
207 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
208 | 208 | |
209 | - wp_deregister_style( 'font-awesome' ); |
|
210 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
211 | - wp_enqueue_style( 'font-awesome' ); |
|
209 | + wp_deregister_style('font-awesome'); |
|
210 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
211 | + wp_enqueue_style('font-awesome'); |
|
212 | 212 | |
213 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
214 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
213 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
214 | + wp_enqueue_style('wpinv_front_style'); |
|
215 | 215 | |
216 | 216 | // Register scripts |
217 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
218 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
217 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
218 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
219 | 219 | |
220 | 220 | $localize = array(); |
221 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
222 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
221 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
222 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
223 | 223 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
224 | 224 | $localize['currency_pos'] = wpinv_currency_position(); |
225 | 225 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
226 | 226 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
227 | 227 | $localize['decimals'] = wpinv_decimals(); |
228 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
228 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
229 | 229 | |
230 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
230 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
231 | 231 | |
232 | - wp_enqueue_script( 'jquery-blockui' ); |
|
232 | + wp_enqueue_script('jquery-blockui'); |
|
233 | 233 | $autofill_api = wpinv_get_option('address_autofill_api'); |
234 | 234 | $autofill_active = wpinv_get_option('address_autofill_active'); |
235 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
236 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
237 | - wp_dequeue_script( 'google-maps-api' ); |
|
235 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
236 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
237 | + wp_dequeue_script('google-maps-api'); |
|
238 | 238 | } |
239 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
240 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
239 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
240 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
241 | 241 | } |
242 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
243 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
242 | + wp_enqueue_script('wpinv-front-script'); |
|
243 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | public function admin_enqueue_scripts() { |
247 | 247 | global $post, $pagenow; |
248 | 248 | |
249 | 249 | $post_type = wpinv_admin_post_type(); |
250 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
251 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
250 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
251 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
252 | 252 | |
253 | - wp_deregister_style( 'font-awesome' ); |
|
254 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
255 | - wp_enqueue_style( 'font-awesome' ); |
|
253 | + wp_deregister_style('font-awesome'); |
|
254 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
255 | + wp_enqueue_style('font-awesome'); |
|
256 | 256 | |
257 | 257 | $jquery_ui_css = false; |
258 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
258 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
259 | 259 | $jquery_ui_css = true; |
260 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
260 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
261 | 261 | $jquery_ui_css = true; |
262 | 262 | } |
263 | - if ( $jquery_ui_css ) { |
|
264 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
265 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
263 | + if ($jquery_ui_css) { |
|
264 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
265 | + wp_enqueue_style('jquery-ui-css'); |
|
266 | 266 | } |
267 | 267 | |
268 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
269 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
268 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
269 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
270 | 270 | |
271 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
272 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
271 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
272 | + wp_enqueue_style('wpinv_admin_style'); |
|
273 | 273 | |
274 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
275 | - if ( $page == 'wpinv-subscriptions' ) { |
|
276 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
274 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
275 | + if ($page == 'wpinv-subscriptions') { |
|
276 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
277 | 277 | } |
278 | - $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ); |
|
278 | + $enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue); |
|
279 | 279 | |
280 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
281 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
280 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
281 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
282 | 282 | } |
283 | 283 | |
284 | - wp_enqueue_style( 'wp-color-picker' ); |
|
285 | - wp_enqueue_script( 'wp-color-picker' ); |
|
284 | + wp_enqueue_style('wp-color-picker'); |
|
285 | + wp_enqueue_script('wp-color-picker'); |
|
286 | 286 | |
287 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
287 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
288 | 288 | |
289 | 289 | if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
290 | 290 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -295,17 +295,17 @@ discard block |
||
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
299 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
298 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
299 | + wp_enqueue_script('wpinv-admin-script'); |
|
300 | 300 | |
301 | 301 | $localize = array(); |
302 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
303 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
304 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
305 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
306 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
307 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
308 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
302 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
303 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
304 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
305 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
306 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
307 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
308 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
309 | 309 | $localize['tax'] = wpinv_tax_amount(); |
310 | 310 | $localize['discount'] = wpinv_discount_amount(); |
311 | 311 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -313,69 +313,69 @@ discard block |
||
313 | 313 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
314 | 314 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
315 | 315 | $localize['decimals'] = wpinv_decimals(); |
316 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
317 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
318 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
319 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
320 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
321 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
322 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
323 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
324 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
325 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
326 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
327 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
328 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
329 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
316 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
317 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
318 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
319 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
320 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
321 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
322 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
323 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
324 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
325 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
326 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
327 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
328 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
329 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
330 | 330 | |
331 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
331 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
332 | 332 | |
333 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
333 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
334 | 334 | |
335 | - if ( $page == 'wpinv-subscriptions' ) { |
|
336 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
337 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
335 | + if ($page == 'wpinv-subscriptions') { |
|
336 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
337 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - public function admin_body_class( $classes ) { |
|
341 | + public function admin_body_class($classes) { |
|
342 | 342 | global $pagenow, $post, $current_screen; |
343 | 343 | |
344 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
344 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
345 | 345 | $classes .= ' wpinv-cpt'; |
346 | 346 | } |
347 | 347 | |
348 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
348 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
349 | 349 | |
350 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
351 | - if ( $add_class ) { |
|
352 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
350 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
351 | + if ($add_class) { |
|
352 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | $settings_class = array(); |
356 | - if ( $page == 'wpinv-settings' ) { |
|
357 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
358 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
356 | + if ($page == 'wpinv-settings') { |
|
357 | + if (!empty($_REQUEST['tab'])) { |
|
358 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
362 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
361 | + if (!empty($_REQUEST['section'])) { |
|
362 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
363 | 363 | } |
364 | 364 | |
365 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
365 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
366 | 366 | } |
367 | 367 | |
368 | - if ( !empty( $settings_class ) ) { |
|
369 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
368 | + if (!empty($settings_class)) { |
|
369 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | $post_type = wpinv_admin_post_type(); |
373 | 373 | |
374 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
374 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
375 | 375 | return $classes .= ' wpinv'; |
376 | 376 | } |
377 | 377 | |
378 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
378 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
379 | 379 | $classes .= ' wpi-editable-n'; |
380 | 380 | } |
381 | 381 | |
@@ -387,20 +387,20 @@ discard block |
||
387 | 387 | } |
388 | 388 | |
389 | 389 | public function wpinv_actions() { |
390 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
391 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
390 | + if (isset($_REQUEST['wpi_action'])) { |
|
391 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
395 | - public function pre_get_posts( $wp_query ) { |
|
396 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
397 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
395 | + public function pre_get_posts($wp_query) { |
|
396 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
397 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | return $wp_query; |
401 | 401 | } |
402 | 402 | |
403 | 403 | public function bp_invoicing_init() { |
404 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
404 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | \ No newline at end of file |
@@ -11,49 +11,49 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | - if ( $wpi_version == WPINV_VERSION ) { |
|
16 | + if ($wpi_version == WPINV_VERSION) { |
|
17 | 17 | return; |
18 | 18 | } |
19 | 19 | |
20 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
20 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
21 | 21 | wpinv_v005_upgrades(); |
22 | 22 | } |
23 | 23 | |
24 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
24 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
25 | 25 | wpinv_v110_upgrades(); |
26 | 26 | } |
27 | 27 | |
28 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
28 | + update_option('wpinv_version', WPINV_VERSION); |
|
29 | 29 | } |
30 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
30 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
31 | 31 | |
32 | 32 | function wpinv_v005_upgrades() { |
33 | 33 | global $wpdb; |
34 | 34 | |
35 | 35 | // Invoices status |
36 | - $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
37 | - if ( !empty( $results ) ) { |
|
38 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
36 | + $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
37 | + if (!empty($results)) { |
|
38 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
39 | 39 | |
40 | 40 | // Clean post cache |
41 | - foreach ( $results as $row ) { |
|
42 | - clean_post_cache( $row->ID ); |
|
41 | + foreach ($results as $row) { |
|
42 | + clean_post_cache($row->ID); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Item meta key changes |
47 | 47 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
48 | - $results = $wpdb->get_results( $query ); |
|
48 | + $results = $wpdb->get_results($query); |
|
49 | 49 | |
50 | - if ( !empty( $results ) ) { |
|
51 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
52 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
53 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
50 | + if (!empty($results)) { |
|
51 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
52 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
53 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
54 | 54 | |
55 | - foreach ( $results as $row ) { |
|
56 | - clean_post_cache( $row->post_id ); |
|
55 | + foreach ($results as $row) { |
|
56 | + clean_post_cache($row->post_id); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -74,79 +74,79 @@ discard block |
||
74 | 74 | function wpinv_convert_old_subscriptions() { |
75 | 75 | global $wpdb; |
76 | 76 | |
77 | - $query = "SELECT ". $wpdb->posts .".ID FROM ". $wpdb->posts ." INNER JOIN ". $wpdb->postmeta ." ON ( ". $wpdb->posts .".ID = ". $wpdb->postmeta .".post_id ) WHERE 1=1 AND ". $wpdb->postmeta .".meta_key = '_wpinv_subscr_status' AND (". $wpdb->postmeta .".meta_value = 'pending' OR ". $wpdb->postmeta .".meta_value = 'active' OR ". $wpdb->postmeta .".meta_value = 'cancelled' OR ". $wpdb->postmeta .".meta_value = 'completed' OR ". $wpdb->postmeta .".meta_value = 'expired' OR ". $wpdb->postmeta .".meta_value = 'trialling' OR ". $wpdb->postmeta .".meta_value = 'failing') AND ". $wpdb->posts .".post_type = 'wpi_invoice' GROUP BY ". $wpdb->posts .".ID ORDER BY ". $wpdb->posts .".ID ASC"; |
|
77 | + $query = "SELECT " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON ( " . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id ) WHERE 1=1 AND " . $wpdb->postmeta . ".meta_key = '_wpinv_subscr_status' AND (" . $wpdb->postmeta . ".meta_value = 'pending' OR " . $wpdb->postmeta . ".meta_value = 'active' OR " . $wpdb->postmeta . ".meta_value = 'cancelled' OR " . $wpdb->postmeta . ".meta_value = 'completed' OR " . $wpdb->postmeta . ".meta_value = 'expired' OR " . $wpdb->postmeta . ".meta_value = 'trialling' OR " . $wpdb->postmeta . ".meta_value = 'failing') AND " . $wpdb->posts . ".post_type = 'wpi_invoice' GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC"; |
|
78 | 78 | |
79 | - $results = $wpdb->get_results( $query ); |
|
79 | + $results = $wpdb->get_results($query); |
|
80 | 80 | |
81 | - if ( empty( $results ) ) { |
|
81 | + if (empty($results)) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - foreach ( $results as $row ) { |
|
86 | - $invoice = new WPInv_Invoice( $row->ID ); |
|
85 | + foreach ($results as $row) { |
|
86 | + $invoice = new WPInv_Invoice($row->ID); |
|
87 | 87 | |
88 | - if ( empty( $invoice->ID ) ) { |
|
88 | + if (empty($invoice->ID)) { |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if ( $invoice->has_status( 'wpi-renewal' ) ) { |
|
92 | + if ($invoice->has_status('wpi-renewal')) { |
|
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | - $item = $invoice->get_recurring( true ); |
|
96 | + $item = $invoice->get_recurring(true); |
|
97 | 97 | |
98 | - if ( empty( $item ) ) { |
|
98 | + if (empty($item)) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | 102 | $is_free_trial = $invoice->is_free_trial(); |
103 | - $profile_id = get_post_meta( $invoice->ID, '_wpinv_subscr_profile_id', true ); |
|
104 | - $subscription_status = get_post_meta( $invoice->ID, '_wpinv_subscr_status', true ); |
|
103 | + $profile_id = get_post_meta($invoice->ID, '_wpinv_subscr_profile_id', true); |
|
104 | + $subscription_status = get_post_meta($invoice->ID, '_wpinv_subscr_status', true); |
|
105 | 105 | $transaction_id = $invoice->get_transaction_id(); |
106 | 106 | |
107 | 107 | // Last invoice |
108 | - $query = "SELECT ID, post_date FROM ". $wpdb->posts ." WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | - $last_payment = $wpdb->get_row( $query ); |
|
108 | + $query = "SELECT ID, post_date FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | + $last_payment = $wpdb->get_row($query); |
|
110 | 110 | |
111 | - if ( !empty( $last_payment ) ) { |
|
112 | - $invoice_date = $last_payment->post_date; |
|
111 | + if (!empty($last_payment)) { |
|
112 | + $invoice_date = $last_payment->post_date; |
|
113 | 113 | |
114 | - $meta_profile_id = get_post_meta( $last_payment->ID, '_wpinv_subscr_profile_id', true ); |
|
115 | - $meta_transaction_id = get_post_meta( $last_payment->ID, '_wpinv_transaction_id', true ); |
|
114 | + $meta_profile_id = get_post_meta($last_payment->ID, '_wpinv_subscr_profile_id', true); |
|
115 | + $meta_transaction_id = get_post_meta($last_payment->ID, '_wpinv_transaction_id', true); |
|
116 | 116 | |
117 | - if ( !empty( $meta_profile_id ) ) { |
|
118 | - $profile_id = $meta_profile_id; |
|
117 | + if (!empty($meta_profile_id)) { |
|
118 | + $profile_id = $meta_profile_id; |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( !empty( $meta_transaction_id ) ) { |
|
122 | - $transaction_id = $meta_transaction_id; |
|
121 | + if (!empty($meta_transaction_id)) { |
|
122 | + $transaction_id = $meta_transaction_id; |
|
123 | 123 | } |
124 | 124 | } else { |
125 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
125 | + $invoice_date = $invoice->get_invoice_date(false); |
|
126 | 126 | } |
127 | 127 | |
128 | - $profile_id = empty( $profile_id ) ? $invoice->ID : $profile_id; |
|
129 | - $status = empty( $subscription_status ) ? 'pending' : $subscription_status; |
|
128 | + $profile_id = empty($profile_id) ? $invoice->ID : $profile_id; |
|
129 | + $status = empty($subscription_status) ? 'pending' : $subscription_status; |
|
130 | 130 | |
131 | - $period = $item->get_recurring_period( true ); |
|
131 | + $period = $item->get_recurring_period(true); |
|
132 | 132 | $interval = $item->get_recurring_interval(); |
133 | 133 | $bill_times = (int)$item->get_recurring_limit(); |
134 | 134 | $add_period = $interval . ' ' . $period; |
135 | 135 | $trial_period = ''; |
136 | 136 | |
137 | - if ( $invoice->is_free_trial() ) { |
|
138 | - $trial_period = $item->get_trial_period( true ); |
|
137 | + if ($invoice->is_free_trial()) { |
|
138 | + $trial_period = $item->get_trial_period(true); |
|
139 | 139 | $free_interval = $item->get_trial_interval(); |
140 | 140 | $trial_period = $free_interval . ' ' . $trial_period; |
141 | 141 | |
142 | - if ( empty( $last_payment ) ) { |
|
142 | + if (empty($last_payment)) { |
|
143 | 143 | $add_period = $trial_period; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
148 | - if ( strtotime( $expiration ) < strtotime( date_i18n( 'Y-m-d' ) ) ) { |
|
149 | - if ( $status == 'active' || $status == 'trialling' || $status == 'pending' ) { |
|
147 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
148 | + if (strtotime($expiration) < strtotime(date_i18n('Y-m-d'))) { |
|
149 | + if ($status == 'active' || $status == 'trialling' || $status == 'pending') { |
|
150 | 150 | $status = 'expired'; |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'frequency' => $interval, |
160 | 160 | 'period' => $period, |
161 | 161 | 'initial_amount' => $invoice->get_total(), |
162 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
162 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
163 | 163 | 'bill_times' => $bill_times, |
164 | 164 | 'created' => $invoice_date, |
165 | 165 | 'expiration' => $expiration, |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | ); |
170 | 170 | |
171 | 171 | $subs_db = new WPInv_Subscriptions_DB; |
172 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) ); |
|
173 | - $subscription = reset( $subs ); |
|
172 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
|
173 | + $subscription = reset($subs); |
|
174 | 174 | |
175 | - if ( empty( $subscription ) || $subscription->id <= 0 ) { |
|
175 | + if (empty($subscription) || $subscription->id <= 0) { |
|
176 | 176 | $subscription = new WPInv_Subscription(); |
177 | - $new_sub = $subscription->create( $args ); |
|
177 | + $new_sub = $subscription->create($args); |
|
178 | 178 | |
179 | - if ( !empty( $bill_times ) && $new_sub->get_times_billed() >= $bill_times && ( 'active' == $new_sub->status || 'trialling' == $new_sub->status ) ) { |
|
179 | + if (!empty($bill_times) && $new_sub->get_times_billed() >= $bill_times && ('active' == $new_sub->status || 'trialling' == $new_sub->status)) { |
|
180 | 180 | $new_sub->complete(); // Mark completed if all times billed |
181 | 181 | } |
182 | 182 | } |
@@ -186,34 +186,34 @@ discard block |
||
186 | 186 | function wpinv_update_new_email_settings() { |
187 | 187 | global $wpinv_options; |
188 | 188 | |
189 | - $current_options = get_option( 'wpinv_settings', array() ); |
|
189 | + $current_options = get_option('wpinv_settings', array()); |
|
190 | 190 | $options = array(); |
191 | 191 | |
192 | 192 | // Populate some default values |
193 | - foreach( wpinv_get_registered_settings() as $tab => $sections ) { |
|
194 | - foreach( $sections as $section => $settings) { |
|
193 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
194 | + foreach ($sections as $section => $settings) { |
|
195 | 195 | // Check for backwards compatibility |
196 | - $tab_sections = wpinv_get_settings_tab_sections( $tab ); |
|
197 | - if( ! is_array( $tab_sections ) || ! array_key_exists( $section, $tab_sections ) ) { |
|
196 | + $tab_sections = wpinv_get_settings_tab_sections($tab); |
|
197 | + if (!is_array($tab_sections) || !array_key_exists($section, $tab_sections)) { |
|
198 | 198 | $section = 'main'; |
199 | 199 | $settings = $sections; |
200 | 200 | } |
201 | 201 | |
202 | - foreach ( $settings as $option ) { |
|
203 | - if ( !empty( $option['id'] ) && !isset( $wpinv_options[ $option['id'] ] ) ) { |
|
204 | - if ( 'checkbox' == $option['type'] && !empty( $option['std'] ) ) { |
|
205 | - $options[ $option['id'] ] = '1'; |
|
206 | - } else if ( !empty( $option['std'] ) ) { |
|
207 | - $options[ $option['id'] ] = $option['std']; |
|
202 | + foreach ($settings as $option) { |
|
203 | + if (!empty($option['id']) && !isset($wpinv_options[$option['id']])) { |
|
204 | + if ('checkbox' == $option['type'] && !empty($option['std'])) { |
|
205 | + $options[$option['id']] = '1'; |
|
206 | + } else if (!empty($option['std'])) { |
|
207 | + $options[$option['id']] = $option['std']; |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - $merged_options_current = array_merge( $wpinv_options, $options ); |
|
215 | - $merged_options = array_merge( $merged_options_current, $current_options ); |
|
214 | + $merged_options_current = array_merge($wpinv_options, $options); |
|
215 | + $merged_options = array_merge($merged_options_current, $current_options); |
|
216 | 216 | $wpinv_options = $merged_options; |
217 | 217 | |
218 | - update_option( 'wpinv_settings', $merged_options ); |
|
218 | + update_option('wpinv_settings', $merged_options); |
|
219 | 219 | } |
220 | 220 | \ No newline at end of file |