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