1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Contains functions related to Invoicing plugin. |
4
|
|
|
* |
5
|
|
|
* @since 1.0.0 |
6
|
|
|
* @package Invoicing |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
// MUST have WordPress. |
10
|
|
|
if ( !defined( 'WPINC' ) ) { |
11
|
|
|
exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
class WPInv_Plugin { |
15
|
|
|
private static $instance; |
16
|
|
|
|
17
|
|
|
public static function run() { |
18
|
|
|
if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
19
|
|
|
self::$instance = new WPInv_Plugin; |
20
|
|
|
self::$instance->includes(); |
21
|
|
|
self::$instance->actions(); |
22
|
|
|
self::$instance->notes = new WPInv_Notes(); |
|
|
|
|
23
|
|
|
self::$instance->reports = new WPInv_Reports(); |
|
|
|
|
24
|
|
|
self::$instance->api = new WPInv_API(); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return self::$instance; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function __construct() { |
31
|
|
|
$this->define_constants(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function define_constants() { |
35
|
|
|
define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
36
|
|
|
define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
private function actions() { |
40
|
|
|
/* Internationalize the text strings used. */ |
41
|
|
|
add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
42
|
|
|
|
43
|
|
|
/* Perform actions on admin initialization. */ |
44
|
|
|
add_action( 'admin_init', array( &$this, 'admin_init') ); |
45
|
|
|
add_action( 'init', array( &$this, 'init' ), 3 ); |
46
|
|
|
add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
47
|
|
|
|
48
|
|
|
if ( class_exists( 'BuddyPress' ) ) { |
49
|
|
|
add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
53
|
|
|
add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
54
|
|
|
|
55
|
|
|
if ( is_admin() ) { |
56
|
|
|
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
57
|
|
|
add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
58
|
|
|
} else { |
59
|
|
|
add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Fires after the setup of all WPInv_Plugin actions. |
64
|
|
|
* |
65
|
|
|
* @since 1.0.0 |
66
|
|
|
* |
67
|
|
|
* @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
68
|
|
|
*/ |
69
|
|
|
do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
70
|
|
|
|
71
|
|
|
add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function plugins_loaded() { |
75
|
|
|
/* Internationalize the text strings used. */ |
76
|
|
|
$this->load_textdomain(); |
77
|
|
|
|
78
|
|
|
do_action( 'wpinv_loaded' ); |
79
|
|
|
|
80
|
|
|
// Fix oxygen page builder conflict |
81
|
|
|
if ( function_exists( 'ct_css_output' ) ) { |
82
|
|
|
wpinv_oxygen_fix_conflict(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Load the translation of the plugin. |
88
|
|
|
* |
89
|
|
|
* @since 1.0 |
90
|
|
|
*/ |
91
|
|
|
public function load_textdomain( $locale = NULL ) { |
92
|
|
|
if ( empty( $locale ) ) { |
93
|
|
|
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
|
|
|
97
|
|
|
|
98
|
|
|
unload_textdomain( 'invoicing' ); |
99
|
|
|
load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
100
|
|
|
load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Define language constants. |
104
|
|
|
*/ |
105
|
|
|
require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function includes() { |
109
|
|
|
global $wpinv_options; |
110
|
|
|
|
111
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
112
|
|
|
$wpinv_options = wpinv_get_settings(); |
113
|
|
|
|
114
|
|
|
require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
115
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
116
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
117
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
118
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
119
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
120
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
121
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
122
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
123
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
124
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
125
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
126
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
127
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
128
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
129
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
130
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
131
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
132
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
133
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
134
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
135
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
136
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
137
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
138
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
139
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
140
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
141
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
142
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
143
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
144
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
145
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
146
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
147
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
148
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
149
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
150
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
151
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
152
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
153
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
154
|
|
|
|
155
|
|
|
if ( !class_exists( 'WPInv_EUVat' ) ) { |
156
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
160
|
|
|
if ( !empty( $gateways ) ) { |
161
|
|
|
foreach ( $gateways as $gateway ) { |
162
|
|
|
if ( $gateway == 'manual' ) { |
163
|
|
|
continue; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
$gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
167
|
|
|
|
168
|
|
|
if ( file_exists( $gateway_file ) ) { |
169
|
|
|
require_once( $gateway_file ); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
174
|
|
|
|
175
|
|
|
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
|
|
|
176
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
177
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
178
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
179
|
|
|
//require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
180
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
181
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
182
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
183
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
184
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
185
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
186
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
187
|
|
|
//require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
188
|
|
|
// load the user class only on the users.php page |
189
|
|
|
global $pagenow; |
190
|
|
|
if($pagenow=='users.php'){ |
191
|
|
|
new WPInv_Admin_Users(); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
// Register cli commands |
196
|
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
197
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
198
|
|
|
WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
|
|
|
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
// include css inliner |
202
|
|
|
if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
203
|
|
|
include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function init() { |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function admin_init() { |
213
|
|
|
add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function activation_redirect() { |
217
|
|
|
// Bail if no activation redirect |
218
|
|
|
if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
219
|
|
|
return; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
// Delete the redirect transient |
223
|
|
|
delete_transient( '_wpinv_activation_redirect' ); |
224
|
|
|
|
225
|
|
|
// Bail if activating from network, or bulk |
226
|
|
|
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
227
|
|
|
return; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
231
|
|
|
exit; |
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function enqueue_scripts() { |
235
|
|
|
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
236
|
|
|
|
237
|
|
|
wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
238
|
|
|
wp_enqueue_style( 'wpinv_front_style' ); |
239
|
|
|
|
240
|
|
|
// Register scripts |
241
|
|
|
wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
242
|
|
|
wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), WPINV_VERSION ); |
243
|
|
|
|
244
|
|
|
$localize = array(); |
245
|
|
|
$localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
246
|
|
|
$localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
247
|
|
|
$localize['currency_symbol'] = wpinv_currency_symbol(); |
248
|
|
|
$localize['currency_pos'] = wpinv_currency_position(); |
249
|
|
|
$localize['thousand_sep'] = wpinv_thousands_separator(); |
250
|
|
|
$localize['decimal_sep'] = wpinv_decimal_separator(); |
251
|
|
|
$localize['decimals'] = wpinv_decimals(); |
252
|
|
|
$localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
253
|
|
|
$localize['UseTaxes'] = wpinv_use_taxes(); |
254
|
|
|
$localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
255
|
|
|
|
256
|
|
|
$localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
257
|
|
|
|
258
|
|
|
wp_enqueue_script( 'jquery-blockui' ); |
259
|
|
|
$autofill_api = wpinv_get_option('address_autofill_api'); |
260
|
|
|
$autofill_active = wpinv_get_option('address_autofill_active'); |
261
|
|
|
if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
262
|
|
|
if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
263
|
|
|
wp_dequeue_script( 'google-maps-api' ); |
264
|
|
|
} |
265
|
|
|
wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
266
|
|
|
wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
270
|
|
|
wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
271
|
|
|
|
272
|
|
|
wp_enqueue_script( 'wpinv-front-script' ); |
273
|
|
|
wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
public function admin_enqueue_scripts() { |
277
|
|
|
global $post, $pagenow; |
278
|
|
|
|
279
|
|
|
$post_type = wpinv_admin_post_type(); |
280
|
|
|
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
281
|
|
|
$page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
282
|
|
|
|
283
|
|
|
$jquery_ui_css = false; |
284
|
|
|
if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
285
|
|
|
$jquery_ui_css = true; |
286
|
|
|
} else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
287
|
|
|
$jquery_ui_css = true; |
288
|
|
|
} |
289
|
|
|
if ( $jquery_ui_css ) { |
290
|
|
|
wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
291
|
|
|
wp_enqueue_style( 'jquery-ui-css' ); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
295
|
|
|
wp_enqueue_style( 'wpinv_meta_box_style' ); |
296
|
|
|
|
297
|
|
|
wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
298
|
|
|
wp_enqueue_style( 'wpinv_admin_style' ); |
299
|
|
|
|
300
|
|
|
$enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
301
|
|
|
if ( $page == 'wpinv-subscriptions' ) { |
302
|
|
|
wp_enqueue_script( 'jquery-ui-datepicker' ); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
|
|
|
306
|
|
|
wp_enqueue_script( 'jquery-ui-datepicker' ); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
wp_enqueue_style( 'wp-color-picker' ); |
310
|
|
|
wp_enqueue_script( 'wp-color-picker' ); |
311
|
|
|
|
312
|
|
|
wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
313
|
|
|
|
314
|
|
|
if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
315
|
|
|
$autofill_api = wpinv_get_option('address_autofill_api'); |
316
|
|
|
$autofill_active = wpinv_get_option('address_autofill_active'); |
317
|
|
|
if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) { |
318
|
|
|
wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
319
|
|
|
wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true); |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
324
|
|
|
wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
325
|
|
|
|
326
|
|
|
wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
327
|
|
|
wp_enqueue_script( 'wpinv-admin-script' ); |
328
|
|
|
|
329
|
|
|
$localize = array(); |
330
|
|
|
$localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
331
|
|
|
$localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
332
|
|
|
$localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
333
|
|
|
$localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
334
|
|
|
$localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
335
|
|
|
$localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
336
|
|
|
$localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
337
|
|
|
$localize['tax'] = wpinv_tax_amount(); |
338
|
|
|
$localize['discount'] = wpinv_discount_amount(); |
339
|
|
|
$localize['currency_symbol'] = wpinv_currency_symbol(); |
340
|
|
|
$localize['currency_pos'] = wpinv_currency_position(); |
341
|
|
|
$localize['thousand_sep'] = wpinv_thousands_separator(); |
342
|
|
|
$localize['decimal_sep'] = wpinv_decimal_separator(); |
343
|
|
|
$localize['decimals'] = wpinv_decimals(); |
344
|
|
|
$localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
345
|
|
|
$localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
346
|
|
|
$localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
347
|
|
|
$localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
348
|
|
|
$localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
349
|
|
|
$localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
350
|
|
|
$localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
351
|
|
|
$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' ); |
352
|
|
|
$localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
353
|
|
|
$localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
354
|
|
|
$localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
355
|
|
|
$localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
356
|
|
|
$localize['action_edit'] = __( 'Edit', 'invoicing' ); |
357
|
|
|
$localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
358
|
|
|
|
359
|
|
|
$localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
360
|
|
|
|
361
|
|
|
wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
362
|
|
|
|
363
|
|
|
if ( $page == 'wpinv-subscriptions' ) { |
364
|
|
|
wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
365
|
|
|
wp_enqueue_script( 'wpinv-sub-admin-script' ); |
366
|
|
|
} |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
public function admin_body_class( $classes ) { |
370
|
|
|
global $pagenow, $post, $current_screen; |
371
|
|
|
|
372
|
|
|
if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
373
|
|
|
$classes .= ' wpinv-cpt'; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
$page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
377
|
|
|
|
378
|
|
|
$add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
379
|
|
|
if ( $add_class ) { |
380
|
|
|
$classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
$settings_class = array(); |
384
|
|
|
if ( $page == 'wpinv-settings' ) { |
385
|
|
|
if ( !empty( $_REQUEST['tab'] ) ) { |
386
|
|
|
$settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
if ( !empty( $_REQUEST['section'] ) ) { |
390
|
|
|
$settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
$settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
if ( !empty( $settings_class ) ) { |
397
|
|
|
$classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
|
|
|
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
$post_type = wpinv_admin_post_type(); |
401
|
|
|
|
402
|
|
|
if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
403
|
|
|
return $classes .= ' wpinv'; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
407
|
|
|
$classes .= ' wpi-editable-n'; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
return $classes; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
public function admin_print_scripts_edit_php() { |
414
|
|
|
|
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
public function wpinv_actions() { |
418
|
|
|
if ( isset( $_REQUEST['wpi_action'] ) ) { |
419
|
|
|
do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
public function pre_get_posts( $wp_query ) { |
424
|
|
|
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() ) { |
425
|
|
|
$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
return $wp_query; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
public function bp_invoicing_init() { |
432
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Register widgets |
437
|
|
|
* |
438
|
|
|
*/ |
439
|
|
|
public function register_widgets() { |
440
|
|
|
register_widget( "WPInv_Checkout_Widget" ); |
441
|
|
|
register_widget( "WPInv_History_Widget" ); |
442
|
|
|
register_widget( "WPInv_Receipt_Widget" ); |
443
|
|
|
register_widget( "WPInv_Subscriptions_Widget" ); |
444
|
|
|
register_widget( "WPInv_Buy_Item_Widget" ); |
445
|
|
|
register_widget( "WPInv_Messages_Widget" ); |
446
|
|
|
} |
447
|
|
|
} |