|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Main Invoicing class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Invoicing |
|
6
|
|
|
* @since 1.0.0 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
defined( 'ABSPATH' ) || exit; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Main Invoicing class. |
|
13
|
|
|
* |
|
14
|
|
|
*/ |
|
15
|
|
|
class WPInv_Plugin { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* GetPaid version. |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
public $version; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Data container. |
|
26
|
|
|
* |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $data = array(); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Form elements instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @var WPInv_Payment_Form_Elements |
|
35
|
|
|
*/ |
|
36
|
|
|
public $form_elements; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Tax instance. |
|
40
|
|
|
* |
|
41
|
|
|
* @var WPInv_EUVat |
|
42
|
|
|
*/ |
|
43
|
|
|
public $tax; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param array An array of payment gateways. |
|
47
|
|
|
*/ |
|
48
|
|
|
public $gateways; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Class constructor. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct() { |
|
54
|
|
|
$this->define_constants(); |
|
55
|
|
|
$this->includes(); |
|
56
|
|
|
$this->init_hooks(); |
|
57
|
|
|
$this->set_properties(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Sets a custom data property. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $prop The prop to set. |
|
64
|
|
|
* @param mixed $value The value to retrieve. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function set( $prop, $value ) { |
|
67
|
|
|
$this->data[ $prop ] = $value; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Gets a custom data property. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $prop The prop to set. |
|
74
|
|
|
* @return mixed The value. |
|
75
|
|
|
*/ |
|
76
|
|
|
public function get( $prop ) { |
|
77
|
|
|
|
|
78
|
|
|
if ( isset( $this->data[ $prop ] ) ) { |
|
79
|
|
|
return $this->data[ $prop ]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return null; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Define class properties. |
|
87
|
|
|
*/ |
|
88
|
|
|
public function set_properties() { |
|
89
|
|
|
|
|
90
|
|
|
// Sessions. |
|
91
|
|
|
$this->set( 'session', new WPInv_Session_Handler() ); |
|
92
|
|
|
$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93
|
|
|
$this->form_elements = new WPInv_Payment_Form_Elements(); |
|
94
|
|
|
$this->tax = new WPInv_EUVat(); |
|
95
|
|
|
$this->tax->init(); |
|
96
|
|
|
$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
97
|
|
|
|
|
98
|
|
|
// Init other objects. |
|
99
|
|
|
$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
100
|
|
|
$this->set( 'session', new WPInv_Session_Handler() ); |
|
101
|
|
|
$this->set( 'notes', new WPInv_Notes() ); |
|
102
|
|
|
$this->set( 'api', new WPInv_API() ); |
|
103
|
|
|
$this->set( 'post_types', new GetPaid_Post_Types() ); |
|
104
|
|
|
$this->set( 'template', new GetPaid_Template() ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Define plugin constants. |
|
109
|
|
|
*/ |
|
110
|
|
|
public function define_constants() { |
|
111
|
|
|
define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
112
|
|
|
define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
113
|
|
|
$this->version = WPINV_VERSION; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Hook into actions and filters. |
|
118
|
|
|
* |
|
119
|
|
|
* @since 1.0.19 |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function init_hooks() { |
|
122
|
|
|
/* Internationalize the text strings used. */ |
|
123
|
|
|
add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
124
|
|
|
|
|
125
|
|
|
/* Perform actions on admin initialization. */ |
|
126
|
|
|
add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
127
|
|
|
|
|
128
|
|
|
// Init the plugin after WordPress inits. |
|
129
|
|
|
add_action( 'init', array( $this, 'init' ), 1 ); |
|
130
|
|
|
add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
131
|
|
|
add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
132
|
|
|
|
|
133
|
|
|
if ( class_exists( 'BuddyPress' ) ) { |
|
134
|
|
|
add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
138
|
|
|
add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
139
|
|
|
add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
140
|
|
|
add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
141
|
|
|
|
|
142
|
|
|
if ( is_admin() ) { |
|
143
|
|
|
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
144
|
|
|
add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
145
|
|
|
add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
146
|
|
|
|
|
147
|
|
|
} else { |
|
148
|
|
|
add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
// Fires after registering actions. |
|
152
|
|
|
do_action( 'wpinv_actions', $this ); |
|
153
|
|
|
do_action( 'getpaid_actions', $this ); |
|
154
|
|
|
add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
155
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Maybe show the AyeCode Connect Notice. |
|
160
|
|
|
*/ |
|
161
|
|
|
public function init_ayecode_connect_helper(){ |
|
162
|
|
|
// AyeCode Connect notice |
|
163
|
|
|
if ( is_admin() ){ |
|
164
|
|
|
// set the strings so they can be translated |
|
165
|
|
|
$strings = array( |
|
166
|
|
|
'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
167
|
|
|
'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
168
|
|
|
'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>" ), |
|
169
|
|
|
'connect_button' => __("Connect Site","invoicing"), |
|
170
|
|
|
'connecting_button' => __("Connecting...","invoicing"), |
|
171
|
|
|
'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
172
|
|
|
'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
173
|
|
|
); |
|
174
|
|
|
new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function plugins_loaded() { |
|
179
|
|
|
/* Internationalize the text strings used. */ |
|
180
|
|
|
$this->load_textdomain(); |
|
181
|
|
|
|
|
182
|
|
|
do_action( 'wpinv_loaded' ); |
|
183
|
|
|
|
|
184
|
|
|
// Fix oxygen page builder conflict |
|
185
|
|
|
if ( function_exists( 'ct_css_output' ) ) { |
|
186
|
|
|
wpinv_oxygen_fix_conflict(); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Load the translation of the plugin. |
|
192
|
|
|
* |
|
193
|
|
|
* @since 1.0 |
|
194
|
|
|
*/ |
|
195
|
|
|
public function load_textdomain( $locale = NULL ) { |
|
196
|
|
|
if ( empty( $locale ) ) { |
|
197
|
|
|
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
unload_textdomain( 'invoicing' ); |
|
203
|
|
|
load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
204
|
|
|
load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Define language constants. |
|
208
|
|
|
*/ |
|
209
|
|
|
require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Include required core files used in admin and on the frontend. |
|
214
|
|
|
*/ |
|
215
|
|
|
public function includes() { |
|
216
|
|
|
|
|
217
|
|
|
// Start with the settings. |
|
218
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
219
|
|
|
|
|
220
|
|
|
// Packages/libraries. |
|
221
|
|
|
require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
222
|
|
|
require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
223
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
224
|
|
|
|
|
225
|
|
|
// Load functions. |
|
226
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
227
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
228
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
229
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
230
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
231
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
232
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
233
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
234
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
235
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
236
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
237
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
238
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
239
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
240
|
|
|
|
|
241
|
|
|
// Register autoloader. |
|
242
|
|
|
try { |
|
243
|
|
|
spl_autoload_register( array( $this, 'autoload' ), true ); |
|
244
|
|
|
} catch ( Exception $e ) { |
|
245
|
|
|
wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
249
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
250
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
251
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
252
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
253
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
254
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
255
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
256
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
257
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
258
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
259
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
260
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
261
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
262
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
263
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
264
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
265
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
266
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
267
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
268
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
269
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
270
|
|
|
require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
271
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* Load the tax class. |
|
275
|
|
|
*/ |
|
276
|
|
|
if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
277
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
$gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
281
|
|
|
if ( !empty( $gateways ) ) { |
|
282
|
|
|
foreach ( $gateways as $gateway ) { |
|
283
|
|
|
if ( $gateway == 'manual' ) { |
|
284
|
|
|
continue; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
$gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
|
288
|
|
|
|
|
289
|
|
|
if ( file_exists( $gateway_file ) ) { |
|
290
|
|
|
require_once( $gateway_file ); |
|
291
|
|
|
} |
|
292
|
|
|
} |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
|
|
|
|
|
296
|
|
|
GetPaid_Post_Types_Admin::init(); |
|
297
|
|
|
|
|
298
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
299
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
300
|
|
|
//require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
301
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
302
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
303
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
304
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
305
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
306
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
307
|
|
|
//require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
308
|
|
|
// load the user class only on the users.php page |
|
309
|
|
|
global $pagenow; |
|
310
|
|
|
if($pagenow=='users.php'){ |
|
311
|
|
|
new WPInv_Admin_Users(); |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
// Register cli commands |
|
316
|
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
317
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
318
|
|
|
WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
|
|
|
|
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
// include css inliner |
|
322
|
|
|
if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
323
|
|
|
include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Class autoloader |
|
331
|
|
|
* |
|
332
|
|
|
* @param string $class_name The name of the class to load. |
|
333
|
|
|
* @access public |
|
334
|
|
|
* @since 1.0.19 |
|
335
|
|
|
* @return void |
|
336
|
|
|
*/ |
|
337
|
|
|
public function autoload( $class_name ) { |
|
338
|
|
|
|
|
339
|
|
|
// Normalize the class name... |
|
340
|
|
|
$class_name = strtolower( $class_name ); |
|
341
|
|
|
|
|
342
|
|
|
// ... and make sure it is our class. |
|
343
|
|
|
if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
344
|
|
|
return; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
// Next, prepare the file name from the class. |
|
348
|
|
|
$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
349
|
|
|
|
|
350
|
|
|
// Base path of the classes. |
|
351
|
|
|
$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
352
|
|
|
|
|
353
|
|
|
// And an array of possible locations in order of importance. |
|
354
|
|
|
$locations = array( |
|
355
|
|
|
"$plugin_path/includes", |
|
356
|
|
|
"$plugin_path/includes/data-stores", |
|
357
|
|
|
"$plugin_path/includes/gateways", |
|
358
|
|
|
"$plugin_path/includes/api", |
|
359
|
|
|
"$plugin_path/includes/admin", |
|
360
|
|
|
"$plugin_path/includes/admin/meta-boxes", |
|
361
|
|
|
); |
|
362
|
|
|
|
|
363
|
|
|
foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
364
|
|
|
|
|
365
|
|
|
if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
366
|
|
|
include trailingslashit( $location ) . $file_name; |
|
367
|
|
|
break; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
/** |
|
375
|
|
|
* Inits hooks etc. |
|
376
|
|
|
*/ |
|
377
|
|
|
public function init() { |
|
378
|
|
|
|
|
379
|
|
|
// Fires before getpaid inits. |
|
380
|
|
|
do_action( 'before_getpaid_init', $this ); |
|
381
|
|
|
|
|
382
|
|
|
// Load default gateways. |
|
383
|
|
|
$gateways = apply_filters( |
|
384
|
|
|
'getpaid_default_gateways', |
|
385
|
|
|
array( |
|
386
|
|
|
'manual' => 'GetPaid_Manual_Gateway', |
|
387
|
|
|
'paypal' => 'GetPaid_Paypal_Gateway', |
|
388
|
|
|
'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
389
|
|
|
'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
390
|
|
|
'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
391
|
|
|
) |
|
392
|
|
|
); |
|
393
|
|
|
|
|
394
|
|
|
foreach ( $gateways as $id => $class ) { |
|
395
|
|
|
$this->gateways[ $id ] = new $class(); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
// Fires after getpaid inits. |
|
399
|
|
|
do_action( 'getpaid_init', $this ); |
|
400
|
|
|
|
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
/** |
|
404
|
|
|
* Checks if this is an IPN request and processes it. |
|
405
|
|
|
*/ |
|
406
|
|
|
public function maybe_process_ipn() { |
|
407
|
|
|
|
|
408
|
|
|
// Ensure that this is an IPN request. |
|
409
|
|
|
if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
410
|
|
|
return; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
$gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
414
|
|
|
|
|
415
|
|
|
do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
416
|
|
|
do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
417
|
|
|
exit; |
|
|
|
|
|
|
418
|
|
|
|
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
public function admin_init() { |
|
422
|
|
|
$this->default_payment_form = wpinv_get_default_payment_form(); |
|
|
|
|
|
|
423
|
|
|
add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
public function activation_redirect() { |
|
427
|
|
|
// Bail if no activation redirect |
|
428
|
|
|
if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
429
|
|
|
return; |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
// Delete the redirect transient |
|
433
|
|
|
delete_transient( '_wpinv_activation_redirect' ); |
|
434
|
|
|
|
|
435
|
|
|
// Bail if activating from network, or bulk |
|
436
|
|
|
if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
437
|
|
|
return; |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
441
|
|
|
exit; |
|
|
|
|
|
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
public function enqueue_scripts() { |
|
445
|
|
|
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
446
|
|
|
|
|
447
|
|
|
$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
448
|
|
|
wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
449
|
|
|
wp_enqueue_style( 'wpinv_front_style' ); |
|
450
|
|
|
|
|
451
|
|
|
// Register scripts |
|
452
|
|
|
wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
453
|
|
|
wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
454
|
|
|
|
|
455
|
|
|
$localize = array(); |
|
456
|
|
|
$localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
457
|
|
|
$localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
458
|
|
|
$localize['currency_symbol'] = wpinv_currency_symbol(); |
|
459
|
|
|
$localize['currency_pos'] = wpinv_currency_position(); |
|
460
|
|
|
$localize['thousand_sep'] = wpinv_thousands_separator(); |
|
461
|
|
|
$localize['decimal_sep'] = wpinv_decimal_separator(); |
|
462
|
|
|
$localize['decimals'] = wpinv_decimals(); |
|
463
|
|
|
$localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
464
|
|
|
$localize['UseTaxes'] = wpinv_use_taxes(); |
|
465
|
|
|
$localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
466
|
|
|
$localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
467
|
|
|
$localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
468
|
|
|
|
|
469
|
|
|
$localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
470
|
|
|
|
|
471
|
|
|
wp_enqueue_script( 'jquery-blockui' ); |
|
472
|
|
|
$autofill_api = wpinv_get_option('address_autofill_api'); |
|
473
|
|
|
$autofill_active = wpinv_get_option('address_autofill_active'); |
|
474
|
|
|
if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
475
|
|
|
if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
476
|
|
|
wp_dequeue_script( 'google-maps-api' ); |
|
477
|
|
|
} |
|
478
|
|
|
wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
479
|
|
|
wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
483
|
|
|
wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
484
|
|
|
|
|
485
|
|
|
wp_enqueue_script( 'wpinv-front-script' ); |
|
486
|
|
|
wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
487
|
|
|
|
|
488
|
|
|
$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
489
|
|
|
wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
public function admin_enqueue_scripts( $hook ) { |
|
493
|
|
|
global $post, $pagenow; |
|
494
|
|
|
|
|
495
|
|
|
$post_type = wpinv_admin_post_type(); |
|
496
|
|
|
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
497
|
|
|
$page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
498
|
|
|
|
|
499
|
|
|
$jquery_ui_css = false; |
|
500
|
|
|
if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
501
|
|
|
$jquery_ui_css = true; |
|
502
|
|
|
} else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
503
|
|
|
$jquery_ui_css = true; |
|
504
|
|
|
} |
|
505
|
|
|
if ( $jquery_ui_css ) { |
|
506
|
|
|
wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
507
|
|
|
wp_enqueue_style( 'jquery-ui-css' ); |
|
508
|
|
|
wp_deregister_style( 'yoast-seo-select2' ); |
|
509
|
|
|
wp_deregister_style( 'yoast-seo-monorepo' ); |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
513
|
|
|
wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
514
|
|
|
|
|
515
|
|
|
$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
516
|
|
|
wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
517
|
|
|
wp_enqueue_style( 'wpinv_admin_style' ); |
|
518
|
|
|
|
|
519
|
|
|
$enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
520
|
|
|
if ( $page == 'wpinv-subscriptions' ) { |
|
521
|
|
|
wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
522
|
|
|
wp_deregister_style( 'yoast-seo-select2' ); |
|
523
|
|
|
wp_deregister_style( 'yoast-seo-monorepo' ); |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
|
|
|
|
|
527
|
|
|
wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
wp_enqueue_style( 'wp-color-picker' ); |
|
531
|
|
|
wp_enqueue_script( 'wp-color-picker' ); |
|
532
|
|
|
|
|
533
|
|
|
wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
534
|
|
|
|
|
535
|
|
|
if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
536
|
|
|
$autofill_api = wpinv_get_option('address_autofill_api'); |
|
537
|
|
|
$autofill_active = wpinv_get_option('address_autofill_active'); |
|
538
|
|
|
if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) { |
|
539
|
|
|
wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
540
|
|
|
wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true); |
|
541
|
|
|
} |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
|
|
wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
545
|
|
|
wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
546
|
|
|
|
|
547
|
|
|
$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
548
|
|
|
wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
549
|
|
|
wp_enqueue_script( 'wpinv-admin-script' ); |
|
550
|
|
|
|
|
551
|
|
|
$localize = array(); |
|
552
|
|
|
$localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
553
|
|
|
$localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
554
|
|
|
$localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
555
|
|
|
$localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
556
|
|
|
$localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
557
|
|
|
$localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
558
|
|
|
$localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
559
|
|
|
$localize['tax'] = wpinv_tax_amount(); |
|
560
|
|
|
$localize['discount'] = wpinv_discount_amount(); |
|
561
|
|
|
$localize['currency_symbol'] = wpinv_currency_symbol(); |
|
562
|
|
|
$localize['currency_pos'] = wpinv_currency_position(); |
|
563
|
|
|
$localize['thousand_sep'] = wpinv_thousands_separator(); |
|
564
|
|
|
$localize['decimal_sep'] = wpinv_decimal_separator(); |
|
565
|
|
|
$localize['decimals'] = wpinv_decimals(); |
|
566
|
|
|
$localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
567
|
|
|
$localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
568
|
|
|
$localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
569
|
|
|
$localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
570
|
|
|
$localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
571
|
|
|
$localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
572
|
|
|
$localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
573
|
|
|
$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' ); |
|
574
|
|
|
$localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
575
|
|
|
$localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
576
|
|
|
$localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
577
|
|
|
$localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
578
|
|
|
$localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
579
|
|
|
$localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
580
|
|
|
$localize['item_description'] = __( 'Item Description', 'invoicing' ); |
|
581
|
|
|
$localize['discount_description'] = __( 'Discount Description', 'invoicing' ); |
|
582
|
|
|
$localize['invoice_description'] = __( 'Invoice Description', 'invoicing' ); |
|
583
|
|
|
$localize['searching'] = __( 'Searching', 'invoicing' ); |
|
584
|
|
|
|
|
585
|
|
|
$localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
586
|
|
|
|
|
587
|
|
|
wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
588
|
|
|
|
|
589
|
|
|
// Load payment form scripts on our admin pages only. |
|
590
|
|
|
if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
591
|
|
|
|
|
592
|
|
|
wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
593
|
|
|
wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
594
|
|
|
wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
595
|
|
|
|
|
596
|
|
|
$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
597
|
|
|
wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
598
|
|
|
|
|
599
|
|
|
wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
600
|
|
|
'elements' => $this->form_elements->get_elements(), |
|
601
|
|
|
'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
602
|
|
|
'all_items' => $this->form_elements->get_published_items(), |
|
603
|
|
|
'currency' => wpinv_currency_symbol(), |
|
604
|
|
|
'position' => wpinv_currency_position(), |
|
605
|
|
|
'decimals' => (int) wpinv_decimals(), |
|
606
|
|
|
'thousands_sep' => wpinv_thousands_separator(), |
|
607
|
|
|
'decimals_sep' => wpinv_decimal_separator(), |
|
608
|
|
|
'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
609
|
|
|
'is_default' => $post->ID == $this->default_payment_form, |
|
610
|
|
|
) ); |
|
611
|
|
|
|
|
612
|
|
|
wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
if ( $page == 'wpinv-subscriptions' ) { |
|
616
|
|
|
wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
617
|
|
|
wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
if ( $page == 'wpinv-reports' ) { |
|
621
|
|
|
wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
public function admin_body_class( $classes ) { |
|
627
|
|
|
global $pagenow, $post, $current_screen; |
|
628
|
|
|
|
|
629
|
|
|
if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
630
|
|
|
$classes .= ' wpinv-cpt'; |
|
631
|
|
|
} |
|
632
|
|
|
|
|
633
|
|
|
$page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
634
|
|
|
|
|
635
|
|
|
$add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
636
|
|
|
if ( $add_class ) { |
|
637
|
|
|
$classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
$settings_class = array(); |
|
641
|
|
|
if ( $page == 'wpinv-settings' ) { |
|
642
|
|
|
if ( !empty( $_REQUEST['tab'] ) ) { |
|
643
|
|
|
$settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
644
|
|
|
} |
|
645
|
|
|
|
|
646
|
|
|
if ( !empty( $_REQUEST['section'] ) ) { |
|
647
|
|
|
$settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
648
|
|
|
} |
|
649
|
|
|
|
|
650
|
|
|
$settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
if ( !empty( $settings_class ) ) { |
|
654
|
|
|
$classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
|
|
|
|
|
655
|
|
|
} |
|
656
|
|
|
|
|
657
|
|
|
$post_type = wpinv_admin_post_type(); |
|
658
|
|
|
|
|
659
|
|
|
if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
660
|
|
|
return $classes .= ' wpinv'; |
|
661
|
|
|
} |
|
662
|
|
|
|
|
663
|
|
|
if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
664
|
|
|
$classes .= ' wpi-editable-n'; |
|
665
|
|
|
} |
|
666
|
|
|
|
|
667
|
|
|
return $classes; |
|
668
|
|
|
} |
|
669
|
|
|
|
|
670
|
|
|
public function admin_print_scripts_edit_php() { |
|
671
|
|
|
|
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
public function wpinv_actions() { |
|
675
|
|
|
if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
676
|
|
|
do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
677
|
|
|
} |
|
678
|
|
|
} |
|
679
|
|
|
|
|
680
|
|
|
public function pre_get_posts( $wp_query ) { |
|
681
|
|
|
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() ) { |
|
682
|
|
|
$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
return $wp_query; |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
|
public function bp_invoicing_init() { |
|
689
|
|
|
require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
690
|
|
|
} |
|
691
|
|
|
|
|
692
|
|
|
/** |
|
693
|
|
|
* Register widgets |
|
694
|
|
|
* |
|
695
|
|
|
*/ |
|
696
|
|
|
public function register_widgets() { |
|
697
|
|
|
$widgets = apply_filters( |
|
698
|
|
|
'getpaid_widget_classes', |
|
699
|
|
|
array( |
|
700
|
|
|
'WPInv_Checkout_Widget', |
|
701
|
|
|
'WPInv_History_Widget', |
|
702
|
|
|
'WPInv_Receipt_Widget', |
|
703
|
|
|
'WPInv_Subscriptions_Widget', |
|
704
|
|
|
'WPInv_Buy_Item_Widget', |
|
705
|
|
|
'WPInv_Messages_Widget', |
|
706
|
|
|
'WPInv_GetPaid_Widget' |
|
707
|
|
|
) |
|
708
|
|
|
); |
|
709
|
|
|
|
|
710
|
|
|
foreach ( $widgets as $widget ) { |
|
711
|
|
|
register_widget( $widget ); |
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
} |
|
715
|
|
|
|
|
716
|
|
|
/** |
|
717
|
|
|
* Remove our pages from yoast sitemaps. |
|
718
|
|
|
* |
|
719
|
|
|
* @since 1.0.19 |
|
720
|
|
|
* @param int[] $excluded_posts_ids |
|
721
|
|
|
*/ |
|
722
|
|
|
public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
723
|
|
|
|
|
724
|
|
|
// Ensure that we have an array. |
|
725
|
|
|
if ( ! is_array( $excluded_posts_ids ) ) { |
|
|
|
|
|
|
726
|
|
|
$excluded_posts_ids = array(); |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
// Prepare our pages. |
|
730
|
|
|
$our_pages = array(); |
|
731
|
|
|
|
|
732
|
|
|
// Checkout page. |
|
733
|
|
|
$our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
734
|
|
|
|
|
735
|
|
|
// Success page. |
|
736
|
|
|
$our_pages[] = wpinv_get_option( 'success_page', false ); |
|
737
|
|
|
|
|
738
|
|
|
// Failure page. |
|
739
|
|
|
$our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
740
|
|
|
|
|
741
|
|
|
// History page. |
|
742
|
|
|
$our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
743
|
|
|
|
|
744
|
|
|
// Subscriptions page. |
|
745
|
|
|
$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
746
|
|
|
|
|
747
|
|
|
$our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
748
|
|
|
|
|
749
|
|
|
$excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
750
|
|
|
return array_unique( $excluded_posts_ids ); |
|
751
|
|
|
|
|
752
|
|
|
} |
|
753
|
|
|
|
|
754
|
|
|
public function wp_footer() { |
|
755
|
|
|
echo ' |
|
756
|
|
|
<div class="bsui"> |
|
757
|
|
|
<div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
|
758
|
|
|
<div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
|
759
|
|
|
<div class="modal-content"> |
|
760
|
|
|
<div class="modal-body"></div> |
|
761
|
|
|
</div> |
|
762
|
|
|
</div> |
|
763
|
|
|
</div> |
|
764
|
|
|
</div> |
|
765
|
|
|
'; |
|
766
|
|
|
} |
|
767
|
|
|
|
|
768
|
|
|
} |
|
769
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.