@@ -14,650 +14,650 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 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 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'notes', new WPInv_Notes() ); |
|
90 | - $this->set( 'api', new WPInv_API() ); |
|
91 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
92 | - $this->set( 'template', new GetPaid_Template() ); |
|
93 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
94 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
95 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
96 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
97 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
98 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
99 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Define plugin constants. |
|
105 | - */ |
|
106 | - public function define_constants() { |
|
107 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
108 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
109 | - $this->version = WPINV_VERSION; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Hook into actions and filters. |
|
114 | - * |
|
115 | - * @since 1.0.19 |
|
116 | - */ |
|
117 | - protected function init_hooks() { |
|
118 | - /* Internationalize the text strings used. */ |
|
119 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | - |
|
121 | - // Init the plugin after WordPress inits. |
|
122 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
123 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
124 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
125 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
126 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
127 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
128 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
129 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
130 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
131 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
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 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'notes', new WPInv_Notes() ); |
|
90 | + $this->set( 'api', new WPInv_API() ); |
|
91 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
92 | + $this->set( 'template', new GetPaid_Template() ); |
|
93 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
94 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
95 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
96 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
97 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
98 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
99 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
100 | + |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Define plugin constants. |
|
105 | + */ |
|
106 | + public function define_constants() { |
|
107 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
108 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
109 | + $this->version = WPINV_VERSION; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Hook into actions and filters. |
|
114 | + * |
|
115 | + * @since 1.0.19 |
|
116 | + */ |
|
117 | + protected function init_hooks() { |
|
118 | + /* Internationalize the text strings used. */ |
|
119 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + |
|
121 | + // Init the plugin after WordPress inits. |
|
122 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
123 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
124 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
125 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
126 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
127 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
128 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
129 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
130 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
131 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
132 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | + |
|
134 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | 135 | add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load Localisation files. |
|
158 | - * |
|
159 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | - * |
|
161 | - * Locales found in: |
|
162 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - */ |
|
167 | - public function load_textdomain() { |
|
168 | - |
|
169 | - load_plugin_textdomain( |
|
170 | - 'invoicing', |
|
171 | - false, |
|
172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | - ); |
|
174 | - |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Include required core files used in admin and on the frontend. |
|
179 | - */ |
|
180 | - public function includes() { |
|
181 | - |
|
182 | - // Start with the settings. |
|
183 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
184 | - |
|
185 | - // Packages/libraries. |
|
186 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
187 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
188 | - |
|
189 | - // Load functions. |
|
190 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
191 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
192 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
193 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
194 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
195 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
205 | - |
|
206 | - // Register autoloader. |
|
207 | - try { |
|
208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | - } catch ( Exception $e ) { |
|
210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | - } |
|
212 | - |
|
213 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
214 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
215 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
216 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
217 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
218 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
235 | - |
|
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | - GetPaid_Post_Types_Admin::init(); |
|
238 | - |
|
239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
241 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
242 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
243 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
245 | - // load the user class only on the users.php page |
|
246 | - global $pagenow; |
|
247 | - if ( $pagenow == 'users.php' ) { |
|
248 | - new WPInv_Admin_Users(); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // Register cli commands |
|
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | - } |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Class autoloader |
|
262 | - * |
|
263 | - * @param string $class_name The name of the class to load. |
|
264 | - * @access public |
|
265 | - * @since 1.0.19 |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function autoload( $class_name ) { |
|
269 | - |
|
270 | - // Normalize the class name... |
|
271 | - $class_name = strtolower( $class_name ); |
|
272 | - |
|
273 | - // ... and make sure it is our class. |
|
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // Next, prepare the file name from the class. |
|
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | - |
|
281 | - // Base path of the classes. |
|
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | - |
|
284 | - // And an array of possible locations in order of importance. |
|
285 | - $locations = array( |
|
286 | - "$plugin_path/includes", |
|
287 | - "$plugin_path/includes/data-stores", |
|
288 | - "$plugin_path/includes/gateways", |
|
289 | - "$plugin_path/includes/payments", |
|
290 | - "$plugin_path/includes/geolocation", |
|
291 | - "$plugin_path/includes/reports", |
|
292 | - "$plugin_path/includes/api", |
|
293 | - "$plugin_path/includes/admin", |
|
294 | - "$plugin_path/includes/admin/meta-boxes", |
|
295 | - ); |
|
296 | - |
|
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | - |
|
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
301 | - break; |
|
302 | - } |
|
136 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load Localisation files. |
|
158 | + * |
|
159 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
160 | + * |
|
161 | + * Locales found in: |
|
162 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
163 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + */ |
|
167 | + public function load_textdomain() { |
|
168 | + |
|
169 | + load_plugin_textdomain( |
|
170 | + 'invoicing', |
|
171 | + false, |
|
172 | + plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
173 | + ); |
|
174 | + |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Include required core files used in admin and on the frontend. |
|
179 | + */ |
|
180 | + public function includes() { |
|
181 | + |
|
182 | + // Start with the settings. |
|
183 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
184 | + |
|
185 | + // Packages/libraries. |
|
186 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
187 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
188 | + |
|
189 | + // Load functions. |
|
190 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
191 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
192 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
193 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
194 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
195 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
205 | + |
|
206 | + // Register autoloader. |
|
207 | + try { |
|
208 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | + } catch ( Exception $e ) { |
|
210 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
211 | + } |
|
212 | + |
|
213 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
214 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
215 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
216 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
217 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
218 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
235 | + |
|
236 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
237 | + GetPaid_Post_Types_Admin::init(); |
|
238 | + |
|
239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
241 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
242 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
243 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
245 | + // load the user class only on the users.php page |
|
246 | + global $pagenow; |
|
247 | + if ( $pagenow == 'users.php' ) { |
|
248 | + new WPInv_Admin_Users(); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // Register cli commands |
|
253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + } |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Class autoloader |
|
262 | + * |
|
263 | + * @param string $class_name The name of the class to load. |
|
264 | + * @access public |
|
265 | + * @since 1.0.19 |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function autoload( $class_name ) { |
|
269 | + |
|
270 | + // Normalize the class name... |
|
271 | + $class_name = strtolower( $class_name ); |
|
272 | + |
|
273 | + // ... and make sure it is our class. |
|
274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // Next, prepare the file name from the class. |
|
279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | + |
|
281 | + // Base path of the classes. |
|
282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | + |
|
284 | + // And an array of possible locations in order of importance. |
|
285 | + $locations = array( |
|
286 | + "$plugin_path/includes", |
|
287 | + "$plugin_path/includes/data-stores", |
|
288 | + "$plugin_path/includes/gateways", |
|
289 | + "$plugin_path/includes/payments", |
|
290 | + "$plugin_path/includes/geolocation", |
|
291 | + "$plugin_path/includes/reports", |
|
292 | + "$plugin_path/includes/api", |
|
293 | + "$plugin_path/includes/admin", |
|
294 | + "$plugin_path/includes/admin/meta-boxes", |
|
295 | + ); |
|
296 | + |
|
297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | + |
|
299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | + include trailingslashit( $location ) . $file_name; |
|
301 | + break; |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | |
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Inits hooks etc. |
|
309 | - */ |
|
310 | - public function init() { |
|
311 | - |
|
312 | - // Fires before getpaid inits. |
|
313 | - do_action( 'before_getpaid_init', $this ); |
|
314 | - |
|
315 | - // Maybe upgrade. |
|
316 | - $this->maybe_upgrade_database(); |
|
317 | - |
|
318 | - // Load default gateways. |
|
319 | - $gateways = apply_filters( |
|
320 | - 'getpaid_default_gateways', |
|
321 | - array( |
|
322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | - ) |
|
328 | - ); |
|
329 | - |
|
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
332 | - } |
|
333 | - |
|
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | - GetPaid_Installer::rename_gateways_label(); |
|
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | - } |
|
338 | - |
|
339 | - // Fires after getpaid inits. |
|
340 | - do_action( 'getpaid_init', $this ); |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - |
|
349 | - // Ensure that this is an IPN request. |
|
350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
355 | - |
|
356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | - exit; |
|
359 | - |
|
360 | - } |
|
361 | - |
|
362 | - public function enqueue_scripts() { |
|
363 | - |
|
364 | - // Fires before adding scripts. |
|
365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
366 | - |
|
367 | - $localize = array(); |
|
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
378 | - |
|
379 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | - |
|
381 | - // reCaptcha. |
|
382 | - if ( getpaid_is_recaptcha_enabled() ) { |
|
383 | - $url = apply_filters( |
|
384 | - 'getpaid_recaptcha_api_url', |
|
385 | - add_query_arg( |
|
386 | - array( |
|
387 | - 'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(), |
|
388 | - ), |
|
389 | - 'https://www.google.com/recaptcha/api.js' |
|
390 | - ) |
|
391 | - ); |
|
392 | - wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
393 | - } |
|
394 | - |
|
395 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
396 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
397 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
398 | - } |
|
399 | - |
|
400 | - public function wpinv_actions() { |
|
401 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
402 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
403 | - } |
|
404 | - |
|
405 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
406 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Inits hooks etc. |
|
309 | + */ |
|
310 | + public function init() { |
|
311 | + |
|
312 | + // Fires before getpaid inits. |
|
313 | + do_action( 'before_getpaid_init', $this ); |
|
314 | + |
|
315 | + // Maybe upgrade. |
|
316 | + $this->maybe_upgrade_database(); |
|
317 | + |
|
318 | + // Load default gateways. |
|
319 | + $gateways = apply_filters( |
|
320 | + 'getpaid_default_gateways', |
|
321 | + array( |
|
322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
327 | + ) |
|
328 | + ); |
|
329 | + |
|
330 | + foreach ( $gateways as $id => $class ) { |
|
331 | + $this->gateways[ $id ] = new $class(); |
|
332 | + } |
|
333 | + |
|
334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + GetPaid_Installer::rename_gateways_label(); |
|
336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + } |
|
338 | + |
|
339 | + // Fires after getpaid inits. |
|
340 | + do_action( 'getpaid_init', $this ); |
|
341 | + |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + |
|
349 | + // Ensure that this is an IPN request. |
|
350 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
355 | + |
|
356 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
358 | + exit; |
|
359 | + |
|
360 | + } |
|
361 | + |
|
362 | + public function enqueue_scripts() { |
|
363 | + |
|
364 | + // Fires before adding scripts. |
|
365 | + do_action( 'getpaid_enqueue_scripts' ); |
|
366 | + |
|
367 | + $localize = array(); |
|
368 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
369 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
370 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
378 | + |
|
379 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
380 | + |
|
381 | + // reCaptcha. |
|
382 | + if ( getpaid_is_recaptcha_enabled() ) { |
|
383 | + $url = apply_filters( |
|
384 | + 'getpaid_recaptcha_api_url', |
|
385 | + add_query_arg( |
|
386 | + array( |
|
387 | + 'render' => 'v2' === getpaid_get_recaptcha_version() ? 'explicit' : getpaid_get_recaptcha_site_key(), |
|
388 | + ), |
|
389 | + 'https://www.google.com/recaptcha/api.js' |
|
390 | + ) |
|
391 | + ); |
|
392 | + wp_enqueue_script( 'recaptcha', $url, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
393 | + } |
|
394 | + |
|
395 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
396 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
397 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
398 | + } |
|
399 | + |
|
400 | + public function wpinv_actions() { |
|
401 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
402 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
403 | + } |
|
404 | + |
|
405 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
406 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | 411 | * Fires an action after verifying that a user can fire them. |
412 | - * |
|
413 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
414 | - * current user owns the invoice/subscription. |
|
412 | + * |
|
413 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
414 | + * current user owns the invoice/subscription. |
|
415 | 415 | */ |
416 | 416 | public function maybe_do_authenticated_action() { |
417 | 417 | |
418 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
418 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
419 | 419 | |
420 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
421 | - $data = wp_unslash( $_REQUEST ); |
|
422 | - if ( is_user_logged_in() ) { |
|
423 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
424 | - } |
|
420 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
421 | + $data = wp_unslash( $_REQUEST ); |
|
422 | + if ( is_user_logged_in() ) { |
|
423 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
424 | + } |
|
425 | 425 | |
426 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
426 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
427 | 427 | |
428 | - } |
|
428 | + } |
|
429 | 429 | |
430 | 430 | } |
431 | 431 | |
432 | - public function pre_get_posts( $wp_query ) { |
|
433 | - |
|
434 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
435 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
436 | - } |
|
437 | - |
|
438 | - return $wp_query; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Register widgets |
|
443 | - * |
|
444 | - */ |
|
445 | - public function register_widgets() { |
|
446 | - global $pagenow; |
|
447 | - |
|
448 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
449 | - // So we disable our widgets when editing a page with UX Builder. |
|
450 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
451 | - return; |
|
452 | - } |
|
453 | - |
|
454 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
455 | - |
|
456 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
457 | - // don't initiate in these conditions. |
|
458 | - } else { |
|
459 | - |
|
460 | - // Only load allowed widgets. |
|
461 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
462 | - $widgets = apply_filters( |
|
463 | - 'getpaid_widget_classes', |
|
464 | - array( |
|
465 | - 'WPInv_Checkout_Widget', |
|
466 | - 'WPInv_History_Widget', |
|
467 | - 'WPInv_Receipt_Widget', |
|
468 | - 'WPInv_Subscriptions_Widget', |
|
469 | - 'WPInv_Buy_Item_Widget', |
|
470 | - 'WPInv_Messages_Widget', |
|
471 | - 'WPInv_GetPaid_Widget', |
|
472 | - 'WPInv_Invoice_Widget', |
|
473 | - ) |
|
474 | - ); |
|
475 | - |
|
476 | - // For each widget... |
|
477 | - foreach ( $widgets as $widget ) { |
|
478 | - |
|
479 | - // Abort early if it is excluded for this page. |
|
480 | - if ( in_array( $widget, $exclude ) ) { |
|
481 | - continue; |
|
482 | - } |
|
483 | - |
|
484 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
485 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
486 | - register_widget( $widget ); |
|
487 | - } else { |
|
488 | - new $widget(); |
|
489 | - } |
|
432 | + public function pre_get_posts( $wp_query ) { |
|
433 | + |
|
434 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
435 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
436 | + } |
|
437 | + |
|
438 | + return $wp_query; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Register widgets |
|
443 | + * |
|
444 | + */ |
|
445 | + public function register_widgets() { |
|
446 | + global $pagenow; |
|
447 | + |
|
448 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
449 | + // So we disable our widgets when editing a page with UX Builder. |
|
450 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
451 | + return; |
|
452 | + } |
|
453 | + |
|
454 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
455 | + |
|
456 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
457 | + // don't initiate in these conditions. |
|
458 | + } else { |
|
459 | + |
|
460 | + // Only load allowed widgets. |
|
461 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
462 | + $widgets = apply_filters( |
|
463 | + 'getpaid_widget_classes', |
|
464 | + array( |
|
465 | + 'WPInv_Checkout_Widget', |
|
466 | + 'WPInv_History_Widget', |
|
467 | + 'WPInv_Receipt_Widget', |
|
468 | + 'WPInv_Subscriptions_Widget', |
|
469 | + 'WPInv_Buy_Item_Widget', |
|
470 | + 'WPInv_Messages_Widget', |
|
471 | + 'WPInv_GetPaid_Widget', |
|
472 | + 'WPInv_Invoice_Widget', |
|
473 | + ) |
|
474 | + ); |
|
475 | + |
|
476 | + // For each widget... |
|
477 | + foreach ( $widgets as $widget ) { |
|
478 | + |
|
479 | + // Abort early if it is excluded for this page. |
|
480 | + if ( in_array( $widget, $exclude ) ) { |
|
481 | + continue; |
|
482 | + } |
|
483 | + |
|
484 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
485 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
486 | + register_widget( $widget ); |
|
487 | + } else { |
|
488 | + new $widget(); |
|
489 | + } |
|
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - } |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Upgrades the database. |
|
497 | + * |
|
498 | + * @since 2.0.2 |
|
499 | + */ |
|
500 | + public function maybe_upgrade_database() { |
|
501 | + |
|
502 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
503 | + |
|
504 | + if ( $wpi_version == WPINV_VERSION ) { |
|
505 | + return; |
|
506 | + } |
|
507 | + |
|
508 | + $installer = new GetPaid_Installer(); |
|
509 | + |
|
510 | + if ( empty( $wpi_version ) ) { |
|
511 | + return $installer->upgrade_db( 0 ); |
|
512 | + } |
|
513 | + |
|
514 | + $upgrades = array( |
|
515 | + '0.0.5' => '004', |
|
516 | + '1.0.3' => '102', |
|
517 | + '2.0.0' => '118', |
|
518 | + '2.0.8' => '207', |
|
519 | + '2.6.16' => '2615', |
|
520 | + ); |
|
521 | + |
|
522 | + foreach ( $upgrades as $key => $method ) { |
|
523 | + |
|
524 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
525 | + return $installer->upgrade_db( $method ); |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Flushes the permalinks if needed. |
|
533 | + * |
|
534 | + * @since 2.0.8 |
|
535 | + */ |
|
536 | + public function maybe_flush_permalinks() { |
|
537 | + |
|
538 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
539 | + |
|
540 | + if ( ! empty( $flush ) ) { |
|
541 | + flush_rewrite_rules(); |
|
542 | + delete_option( 'wpinv_flush_permalinks' ); |
|
543 | + } |
|
544 | + |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Remove our pages from yoast sitemaps. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param int[] $excluded_posts_ids |
|
552 | + */ |
|
553 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
554 | + |
|
555 | + // Ensure that we have an array. |
|
556 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
557 | + $excluded_posts_ids = array(); |
|
558 | + } |
|
559 | + |
|
560 | + // Prepare our pages. |
|
561 | + $our_pages = array(); |
|
562 | + |
|
563 | + // Checkout page. |
|
564 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
565 | + |
|
566 | + // Success page. |
|
567 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
568 | + |
|
569 | + // Failure page. |
|
570 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
571 | + |
|
572 | + // History page. |
|
573 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
494 | 574 | |
495 | - /** |
|
496 | - * Upgrades the database. |
|
497 | - * |
|
498 | - * @since 2.0.2 |
|
499 | - */ |
|
500 | - public function maybe_upgrade_database() { |
|
575 | + // Subscriptions page. |
|
576 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
501 | 577 | |
502 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
578 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
503 | 579 | |
504 | - if ( $wpi_version == WPINV_VERSION ) { |
|
505 | - return; |
|
506 | - } |
|
580 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
581 | + return array_unique( $excluded_posts_ids ); |
|
507 | 582 | |
508 | - $installer = new GetPaid_Installer(); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Remove our pages from yoast sitemaps. |
|
587 | + * |
|
588 | + * @since 1.0.19 |
|
589 | + * @param string[] $post_types |
|
590 | + */ |
|
591 | + public function exclude_invoicing_post_types( $post_types ) { |
|
592 | + |
|
593 | + // Ensure that we have an array. |
|
594 | + if ( ! is_array( $post_types ) ) { |
|
595 | + $post_types = array(); |
|
596 | + } |
|
597 | + |
|
598 | + // Remove our post types. |
|
599 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * Displays additional footer code. |
|
604 | + * |
|
605 | + * @since 2.0.0 |
|
606 | + */ |
|
607 | + public function wp_footer() { |
|
608 | + wpinv_get_template( 'frontend-footer.php' ); |
|
609 | + } |
|
509 | 610 | |
510 | - if ( empty( $wpi_version ) ) { |
|
511 | - return $installer->upgrade_db( 0 ); |
|
512 | - } |
|
611 | + /** |
|
612 | + * Displays additional header code. |
|
613 | + * |
|
614 | + * @since 2.0.0 |
|
615 | + */ |
|
616 | + public function wp_head() { |
|
617 | + wpinv_get_template( 'frontend-head.php' ); |
|
618 | + } |
|
513 | 619 | |
514 | - $upgrades = array( |
|
515 | - '0.0.5' => '004', |
|
516 | - '1.0.3' => '102', |
|
517 | - '2.0.0' => '118', |
|
518 | - '2.0.8' => '207', |
|
519 | - '2.6.16' => '2615', |
|
520 | - ); |
|
521 | - |
|
522 | - foreach ( $upgrades as $key => $method ) { |
|
523 | - |
|
524 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
525 | - return $installer->upgrade_db( $method ); |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Flushes the permalinks if needed. |
|
533 | - * |
|
534 | - * @since 2.0.8 |
|
535 | - */ |
|
536 | - public function maybe_flush_permalinks() { |
|
537 | - |
|
538 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
539 | - |
|
540 | - if ( ! empty( $flush ) ) { |
|
541 | - flush_rewrite_rules(); |
|
542 | - delete_option( 'wpinv_flush_permalinks' ); |
|
543 | - } |
|
544 | - |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Remove our pages from yoast sitemaps. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param int[] $excluded_posts_ids |
|
552 | - */ |
|
553 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
554 | - |
|
555 | - // Ensure that we have an array. |
|
556 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
557 | - $excluded_posts_ids = array(); |
|
558 | - } |
|
559 | - |
|
560 | - // Prepare our pages. |
|
561 | - $our_pages = array(); |
|
562 | - |
|
563 | - // Checkout page. |
|
564 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
565 | - |
|
566 | - // Success page. |
|
567 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
568 | - |
|
569 | - // Failure page. |
|
570 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
571 | - |
|
572 | - // History page. |
|
573 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
574 | - |
|
575 | - // Subscriptions page. |
|
576 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
577 | - |
|
578 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
579 | - |
|
580 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
581 | - return array_unique( $excluded_posts_ids ); |
|
582 | - |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Remove our pages from yoast sitemaps. |
|
587 | - * |
|
588 | - * @since 1.0.19 |
|
589 | - * @param string[] $post_types |
|
590 | - */ |
|
591 | - public function exclude_invoicing_post_types( $post_types ) { |
|
592 | - |
|
593 | - // Ensure that we have an array. |
|
594 | - if ( ! is_array( $post_types ) ) { |
|
595 | - $post_types = array(); |
|
596 | - } |
|
597 | - |
|
598 | - // Remove our post types. |
|
599 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * Displays additional footer code. |
|
604 | - * |
|
605 | - * @since 2.0.0 |
|
606 | - */ |
|
607 | - public function wp_footer() { |
|
608 | - wpinv_get_template( 'frontend-footer.php' ); |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * Displays additional header code. |
|
613 | - * |
|
614 | - * @since 2.0.0 |
|
615 | - */ |
|
616 | - public function wp_head() { |
|
617 | - wpinv_get_template( 'frontend-head.php' ); |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Custom query vars. |
|
622 | - * |
|
623 | - */ |
|
624 | - public function custom_query_vars( $vars ) { |
|
620 | + /** |
|
621 | + * Custom query vars. |
|
622 | + * |
|
623 | + */ |
|
624 | + public function custom_query_vars( $vars ) { |
|
625 | 625 | $vars[] = 'getpaid-ipn'; |
626 | 626 | return $vars; |
627 | - } |
|
627 | + } |
|
628 | 628 | |
629 | - /** |
|
630 | - * Add rewrite tags and rules. |
|
631 | - * |
|
632 | - */ |
|
633 | - public function add_rewrite_rule() { |
|
629 | + /** |
|
630 | + * Add rewrite tags and rules. |
|
631 | + * |
|
632 | + */ |
|
633 | + public function add_rewrite_rule() { |
|
634 | 634 | $tag = 'getpaid-ipn'; |
635 | 635 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
636 | 636 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
637 | - } |
|
637 | + } |
|
638 | 638 | |
639 | - /** |
|
640 | - * Processes non-query string ipns. |
|
641 | - * |
|
642 | - */ |
|
643 | - public function maybe_process_new_ipn( $query ) { |
|
639 | + /** |
|
640 | + * Processes non-query string ipns. |
|
641 | + * |
|
642 | + */ |
|
643 | + public function maybe_process_new_ipn( $query ) { |
|
644 | 644 | |
645 | 645 | if ( is_admin() || ! $query->is_main_query() ) { |
646 | 646 | return; |
647 | 647 | } |
648 | 648 | |
649 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
649 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
650 | 650 | |
651 | 651 | if ( ! empty( $gateway ) ) { |
652 | 652 | |
653 | - $gateway = sanitize_text_field( $gateway ); |
|
654 | - nocache_headers(); |
|
655 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
656 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
657 | - exit; |
|
653 | + $gateway = sanitize_text_field( $gateway ); |
|
654 | + nocache_headers(); |
|
655 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
656 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
657 | + exit; |
|
658 | 658 | |
659 | 659 | } |
660 | 660 | |
661 | - } |
|
661 | + } |
|
662 | 662 | |
663 | 663 | } |
@@ -1,196 +1,196 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | function wpinv_is_subscription_payment( $invoice = '' ) { |
3 | - if ( empty( $invoice ) ) { |
|
4 | - return false; |
|
5 | - } |
|
3 | + if ( empty( $invoice ) ) { |
|
4 | + return false; |
|
5 | + } |
|
6 | 6 | |
7 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice ); |
|
9 | - } |
|
7 | + if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | + $invoice = wpinv_get_invoice( $invoice ); |
|
9 | + } |
|
10 | 10 | |
11 | - if ( empty( $invoice ) ) { |
|
12 | - return false; |
|
13 | - } |
|
11 | + if ( empty( $invoice ) ) { |
|
12 | + return false; |
|
13 | + } |
|
14 | 14 | |
15 | - if ( $invoice->is_renewal() ) { |
|
16 | - return true; |
|
17 | - } |
|
15 | + if ( $invoice->is_renewal() ) { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - return false; |
|
19 | + return false; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | function wpinv_payment_link_transaction_id( $invoice = '' ) { |
23 | - if ( empty( $invoice ) ) { |
|
24 | - return false; |
|
25 | - } |
|
23 | + if ( empty( $invoice ) ) { |
|
24 | + return false; |
|
25 | + } |
|
26 | 26 | |
27 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | - $invoice = wpinv_get_invoice( $invoice ); |
|
29 | - } |
|
27 | + if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | + $invoice = wpinv_get_invoice( $invoice ); |
|
29 | + } |
|
30 | 30 | |
31 | - if ( empty( $invoice ) ) { |
|
32 | - return false; |
|
33 | - } |
|
31 | + if ( empty( $invoice ) ) { |
|
32 | + return false; |
|
33 | + } |
|
34 | 34 | |
35 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
35 | + return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
39 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
40 | - |
|
41 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
42 | - $amount = __( 'Free', 'invoicing' ); |
|
43 | - $interval = $trial_interval; |
|
44 | - $period = $trial_period; |
|
45 | - } |
|
46 | - |
|
47 | - $description = ''; |
|
48 | - switch ( $period ) { |
|
49 | - case 'D': |
|
50 | - case 'day': |
|
51 | - $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
52 | - break; |
|
53 | - case 'W': |
|
54 | - case 'week': |
|
55 | - $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
56 | - break; |
|
57 | - case 'M': |
|
58 | - case 'month': |
|
59 | - $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
60 | - break; |
|
61 | - case 'Y': |
|
62 | - case 'year': |
|
63 | - $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
64 | - break; |
|
65 | - } |
|
66 | - |
|
67 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
39 | + $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
40 | + |
|
41 | + if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
42 | + $amount = __( 'Free', 'invoicing' ); |
|
43 | + $interval = $trial_interval; |
|
44 | + $period = $trial_period; |
|
45 | + } |
|
46 | + |
|
47 | + $description = ''; |
|
48 | + switch ( $period ) { |
|
49 | + case 'D': |
|
50 | + case 'day': |
|
51 | + $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
52 | + break; |
|
53 | + case 'W': |
|
54 | + case 'week': |
|
55 | + $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
56 | + break; |
|
57 | + case 'M': |
|
58 | + case 'month': |
|
59 | + $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
60 | + break; |
|
61 | + case 'Y': |
|
62 | + case 'year': |
|
63 | + $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
64 | + break; |
|
65 | + } |
|
66 | + |
|
67 | + return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
71 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | - $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
73 | - |
|
74 | - $description = ''; |
|
75 | - switch ( $period ) { |
|
76 | - case 'D': |
|
77 | - case 'day': |
|
78 | - if ( (int)$bill_times > 0 ) { |
|
79 | - if ( $interval > 1 ) { |
|
80 | - if ( $bill_times > 1 ) { |
|
81 | - $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
82 | - } else { |
|
83 | - $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
84 | - } |
|
85 | - } else { |
|
86 | - $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
87 | - } |
|
88 | - } else { |
|
89 | - $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
90 | - } |
|
91 | - break; |
|
92 | - case 'W': |
|
93 | - case 'week': |
|
94 | - if ( (int)$bill_times > 0 ) { |
|
95 | - if ( $interval > 1 ) { |
|
96 | - if ( $bill_times > 1 ) { |
|
97 | - $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
98 | - } else { |
|
99 | - $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
100 | - } |
|
101 | - } else { |
|
102 | - $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
103 | - } |
|
104 | - } else { |
|
105 | - $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
106 | - } |
|
107 | - break; |
|
108 | - case 'M': |
|
109 | - case 'month': |
|
110 | - if ( (int)$bill_times > 0 ) { |
|
111 | - if ( $interval > 1 ) { |
|
112 | - if ( $bill_times > 1 ) { |
|
113 | - $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
114 | - } else { |
|
115 | - $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
116 | - } |
|
117 | - } else { |
|
118 | - $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
119 | - } |
|
120 | - } else { |
|
121 | - $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
122 | - } |
|
123 | - break; |
|
124 | - case 'Y': |
|
125 | - case 'year': |
|
126 | - if ( (int)$bill_times > 0 ) { |
|
127 | - if ( $interval > 1 ) { |
|
128 | - if ( $bill_times > 1 ) { |
|
129 | - $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
130 | - } else { |
|
131 | - $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
132 | - } |
|
133 | - } else { |
|
134 | - $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
135 | - } |
|
136 | - } else { |
|
137 | - $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
138 | - } |
|
139 | - break; |
|
140 | - } |
|
141 | - |
|
142 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
71 | + $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | + $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
73 | + |
|
74 | + $description = ''; |
|
75 | + switch ( $period ) { |
|
76 | + case 'D': |
|
77 | + case 'day': |
|
78 | + if ( (int)$bill_times > 0 ) { |
|
79 | + if ( $interval > 1 ) { |
|
80 | + if ( $bill_times > 1 ) { |
|
81 | + $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
82 | + } else { |
|
83 | + $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
84 | + } |
|
85 | + } else { |
|
86 | + $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
87 | + } |
|
88 | + } else { |
|
89 | + $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
90 | + } |
|
91 | + break; |
|
92 | + case 'W': |
|
93 | + case 'week': |
|
94 | + if ( (int)$bill_times > 0 ) { |
|
95 | + if ( $interval > 1 ) { |
|
96 | + if ( $bill_times > 1 ) { |
|
97 | + $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
98 | + } else { |
|
99 | + $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
100 | + } |
|
101 | + } else { |
|
102 | + $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
103 | + } |
|
104 | + } else { |
|
105 | + $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
106 | + } |
|
107 | + break; |
|
108 | + case 'M': |
|
109 | + case 'month': |
|
110 | + if ( (int)$bill_times > 0 ) { |
|
111 | + if ( $interval > 1 ) { |
|
112 | + if ( $bill_times > 1 ) { |
|
113 | + $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
114 | + } else { |
|
115 | + $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
116 | + } |
|
117 | + } else { |
|
118 | + $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
119 | + } |
|
120 | + } else { |
|
121 | + $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
122 | + } |
|
123 | + break; |
|
124 | + case 'Y': |
|
125 | + case 'year': |
|
126 | + if ( (int)$bill_times > 0 ) { |
|
127 | + if ( $interval > 1 ) { |
|
128 | + if ( $bill_times > 1 ) { |
|
129 | + $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
130 | + } else { |
|
131 | + $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
132 | + } |
|
133 | + } else { |
|
134 | + $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
135 | + } |
|
136 | + } else { |
|
137 | + $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
138 | + } |
|
139 | + break; |
|
140 | + } |
|
141 | + |
|
142 | + return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | function wpinv_subscription_payment_desc( $invoice ) { |
146 | - if ( empty( $invoice ) ) { |
|
147 | - return null; |
|
148 | - } |
|
149 | - |
|
150 | - $description = ''; |
|
151 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | - if ( $item->has_free_trial() ) { |
|
153 | - $trial_period = $item->get_trial_period(); |
|
154 | - $trial_interval = $item->get_trial_interval(); |
|
155 | - } else { |
|
156 | - $trial_period = ''; |
|
157 | - $trial_interval = 0; |
|
158 | - } |
|
159 | - |
|
160 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
161 | - } |
|
162 | - |
|
163 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
146 | + if ( empty( $invoice ) ) { |
|
147 | + return null; |
|
148 | + } |
|
149 | + |
|
150 | + $description = ''; |
|
151 | + if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | + if ( $item->has_free_trial() ) { |
|
153 | + $trial_period = $item->get_trial_period(); |
|
154 | + $trial_interval = $item->get_trial_interval(); |
|
155 | + } else { |
|
156 | + $trial_period = ''; |
|
157 | + $trial_interval = 0; |
|
158 | + } |
|
159 | + |
|
160 | + $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
161 | + } |
|
162 | + |
|
163 | + return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
167 | - $initial_total = wpinv_round_amount( $initial ); |
|
168 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
167 | + $initial_total = wpinv_round_amount( $initial ); |
|
168 | + $recurring_total = wpinv_round_amount( $recurring ); |
|
169 | 169 | |
170 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
171 | - // Free trial |
|
172 | - } else { |
|
173 | - if ( $bill_times == 1 ) { |
|
174 | - $recurring_total = $initial_total; |
|
175 | - } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
176 | - $bill_times--; |
|
177 | - } |
|
178 | - } |
|
170 | + if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
171 | + // Free trial |
|
172 | + } else { |
|
173 | + if ( $bill_times == 1 ) { |
|
174 | + $recurring_total = $initial_total; |
|
175 | + } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
176 | + $bill_times--; |
|
177 | + } |
|
178 | + } |
|
179 | 179 | |
180 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
181 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
180 | + $initial_amount = wpinv_price( $initial_total, $currency ); |
|
181 | + $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
182 | 182 | |
183 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
183 | + $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
184 | 184 | |
185 | - if ( $initial_total != $recurring_total ) { |
|
186 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
185 | + if ( $initial_total != $recurring_total ) { |
|
186 | + $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
187 | 187 | |
188 | - $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
189 | - } else { |
|
190 | - $description = $recurring; |
|
191 | - } |
|
188 | + $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
189 | + } else { |
|
190 | + $description = $recurring; |
|
191 | + } |
|
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
193 | + return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -202,25 +202,25 @@ discard block |
||
202 | 202 | */ |
203 | 203 | function getpaid_get_card_name( $card_number ) { |
204 | 204 | |
205 | - // Known regexes. |
|
206 | - $regexes = array( |
|
207 | - '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | - '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | - '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | - '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | - '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | - '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
213 | - ); |
|
214 | - |
|
215 | - // Confirm if one matches. |
|
216 | - foreach ( $regexes as $regex => $card ) { |
|
217 | - if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
218 | - return $card; |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - // None matched. |
|
223 | - return __( 'Card', 'invoicing' ); |
|
205 | + // Known regexes. |
|
206 | + $regexes = array( |
|
207 | + '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | + '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | + '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | + '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | + '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | + '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
213 | + ); |
|
214 | + |
|
215 | + // Confirm if one matches. |
|
216 | + foreach ( $regexes as $regex => $card ) { |
|
217 | + if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
218 | + return $card; |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + // None matched. |
|
223 | + return __( 'Card', 'invoicing' ); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -230,24 +230,24 @@ discard block |
||
230 | 230 | * @param WPInv_Invoice|int|null $invoice |
231 | 231 | */ |
232 | 232 | function wpinv_send_back_to_checkout( $invoice = null ) { |
233 | - $response = array( 'success' => false ); |
|
234 | - $invoice = wpinv_get_invoice( $invoice ); |
|
235 | - |
|
236 | - // Was an invoice created? |
|
237 | - if ( ! empty( $invoice ) ) { |
|
238 | - $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
239 | - $response['invoice'] = $invoice->get_id(); |
|
240 | - do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
241 | - } |
|
242 | - |
|
243 | - // Do we have any errors? |
|
244 | - if ( wpinv_get_errors() ) { |
|
245 | - $response['data'] = getpaid_get_errors_html( true, false ); |
|
246 | - } else { |
|
247 | - $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
248 | - } |
|
249 | - |
|
250 | - wp_send_json( $response ); |
|
233 | + $response = array( 'success' => false ); |
|
234 | + $invoice = wpinv_get_invoice( $invoice ); |
|
235 | + |
|
236 | + // Was an invoice created? |
|
237 | + if ( ! empty( $invoice ) ) { |
|
238 | + $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
239 | + $response['invoice'] = $invoice->get_id(); |
|
240 | + do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
241 | + } |
|
242 | + |
|
243 | + // Do we have any errors? |
|
244 | + if ( wpinv_get_errors() ) { |
|
245 | + $response['data'] = getpaid_get_errors_html( true, false ); |
|
246 | + } else { |
|
247 | + $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
248 | + } |
|
249 | + |
|
250 | + wp_send_json( $response ); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @return string |
257 | 257 | */ |
258 | 258 | function getpaid_get_recaptcha_site_key() { |
259 | - return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) ); |
|
259 | + return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @return string |
266 | 266 | */ |
267 | 267 | function getpaid_get_recaptcha_secret_key() { |
268 | - return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) ); |
|
268 | + return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) ); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @return bool |
275 | 275 | */ |
276 | 276 | function getpaid_is_recaptcha_enabled() { |
277 | - return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
277 | + return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return string |
284 | 284 | */ |
285 | 285 | function getpaid_get_recaptcha_version() { |
286 | - return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) ); |
|
286 | + return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -292,42 +292,42 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | function getpaid_get_recaptcha_settings() { |
295 | - $settings = array( |
|
296 | - 'enabled' => getpaid_is_recaptcha_enabled(), |
|
297 | - 'version' => getpaid_get_recaptcha_version(), |
|
298 | - ); |
|
299 | - |
|
300 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
301 | - return $settings; |
|
302 | - } |
|
303 | - |
|
304 | - $settings['sitekey'] = getpaid_get_recaptcha_site_key(); |
|
305 | - |
|
306 | - // Version 2 render params. |
|
307 | - if ( 'v2' === getpaid_get_recaptcha_version() ) { |
|
308 | - $settings['render_params'] = array( |
|
309 | - 'sitekey' => getpaid_get_recaptcha_site_key(), |
|
310 | - 'theme' => 'light', |
|
311 | - 'size' => 'normal', |
|
312 | - 'tabindex' => 0, |
|
313 | - ); |
|
314 | - } |
|
315 | - |
|
316 | - return apply_filters( 'getpaid_recaptcha_settings', $settings ); |
|
295 | + $settings = array( |
|
296 | + 'enabled' => getpaid_is_recaptcha_enabled(), |
|
297 | + 'version' => getpaid_get_recaptcha_version(), |
|
298 | + ); |
|
299 | + |
|
300 | + if ( ! getpaid_is_recaptcha_enabled() ) { |
|
301 | + return $settings; |
|
302 | + } |
|
303 | + |
|
304 | + $settings['sitekey'] = getpaid_get_recaptcha_site_key(); |
|
305 | + |
|
306 | + // Version 2 render params. |
|
307 | + if ( 'v2' === getpaid_get_recaptcha_version() ) { |
|
308 | + $settings['render_params'] = array( |
|
309 | + 'sitekey' => getpaid_get_recaptcha_site_key(), |
|
310 | + 'theme' => 'light', |
|
311 | + 'size' => 'normal', |
|
312 | + 'tabindex' => 0, |
|
313 | + ); |
|
314 | + } |
|
315 | + |
|
316 | + return apply_filters( 'getpaid_recaptcha_settings', $settings ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
320 | 320 | * Displays reCAPTCHA before payment button. |
321 | 321 | */ |
322 | 322 | function getpaid_display_recaptcha_before_payment_button() { |
323 | - if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) { |
|
324 | - return; |
|
325 | - } |
|
326 | - |
|
327 | - printf( |
|
328 | - '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha mw-100 overflow-hidden my-2" id="getpaid-recaptcha-%s"></div></div>', |
|
329 | - esc_attr( wp_unique_id() ) |
|
330 | - ); |
|
323 | + if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) { |
|
324 | + return; |
|
325 | + } |
|
326 | + |
|
327 | + printf( |
|
328 | + '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha mw-100 overflow-hidden my-2" id="getpaid-recaptcha-%s"></div></div>', |
|
329 | + esc_attr( wp_unique_id() ) |
|
330 | + ); |
|
331 | 331 | } |
332 | 332 | add_action( 'getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button' ); |
333 | 333 | |
@@ -338,43 +338,43 @@ discard block |
||
338 | 338 | */ |
339 | 339 | function getpaid_validate_recaptcha_response( $submission ) { |
340 | 340 | |
341 | - // Check if reCAPTCHA is enabled. |
|
342 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
343 | - return; |
|
344 | - } |
|
345 | - |
|
346 | - $token = $submission->get_field( 'g-recaptcha-response' ); |
|
347 | - |
|
348 | - // Abort if no token was provided. |
|
349 | - if ( empty( $token ) ) { |
|
350 | - wp_send_json_error( 'v2' === getpaid_get_recaptcha_version() ? __( 'Please confirm that you are not a robot.', 'invoicing' ) : __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
351 | - } |
|
352 | - |
|
353 | - $result = wp_remote_post( |
|
354 | - 'https://www.google.com/recaptcha/api/siteverify', |
|
355 | - array( |
|
356 | - 'body' => array( |
|
357 | - 'secret' => getpaid_get_recaptcha_secret_key(), |
|
358 | - 'response' => $token, |
|
359 | - ), |
|
360 | - ) |
|
361 | - ); |
|
362 | - |
|
363 | - // Site not reachable, give benefit of doubt. |
|
364 | - if ( is_wp_error( $result ) ) { |
|
365 | - return; |
|
366 | - } |
|
367 | - |
|
368 | - $result = json_decode( wp_remote_retrieve_body( $result ), true ); |
|
369 | - |
|
370 | - if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { |
|
371 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
372 | - } |
|
373 | - |
|
374 | - // For v3, check the score. |
|
375 | - $minimum_score = apply_filters( 'getpaid_recaptcha_minimum_score', 0.4 ); |
|
376 | - if ( 'v3' === getpaid_get_recaptcha_version() && ( empty( $result['score'] ) || $result['score'] < $minimum_score ) ) { |
|
377 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
378 | - } |
|
341 | + // Check if reCAPTCHA is enabled. |
|
342 | + if ( ! getpaid_is_recaptcha_enabled() ) { |
|
343 | + return; |
|
344 | + } |
|
345 | + |
|
346 | + $token = $submission->get_field( 'g-recaptcha-response' ); |
|
347 | + |
|
348 | + // Abort if no token was provided. |
|
349 | + if ( empty( $token ) ) { |
|
350 | + wp_send_json_error( 'v2' === getpaid_get_recaptcha_version() ? __( 'Please confirm that you are not a robot.', 'invoicing' ) : __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
351 | + } |
|
352 | + |
|
353 | + $result = wp_remote_post( |
|
354 | + 'https://www.google.com/recaptcha/api/siteverify', |
|
355 | + array( |
|
356 | + 'body' => array( |
|
357 | + 'secret' => getpaid_get_recaptcha_secret_key(), |
|
358 | + 'response' => $token, |
|
359 | + ), |
|
360 | + ) |
|
361 | + ); |
|
362 | + |
|
363 | + // Site not reachable, give benefit of doubt. |
|
364 | + if ( is_wp_error( $result ) ) { |
|
365 | + return; |
|
366 | + } |
|
367 | + |
|
368 | + $result = json_decode( wp_remote_retrieve_body( $result ), true ); |
|
369 | + |
|
370 | + if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { |
|
371 | + wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
372 | + } |
|
373 | + |
|
374 | + // For v3, check the score. |
|
375 | + $minimum_score = apply_filters( 'getpaid_recaptcha_minimum_score', 0.4 ); |
|
376 | + if ( 'v3' === getpaid_get_recaptcha_version() && ( empty( $result['score'] ) || $result['score'] < $minimum_score ) ) { |
|
377 | + wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
378 | + } |
|
379 | 379 | } |
380 | 380 | add_action( 'getpaid_checkout_error_checks', 'getpaid_validate_recaptcha_response' ); |