@@ -14,617 +14,617 @@ |
||
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( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
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( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
131 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
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 | - |
|
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | - |
|
380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | - } |
|
384 | - |
|
385 | - public function wpinv_actions() { |
|
386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | - } |
|
389 | - |
|
390 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
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 | + |
|
378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + |
|
380 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | + } |
|
384 | + |
|
385 | + public function wpinv_actions() { |
|
386 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | + } |
|
389 | + |
|
390 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | 396 | * Fires an action after verifying that a user can fire them. |
397 | - * |
|
398 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
399 | - * current user owns the invoice/subscription. |
|
397 | + * |
|
398 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
399 | + * current user owns the invoice/subscription. |
|
400 | 400 | */ |
401 | 401 | public function maybe_do_authenticated_action() { |
402 | 402 | |
403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
403 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
404 | 404 | |
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - if ( is_user_logged_in() ) { |
|
408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | - } |
|
405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | + $data = wp_unslash( $_REQUEST ); |
|
407 | + if ( is_user_logged_in() ) { |
|
408 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
409 | + } |
|
410 | 410 | |
411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
411 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | 412 | |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | 415 | } |
416 | 416 | |
417 | - public function pre_get_posts( $wp_query ) { |
|
418 | - |
|
419 | - 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() ) { |
|
420 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
421 | - } |
|
422 | - |
|
423 | - return $wp_query; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Register widgets |
|
428 | - * |
|
429 | - */ |
|
430 | - public function register_widgets() { |
|
431 | - global $pagenow; |
|
432 | - |
|
433 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
434 | - // So we disable our widgets when editing a page with UX Builder. |
|
435 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
436 | - return; |
|
437 | - } |
|
438 | - |
|
439 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
440 | - |
|
441 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
442 | - // don't initiate in these conditions. |
|
443 | - } else { |
|
444 | - |
|
445 | - // Only load allowed widgets. |
|
446 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
447 | - $widgets = apply_filters( |
|
448 | - 'getpaid_widget_classes', |
|
449 | - array( |
|
450 | - 'WPInv_Checkout_Widget', |
|
451 | - 'WPInv_History_Widget', |
|
452 | - 'WPInv_Receipt_Widget', |
|
453 | - 'WPInv_Subscriptions_Widget', |
|
454 | - 'WPInv_Buy_Item_Widget', |
|
455 | - 'WPInv_Messages_Widget', |
|
456 | - 'WPInv_GetPaid_Widget', |
|
457 | - 'WPInv_Invoice_Widget', |
|
458 | - ) |
|
459 | - ); |
|
460 | - |
|
461 | - // For each widget... |
|
462 | - foreach ( $widgets as $widget ) { |
|
463 | - |
|
464 | - // Abort early if it is excluded for this page. |
|
465 | - if ( in_array( $widget, $exclude ) ) { |
|
466 | - continue; |
|
467 | - } |
|
468 | - |
|
469 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
470 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
471 | - register_widget( $widget ); |
|
472 | - } else { |
|
473 | - new $widget(); |
|
474 | - } |
|
417 | + public function pre_get_posts( $wp_query ) { |
|
418 | + |
|
419 | + 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() ) { |
|
420 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
421 | + } |
|
422 | + |
|
423 | + return $wp_query; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Register widgets |
|
428 | + * |
|
429 | + */ |
|
430 | + public function register_widgets() { |
|
431 | + global $pagenow; |
|
432 | + |
|
433 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
434 | + // So we disable our widgets when editing a page with UX Builder. |
|
435 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
436 | + return; |
|
437 | + } |
|
438 | + |
|
439 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
440 | + |
|
441 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
442 | + // don't initiate in these conditions. |
|
443 | + } else { |
|
444 | + |
|
445 | + // Only load allowed widgets. |
|
446 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
447 | + $widgets = apply_filters( |
|
448 | + 'getpaid_widget_classes', |
|
449 | + array( |
|
450 | + 'WPInv_Checkout_Widget', |
|
451 | + 'WPInv_History_Widget', |
|
452 | + 'WPInv_Receipt_Widget', |
|
453 | + 'WPInv_Subscriptions_Widget', |
|
454 | + 'WPInv_Buy_Item_Widget', |
|
455 | + 'WPInv_Messages_Widget', |
|
456 | + 'WPInv_GetPaid_Widget', |
|
457 | + 'WPInv_Invoice_Widget', |
|
458 | + ) |
|
459 | + ); |
|
460 | + |
|
461 | + // For each widget... |
|
462 | + foreach ( $widgets as $widget ) { |
|
463 | + |
|
464 | + // Abort early if it is excluded for this page. |
|
465 | + if ( in_array( $widget, $exclude ) ) { |
|
466 | + continue; |
|
467 | + } |
|
468 | + |
|
469 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
470 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
471 | + register_widget( $widget ); |
|
472 | + } else { |
|
473 | + new $widget(); |
|
474 | + } |
|
475 | 475 | } |
476 | 476 | } |
477 | 477 | |
478 | - } |
|
478 | + } |
|
479 | 479 | |
480 | - /** |
|
481 | - * Upgrades the database. |
|
482 | - * |
|
483 | - * @since 2.0.2 |
|
484 | - */ |
|
485 | - public function maybe_upgrade_database() { |
|
480 | + /** |
|
481 | + * Upgrades the database. |
|
482 | + * |
|
483 | + * @since 2.0.2 |
|
484 | + */ |
|
485 | + public function maybe_upgrade_database() { |
|
486 | 486 | |
487 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
487 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
488 | 488 | |
489 | - if ( $wpi_version == WPINV_VERSION ) { |
|
490 | - return; |
|
491 | - } |
|
489 | + if ( $wpi_version == WPINV_VERSION ) { |
|
490 | + return; |
|
491 | + } |
|
492 | 492 | |
493 | - $installer = new GetPaid_Installer(); |
|
493 | + $installer = new GetPaid_Installer(); |
|
494 | 494 | |
495 | - if ( empty( $wpi_version ) ) { |
|
496 | - return $installer->upgrade_db( 0 ); |
|
497 | - } |
|
495 | + if ( empty( $wpi_version ) ) { |
|
496 | + return $installer->upgrade_db( 0 ); |
|
497 | + } |
|
498 | 498 | |
499 | - $upgrades = array( |
|
500 | - '0.0.5' => '004', |
|
501 | - '1.0.3' => '102', |
|
502 | - '2.0.0' => '118', |
|
503 | - '2.0.8' => '207', |
|
504 | - ); |
|
499 | + $upgrades = array( |
|
500 | + '0.0.5' => '004', |
|
501 | + '1.0.3' => '102', |
|
502 | + '2.0.0' => '118', |
|
503 | + '2.0.8' => '207', |
|
504 | + ); |
|
505 | 505 | |
506 | - foreach ( $upgrades as $key => $method ) { |
|
506 | + foreach ( $upgrades as $key => $method ) { |
|
507 | 507 | |
508 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
509 | - return $installer->upgrade_db( $method ); |
|
510 | - } |
|
508 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
509 | + return $installer->upgrade_db( $method ); |
|
510 | + } |
|
511 | 511 | } |
512 | 512 | |
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * Flushes the permalinks if needed. |
|
517 | - * |
|
518 | - * @since 2.0.8 |
|
519 | - */ |
|
520 | - public function maybe_flush_permalinks() { |
|
521 | - |
|
522 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
523 | - |
|
524 | - if ( ! empty( $flush ) ) { |
|
525 | - flush_rewrite_rules(); |
|
526 | - delete_option( 'wpinv_flush_permalinks' ); |
|
527 | - } |
|
528 | - |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Remove our pages from yoast sitemaps. |
|
533 | - * |
|
534 | - * @since 1.0.19 |
|
535 | - * @param int[] $excluded_posts_ids |
|
536 | - */ |
|
537 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
538 | - |
|
539 | - // Ensure that we have an array. |
|
540 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
541 | - $excluded_posts_ids = array(); |
|
542 | - } |
|
543 | - |
|
544 | - // Prepare our pages. |
|
545 | - $our_pages = array(); |
|
546 | - |
|
547 | - // Checkout page. |
|
548 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
549 | - |
|
550 | - // Success page. |
|
551 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
552 | - |
|
553 | - // Failure page. |
|
554 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
555 | - |
|
556 | - // History page. |
|
557 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
558 | - |
|
559 | - // Subscriptions page. |
|
560 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
561 | - |
|
562 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
563 | - |
|
564 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
565 | - return array_unique( $excluded_posts_ids ); |
|
566 | - |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Displays additional footer code. |
|
571 | - * |
|
572 | - * @since 2.0.0 |
|
573 | - */ |
|
574 | - public function wp_footer() { |
|
575 | - wpinv_get_template( 'frontend-footer.php' ); |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * Displays additional header code. |
|
580 | - * |
|
581 | - * @since 2.0.0 |
|
582 | - */ |
|
583 | - public function wp_head() { |
|
584 | - wpinv_get_template( 'frontend-head.php' ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Custom query vars. |
|
589 | - * |
|
590 | - */ |
|
591 | - public function custom_query_vars( $vars ) { |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * Flushes the permalinks if needed. |
|
517 | + * |
|
518 | + * @since 2.0.8 |
|
519 | + */ |
|
520 | + public function maybe_flush_permalinks() { |
|
521 | + |
|
522 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
523 | + |
|
524 | + if ( ! empty( $flush ) ) { |
|
525 | + flush_rewrite_rules(); |
|
526 | + delete_option( 'wpinv_flush_permalinks' ); |
|
527 | + } |
|
528 | + |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Remove our pages from yoast sitemaps. |
|
533 | + * |
|
534 | + * @since 1.0.19 |
|
535 | + * @param int[] $excluded_posts_ids |
|
536 | + */ |
|
537 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
538 | + |
|
539 | + // Ensure that we have an array. |
|
540 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
541 | + $excluded_posts_ids = array(); |
|
542 | + } |
|
543 | + |
|
544 | + // Prepare our pages. |
|
545 | + $our_pages = array(); |
|
546 | + |
|
547 | + // Checkout page. |
|
548 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
549 | + |
|
550 | + // Success page. |
|
551 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
552 | + |
|
553 | + // Failure page. |
|
554 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
555 | + |
|
556 | + // History page. |
|
557 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
558 | + |
|
559 | + // Subscriptions page. |
|
560 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
561 | + |
|
562 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
563 | + |
|
564 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
565 | + return array_unique( $excluded_posts_ids ); |
|
566 | + |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Displays additional footer code. |
|
571 | + * |
|
572 | + * @since 2.0.0 |
|
573 | + */ |
|
574 | + public function wp_footer() { |
|
575 | + wpinv_get_template( 'frontend-footer.php' ); |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Displays additional header code. |
|
580 | + * |
|
581 | + * @since 2.0.0 |
|
582 | + */ |
|
583 | + public function wp_head() { |
|
584 | + wpinv_get_template( 'frontend-head.php' ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Custom query vars. |
|
589 | + * |
|
590 | + */ |
|
591 | + public function custom_query_vars( $vars ) { |
|
592 | 592 | $vars[] = 'getpaid-ipn'; |
593 | 593 | return $vars; |
594 | - } |
|
594 | + } |
|
595 | 595 | |
596 | - /** |
|
597 | - * Add rewrite tags and rules. |
|
598 | - * |
|
599 | - */ |
|
600 | - public function add_rewrite_rule() { |
|
596 | + /** |
|
597 | + * Add rewrite tags and rules. |
|
598 | + * |
|
599 | + */ |
|
600 | + public function add_rewrite_rule() { |
|
601 | 601 | $tag = 'getpaid-ipn'; |
602 | 602 | add_rewrite_tag( "%$tag%", '([^&]+)' ); |
603 | 603 | add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
604 | - } |
|
604 | + } |
|
605 | 605 | |
606 | - /** |
|
607 | - * Processes non-query string ipns. |
|
608 | - * |
|
609 | - */ |
|
610 | - public function maybe_process_new_ipn( $query ) { |
|
606 | + /** |
|
607 | + * Processes non-query string ipns. |
|
608 | + * |
|
609 | + */ |
|
610 | + public function maybe_process_new_ipn( $query ) { |
|
611 | 611 | |
612 | 612 | if ( is_admin() || ! $query->is_main_query() ) { |
613 | 613 | return; |
614 | 614 | } |
615 | 615 | |
616 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
616 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
617 | 617 | |
618 | 618 | if ( ! empty( $gateway ) ) { |
619 | 619 | |
620 | - $gateway = sanitize_text_field( $gateway ); |
|
621 | - nocache_headers(); |
|
622 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
623 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
624 | - exit; |
|
620 | + $gateway = sanitize_text_field( $gateway ); |
|
621 | + nocache_headers(); |
|
622 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
623 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
624 | + exit; |
|
625 | 625 | |
626 | 626 | } |
627 | 627 | |
628 | - } |
|
628 | + } |
|
629 | 629 | |
630 | 630 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
128 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
129 | + add_action('wp_head', array($this, 'wp_head')); |
|
130 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
131 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
132 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
133 | + |
|
134 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
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 | 137 | |
138 | 138 | // Fires after registering actions. |
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
139 | + do_action('wpinv_actions', $this); |
|
140 | + do_action('getpaid_actions', $this); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | /* Internationalize the text strings used. */ |
146 | 146 | $this->load_textdomain(); |
147 | 147 | |
148 | - do_action( 'wpinv_loaded' ); |
|
148 | + do_action('wpinv_loaded'); |
|
149 | 149 | |
150 | 150 | // Fix oxygen page builder conflict |
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
151 | + if (function_exists('ct_css_output')) { |
|
152 | 152 | wpinv_oxygen_fix_conflict(); |
153 | 153 | } |
154 | 154 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | load_plugin_textdomain( |
170 | 170 | 'invoicing', |
171 | 171 | false, |
172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
172 | + plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/' |
|
173 | 173 | ); |
174 | 174 | |
175 | 175 | } |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | |
206 | 206 | // Register autoloader. |
207 | 207 | try { |
208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | - } catch ( Exception $e ) { |
|
210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
208 | + spl_autoload_register(array($this, 'autoload'), true); |
|
209 | + } catch (Exception $e) { |
|
210 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
234 | 234 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
235 | 235 | |
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
237 | 237 | GetPaid_Post_Types_Admin::init(); |
238 | 238 | |
239 | 239 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -244,15 +244,15 @@ discard block |
||
244 | 244 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
245 | 245 | // load the user class only on the users.php page |
246 | 246 | global $pagenow; |
247 | - if ( $pagenow == 'users.php' ) { |
|
247 | + if ($pagenow == 'users.php') { |
|
248 | 248 | new WPInv_Admin_Users(); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Register cli commands |
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
253 | + if (defined('WP_CLI') && WP_CLI) { |
|
254 | 254 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
255 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @since 1.0.19 |
266 | 266 | * @return void |
267 | 267 | */ |
268 | - public function autoload( $class_name ) { |
|
268 | + public function autoload($class_name) { |
|
269 | 269 | |
270 | 270 | // Normalize the class name... |
271 | - $class_name = strtolower( $class_name ); |
|
271 | + $class_name = strtolower($class_name); |
|
272 | 272 | |
273 | 273 | // ... and make sure it is our class. |
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Next, prepare the file name from the class. |
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
280 | 280 | |
281 | 281 | // Base path of the classes. |
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
283 | 283 | |
284 | 284 | // And an array of possible locations in order of importance. |
285 | 285 | $locations = array( |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | "$plugin_path/includes/admin/meta-boxes", |
295 | 295 | ); |
296 | 296 | |
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
298 | 298 | |
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
299 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
300 | + include trailingslashit($location) . $file_name; |
|
301 | 301 | break; |
302 | 302 | } |
303 | 303 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | public function init() { |
311 | 311 | |
312 | 312 | // Fires before getpaid inits. |
313 | - do_action( 'before_getpaid_init', $this ); |
|
313 | + do_action('before_getpaid_init', $this); |
|
314 | 314 | |
315 | 315 | // Maybe upgrade. |
316 | 316 | $this->maybe_upgrade_database(); |
@@ -327,17 +327,17 @@ discard block |
||
327 | 327 | ) |
328 | 328 | ); |
329 | 329 | |
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
330 | + foreach ($gateways as $id => $class) { |
|
331 | + $this->gateways[$id] = new $class(); |
|
332 | 332 | } |
333 | 333 | |
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
334 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
335 | 335 | GetPaid_Installer::rename_gateways_label(); |
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
336 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Fires after getpaid inits. |
340 | - do_action( 'getpaid_init', $this ); |
|
340 | + do_action('getpaid_init', $this); |
|
341 | 341 | |
342 | 342 | } |
343 | 343 | |
@@ -347,14 +347,14 @@ discard block |
||
347 | 347 | public function maybe_process_ipn() { |
348 | 348 | |
349 | 349 | // Ensure that this is an IPN request. |
350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
351 | 351 | return; |
352 | 352 | } |
353 | 353 | |
354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
355 | 355 | |
356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
356 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
357 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
358 | 358 | exit; |
359 | 359 | |
360 | 360 | } |
@@ -362,33 +362,33 @@ discard block |
||
362 | 362 | public function enqueue_scripts() { |
363 | 363 | |
364 | 364 | // Fires before adding scripts. |
365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
365 | + do_action('getpaid_enqueue_scripts'); |
|
366 | 366 | |
367 | 367 | $localize = array(); |
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
368 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
369 | 369 | $localize['thousands'] = wpinv_thousands_separator(); |
370 | 370 | $localize['decimals'] = wpinv_decimal_separator(); |
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
371 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
372 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
373 | 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' ); |
|
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 | 377 | |
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
378 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
379 | 379 | |
380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
380 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
381 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true); |
|
382 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | public function wpinv_actions() { |
386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
386 | + if (isset($_REQUEST['wpi_action'])) { |
|
387 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
388 | 388 | } |
389 | 389 | |
390 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
390 | + if (defined('WP_ALL_IMPORT_ROOT_DIR')) { |
|
391 | + include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
@@ -400,24 +400,24 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function maybe_do_authenticated_action() { |
402 | 402 | |
403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
403 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
404 | 404 | |
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - if ( is_user_logged_in() ) { |
|
408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
405 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
406 | + $data = wp_unslash($_REQUEST); |
|
407 | + if (is_user_logged_in()) { |
|
408 | + do_action("getpaid_authenticated_action_$key", $data); |
|
409 | 409 | } |
410 | 410 | |
411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
411 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | |
415 | 415 | } |
416 | 416 | |
417 | - public function pre_get_posts( $wp_query ) { |
|
417 | + public function pre_get_posts($wp_query) { |
|
418 | 418 | |
419 | - 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() ) { |
|
420 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | + 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()) { |
|
420 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | return $wp_query; |
@@ -432,18 +432,18 @@ discard block |
||
432 | 432 | |
433 | 433 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
434 | 434 | // So we disable our widgets when editing a page with UX Builder. |
435 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
435 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
436 | 436 | return; |
437 | 437 | } |
438 | 438 | |
439 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
439 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
440 | 440 | |
441 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
441 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
442 | 442 | // don't initiate in these conditions. |
443 | 443 | } else { |
444 | 444 | |
445 | 445 | // Only load allowed widgets. |
446 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
446 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
447 | 447 | $widgets = apply_filters( |
448 | 448 | 'getpaid_widget_classes', |
449 | 449 | array( |
@@ -459,16 +459,16 @@ discard block |
||
459 | 459 | ); |
460 | 460 | |
461 | 461 | // For each widget... |
462 | - foreach ( $widgets as $widget ) { |
|
462 | + foreach ($widgets as $widget) { |
|
463 | 463 | |
464 | 464 | // Abort early if it is excluded for this page. |
465 | - if ( in_array( $widget, $exclude ) ) { |
|
465 | + if (in_array($widget, $exclude)) { |
|
466 | 466 | continue; |
467 | 467 | } |
468 | 468 | |
469 | 469 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
470 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
471 | - register_widget( $widget ); |
|
470 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
471 | + register_widget($widget); |
|
472 | 472 | } else { |
473 | 473 | new $widget(); |
474 | 474 | } |
@@ -484,29 +484,29 @@ discard block |
||
484 | 484 | */ |
485 | 485 | public function maybe_upgrade_database() { |
486 | 486 | |
487 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
487 | + $wpi_version = get_option('wpinv_version', 0); |
|
488 | 488 | |
489 | - if ( $wpi_version == WPINV_VERSION ) { |
|
489 | + if ($wpi_version == WPINV_VERSION) { |
|
490 | 490 | return; |
491 | 491 | } |
492 | 492 | |
493 | 493 | $installer = new GetPaid_Installer(); |
494 | 494 | |
495 | - if ( empty( $wpi_version ) ) { |
|
496 | - return $installer->upgrade_db( 0 ); |
|
495 | + if (empty($wpi_version)) { |
|
496 | + return $installer->upgrade_db(0); |
|
497 | 497 | } |
498 | 498 | |
499 | - $upgrades = array( |
|
499 | + $upgrades = array( |
|
500 | 500 | '0.0.5' => '004', |
501 | 501 | '1.0.3' => '102', |
502 | 502 | '2.0.0' => '118', |
503 | 503 | '2.0.8' => '207', |
504 | 504 | ); |
505 | 505 | |
506 | - foreach ( $upgrades as $key => $method ) { |
|
506 | + foreach ($upgrades as $key => $method) { |
|
507 | 507 | |
508 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
509 | - return $installer->upgrade_db( $method ); |
|
508 | + if (version_compare($wpi_version, $key, '<')) { |
|
509 | + return $installer->upgrade_db($method); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
@@ -519,11 +519,11 @@ discard block |
||
519 | 519 | */ |
520 | 520 | public function maybe_flush_permalinks() { |
521 | 521 | |
522 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
522 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
523 | 523 | |
524 | - if ( ! empty( $flush ) ) { |
|
524 | + if (!empty($flush)) { |
|
525 | 525 | flush_rewrite_rules(); |
526 | - delete_option( 'wpinv_flush_permalinks' ); |
|
526 | + delete_option('wpinv_flush_permalinks'); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | } |
@@ -534,10 +534,10 @@ discard block |
||
534 | 534 | * @since 1.0.19 |
535 | 535 | * @param int[] $excluded_posts_ids |
536 | 536 | */ |
537 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
537 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
538 | 538 | |
539 | 539 | // Ensure that we have an array. |
540 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
540 | + if (!is_array($excluded_posts_ids)) { |
|
541 | 541 | $excluded_posts_ids = array(); |
542 | 542 | } |
543 | 543 | |
@@ -545,24 +545,24 @@ discard block |
||
545 | 545 | $our_pages = array(); |
546 | 546 | |
547 | 547 | // Checkout page. |
548 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
548 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
549 | 549 | |
550 | 550 | // Success page. |
551 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
551 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
552 | 552 | |
553 | 553 | // Failure page. |
554 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
554 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
555 | 555 | |
556 | 556 | // History page. |
557 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
557 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
558 | 558 | |
559 | 559 | // Subscriptions page. |
560 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
560 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
561 | 561 | |
562 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
562 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
563 | 563 | |
564 | 564 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
565 | - return array_unique( $excluded_posts_ids ); |
|
565 | + return array_unique($excluded_posts_ids); |
|
566 | 566 | |
567 | 567 | } |
568 | 568 | |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * @since 2.0.0 |
573 | 573 | */ |
574 | 574 | public function wp_footer() { |
575 | - wpinv_get_template( 'frontend-footer.php' ); |
|
575 | + wpinv_get_template('frontend-footer.php'); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -581,14 +581,14 @@ discard block |
||
581 | 581 | * @since 2.0.0 |
582 | 582 | */ |
583 | 583 | public function wp_head() { |
584 | - wpinv_get_template( 'frontend-head.php' ); |
|
584 | + wpinv_get_template('frontend-head.php'); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
588 | 588 | * Custom query vars. |
589 | 589 | * |
590 | 590 | */ |
591 | - public function custom_query_vars( $vars ) { |
|
591 | + public function custom_query_vars($vars) { |
|
592 | 592 | $vars[] = 'getpaid-ipn'; |
593 | 593 | return $vars; |
594 | 594 | } |
@@ -599,28 +599,28 @@ discard block |
||
599 | 599 | */ |
600 | 600 | public function add_rewrite_rule() { |
601 | 601 | $tag = 'getpaid-ipn'; |
602 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
603 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
602 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
603 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
607 | 607 | * Processes non-query string ipns. |
608 | 608 | * |
609 | 609 | */ |
610 | - public function maybe_process_new_ipn( $query ) { |
|
610 | + public function maybe_process_new_ipn($query) { |
|
611 | 611 | |
612 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
612 | + if (is_admin() || !$query->is_main_query()) { |
|
613 | 613 | return; |
614 | 614 | } |
615 | 615 | |
616 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
616 | + $gateway = get_query_var('getpaid-ipn'); |
|
617 | 617 | |
618 | - if ( ! empty( $gateway ) ) { |
|
618 | + if (!empty($gateway)) { |
|
619 | 619 | |
620 | - $gateway = sanitize_text_field( $gateway ); |
|
620 | + $gateway = sanitize_text_field($gateway); |
|
621 | 621 | nocache_headers(); |
622 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
623 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
622 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
623 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
624 | 624 | exit; |
625 | 625 | |
626 | 626 | } |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | - $can_checkout = true; // Always true for now |
|
34 | + $can_checkout = true; // Always true for now |
|
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | + $page_id = absint( $page_id ); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,22 +51,22 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
53 | 53 | $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
54 | + $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | + $page_id = absint( $page_id ); |
|
56 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | + $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | + $ret = $ret ? is_page( $ret ) : false; |
|
69 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | function wpinv_send_to_failed_page( $args = null ) { |
95 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
95 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
96 | 96 | |
97 | 97 | if ( ! empty( $args ) ) { |
98 | 98 | // Check for backward compatibility |
@@ -113,58 +113,58 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | function wpinv_get_checkout_uri( $args = array() ) { |
116 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
117 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
116 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
117 | + $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
118 | 118 | |
119 | - if ( ! empty( $args ) ) { |
|
120 | - // Check for backward compatibility |
|
121 | - if ( is_string( $args ) ) { |
|
122 | - $args = str_replace( '?', '', $args ); |
|
119 | + if ( ! empty( $args ) ) { |
|
120 | + // Check for backward compatibility |
|
121 | + if ( is_string( $args ) ) { |
|
122 | + $args = str_replace( '?', '', $args ); |
|
123 | 123 | } |
124 | 124 | |
125 | - $args = wp_parse_args( $args ); |
|
125 | + $args = wp_parse_args( $args ); |
|
126 | 126 | |
127 | - $uri = add_query_arg( $args, $uri ); |
|
128 | - } |
|
127 | + $uri = add_query_arg( $args, $uri ); |
|
128 | + } |
|
129 | 129 | |
130 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
130 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
131 | 131 | |
132 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
132 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
133 | 133 | |
134 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
135 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
136 | - } |
|
134 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
135 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
136 | + } |
|
137 | 137 | |
138 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
138 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | function wpinv_get_success_page_url( $query_string = null ) { |
142 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
143 | - $success_page = get_permalink( $success_page ); |
|
142 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
143 | + $success_page = get_permalink( $success_page ); |
|
144 | 144 | |
145 | - if ( $query_string ) { |
|
146 | - $success_page .= $query_string; |
|
145 | + if ( $query_string ) { |
|
146 | + $success_page .= $query_string; |
|
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
149 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
153 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
154 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
153 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
154 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
155 | 155 | |
156 | - if ( $extras ) { |
|
157 | - $uri .= $extras; |
|
156 | + if ( $extras ) { |
|
157 | + $uri .= $extras; |
|
158 | 158 | } |
159 | 159 | |
160 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
160 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_is_failed_transaction_page() { |
164 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
165 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
164 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
165 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
166 | 166 | |
167 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
167 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -244,36 +244,36 @@ discard block |
||
244 | 244 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
245 | 245 | |
246 | 246 | if ( $require_billing_details ) { |
247 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
248 | - $required_fields['first_name'] = array( |
|
249 | - 'error_id' => 'invalid_first_name', |
|
250 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
251 | - ); |
|
252 | - } |
|
253 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
254 | - $required_fields['address'] = array( |
|
255 | - 'error_id' => 'invalid_address', |
|
256 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
257 | - ); |
|
258 | - } |
|
259 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
260 | - $required_fields['city'] = array( |
|
261 | - 'error_id' => 'invalid_city', |
|
262 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
263 | - ); |
|
264 | - } |
|
265 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
266 | - $required_fields['state'] = array( |
|
267 | - 'error_id' => 'invalid_state', |
|
268 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
269 | - ); |
|
270 | - } |
|
271 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
272 | - $required_fields['country'] = array( |
|
273 | - 'error_id' => 'invalid_country', |
|
274 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
275 | - ); |
|
276 | - } |
|
247 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
248 | + $required_fields['first_name'] = array( |
|
249 | + 'error_id' => 'invalid_first_name', |
|
250 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
251 | + ); |
|
252 | + } |
|
253 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
254 | + $required_fields['address'] = array( |
|
255 | + 'error_id' => 'invalid_address', |
|
256 | + 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
257 | + ); |
|
258 | + } |
|
259 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
260 | + $required_fields['city'] = array( |
|
261 | + 'error_id' => 'invalid_city', |
|
262 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
263 | + ); |
|
264 | + } |
|
265 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
266 | + $required_fields['state'] = array( |
|
267 | + 'error_id' => 'invalid_state', |
|
268 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
269 | + ); |
|
270 | + } |
|
271 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
272 | + $required_fields['country'] = array( |
|
273 | + 'error_id' => 'invalid_country', |
|
274 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
275 | + ); |
|
276 | + } |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
21 | 21 | |
22 | - if ( ! $is_object_set ) { |
|
23 | - unset( $wp_query->queried_object ); |
|
22 | + if (!$is_object_set) { |
|
23 | + unset($wp_query->queried_object); |
|
24 | 24 | } |
25 | 25 | |
26 | - if ( ! $is_object_id_set ) { |
|
27 | - unset( $wp_query->queried_object_id ); |
|
26 | + if (!$is_object_id_set) { |
|
27 | + unset($wp_query->queried_object_id); |
|
28 | 28 | } |
29 | 29 | |
30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | 34 | $can_checkout = true; // Always true for now |
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option('success_page', 0); |
|
41 | + $page_id = absint($page_id); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -49,143 +49,143 @@ discard block |
||
49 | 49 | * @param string $post_type The post type or invoice type. |
50 | 50 | * @return string The history page URL. |
51 | 51 | */ |
52 | -function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
|
53 | - $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
|
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
52 | +function wpinv_get_history_page_uri($post_type = 'wpi_invoice') { |
|
53 | + $post_type = sanitize_key(str_replace('wpi_', '', $post_type)); |
|
54 | + $page_id = wpinv_get_option("{$post_type}_history_page", 0); |
|
55 | + $page_id = absint($page_id); |
|
56 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option('success_page', false); |
|
61 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
73 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
74 | - $ret = $ret ? is_page( $ret ) : false; |
|
75 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
73 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
74 | + $ret = $ret ? is_page($ret) : false; |
|
75 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Redirects a user the success page. |
80 | 80 | */ |
81 | -function wpinv_send_to_success_page( $args = array() ) { |
|
81 | +function wpinv_send_to_success_page($args = array()) { |
|
82 | 82 | |
83 | 83 | $redirect = add_query_arg( |
84 | - wp_parse_args( $args ), |
|
84 | + wp_parse_args($args), |
|
85 | 85 | wpinv_get_success_page_uri() |
86 | 86 | ); |
87 | 87 | |
88 | - $redirect = apply_filters( 'wpinv_send_to_success_page_url', $redirect, $args ); |
|
88 | + $redirect = apply_filters('wpinv_send_to_success_page_url', $redirect, $args); |
|
89 | 89 | |
90 | - wp_redirect( $redirect ); |
|
90 | + wp_redirect($redirect); |
|
91 | 91 | exit; |
92 | 92 | } |
93 | 93 | |
94 | -function wpinv_send_to_failed_page( $args = null ) { |
|
94 | +function wpinv_send_to_failed_page($args = null) { |
|
95 | 95 | $redirect = wpinv_get_failed_transaction_uri(); |
96 | 96 | |
97 | - if ( ! empty( $args ) ) { |
|
97 | + if (!empty($args)) { |
|
98 | 98 | // Check for backward compatibility |
99 | - if ( is_string( $args ) ) { |
|
100 | - $args = str_replace( '?', '', $args ); |
|
99 | + if (is_string($args)) { |
|
100 | + $args = str_replace('?', '', $args); |
|
101 | 101 | } |
102 | 102 | |
103 | - $args = wp_parse_args( $args ); |
|
103 | + $args = wp_parse_args($args); |
|
104 | 104 | |
105 | - $redirect = add_query_arg( $args, $redirect ); |
|
105 | + $redirect = add_query_arg($args, $redirect); |
|
106 | 106 | } |
107 | 107 | |
108 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
108 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
109 | 109 | |
110 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
111 | - wp_redirect( $redirect ); |
|
110 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
111 | + wp_redirect($redirect); |
|
112 | 112 | exit; |
113 | 113 | } |
114 | 114 | |
115 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
116 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
117 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
115 | +function wpinv_get_checkout_uri($args = array()) { |
|
116 | + $uri = wpinv_get_option('checkout_page', false); |
|
117 | + $uri = isset($uri) ? get_permalink($uri) : null; |
|
118 | 118 | |
119 | - if ( ! empty( $args ) ) { |
|
119 | + if (!empty($args)) { |
|
120 | 120 | // Check for backward compatibility |
121 | - if ( is_string( $args ) ) { |
|
122 | - $args = str_replace( '?', '', $args ); |
|
121 | + if (is_string($args)) { |
|
122 | + $args = str_replace('?', '', $args); |
|
123 | 123 | } |
124 | 124 | |
125 | - $args = wp_parse_args( $args ); |
|
125 | + $args = wp_parse_args($args); |
|
126 | 126 | |
127 | - $uri = add_query_arg( $args, $uri ); |
|
127 | + $uri = add_query_arg($args, $uri); |
|
128 | 128 | } |
129 | 129 | |
130 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
130 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
131 | 131 | |
132 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
132 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
133 | 133 | |
134 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
135 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
134 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
135 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
136 | 136 | } |
137 | 137 | |
138 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
138 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
139 | 139 | } |
140 | 140 | |
141 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
142 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
143 | - $success_page = get_permalink( $success_page ); |
|
141 | +function wpinv_get_success_page_url($query_string = null) { |
|
142 | + $success_page = wpinv_get_option('success_page', 0); |
|
143 | + $success_page = get_permalink($success_page); |
|
144 | 144 | |
145 | - if ( $query_string ) { |
|
145 | + if ($query_string) { |
|
146 | 146 | $success_page .= $query_string; |
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
149 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
153 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
154 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
152 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
153 | + $uri = wpinv_get_option('failure_page', ''); |
|
154 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
155 | 155 | |
156 | - if ( $extras ) { |
|
156 | + if ($extras) { |
|
157 | 157 | $uri .= $extras; |
158 | 158 | } |
159 | 159 | |
160 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
160 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_is_failed_transaction_page() { |
164 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
165 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
164 | + $ret = wpinv_get_option('failure_page', false); |
|
165 | + $ret = isset($ret) ? is_page($ret) : false; |
|
166 | 166 | |
167 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
167 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
168 | 168 | } |
169 | 169 | |
170 | -function wpinv_transaction_query( $type = 'start' ) { |
|
170 | +function wpinv_transaction_query($type = 'start') { |
|
171 | 171 | global $wpdb; |
172 | 172 | |
173 | 173 | $wpdb->hide_errors(); |
174 | 174 | |
175 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
176 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
175 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
176 | + define('WPINV_USE_TRANSACTIONS', true); |
|
177 | 177 | } |
178 | 178 | |
179 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
180 | - switch ( $type ) { |
|
179 | + if (WPINV_USE_TRANSACTIONS) { |
|
180 | + switch ($type) { |
|
181 | 181 | case 'commit': |
182 | - $wpdb->query( 'COMMIT' ); |
|
182 | + $wpdb->query('COMMIT'); |
|
183 | 183 | break; |
184 | 184 | case 'rollback': |
185 | - $wpdb->query( 'ROLLBACK' ); |
|
185 | + $wpdb->query('ROLLBACK'); |
|
186 | 186 | break; |
187 | 187 | default: |
188 | - $wpdb->query( 'START TRANSACTION' ); |
|
188 | + $wpdb->query('START TRANSACTION'); |
|
189 | 189 | break; |
190 | 190 | } |
191 | 191 | } |
@@ -194,146 +194,146 @@ discard block |
||
194 | 194 | function wpinv_get_prefix() { |
195 | 195 | $invoice_prefix = 'INV-'; |
196 | 196 | |
197 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
197 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | function wpinv_get_business_logo() { |
201 | - $business_logo = wpinv_get_option( 'logo' ); |
|
202 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
201 | + $business_logo = wpinv_get_option('logo'); |
|
202 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | function wpinv_get_business_name() { |
206 | - $name = wpinv_get_option( 'store_name', wpinv_get_blogname() ); |
|
206 | + $name = wpinv_get_option('store_name', wpinv_get_blogname()); |
|
207 | 207 | |
208 | - if ( empty( $name ) ) { |
|
208 | + if (empty($name)) { |
|
209 | 209 | $name = wpinv_get_blogname(); |
210 | 210 | } |
211 | 211 | |
212 | - return apply_filters( 'wpinv_get_business_name', $name ); |
|
212 | + return apply_filters('wpinv_get_business_name', $name); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | function wpinv_get_blogname() { |
216 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
216 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | function wpinv_get_admin_email() { |
220 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
221 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
220 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
221 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_business_website() { |
225 | - $business_website = home_url( '/' ); |
|
226 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
225 | + $business_website = home_url('/'); |
|
226 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
227 | 227 | } |
228 | 228 | |
229 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
229 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
230 | 230 | $terms_text = ''; |
231 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
231 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | function wpinv_get_business_footer() { |
235 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
236 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
237 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
235 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
236 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
237 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | function wpinv_checkout_required_fields() { |
241 | 241 | $required_fields = array(); |
242 | 242 | |
243 | 243 | // Let payment gateways and other extensions determine if address fields should be required |
244 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
244 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
245 | 245 | |
246 | - if ( $require_billing_details ) { |
|
247 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
246 | + if ($require_billing_details) { |
|
247 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
248 | 248 | $required_fields['first_name'] = array( |
249 | 249 | 'error_id' => 'invalid_first_name', |
250 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
250 | + 'error_message' => __('Please enter your first name', 'invoicing'), |
|
251 | 251 | ); |
252 | 252 | } |
253 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
253 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
254 | 254 | $required_fields['address'] = array( |
255 | 255 | 'error_id' => 'invalid_address', |
256 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
256 | + 'error_message' => __('Please enter your address', 'invoicing'), |
|
257 | 257 | ); |
258 | 258 | } |
259 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
259 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
260 | 260 | $required_fields['city'] = array( |
261 | 261 | 'error_id' => 'invalid_city', |
262 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
262 | + 'error_message' => __('Please enter your billing city', 'invoicing'), |
|
263 | 263 | ); |
264 | 264 | } |
265 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
265 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
266 | 266 | $required_fields['state'] = array( |
267 | 267 | 'error_id' => 'invalid_state', |
268 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
268 | + 'error_message' => __('Please enter billing state / province', 'invoicing'), |
|
269 | 269 | ); |
270 | 270 | } |
271 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
271 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
272 | 272 | $required_fields['country'] = array( |
273 | 273 | 'error_id' => 'invalid_country', |
274 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
274 | + 'error_message' => __('Please select your billing country', 'invoicing'), |
|
275 | 275 | ); |
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
279 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
279 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | function wpinv_is_ssl_enforced() { |
283 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
284 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
283 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
284 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | function wpinv_schedule_event_twicedaily() { |
288 | 288 | wpinv_email_payment_reminders(); |
289 | 289 | } |
290 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
290 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
291 | 291 | |
292 | 292 | function wpinv_require_login_to_checkout() { |
293 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
294 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
293 | + $return = wpinv_get_option('login_to_checkout', false); |
|
294 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_sequential_number_active( $type = '' ) { |
|
298 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
299 | - if ( null !== $check ) { |
|
297 | +function wpinv_sequential_number_active($type = '') { |
|
298 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
299 | + if (null !== $check) { |
|
300 | 300 | return $check; |
301 | 301 | } |
302 | 302 | |
303 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
303 | + return wpinv_get_option('sequential_invoice_number'); |
|
304 | 304 | } |
305 | 305 | |
306 | -function wpinv_switch_to_locale( $locale = null ) { |
|
306 | +function wpinv_switch_to_locale($locale = null) { |
|
307 | 307 | global $invoicing, $wpi_switch_locale; |
308 | 308 | |
309 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
310 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
309 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
310 | + $locale = empty($locale) ? get_locale() : $locale; |
|
311 | 311 | |
312 | - switch_to_locale( $locale ); |
|
312 | + switch_to_locale($locale); |
|
313 | 313 | |
314 | 314 | $wpi_switch_locale = $locale; |
315 | 315 | |
316 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
316 | + add_filter('plugin_locale', 'get_locale'); |
|
317 | 317 | |
318 | 318 | $invoicing->load_textdomain(); |
319 | 319 | |
320 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
320 | + do_action('wpinv_switch_to_locale', $locale); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | function wpinv_restore_locale() { |
325 | 325 | global $invoicing, $wpi_switch_locale; |
326 | 326 | |
327 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
327 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
328 | 328 | restore_previous_locale(); |
329 | 329 | |
330 | 330 | $wpi_switch_locale = null; |
331 | 331 | |
332 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
332 | + remove_filter('plugin_locale', 'get_locale'); |
|
333 | 333 | |
334 | 334 | $invoicing->load_textdomain(); |
335 | 335 | |
336 | - do_action( 'wpinv_restore_locale' ); |
|
336 | + do_action('wpinv_restore_locale'); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
@@ -341,26 +341,26 @@ discard block |
||
341 | 341 | * Returns the default form's id. |
342 | 342 | */ |
343 | 343 | function wpinv_get_default_payment_form() { |
344 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
344 | + $form = get_option('wpinv_default_payment_form'); |
|
345 | 345 | |
346 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
346 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
347 | 347 | $form = wp_insert_post( |
348 | 348 | array( |
349 | 349 | 'post_type' => 'wpi_payment_form', |
350 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
350 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
351 | 351 | 'post_status' => 'publish', |
352 | 352 | 'meta_input' => array( |
353 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
353 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
354 | 354 | 'wpinv_form_items' => array(), |
355 | 355 | ), |
356 | 356 | ) |
357 | 357 | ); |
358 | 358 | |
359 | - update_option( 'wpinv_default_payment_form', $form ); |
|
359 | + update_option('wpinv_default_payment_form', $form); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | // WPML support. |
363 | - $form = apply_filters( 'wpml_object_id', $form, 'wpi_payment_form', true ); |
|
363 | + $form = apply_filters('wpml_object_id', $form, 'wpi_payment_form', true); |
|
364 | 364 | return (int) $form; |
365 | 365 | } |
366 | 366 | |
@@ -369,19 +369,19 @@ discard block |
||
369 | 369 | * |
370 | 370 | * @param int $payment_form |
371 | 371 | */ |
372 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
372 | +function getpaid_get_payment_form_elements($payment_form) { |
|
373 | 373 | |
374 | - if ( empty( $payment_form ) ) { |
|
375 | - return wpinv_get_data( 'sample-payment-form' ); |
|
374 | + if (empty($payment_form)) { |
|
375 | + return wpinv_get_data('sample-payment-form'); |
|
376 | 376 | } |
377 | 377 | |
378 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
378 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
379 | 379 | |
380 | - if ( is_array( $form_elements ) ) { |
|
380 | + if (is_array($form_elements)) { |
|
381 | 381 | return $form_elements; |
382 | 382 | } |
383 | 383 | |
384 | - return wpinv_get_data( 'sample-payment-form' ); |
|
384 | + return wpinv_get_data('sample-payment-form'); |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | |
@@ -390,65 +390,65 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @param int $payment_form |
392 | 392 | */ |
393 | -function gepaid_get_form_items( $id ) { |
|
394 | - $form = new GetPaid_Payment_Form( $id ); |
|
393 | +function gepaid_get_form_items($id) { |
|
394 | + $form = new GetPaid_Payment_Form($id); |
|
395 | 395 | |
396 | 396 | // Is this a default form? |
397 | - if ( $form->is_default() ) { |
|
397 | + if ($form->is_default()) { |
|
398 | 398 | return array(); |
399 | 399 | } |
400 | 400 | |
401 | - return $form->get_items( 'view', 'arrays' ); |
|
401 | + return $form->get_items('view', 'arrays'); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
405 | 405 | * Trims each line in a paragraph. |
406 | 406 | * |
407 | 407 | */ |
408 | -function gepaid_trim_lines( $content ) { |
|
409 | - return implode( "\n", array_map( 'trim', explode( "\n", $content ) ) ); |
|
408 | +function gepaid_trim_lines($content) { |
|
409 | + return implode("\n", array_map('trim', explode("\n", $content))); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | |
413 | -function wpinv_add_elementor_widget_categories( $elements_manager ) { |
|
413 | +function wpinv_add_elementor_widget_categories($elements_manager) { |
|
414 | 414 | $elements_manager->add_category( |
415 | 415 | 'getpaid', |
416 | 416 | array( |
417 | - 'title' => esc_html__( 'GetPaid', 'invoicing' ), |
|
417 | + 'title' => esc_html__('GetPaid', 'invoicing'), |
|
418 | 418 | 'icon' => 'fa fa-plug', |
419 | 419 | ) |
420 | 420 | ); |
421 | 421 | } |
422 | -add_filter( 'elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories' ); |
|
422 | +add_filter('elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories'); |
|
423 | 423 | |
424 | -function wpinv_alter_elementor_widget_config( $config ) { |
|
424 | +function wpinv_alter_elementor_widget_config($config) { |
|
425 | 425 | |
426 | - if ( ! empty( $config['initial_document']['widgets'] ) ) { |
|
427 | - foreach ( $config['initial_document']['widgets'] as $key => $widget ) { |
|
428 | - if ( substr( $key, 0, 16 ) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid' ) { |
|
429 | - $config['initial_document']['widgets'][ $key ]['categories'][] = 'getpaid'; |
|
430 | - $config['initial_document']['widgets'][ $key ]['hide_on_search'] = false; |
|
431 | - $config['initial_document']['widgets'][ $key ]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
426 | + if (!empty($config['initial_document']['widgets'])) { |
|
427 | + foreach ($config['initial_document']['widgets'] as $key => $widget) { |
|
428 | + if (substr($key, 0, 16) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid') { |
|
429 | + $config['initial_document']['widgets'][$key]['categories'][] = 'getpaid'; |
|
430 | + $config['initial_document']['widgets'][$key]['hide_on_search'] = false; |
|
431 | + $config['initial_document']['widgets'][$key]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | } |
435 | 435 | |
436 | 436 | return $config; |
437 | 437 | } |
438 | -add_filter( 'elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config' ); |
|
438 | +add_filter('elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config'); |
|
439 | 439 | |
440 | 440 | function wpinv_get_report_graphs() { |
441 | 441 | |
442 | 442 | return apply_filters( |
443 | 443 | 'getpaid_report_graphs', |
444 | 444 | array( |
445 | - 'sales' => __( 'Earnings', 'invoicing' ), |
|
446 | - 'refunds' => __( 'Refunds', 'invoicing' ), |
|
447 | - 'tax' => __( 'Taxes', 'invoicing' ), |
|
448 | - 'fees' => __( 'Fees', 'invoicing' ), |
|
449 | - 'discount' => __( 'Discounts', 'invoicing' ), |
|
450 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
451 | - 'items' => __( 'Purchased Items', 'invoicing' ), |
|
445 | + 'sales' => __('Earnings', 'invoicing'), |
|
446 | + 'refunds' => __('Refunds', 'invoicing'), |
|
447 | + 'tax' => __('Taxes', 'invoicing'), |
|
448 | + 'fees' => __('Fees', 'invoicing'), |
|
449 | + 'discount' => __('Discounts', 'invoicing'), |
|
450 | + 'invoices' => __('Invoices', 'invoicing'), |
|
451 | + 'items' => __('Purchased Items', 'invoicing'), |
|
452 | 452 | ) |
453 | 453 | ); |
454 | 454 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Personal data exporters. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy_Exporters Class. |
@@ -17,39 +17,39 @@ discard block |
||
17 | 17 | * @param int $page Page. |
18 | 18 | * @return array An array of invoice data in name value pairs |
19 | 19 | */ |
20 | - public static function customer_invoice_data_exporter( $email_address, $page ) { |
|
20 | + public static function customer_invoice_data_exporter($email_address, $page) { |
|
21 | 21 | $done = false; |
22 | 22 | $page = (int) $page; |
23 | 23 | $data_to_export = array(); |
24 | 24 | |
25 | - $user = get_user_by( 'email', $email_address ); |
|
26 | - if ( ! $user instanceof WP_User ) { |
|
25 | + $user = get_user_by('email', $email_address); |
|
26 | + if (!$user instanceof WP_User) { |
|
27 | 27 | return array( |
28 | 28 | 'data' => $data_to_export, |
29 | 29 | 'done' => true, |
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
33 | - $args = array( |
|
34 | - 'limit' => get_option( 'posts_per_page' ), |
|
33 | + $args = array( |
|
34 | + 'limit' => get_option('posts_per_page'), |
|
35 | 35 | 'page' => $page, |
36 | 36 | 'user' => $user->ID, |
37 | 37 | 'paginate' => false, |
38 | 38 | ); |
39 | 39 | |
40 | - $invoices = wpinv_get_invoices( $args ); |
|
40 | + $invoices = wpinv_get_invoices($args); |
|
41 | 41 | |
42 | - if ( 0 < count( $invoices ) ) { |
|
43 | - foreach ( $invoices as $invoice ) { |
|
42 | + if (0 < count($invoices)) { |
|
43 | + foreach ($invoices as $invoice) { |
|
44 | 44 | $data_to_export[] = array( |
45 | 45 | 'group_id' => 'customer_invoices', |
46 | - 'group_label' => __( 'GetPaid: Invoices', 'invoicing' ), |
|
47 | - 'group_description' => __( 'Customer invoices.', 'invoicing' ), |
|
46 | + 'group_label' => __('GetPaid: Invoices', 'invoicing'), |
|
47 | + 'group_description' => __('Customer invoices.', 'invoicing'), |
|
48 | 48 | 'item_id' => "wpinv-{$invoice->get_id()}", |
49 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
49 | + 'data' => self::get_customer_invoice_data($invoice), |
|
50 | 50 | ); |
51 | 51 | } |
52 | - $done = get_option( 'posts_per_page' ) > count( $invoices ); |
|
52 | + $done = get_option('posts_per_page') > count($invoices); |
|
53 | 53 | } else { |
54 | 54 | $done = true; |
55 | 55 | } |
@@ -67,116 +67,116 @@ discard block |
||
67 | 67 | * @param WPInv_Invoice $invoice invoice object. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public static function get_customer_invoice_data( $invoice ) { |
|
70 | + public static function get_customer_invoice_data($invoice) { |
|
71 | 71 | |
72 | 72 | // Prepare basic properties. |
73 | 73 | $props_to_export = array( |
74 | 74 | 'number' => array( |
75 | - 'name' => __( 'Invoice Number', 'invoicing' ), |
|
75 | + 'name' => __('Invoice Number', 'invoicing'), |
|
76 | 76 | 'value' => $invoice->get_number(), |
77 | 77 | ), |
78 | 78 | 'created_date' => array( |
79 | - 'name' => __( 'Created Date', 'invoicing' ), |
|
79 | + 'name' => __('Created Date', 'invoicing'), |
|
80 | 80 | 'value' => $invoice->get_date_created(), |
81 | 81 | ), |
82 | 82 | 'due_date' => array( |
83 | - 'name' => __( 'Due Date', 'invoicing' ), |
|
83 | + 'name' => __('Due Date', 'invoicing'), |
|
84 | 84 | 'value' => $invoice->get_due_date(), |
85 | 85 | ), |
86 | 86 | 'items' => array( |
87 | - 'name' => __( 'Invoice Items', 'invoicing' ), |
|
88 | - 'value' => self::process_invoice_items( $invoice ), |
|
87 | + 'name' => __('Invoice Items', 'invoicing'), |
|
88 | + 'value' => self::process_invoice_items($invoice), |
|
89 | 89 | ), |
90 | 90 | 'discount' => array( |
91 | - 'name' => __( 'Invoice Discount', 'invoicing' ), |
|
92 | - 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
91 | + 'name' => __('Invoice Discount', 'invoicing'), |
|
92 | + 'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
93 | 93 | ), |
94 | 94 | 'total' => array( |
95 | - 'name' => __( 'Invoice Total', 'invoicing' ), |
|
96 | - 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
95 | + 'name' => __('Invoice Total', 'invoicing'), |
|
96 | + 'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
97 | 97 | ), |
98 | 98 | 'status' => array( |
99 | - 'name' => __( 'Invoice Status', 'invoicing' ), |
|
99 | + 'name' => __('Invoice Status', 'invoicing'), |
|
100 | 100 | 'value' => $invoice->get_status_nicename(), |
101 | 101 | ), |
102 | 102 | 'first_name' => array( |
103 | - 'name' => __( 'First Name', 'invoicing' ), |
|
103 | + 'name' => __('First Name', 'invoicing'), |
|
104 | 104 | 'value' => $invoice->get_first_name(), |
105 | 105 | ), |
106 | 106 | 'last_name' => array( |
107 | - 'name' => __( 'Last Name', 'invoicing' ), |
|
107 | + 'name' => __('Last Name', 'invoicing'), |
|
108 | 108 | 'value' => $invoice->get_last_name(), |
109 | 109 | ), |
110 | 110 | 'email' => array( |
111 | - 'name' => __( 'Email Address', 'invoicing' ), |
|
111 | + 'name' => __('Email Address', 'invoicing'), |
|
112 | 112 | 'value' => $invoice->get_email(), |
113 | 113 | ), |
114 | 114 | 'company' => array( |
115 | - 'name' => __( 'Company', 'invoicing' ), |
|
115 | + 'name' => __('Company', 'invoicing'), |
|
116 | 116 | 'value' => $invoice->get_company(), |
117 | 117 | ), |
118 | 118 | 'phone' => array( |
119 | - 'name' => __( 'Phone Number', 'invoicing' ), |
|
119 | + 'name' => __('Phone Number', 'invoicing'), |
|
120 | 120 | 'value' => $invoice->get_phone(), |
121 | 121 | ), |
122 | 122 | 'address' => array( |
123 | - 'name' => __( 'Address', 'invoicing' ), |
|
123 | + 'name' => __('Address', 'invoicing'), |
|
124 | 124 | 'value' => $invoice->get_address(), |
125 | 125 | ), |
126 | 126 | 'city' => array( |
127 | - 'name' => __( 'City', 'invoicing' ), |
|
127 | + 'name' => __('City', 'invoicing'), |
|
128 | 128 | 'value' => $invoice->get_city(), |
129 | 129 | ), |
130 | 130 | 'state' => array( |
131 | - 'name' => __( 'State', 'invoicing' ), |
|
131 | + 'name' => __('State', 'invoicing'), |
|
132 | 132 | 'value' => $invoice->get_state(), |
133 | 133 | ), |
134 | 134 | 'zip' => array( |
135 | - 'name' => __( 'Zip', 'invoicing' ), |
|
135 | + 'name' => __('Zip', 'invoicing'), |
|
136 | 136 | 'value' => $invoice->get_zip(), |
137 | 137 | ), |
138 | 138 | 'vat_number' => array( |
139 | - 'name' => __( 'VAT Number', 'invoicing' ), |
|
139 | + 'name' => __('VAT Number', 'invoicing'), |
|
140 | 140 | 'value' => $invoice->get_vat_number(), |
141 | 141 | ), |
142 | 142 | 'description' => array( |
143 | - 'name' => __( 'Description', 'invoicing' ), |
|
143 | + 'name' => __('Description', 'invoicing'), |
|
144 | 144 | 'value' => $invoice->get_description(), |
145 | 145 | ), |
146 | 146 | ); |
147 | 147 | |
148 | 148 | // In case the invoice is paid, add the payment date and gateway. |
149 | - if ( $invoice->is_paid() ) { |
|
149 | + if ($invoice->is_paid()) { |
|
150 | 150 | |
151 | 151 | $props_to_export['completed_date'] = array( |
152 | - 'name' => __( 'Completed Date', 'invoicing' ), |
|
152 | + 'name' => __('Completed Date', 'invoicing'), |
|
153 | 153 | 'value' => $invoice->get_completed_date(), |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $props_to_export['gateway'] = array( |
157 | - 'name' => __( 'Paid Via', 'invoicing' ), |
|
157 | + 'name' => __('Paid Via', 'invoicing'), |
|
158 | 158 | 'value' => $invoice->get_gateway(), |
159 | 159 | ); |
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Maybe add subscription details. |
164 | - $props_to_export = self::process_subscription( $invoice, $props_to_export ); |
|
164 | + $props_to_export = self::process_subscription($invoice, $props_to_export); |
|
165 | 165 | |
166 | 166 | // Add the ip address. |
167 | 167 | $props_to_export['ip'] = array( |
168 | - 'name' => __( 'IP Address', 'invoicing' ), |
|
168 | + 'name' => __('IP Address', 'invoicing'), |
|
169 | 169 | 'value' => $invoice->get_ip(), |
170 | 170 | ); |
171 | 171 | |
172 | 172 | // Add the invoice url. |
173 | 173 | $props_to_export['view_url'] = array( |
174 | - 'name' => __( 'Invoice URL', 'invoicing' ), |
|
174 | + 'name' => __('Invoice URL', 'invoicing'), |
|
175 | 175 | 'value' => $invoice->get_view_url(), |
176 | 176 | ); |
177 | 177 | |
178 | 178 | // Return the values. |
179 | - return apply_filters( 'getpaid_privacy_export_invoice_personal_data', array_values( $props_to_export ), $invoice ); |
|
179 | + return apply_filters('getpaid_privacy_export_invoice_personal_data', array_values($props_to_export), $invoice); |
|
180 | 180 | |
181 | 181 | } |
182 | 182 | |
@@ -188,40 +188,40 @@ discard block |
||
188 | 188 | * @param array $props invoice props. |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - public static function process_subscription( $invoice, $props ) { |
|
191 | + public static function process_subscription($invoice, $props) { |
|
192 | 192 | |
193 | - $subscription = wpinv_get_subscription( $invoice ); |
|
194 | - if ( ! empty( $subscription ) ) { |
|
193 | + $subscription = wpinv_get_subscription($invoice); |
|
194 | + if (!empty($subscription)) { |
|
195 | 195 | |
196 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency() ); |
|
197 | - $period = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency; |
|
198 | - $initial_amt = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
199 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() ); |
|
200 | - $renewal_date = getpaid_format_date_value( $subscription->get_expiration() ); |
|
196 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency()); |
|
197 | + $period = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency; |
|
198 | + $initial_amt = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
199 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times()); |
|
200 | + $renewal_date = getpaid_format_date_value($subscription->get_expiration()); |
|
201 | 201 | |
202 | 202 | // Billing cycle. |
203 | 203 | $props['period'] = array( |
204 | - 'name' => __( 'Billing Cycle', 'invoicing' ), |
|
204 | + 'name' => __('Billing Cycle', 'invoicing'), |
|
205 | 205 | 'value' => $period, |
206 | 206 | ); |
207 | 207 | |
208 | 208 | // Initial amount. |
209 | 209 | $props['initial_amount'] = array( |
210 | - 'name' => __( 'Initial Amount', 'invoicing' ), |
|
210 | + 'name' => __('Initial Amount', 'invoicing'), |
|
211 | 211 | 'value' => $initial_amt, |
212 | 212 | ); |
213 | 213 | |
214 | 214 | // Bill times. |
215 | 215 | $props['bill_times'] = array( |
216 | - 'name' => __( 'Times Billed', 'invoicing' ), |
|
216 | + 'name' => __('Times Billed', 'invoicing'), |
|
217 | 217 | 'value' => $bill_times, |
218 | 218 | ); |
219 | 219 | |
220 | 220 | // Add expiry date. |
221 | - if ( $subscription->is_active() ) { |
|
221 | + if ($subscription->is_active()) { |
|
222 | 222 | |
223 | 223 | $props['renewal_date'] = array( |
224 | - 'name' => __( 'Expires', 'invoicing' ), |
|
224 | + 'name' => __('Expires', 'invoicing'), |
|
225 | 225 | 'value' => $renewal_date, |
226 | 226 | ); |
227 | 227 | |
@@ -239,19 +239,19 @@ discard block |
||
239 | 239 | * @param WPInv_Invoice $invoice invoice object. |
240 | 240 | * @return array |
241 | 241 | */ |
242 | - public static function process_invoice_items( $invoice ) { |
|
242 | + public static function process_invoice_items($invoice) { |
|
243 | 243 | |
244 | 244 | $item_names = array(); |
245 | - foreach ( $invoice->get_items() as $cart_item ) { |
|
245 | + foreach ($invoice->get_items() as $cart_item) { |
|
246 | 246 | $item_names[] = sprintf( |
247 | 247 | '%s x %s - %s', |
248 | 248 | $cart_item->get_name(), |
249 | 249 | $cart_item->get_quantity(), |
250 | - wpinv_price( $invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency() ) |
|
250 | + wpinv_price($invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency()) |
|
251 | 251 | ); |
252 | 252 | } |
253 | 253 | |
254 | - return implode( ', ', $item_names ); |
|
254 | + return implode(', ', $item_names); |
|
255 | 255 | |
256 | 256 | } |
257 | 257 |
@@ -160,50 +160,50 @@ |
||
160 | 160 | */ |
161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
162 | 162 | |
163 | - $initial_discount = 0; |
|
164 | - $recurring_discount = 0; |
|
163 | + $initial_discount = 0; |
|
164 | + $recurring_discount = 0; |
|
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ( $invoice->get_items() as $item ) { |
|
167 | 167 | |
168 | - // Abort if it is not valid for this item. |
|
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | - continue; |
|
171 | - } |
|
168 | + // Abort if it is not valid for this item. |
|
169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
170 | + continue; |
|
171 | + } |
|
172 | 172 | |
173 | - // Calculate the initial amount... |
|
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | - $recurring_item_discount = 0; |
|
173 | + // Calculate the initial amount... |
|
174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
175 | + $recurring_item_discount = 0; |
|
176 | 176 | |
177 | - // ... and maybe the recurring amount. |
|
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | - } |
|
177 | + // ... and maybe the recurring amount. |
|
178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
180 | + } |
|
181 | 181 | |
182 | - // Discount should not exceed discounted amount. |
|
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
182 | + // Discount should not exceed discounted amount. |
|
183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | - } |
|
185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
187 | + } |
|
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | - } |
|
189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - $initial_discount += $item_discount; |
|
195 | - $recurring_discount += $recurring_item_discount; |
|
196 | - $item->item_discount = $item_discount; |
|
197 | - $item->recurring_item_discount = $recurring_item_discount; |
|
194 | + $initial_discount += $item_discount; |
|
195 | + $recurring_discount += $recurring_item_discount; |
|
196 | + $item->item_discount = $item_discount; |
|
197 | + $item->recurring_item_discount = $recurring_item_discount; |
|
198 | 198 | |
199 | - } |
|
199 | + } |
|
200 | 200 | |
201 | - return array( |
|
202 | - 'name' => 'discount_code', |
|
203 | - 'discount_code' => $discount->get_code(), |
|
204 | - 'initial_discount' => $initial_discount, |
|
205 | - 'recurring_discount' => $recurring_discount, |
|
206 | - ); |
|
201 | + return array( |
|
202 | + 'name' => 'discount_code', |
|
203 | + 'discount_code' => $discount->get_code(), |
|
204 | + 'initial_discount' => $initial_discount, |
|
205 | + 'recurring_discount' => $recurring_discount, |
|
206 | + ); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | return apply_filters( |
18 | 18 | 'wpinv_discount_types', |
19 | 19 | array( |
20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
20 | + 'percent' => __('Percentage', 'invoicing'), |
|
21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
31 | +function wpinv_get_discount_type_name($type = '') { |
|
32 | 32 | $types = wpinv_get_discount_types(); |
33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Deletes a discount via the admin page. |
38 | 38 | * |
39 | 39 | */ |
40 | -function wpinv_delete_discount( $data ) { |
|
40 | +function wpinv_delete_discount($data) { |
|
41 | 41 | |
42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
43 | - $discount->delete( true ); |
|
42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
43 | + $discount->delete(true); |
|
44 | 44 | |
45 | 45 | } |
46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Deactivates a discount via the admin page. |
50 | 50 | */ |
51 | -function wpinv_activate_discount( $data ) { |
|
51 | +function wpinv_activate_discount($data) { |
|
52 | 52 | |
53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
54 | - $discount->set_status( 'publish' ); |
|
53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
54 | + $discount->set_status('publish'); |
|
55 | 55 | $discount->save(); |
56 | 56 | |
57 | 57 | } |
58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Activates a discount via the admin page. |
62 | 62 | */ |
63 | -function wpinv_deactivate_discount( $data ) { |
|
63 | +function wpinv_deactivate_discount($data) { |
|
64 | 64 | |
65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
66 | - $discount->set_status( 'pending' ); |
|
65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
66 | + $discount->set_status('pending'); |
|
67 | 67 | $discount->save(); |
68 | 68 | |
69 | 69 | } |
70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @since 1.0.15 |
77 | 77 | * @return WPInv_Discount |
78 | 78 | */ |
79 | -function wpinv_get_discount( $discount ) { |
|
80 | - return new WPInv_Discount( $discount ); |
|
79 | +function wpinv_get_discount($discount) { |
|
80 | + return new WPInv_Discount($discount); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @since 1.0.15 |
88 | 88 | * @return WPInv_Discount |
89 | 89 | */ |
90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
91 | - return new WPInv_Discount( $discount ); |
|
90 | +function wpinv_get_discount_obj($discount = 0) { |
|
91 | + return new WPInv_Discount($discount); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param string|int $value The field value |
99 | 99 | * @return bool|WPInv_Discount |
100 | 100 | */ |
101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
102 | - $discount = new WPInv_Discount( $value ); |
|
101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
102 | + $discount = new WPInv_Discount($value); |
|
103 | 103 | |
104 | - if ( $discount->get_id() != 0 ) { |
|
104 | + if ($discount->get_id() != 0) { |
|
105 | 105 | return $discount; |
106 | 106 | } |
107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | function wpinv_get_discount_statuses() { |
117 | 117 | |
118 | 118 | return array( |
119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
119 | + 'expired' => __('Expired', 'invoicing'), |
|
120 | + 'publish' => __('Active', 'invoicing'), |
|
121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * Retrieves an invoice status label. |
128 | 128 | */ |
129 | -function wpinv_discount_status( $status ) { |
|
129 | +function wpinv_discount_status($status) { |
|
130 | 130 | $statuses = wpinv_get_discount_statuses(); |
131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
142 | 142 | |
143 | - if ( ! empty( $discount ) ) { |
|
144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
143 | + if (!empty($discount)) { |
|
144 | + $discount = wpinv_get_discount_obj($discount); |
|
145 | 145 | } else { |
146 | - $discount = wpinv_get_discount_obj( $code ); |
|
146 | + $discount = wpinv_get_discount_obj($code); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param WPInv_Discount $discount |
159 | 159 | * @return array |
160 | 160 | */ |
161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
162 | 162 | |
163 | 163 | $initial_discount = 0; |
164 | 164 | $recurring_discount = 0; |
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ($invoice->get_items() as $item) { |
|
167 | 167 | |
168 | 168 | // Abort if it is not valid for this item. |
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Calculate the initial amount... |
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
175 | 175 | $recurring_item_discount = 0; |
176 | 176 | |
177 | 177 | // ... and maybe the recurring amount. |
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Discount should not exceed discounted amount. |
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
183 | + if (!$discount->is_type('percent')) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
187 | 187 | } |
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
191 | 191 | } |
192 | 192 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | array( |
219 | 219 | 'post_type' => 'wpi_discount', |
220 | 220 | 'numberposts' => 1, |
221 | - 'fields' => array( 'ids' ), |
|
221 | + 'fields' => array('ids'), |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | |
225 | - return ! empty( $discounts ); |
|
225 | + return !empty($discounts); |
|
226 | 226 | |
227 | 227 | } |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | $css = getpaid_get_email_css(); |
110 | 110 | |
111 | 111 | // include css inliner |
112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
113 | - include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
112 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
113 | + include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | // Inline the css. |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $message = wpinv_email_style_body( $message ); |
190 | 190 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
191 | 191 | |
192 | - return $mailer->send( |
|
192 | + return $mailer->send( |
|
193 | 193 | $to, |
194 | 194 | $subject, |
195 | 195 | $message, |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * Please use GetPaid_Notification_Email_Sender |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /* |
12 | 12 | |-------------------------------------------------------------------------- |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Generates the email header. |
19 | 19 | */ |
20 | -function wpinv_email_header( $email_heading ) { |
|
21 | - wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) ); |
|
20 | +function wpinv_email_header($email_heading) { |
|
21 | + wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading')); |
|
22 | 22 | } |
23 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
23 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Generates the email footer. |
28 | 28 | */ |
29 | 29 | function wpinv_email_footer() { |
30 | - wpinv_get_template( 'emails/wpinv-email-footer.php' ); |
|
30 | + wpinv_get_template('emails/wpinv-email-footer.php'); |
|
31 | 31 | } |
32 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
32 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
33 | 33 | |
34 | 34 | |
35 | 35 | /** |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | * @param string $email_type |
40 | 40 | * @param bool $sent_to_admin |
41 | 41 | */ |
42 | -function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) { |
|
42 | +function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) { |
|
43 | 43 | |
44 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
45 | - wpinv_get_template( 'emails/invoice-details.php', $args ); |
|
44 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
45 | + wpinv_get_template('emails/invoice-details.php', $args); |
|
46 | 46 | |
47 | 47 | } |
48 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
48 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Display line items in emails. |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | * @param string $email_type |
55 | 55 | * @param bool $sent_to_admin |
56 | 56 | */ |
57 | -function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) { |
|
57 | +function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) { |
|
58 | 58 | |
59 | 59 | // Prepare line items. |
60 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
61 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
60 | + $columns = getpaid_invoice_item_columns($invoice); |
|
61 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
62 | 62 | |
63 | 63 | // Load the template. |
64 | - wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) ); |
|
64 | + wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin')); |
|
65 | 65 | |
66 | 66 | } |
67 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
67 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | /** |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | * @param string $email_type |
75 | 75 | * @param bool $sent_to_admin |
76 | 76 | */ |
77 | -function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) { |
|
77 | +function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) { |
|
78 | 78 | |
79 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
80 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args ); |
|
79 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
80 | + wpinv_get_template('emails/wpinv-email-billing-details.php', $args); |
|
81 | 81 | |
82 | 82 | } |
83 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
83 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * Returns email css. |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | */ |
89 | 89 | function getpaid_get_email_css() { |
90 | 90 | |
91 | - $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' ); |
|
92 | - return apply_filters( 'wpinv_email_styles', $css ); |
|
91 | + $css = wpinv_get_template_html('emails/wpinv-email-styles.php'); |
|
92 | + return apply_filters('wpinv_email_styles', $css); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
@@ -100,26 +100,26 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | * |
102 | 102 | */ |
103 | -function wpinv_email_style_body( $content ) { |
|
103 | +function wpinv_email_style_body($content) { |
|
104 | 104 | |
105 | - if ( ! class_exists( 'DOMDocument' ) ) { |
|
105 | + if (!class_exists('DOMDocument')) { |
|
106 | 106 | return $content; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $css = getpaid_get_email_css(); |
110 | 110 | |
111 | 111 | // include css inliner |
112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
112 | + if (!class_exists('Emogrifier')) { |
|
113 | 113 | include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Inline the css. |
117 | 117 | try { |
118 | - $emogrifier = new Emogrifier( $content, $css ); |
|
118 | + $emogrifier = new Emogrifier($content, $css); |
|
119 | 119 | $_content = $emogrifier->emogrify(); |
120 | 120 | $content = $_content; |
121 | - } catch ( Exception $e ) { |
|
122 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
121 | + } catch (Exception $e) { |
|
122 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | return $content; |
@@ -128,37 +128,37 @@ discard block |
||
128 | 128 | |
129 | 129 | // Backwards compatibility. |
130 | 130 | function wpinv_init_transactional_emails() { |
131 | - foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) { |
|
132 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
131 | + foreach (apply_filters('wpinv_email_actions', array()) as $action) { |
|
132 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
133 | 133 | } |
134 | 134 | } |
135 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
135 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
136 | 136 | |
137 | 137 | function wpinv_send_transactional_email() { |
138 | 138 | $args = func_get_args(); |
139 | 139 | $function = current_filter() . '_notification'; |
140 | - do_action_ref_array( $function, $args ); |
|
140 | + do_action_ref_array($function, $args); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | function wpinv_mail_get_from_address() { |
144 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from', get_option( 'admin_email' ) ) ); |
|
145 | - return sanitize_email( $from_address ); |
|
144 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from', get_option('admin_email'))); |
|
145 | + return sanitize_email($from_address); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | function wpinv_mail_get_from_name() { |
149 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name', get_bloginfo( 'name', 'display' ) ) ); |
|
150 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
149 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name', get_bloginfo('name', 'display'))); |
|
150 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
151 | 151 | } |
152 | 152 | |
153 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
154 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
155 | - return ( $active ? true : false ); |
|
153 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
154 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
155 | + return ($active ? true : false); |
|
156 | 156 | } |
157 | 157 | |
158 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
159 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
158 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
159 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
160 | 160 | |
161 | - switch ( $email_type ) { |
|
161 | + switch ($email_type) { |
|
162 | 162 | case 'html': |
163 | 163 | $content_type = 'text/html'; |
164 | 164 | break; |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @param array $attachments Any files to attach to the email. |
184 | 184 | * @param string|array $cc An email or array of extra emails to send a copy of the email to. |
185 | 185 | */ |
186 | -function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) { |
|
186 | +function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) { |
|
187 | 187 | |
188 | 188 | $mailer = new GetPaid_Notification_Email_Sender(); |
189 | - $message = wpinv_email_style_body( $message ); |
|
190 | - $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
|
189 | + $message = wpinv_email_style_body($message); |
|
190 | + $to = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc)); |
|
191 | 191 | |
192 | 192 | return $mailer->send( |
193 | 193 | $to, |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @return array |
205 | 205 | */ |
206 | 206 | function wpinv_get_emails() { |
207 | - return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) ); |
|
207 | + return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings')); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -213,172 +213,172 @@ discard block |
||
213 | 213 | * @param array $settings |
214 | 214 | * @return array |
215 | 215 | */ |
216 | -function wpinv_settings_emails( $settings = array() ) { |
|
217 | - $settings = array_merge( $settings, wpinv_get_emails() ); |
|
218 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
216 | +function wpinv_settings_emails($settings = array()) { |
|
217 | + $settings = array_merge($settings, wpinv_get_emails()); |
|
218 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
219 | 219 | } |
220 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
220 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Filter email section names. |
224 | 224 | * |
225 | 225 | */ |
226 | -function wpinv_settings_sections_emails( $settings ) { |
|
227 | - foreach ( wpinv_get_emails() as $key => $email ) { |
|
228 | - $settings[ $key ] = ! empty( $email[ 'email_' . $key . '_header' ]['name'] ) ? strip_tags( $email[ 'email_' . $key . '_header' ]['name'] ) : strip_tags( $key ); |
|
226 | +function wpinv_settings_sections_emails($settings) { |
|
227 | + foreach (wpinv_get_emails() as $key => $email) { |
|
228 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | return $settings; |
232 | 232 | } |
233 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
233 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
234 | 234 | |
235 | -function wpinv_email_is_enabled( $email_type ) { |
|
235 | +function wpinv_email_is_enabled($email_type) { |
|
236 | 236 | $emails = wpinv_get_emails(); |
237 | - $enabled = isset( $emails[ $email_type ] ) && wpinv_get_option( 'email_' . $email_type . '_active', 0 ) ? true : false; |
|
237 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
238 | 238 | |
239 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
239 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
240 | 240 | } |
241 | 241 | |
242 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
243 | - switch ( $email_type ) { |
|
242 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
243 | + switch ($email_type) { |
|
244 | 244 | case 'new_invoice': |
245 | 245 | case 'cancelled_invoice': |
246 | 246 | case 'failed_invoice': |
247 | 247 | $recipient = wpinv_get_admin_email(); |
248 | 248 | break; |
249 | 249 | default: |
250 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
251 | - $recipient = ! empty( $invoice ) ? $invoice->get_email() : ''; |
|
250 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
251 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
252 | 252 | break; |
253 | 253 | } |
254 | 254 | |
255 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
255 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | 259 | * Returns invoice CC recipients |
260 | 260 | */ |
261 | -function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
262 | - switch ( $email_type ) { |
|
261 | +function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
262 | + switch ($email_type) { |
|
263 | 263 | case 'new_invoice': |
264 | 264 | case 'cancelled_invoice': |
265 | 265 | case 'failed_invoice': |
266 | 266 | return array(); |
267 | 267 | break; |
268 | 268 | default: |
269 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
270 | - $recipient = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true ); |
|
271 | - if ( empty( $recipient ) ) { |
|
269 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
270 | + $recipient = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true); |
|
271 | + if (empty($recipient)) { |
|
272 | 272 | return array(); |
273 | 273 | } |
274 | - return array_filter( array_map( 'trim', explode( ',', $recipient ) ) ); |
|
274 | + return array_filter(array_map('trim', explode(',', $recipient))); |
|
275 | 275 | break; |
276 | 276 | } |
277 | 277 | |
278 | 278 | } |
279 | 279 | |
280 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
281 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
282 | - $subject = __( $subject, 'invoicing' ); |
|
280 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
281 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
282 | + $subject = __($subject, 'invoicing'); |
|
283 | 283 | |
284 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
284 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
285 | 285 | |
286 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
286 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
287 | 287 | } |
288 | 288 | |
289 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
290 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
291 | - $email_heading = __( $email_heading, 'invoicing' ); |
|
289 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
290 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
291 | + $email_heading = __($email_heading, 'invoicing'); |
|
292 | 292 | |
293 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
293 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
294 | 294 | |
295 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
295 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
296 | 296 | } |
297 | 297 | |
298 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
299 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
300 | - $content = __( $content, 'invoicing' ); |
|
298 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
299 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
300 | + $content = __($content, 'invoicing'); |
|
301 | 301 | |
302 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
302 | + $content = wpinv_email_format_text($content, $invoice); |
|
303 | 303 | |
304 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
304 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
305 | 305 | } |
306 | 306 | |
307 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
307 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
308 | 308 | $from_name = wpinv_mail_get_from_address(); |
309 | 309 | $from_email = wpinv_mail_get_from_address(); |
310 | 310 | |
311 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
311 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
312 | 312 | |
313 | - $headers = 'From: ' . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
313 | + $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
314 | 314 | $headers .= 'Reply-To: ' . $from_email . "\r\n"; |
315 | 315 | $headers .= 'Content-Type: ' . wpinv_mail_get_content_type() . "\r\n"; |
316 | 316 | |
317 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
317 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
320 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
321 | 321 | $attachments = array(); |
322 | 322 | |
323 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
323 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | 327 | * Searches for and replaces certain placeholders in an email. |
328 | 328 | */ |
329 | -function wpinv_email_format_text( $content, $invoice ) { |
|
329 | +function wpinv_email_format_text($content, $invoice) { |
|
330 | 330 | |
331 | 331 | $replace_array = array( |
332 | 332 | '{site_title}' => wpinv_get_blogname(), |
333 | - '{date}' => getpaid_format_date( current_time( 'mysql' ) ), |
|
333 | + '{date}' => getpaid_format_date(current_time('mysql')), |
|
334 | 334 | ); |
335 | 335 | |
336 | - $invoice = new WPInv_Invoice( $invoice ); |
|
336 | + $invoice = new WPInv_Invoice($invoice); |
|
337 | 337 | |
338 | - if ( $invoice->get_id() ) { |
|
338 | + if ($invoice->get_id()) { |
|
339 | 339 | |
340 | 340 | $replace_array = array_merge( |
341 | 341 | $replace_array, |
342 | 342 | array( |
343 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
344 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
345 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
346 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
347 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
348 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
349 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ), |
|
350 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
351 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
352 | - '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
353 | - '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
354 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_invoice_quote_type() ), |
|
355 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ), |
|
356 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
343 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
344 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
345 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
346 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
347 | + '{email}' => sanitize_email($invoice->get_email()), |
|
348 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
349 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())), |
|
350 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
351 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
352 | + '{invoice_date}' => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))), |
|
353 | + '{invoice_due_date}' => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))), |
|
354 | + '{invoice_quote}' => sanitize_text_field($invoice->get_invoice_quote_type()), |
|
355 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())), |
|
356 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
357 | 357 | ) |
358 | 358 | ); |
359 | 359 | |
360 | 360 | } |
361 | 361 | |
362 | 362 | // Let third party plugins filter the arra. |
363 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
363 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
364 | 364 | |
365 | - foreach ( $replace_array as $key => $value ) { |
|
366 | - $content = str_replace( $key, $value, $content ); |
|
365 | + foreach ($replace_array as $key => $value) { |
|
366 | + $content = str_replace($key, $value, $content); |
|
367 | 367 | } |
368 | 368 | |
369 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
369 | + return apply_filters('wpinv_email_content_replace', $content); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | |
373 | -function wpinv_email_wrap_message( $message ) { |
|
373 | +function wpinv_email_wrap_message($message) { |
|
374 | 374 | // Buffer |
375 | 375 | ob_start(); |
376 | 376 | |
377 | - do_action( 'wpinv_email_header' ); |
|
377 | + do_action('wpinv_email_header'); |
|
378 | 378 | |
379 | - echo wp_kses_post( wpautop( wptexturize( $message ) ) ); |
|
379 | + echo wp_kses_post(wpautop(wptexturize($message))); |
|
380 | 380 | |
381 | - do_action( 'wpinv_email_footer' ); |
|
381 | + do_action('wpinv_email_footer'); |
|
382 | 382 | |
383 | 383 | // Get contents |
384 | 384 | $message = ob_get_clean(); |
@@ -386,21 +386,21 @@ discard block |
||
386 | 386 | return $message; |
387 | 387 | } |
388 | 388 | |
389 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) { |
|
390 | - if ( ! empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) { |
|
391 | - $date_format = get_option( 'date_format' ); |
|
392 | - $time_format = get_option( 'time_format' ); |
|
389 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type) { |
|
390 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) { |
|
391 | + $date_format = get_option('date_format'); |
|
392 | + $time_format = get_option('time_format'); |
|
393 | 393 | ?> |
394 | 394 | <div id="wpinv-email-notes"> |
395 | - <h3 class="wpinv-notes-t"><?php echo esc_html( apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ) ); ?></h3> |
|
395 | + <h3 class="wpinv-notes-t"><?php echo esc_html(apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing'))); ?></h3> |
|
396 | 396 | <ol class="wpinv-notes-lists"> |
397 | 397 | <?php |
398 | - foreach ( $invoice_notes as $note ) { |
|
399 | - $note_time = strtotime( $note->comment_date ); |
|
398 | + foreach ($invoice_notes as $note) { |
|
399 | + $note_time = strtotime($note->comment_date); |
|
400 | 400 | ?> |
401 | 401 | <li class="comment wpinv-note"> |
402 | - <p class="wpinv-note-date meta"><?php printf( esc_html__( '%2$s at %3$s', 'invoicing' ), esc_html( $note->comment_author ), esc_html( date_i18n( $date_format, $note_time ) ), esc_html( date_i18n( $time_format, $note_time ) ), esc_html( $note_time ) ); ?></p> |
|
403 | - <div class="wpinv-note-desc description"><?php echo wp_kses_post( wpautop( wptexturize( $note->comment_content ) ) ); ?></div> |
|
402 | + <p class="wpinv-note-date meta"><?php printf(esc_html__('%2$s at %3$s', 'invoicing'), esc_html($note->comment_author), esc_html(date_i18n($date_format, $note_time)), esc_html(date_i18n($time_format, $note_time)), esc_html($note_time)); ?></p> |
|
403 | + <div class="wpinv-note-desc description"><?php echo wp_kses_post(wpautop(wptexturize($note->comment_content))); ?></div> |
|
404 | 404 | </li> |
405 | 405 | <?php |
406 | 406 | } |
@@ -410,4 +410,4 @@ discard block |
||
410 | 410 | <?php |
411 | 411 | } |
412 | 412 | } |
413 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
413 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
@@ -12,207 +12,207 @@ |
||
12 | 12 | */ |
13 | 13 | class WPInv_Notes { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct() { |
|
19 | - |
|
20 | - // Filter inovice notes. |
|
21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
23 | - |
|
24 | - // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
27 | - |
|
28 | - // Count comments. |
|
29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
30 | - |
|
31 | - // Fires after notes are loaded. |
|
32 | - do_action( 'wpinv_notes_init', $this ); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Filters invoice notes query to only include our notes. |
|
37 | - * |
|
38 | - * @param WP_Comment_Query $query |
|
39 | - */ |
|
40 | - public function set_invoice_note_type( $query ) { |
|
41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
42 | - |
|
43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
44 | - $query->query_vars['type'] = 'wpinv_note'; |
|
45 | - } else { |
|
46 | - |
|
47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
48 | - $query->query_vars['type__not_in'] = array(); |
|
49 | - } |
|
50 | - |
|
51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
53 | - } |
|
54 | - |
|
55 | - return $query; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Exclude notes from the comments feed. |
|
60 | - */ |
|
61 | - function wpinv_comment_feed_where( $where ) { |
|
62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Delete comments count cache whenever there is |
|
67 | - * new comment or the status of a comment changes. Cache |
|
68 | - * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
69 | - * is called. |
|
70 | - */ |
|
71 | - public function delete_comments_count_cache() { |
|
72 | - delete_transient( 'getpaid_count_comments' ); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Remove invoice notes from wp_count_comments(). |
|
77 | - * |
|
78 | - * @since 2.2 |
|
79 | - * @param object $stats Comment stats. |
|
80 | - * @param int $post_id Post ID. |
|
81 | - * @return object |
|
82 | - */ |
|
83 | - public function wp_count_comments( $stats, $post_id ) { |
|
84 | - global $wpdb; |
|
85 | - |
|
86 | - if ( empty( $post_id ) ) { |
|
87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
88 | - |
|
89 | - if ( ! $stats ) { |
|
90 | - $stats = array( |
|
91 | - 'total_comments' => 0, |
|
92 | - 'all' => 0, |
|
93 | - ); |
|
94 | - |
|
95 | - $count = $wpdb->get_results( |
|
96 | - " |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct() { |
|
19 | + |
|
20 | + // Filter inovice notes. |
|
21 | + add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
22 | + add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
23 | + |
|
24 | + // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
25 | + add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
26 | + add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
27 | + |
|
28 | + // Count comments. |
|
29 | + add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
30 | + |
|
31 | + // Fires after notes are loaded. |
|
32 | + do_action( 'wpinv_notes_init', $this ); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Filters invoice notes query to only include our notes. |
|
37 | + * |
|
38 | + * @param WP_Comment_Query $query |
|
39 | + */ |
|
40 | + public function set_invoice_note_type( $query ) { |
|
41 | + $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
42 | + |
|
43 | + if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
44 | + $query->query_vars['type'] = 'wpinv_note'; |
|
45 | + } else { |
|
46 | + |
|
47 | + if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
48 | + $query->query_vars['type__not_in'] = array(); |
|
49 | + } |
|
50 | + |
|
51 | + $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
52 | + $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
53 | + } |
|
54 | + |
|
55 | + return $query; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Exclude notes from the comments feed. |
|
60 | + */ |
|
61 | + function wpinv_comment_feed_where( $where ) { |
|
62 | + return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Delete comments count cache whenever there is |
|
67 | + * new comment or the status of a comment changes. Cache |
|
68 | + * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
69 | + * is called. |
|
70 | + */ |
|
71 | + public function delete_comments_count_cache() { |
|
72 | + delete_transient( 'getpaid_count_comments' ); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Remove invoice notes from wp_count_comments(). |
|
77 | + * |
|
78 | + * @since 2.2 |
|
79 | + * @param object $stats Comment stats. |
|
80 | + * @param int $post_id Post ID. |
|
81 | + * @return object |
|
82 | + */ |
|
83 | + public function wp_count_comments( $stats, $post_id ) { |
|
84 | + global $wpdb; |
|
85 | + |
|
86 | + if ( empty( $post_id ) ) { |
|
87 | + $stats = get_transient( 'getpaid_count_comments' ); |
|
88 | + |
|
89 | + if ( ! $stats ) { |
|
90 | + $stats = array( |
|
91 | + 'total_comments' => 0, |
|
92 | + 'all' => 0, |
|
93 | + ); |
|
94 | + |
|
95 | + $count = $wpdb->get_results( |
|
96 | + " |
|
97 | 97 | SELECT comment_approved, COUNT(*) AS num_comments |
98 | 98 | FROM {$wpdb->comments} |
99 | 99 | WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note') |
100 | 100 | GROUP BY comment_approved |
101 | 101 | ", |
102 | - ARRAY_A |
|
103 | - ); |
|
104 | - |
|
105 | - $approved = array( |
|
106 | - '0' => 'moderated', |
|
107 | - '1' => 'approved', |
|
108 | - 'spam' => 'spam', |
|
109 | - 'trash' => 'trash', |
|
110 | - 'post-trashed' => 'post-trashed', |
|
111 | - ); |
|
112 | - |
|
113 | - foreach ( (array) $count as $row ) { |
|
114 | - // Don't count post-trashed toward totals. |
|
115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
116 | - $stats['all'] += $row['num_comments']; |
|
117 | - $stats['total_comments'] += $row['num_comments']; |
|
118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
119 | - $stats['total_comments'] += $row['num_comments']; |
|
120 | - } |
|
121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - foreach ( $approved as $key ) { |
|
127 | - if ( empty( $stats[ $key ] ) ) { |
|
128 | - $stats[ $key ] = 0; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - $stats = (object) $stats; |
|
133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
134 | - } |
|
102 | + ARRAY_A |
|
103 | + ); |
|
104 | + |
|
105 | + $approved = array( |
|
106 | + '0' => 'moderated', |
|
107 | + '1' => 'approved', |
|
108 | + 'spam' => 'spam', |
|
109 | + 'trash' => 'trash', |
|
110 | + 'post-trashed' => 'post-trashed', |
|
111 | + ); |
|
112 | + |
|
113 | + foreach ( (array) $count as $row ) { |
|
114 | + // Don't count post-trashed toward totals. |
|
115 | + if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
116 | + $stats['all'] += $row['num_comments']; |
|
117 | + $stats['total_comments'] += $row['num_comments']; |
|
118 | + } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
119 | + $stats['total_comments'] += $row['num_comments']; |
|
120 | + } |
|
121 | + if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
122 | + $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + foreach ( $approved as $key ) { |
|
127 | + if ( empty( $stats[ $key ] ) ) { |
|
128 | + $stats[ $key ] = 0; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + $stats = (object) $stats; |
|
133 | + set_transient( 'getpaid_count_comments', $stats ); |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | |
137 | - return $stats; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns an array of invoice notes. |
|
142 | - * |
|
143 | - * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
144 | - * @param string $type Optional. Pass in customer to only return customer notes. |
|
145 | - * @return WP_Comment[] |
|
146 | - */ |
|
147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
148 | - |
|
149 | - // Default comment args. |
|
150 | - $args = array( |
|
151 | - 'post_id' => $invoice_id, |
|
152 | - 'orderby' => 'comment_ID', |
|
153 | - 'order' => 'ASC', |
|
154 | - ); |
|
155 | - |
|
156 | - // Maybe only show customer comments. |
|
157 | - if ( $type == 'customer' ) { |
|
158 | - $args['meta_key'] = '_wpi_customer_note'; |
|
159 | - $args['meta_value'] = 1; |
|
160 | - } |
|
161 | - |
|
162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
163 | - |
|
164 | - return get_comments( $args ); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Saves an invoice comment. |
|
169 | - * |
|
170 | - * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
171 | - * @param string $note The note content. |
|
172 | - * @param string $note_author The name of the author of the note. |
|
173 | - * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
174 | - * @return int|false The new note's ID on success, false on failure. |
|
175 | - */ |
|
176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
177 | - |
|
178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
179 | - |
|
180 | - /** |
|
181 | - * Insert the comment. |
|
182 | - */ |
|
183 | - $note_id = wp_insert_comment( |
|
184 | - wp_filter_comment( |
|
185 | - array( |
|
186 | - 'comment_post_ID' => $invoice->get_id(), |
|
187 | - 'comment_content' => $note, |
|
188 | - 'comment_agent' => 'Invoicing', |
|
189 | - 'user_id' => get_current_user_id(), |
|
190 | - 'comment_author' => $note_author, |
|
191 | - 'comment_author_IP' => wpinv_get_ip(), |
|
192 | - 'comment_author_email' => $author_email, |
|
193 | - 'comment_author_url' => $invoice->get_view_url(), |
|
194 | - 'comment_type' => 'wpinv_note', |
|
195 | - ) |
|
196 | - ) |
|
197 | - ); |
|
198 | - |
|
199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
200 | - |
|
201 | - // Are we notifying the customer? |
|
202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
203 | - return $note_id; |
|
204 | - } |
|
205 | - |
|
206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
207 | - do_action( |
|
137 | + return $stats; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns an array of invoice notes. |
|
142 | + * |
|
143 | + * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
144 | + * @param string $type Optional. Pass in customer to only return customer notes. |
|
145 | + * @return WP_Comment[] |
|
146 | + */ |
|
147 | + public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
148 | + |
|
149 | + // Default comment args. |
|
150 | + $args = array( |
|
151 | + 'post_id' => $invoice_id, |
|
152 | + 'orderby' => 'comment_ID', |
|
153 | + 'order' => 'ASC', |
|
154 | + ); |
|
155 | + |
|
156 | + // Maybe only show customer comments. |
|
157 | + if ( $type == 'customer' ) { |
|
158 | + $args['meta_key'] = '_wpi_customer_note'; |
|
159 | + $args['meta_value'] = 1; |
|
160 | + } |
|
161 | + |
|
162 | + $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
163 | + |
|
164 | + return get_comments( $args ); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Saves an invoice comment. |
|
169 | + * |
|
170 | + * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
171 | + * @param string $note The note content. |
|
172 | + * @param string $note_author The name of the author of the note. |
|
173 | + * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
174 | + * @return int|false The new note's ID on success, false on failure. |
|
175 | + */ |
|
176 | + function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
177 | + |
|
178 | + do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
179 | + |
|
180 | + /** |
|
181 | + * Insert the comment. |
|
182 | + */ |
|
183 | + $note_id = wp_insert_comment( |
|
184 | + wp_filter_comment( |
|
185 | + array( |
|
186 | + 'comment_post_ID' => $invoice->get_id(), |
|
187 | + 'comment_content' => $note, |
|
188 | + 'comment_agent' => 'Invoicing', |
|
189 | + 'user_id' => get_current_user_id(), |
|
190 | + 'comment_author' => $note_author, |
|
191 | + 'comment_author_IP' => wpinv_get_ip(), |
|
192 | + 'comment_author_email' => $author_email, |
|
193 | + 'comment_author_url' => $invoice->get_view_url(), |
|
194 | + 'comment_type' => 'wpinv_note', |
|
195 | + ) |
|
196 | + ) |
|
197 | + ); |
|
198 | + |
|
199 | + do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
200 | + |
|
201 | + // Are we notifying the customer? |
|
202 | + if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
203 | + return $note_id; |
|
204 | + } |
|
205 | + |
|
206 | + add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
207 | + do_action( |
|
208 | 208 | 'wpinv_new_customer_note', |
209 | 209 | array( |
210 | - 'invoice_id' => $invoice->get_id(), |
|
211 | - 'user_note' => $note, |
|
210 | + 'invoice_id' => $invoice->get_id(), |
|
211 | + 'user_note' => $note, |
|
212 | 212 | ) |
213 | 213 | ); |
214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
215 | - return $note_id; |
|
216 | - } |
|
214 | + do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
215 | + return $note_id; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Handles invoice notes. |
@@ -18,18 +18,18 @@ discard block |
||
18 | 18 | public function __construct() { |
19 | 19 | |
20 | 20 | // Filter inovice notes. |
21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
21 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
22 | + add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1); |
|
23 | 23 | |
24 | 24 | // Delete comments count cache whenever there is a new comment or a comment status changes. |
25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
25 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
26 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
27 | 27 | |
28 | 28 | // Count comments. |
29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 100, 2); |
|
30 | 30 | |
31 | 31 | // Fires after notes are loaded. |
32 | - do_action( 'wpinv_notes_init', $this ); |
|
32 | + do_action('wpinv_notes_init', $this); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param WP_Comment_Query $query |
39 | 39 | */ |
40 | - public function set_invoice_note_type( $query ) { |
|
41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
40 | + public function set_invoice_note_type($query) { |
|
41 | + $post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
42 | 42 | |
43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
43 | + if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) { |
|
44 | 44 | $query->query_vars['type'] = 'wpinv_note'; |
45 | 45 | } else { |
46 | 46 | |
47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
47 | + if (empty($query->query_vars['type__not_in'])) { |
|
48 | 48 | $query->query_vars['type__not_in'] = array(); |
49 | 49 | } |
50 | 50 | |
51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
51 | + $query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']); |
|
52 | + $query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return $query; |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * Exclude notes from the comments feed. |
60 | 60 | */ |
61 | - function wpinv_comment_feed_where( $where ) { |
|
62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
61 | + function wpinv_comment_feed_where($where) { |
|
62 | + return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' "; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * is called. |
70 | 70 | */ |
71 | 71 | public function delete_comments_count_cache() { |
72 | - delete_transient( 'getpaid_count_comments' ); |
|
72 | + delete_transient('getpaid_count_comments'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | * @param int $post_id Post ID. |
81 | 81 | * @return object |
82 | 82 | */ |
83 | - public function wp_count_comments( $stats, $post_id ) { |
|
83 | + public function wp_count_comments($stats, $post_id) { |
|
84 | 84 | global $wpdb; |
85 | 85 | |
86 | - if ( empty( $post_id ) ) { |
|
87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
86 | + if (empty($post_id)) { |
|
87 | + $stats = get_transient('getpaid_count_comments'); |
|
88 | 88 | |
89 | - if ( ! $stats ) { |
|
89 | + if (!$stats) { |
|
90 | 90 | $stats = array( |
91 | 91 | 'total_comments' => 0, |
92 | 92 | 'all' => 0, |
@@ -110,27 +110,27 @@ discard block |
||
110 | 110 | 'post-trashed' => 'post-trashed', |
111 | 111 | ); |
112 | 112 | |
113 | - foreach ( (array) $count as $row ) { |
|
113 | + foreach ((array) $count as $row) { |
|
114 | 114 | // Don't count post-trashed toward totals. |
115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
115 | + if (!in_array($row['comment_approved'], array('post-trashed', 'trash', 'spam'), true)) { |
|
116 | 116 | $stats['all'] += $row['num_comments']; |
117 | 117 | $stats['total_comments'] += $row['num_comments']; |
118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
118 | + } elseif (!in_array($row['comment_approved'], array('post-trashed', 'trash'), true)) { |
|
119 | 119 | $stats['total_comments'] += $row['num_comments']; |
120 | 120 | } |
121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
121 | + if (isset($approved[$row['comment_approved']])) { |
|
122 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - foreach ( $approved as $key ) { |
|
127 | - if ( empty( $stats[ $key ] ) ) { |
|
128 | - $stats[ $key ] = 0; |
|
126 | + foreach ($approved as $key) { |
|
127 | + if (empty($stats[$key])) { |
|
128 | + $stats[$key] = 0; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | 132 | $stats = (object) $stats; |
133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
133 | + set_transient('getpaid_count_comments', $stats); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param string $type Optional. Pass in customer to only return customer notes. |
145 | 145 | * @return WP_Comment[] |
146 | 146 | */ |
147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
147 | + public function get_invoice_notes($invoice_id = 0, $type = 'all') { |
|
148 | 148 | |
149 | 149 | // Default comment args. |
150 | 150 | $args = array( |
@@ -154,14 +154,14 @@ discard block |
||
154 | 154 | ); |
155 | 155 | |
156 | 156 | // Maybe only show customer comments. |
157 | - if ( $type == 'customer' ) { |
|
157 | + if ($type == 'customer') { |
|
158 | 158 | $args['meta_key'] = '_wpi_customer_note'; |
159 | 159 | $args['meta_value'] = 1; |
160 | 160 | } |
161 | 161 | |
162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
162 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
163 | 163 | |
164 | - return get_comments( $args ); |
|
164 | + return get_comments($args); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
174 | 174 | * @return int|false The new note's ID on success, false on failure. |
175 | 175 | */ |
176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
176 | + function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) { |
|
177 | 177 | |
178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
178 | + do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Insert the comment. |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | ) |
197 | 197 | ); |
198 | 198 | |
199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
199 | + do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer); |
|
200 | 200 | |
201 | 201 | // Are we notifying the customer? |
202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
202 | + if (empty($note_id) || empty($for_customer)) { |
|
203 | 203 | return $note_id; |
204 | 204 | } |
205 | 205 | |
206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
206 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
207 | 207 | do_action( |
208 | 208 | 'wpinv_new_customer_note', |
209 | 209 | array( |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | 'user_note' => $note, |
212 | 212 | ) |
213 | 213 | ); |
214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
214 | + do_action('getpaid_new_customer_note', $invoice, $note); |
|
215 | 215 | return $note_id; |
216 | 216 | } |
217 | 217 |
@@ -17,45 +17,45 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class BP_GetPaid_Component extends BP_Component { |
19 | 19 | |
20 | - /** |
|
21 | - * Start the component setup process. |
|
22 | - * |
|
23 | - * @since 2.1.5 |
|
24 | - */ |
|
25 | - public function __construct() { |
|
26 | - parent::start( |
|
27 | - 'getpaid', |
|
28 | - 'GetPaid', |
|
29 | - buddypress()->plugin_dir, |
|
30 | - array( |
|
31 | - 'adminbar_myaccount_order' => 30, |
|
32 | - ) |
|
33 | - ); |
|
34 | - } |
|
20 | + /** |
|
21 | + * Start the component setup process. |
|
22 | + * |
|
23 | + * @since 2.1.5 |
|
24 | + */ |
|
25 | + public function __construct() { |
|
26 | + parent::start( |
|
27 | + 'getpaid', |
|
28 | + 'GetPaid', |
|
29 | + buddypress()->plugin_dir, |
|
30 | + array( |
|
31 | + 'adminbar_myaccount_order' => 30, |
|
32 | + ) |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Set up component global variables. |
|
38 | - * |
|
39 | - * @since 2.1.5 |
|
40 | - * |
|
41 | - * |
|
42 | - * @param array $args { |
|
43 | - * All values are optional. |
|
44 | - * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | - * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | - * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | - * component has a root directory (the slug will be overridden by the |
|
48 | - * post_name of the directory page). Default: the slug of the directory page |
|
49 | - * if one is found, otherwise an empty string. |
|
50 | - * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | - * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | - * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | - * 'Search Groups...'. |
|
54 | - * @type array $global_tables Optional. An array of database table names. |
|
55 | - * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | - * } |
|
57 | - */ |
|
58 | - public function setup_globals( $args = array() ) { |
|
37 | + * Set up component global variables. |
|
38 | + * |
|
39 | + * @since 2.1.5 |
|
40 | + * |
|
41 | + * |
|
42 | + * @param array $args { |
|
43 | + * All values are optional. |
|
44 | + * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | + * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | + * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | + * component has a root directory (the slug will be overridden by the |
|
48 | + * post_name of the directory page). Default: the slug of the directory page |
|
49 | + * if one is found, otherwise an empty string. |
|
50 | + * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | + * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | + * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | + * 'Search Groups...'. |
|
54 | + * @type array $global_tables Optional. An array of database table names. |
|
55 | + * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | + * } |
|
57 | + */ |
|
58 | + public function setup_globals( $args = array() ) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -64,21 +64,21 @@ discard block |
||
64 | 64 | 'has_directory' => false, |
65 | 65 | ) |
66 | 66 | ); |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Set up component navigation. |
|
71 | - * |
|
72 | - * @since 2.1.5 |
|
73 | - * |
|
74 | - * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | - * |
|
76 | - * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | - * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | - */ |
|
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | - |
|
81 | - // Abort if the integration is inactive. |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Set up component navigation. |
|
71 | + * |
|
72 | + * @since 2.1.5 |
|
73 | + * |
|
74 | + * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | + * |
|
76 | + * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | + * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | + */ |
|
79 | + public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | + |
|
81 | + // Abort if the integration is inactive. |
|
82 | 82 | if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
83 | 83 | return; |
84 | 84 | } |
@@ -88,25 +88,25 @@ discard block |
||
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - // Determine user to use. |
|
92 | - $user_domain = bp_loggedin_user_domain(); |
|
93 | - $slug = 'getpaid'; |
|
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | - |
|
96 | - // Add 'Payments' to the main navigation. |
|
97 | - $main_nav = array( |
|
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | - 'slug' => $slug, |
|
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
91 | + // Determine user to use. |
|
92 | + $user_domain = bp_loggedin_user_domain(); |
|
93 | + $slug = 'getpaid'; |
|
94 | + $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | + |
|
96 | + // Add 'Payments' to the main navigation. |
|
97 | + $main_nav = array( |
|
98 | + 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | + 'slug' => $slug, |
|
100 | + 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | + 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | + 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | - 'item_css_id' => $this->id, |
|
105 | - 'parent_url' => $user_domain, |
|
106 | - 'parent_slug' => buddypress()->slug, |
|
107 | - ); |
|
104 | + 'item_css_id' => $this->id, |
|
105 | + 'parent_url' => $user_domain, |
|
106 | + 'parent_slug' => buddypress()->slug, |
|
107 | + ); |
|
108 | 108 | |
109 | - // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
109 | + // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
110 | 110 | foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | 118 | 'screen_function' => function() use ( $tab ) { |
119 | - $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | - $this->display_current_tab(); |
|
119 | + $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | + $this->display_current_tab(); |
|
121 | 121 | }, |
122 | 122 | 'show_for_displayed_user' => false, |
123 | 123 | 'item_css_id' => "getpaid-bp-$_slug", |
@@ -125,27 +125,27 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Set up the component entries in the WordPress Admin Bar. |
|
133 | - * |
|
134 | - * @since 2.1.5 |
|
135 | - * |
|
136 | - * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | - * parameter array. |
|
138 | - * |
|
139 | - * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | - * description. |
|
141 | - */ |
|
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
128 | + parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | + } |
|
143 | 130 | |
144 | - // Menus for logged in user. |
|
145 | - if ( is_user_logged_in() ) { |
|
146 | - |
|
147 | - // Setup the logged in user variables. |
|
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
131 | + /** |
|
132 | + * Set up the component entries in the WordPress Admin Bar. |
|
133 | + * |
|
134 | + * @since 2.1.5 |
|
135 | + * |
|
136 | + * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | + * parameter array. |
|
138 | + * |
|
139 | + * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | + * description. |
|
141 | + */ |
|
142 | + public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
143 | + |
|
144 | + // Menus for logged in user. |
|
145 | + if ( is_user_logged_in() ) { |
|
146 | + |
|
147 | + // Setup the logged in user variables. |
|
148 | + $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
@@ -168,48 +168,48 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Retrieves the current tab. |
|
176 | - * |
|
177 | - * @since 2.1.5 |
|
178 | - */ |
|
179 | - public function get_current_tab() { |
|
180 | - global $getpaid_bp_current_tab; |
|
181 | - |
|
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | - return array( |
|
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | - 'content' => '[wpinv_history]', |
|
186 | - 'icon' => 'fas fa-file-invoice', |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - return $getpaid_bp_current_tab; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Displays the current tab. |
|
195 | - * |
|
196 | - * @since 2.1.5 |
|
197 | - */ |
|
198 | - public function display_current_tab() { |
|
199 | - |
|
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
171 | + parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Retrieves the current tab. |
|
176 | + * |
|
177 | + * @since 2.1.5 |
|
178 | + */ |
|
179 | + public function get_current_tab() { |
|
180 | + global $getpaid_bp_current_tab; |
|
181 | + |
|
182 | + if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | + return array( |
|
184 | + 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | + 'content' => '[wpinv_history]', |
|
186 | + 'icon' => 'fas fa-file-invoice', |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + return $getpaid_bp_current_tab; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Displays the current tab. |
|
195 | + * |
|
196 | + * @since 2.1.5 |
|
197 | + */ |
|
198 | + public function display_current_tab() { |
|
199 | + |
|
200 | + add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | + $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
202 | 202 | |
203 | 203 | bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Handles the actual display of the current tab. |
|
208 | - * |
|
209 | - * @since 2.1.5 |
|
210 | - */ |
|
211 | - public function handle_display_current_tab() { |
|
212 | - getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | - } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Handles the actual display of the current tab. |
|
208 | + * |
|
209 | + * @since 2.1.5 |
|
210 | + */ |
|
211 | + public function handle_display_current_tab() { |
|
212 | + getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | // Exit if accessed directly. |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Main GetPaid Class. |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @type array $meta_tables Optional. An array of metadata table names. |
56 | 56 | * } |
57 | 57 | */ |
58 | - public function setup_globals( $args = array() ) { |
|
58 | + public function setup_globals($args = array()) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -76,30 +76,30 @@ discard block |
||
76 | 76 | * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
77 | 77 | * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
78 | 78 | */ |
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
79 | + public function setup_nav($main_nav = array(), $sub_nav = array()) { |
|
80 | 80 | |
81 | 81 | // Abort if the integration is inactive. |
82 | - if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
|
82 | + if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Or a user is not viewing their profile. |
87 | - if ( bp_displayed_user_id() != bp_loggedin_user_id() ) { |
|
87 | + if (bp_displayed_user_id() != bp_loggedin_user_id()) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Determine user to use. |
92 | 92 | $user_domain = bp_loggedin_user_domain(); |
93 | 93 | $slug = 'getpaid'; |
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
94 | + $payments_link = trailingslashit($user_domain . $slug); |
|
95 | 95 | |
96 | 96 | // Add 'Payments' to the main navigation. |
97 | 97 | $main_nav = array( |
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
98 | + 'name' => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'), |
|
99 | 99 | 'slug' => $slug, |
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
100 | + 'position' => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug), |
|
101 | + 'screen_function' => array($this, 'display_current_tab'), |
|
102 | + 'default_subnav_slug' => apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | 104 | 'item_css_id' => $this->id, |
105 | 105 | 'parent_url' => $user_domain, |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | |
109 | 109 | // Add the subnav items to the payments nav item if we are using a theme that supports this. |
110 | - foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
|
110 | + foreach (getpaid_get_user_content_tabs() as $_slug => $tab) { |
|
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
113 | 113 | 'name' => $tab['label'], |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'parent_url' => $payments_link, |
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | - 'screen_function' => function() use ( $tab ) { |
|
118 | + 'screen_function' => function() use ($tab) { |
|
119 | 119 | $GLOBALS['getpaid_bp_current_tab'] = $tab; |
120 | 120 | $this->display_current_tab(); |
121 | 121 | }, |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
128 | + parent::setup_nav($main_nav, $sub_nav); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -139,36 +139,36 @@ discard block |
||
139 | 139 | * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
140 | 140 | * description. |
141 | 141 | */ |
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
142 | + public function setup_admin_bar($wp_admin_nav = array()) { |
|
143 | 143 | |
144 | 144 | // Menus for logged in user. |
145 | - if ( is_user_logged_in() ) { |
|
145 | + if (is_user_logged_in()) { |
|
146 | 146 | |
147 | 147 | // Setup the logged in user variables. |
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
148 | + $payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/'); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
152 | 152 | 'parent' => buddypress()->my_account_menu_id, |
153 | 153 | 'id' => 'my-account-getpaid', |
154 | - 'title' => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ), |
|
155 | - 'href' => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
154 | + 'title' => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'), |
|
155 | + 'href' => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
156 | 156 | ); |
157 | 157 | |
158 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
158 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
159 | 159 | |
160 | 160 | $wp_admin_nav[] = array( |
161 | 161 | 'parent' => 'my-account-getpaid', |
162 | 162 | 'id' => 'my-account-getpaid' . $slug, |
163 | 163 | 'title' => $tab['label'], |
164 | - 'href' => trailingslashit( $payments_link . $slug ), |
|
164 | + 'href' => trailingslashit($payments_link . $slug), |
|
165 | 165 | 'position' => 20, |
166 | 166 | ); |
167 | 167 | |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
171 | + parent::setup_admin_bar($wp_admin_nav); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | public function get_current_tab() { |
180 | 180 | global $getpaid_bp_current_tab; |
181 | 181 | |
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
182 | + if (empty($getpaid_bp_current_tab)) { |
|
183 | 183 | return array( |
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
184 | + 'label' => __('Invoices', 'invoicing'), |
|
185 | 185 | 'content' => '[wpinv_history]', |
186 | 186 | 'icon' => 'fas fa-file-invoice', |
187 | 187 | ); |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function display_current_tab() { |
199 | 199 | |
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
200 | + add_action('bp_template_content', array($this, 'handle_display_current_tab')); |
|
201 | + $template = apply_filters('bp_core_template_plugin', 'members/single/plugins'); |
|
202 | 202 | |
203 | - bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
|
203 | + bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @since 2.1.5 |
210 | 210 | */ |
211 | 211 | public function handle_display_current_tab() { |
212 | - getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
212 | + getpaid_prepare_user_content_tab($this->get_current_tab()); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | } |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ) { |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | - * Returns the API authentication params. |
|
93 | - * |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function get_auth_params() { |
|
92 | + * Returns the API authentication params. |
|
93 | + * |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function get_auth_params() { |
|
98 | 98 | |
99 | 99 | return array( |
100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * Cancels a subscription remotely |
|
108 | - * |
|
109 | - * |
|
110 | - * @param WPInv_Subscription $subscription Subscription. |
|
107 | + * Cancels a subscription remotely |
|
108 | + * |
|
109 | + * |
|
110 | + * @param WPInv_Subscription $subscription Subscription. |
|
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | - */ |
|
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
112 | + */ |
|
113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Processes ipns. |
|
130 | - * |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function verify_ipn() { |
|
129 | + * Processes ipns. |
|
130 | + * |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function verify_ipn() { |
|
134 | 134 | |
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Validates IPN invoices. |
|
179 | - * |
|
178 | + * Validates IPN invoices. |
|
179 | + * |
|
180 | 180 | * @param WPInv_Invoice $invoice |
181 | 181 | * @param object $payload |
182 | - * @return void |
|
183 | - */ |
|
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * Process subscriptio IPNS. |
|
192 | - * |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function maybe_process_old_ipn() { |
|
191 | + * Process subscriptio IPNS. |
|
192 | + * |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function maybe_process_old_ipn() { |
|
196 | 196 | |
197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | - * Validates the old IPN signature. |
|
237 | + * Validates the old IPN signature. |
|
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | - */ |
|
241 | - public function validate_old_ipn_signature( $posted ) { |
|
240 | + */ |
|
241 | + public function validate_old_ipn_signature( $posted ) { |
|
242 | 242 | |
243 | 243 | $signature = $this->get_option( 'signature_key' ); |
244 | 244 | if ( ! empty( $signature ) ) { |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | - * Check Authorize.NET IPN validity. |
|
260 | - */ |
|
261 | - public function validate_ipn() { |
|
259 | + * Check Authorize.NET IPN validity. |
|
260 | + */ |
|
261 | + public function validate_ipn() { |
|
262 | 262 | |
263 | 263 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
264 | 264 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function get_api_url( $invoice ) { |
|
32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
31 | + public function get_api_url($invoice) { |
|
32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,48 +40,48 @@ discard block |
||
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | 41 | * @return stdClass|WP_Error |
42 | 42 | */ |
43 | - public function post( $post, $invoice ) { |
|
43 | + public function post($post, $invoice) { |
|
44 | 44 | |
45 | - $url = $this->get_api_url( $invoice ); |
|
45 | + $url = $this->get_api_url($invoice); |
|
46 | 46 | $response = wp_remote_post( |
47 | 47 | $url, |
48 | 48 | array( |
49 | 49 | 'headers' => array( |
50 | 50 | 'Content-Type' => 'application/json; charset=utf-8', |
51 | 51 | ), |
52 | - 'body' => json_encode( $post ), |
|
52 | + 'body' => json_encode($post), |
|
53 | 53 | 'method' => 'POST', |
54 | 54 | ) |
55 | 55 | ); |
56 | 56 | |
57 | - if ( is_wp_error( $response ) ) { |
|
57 | + if (is_wp_error($response)) { |
|
58 | 58 | return $response; |
59 | 59 | } |
60 | 60 | |
61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
62 | - $response = preg_replace( '/\xEF\xBB\xBF/', '', $response ); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
63 | - $response = json_decode( $response ); |
|
61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
62 | + $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
63 | + $response = json_decode($response); |
|
64 | 64 | |
65 | - if ( empty( $response ) ) { |
|
66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
65 | + if (empty($response)) { |
|
66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
67 | 67 | } |
68 | 68 | |
69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
69 | + if ($response->messages->resultCode == 'Error') { |
|
70 | 70 | |
71 | - if ( $this->is_sandbox( $invoice ) ) { |
|
72 | - wpinv_error_log( $response ); |
|
71 | + if ($this->is_sandbox($invoice)) { |
|
72 | + wpinv_error_log($response); |
|
73 | 73 | } |
74 | 74 | |
75 | - if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) { |
|
76 | - return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId ); |
|
75 | + if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) { |
|
76 | + return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId); |
|
77 | 77 | } |
78 | 78 | |
79 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
79 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
80 | 80 | $error = $response->transactionResponse->errors[0]; |
81 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
81 | + return new WP_Error($error->errorCode, $error->errorText); |
|
82 | 82 | } |
83 | 83 | |
84 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
84 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $response; |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | public function get_auth_params() { |
98 | 98 | |
99 | 99 | return array( |
100 | - 'name' => $this->get_option( 'login_id' ), |
|
101 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
100 | + 'name' => $this->get_option('login_id'), |
|
101 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param WPInv_Subscription $subscription Subscription. |
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | 112 | */ |
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
113 | + public function cancel_subscription($subscription, $invoice) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -135,38 +135,38 @@ discard block |
||
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
138 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
139 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 200)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
143 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
144 | - if ( empty( $posted ) ) { |
|
145 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
143 | + $posted = json_decode(file_get_contents('php://input')); |
|
144 | + if (empty($posted)) { |
|
145 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 200)); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // Process the IPN. |
149 | - $posted = (object) wp_unslash( $posted ); |
|
149 | + $posted = (object) wp_unslash($posted); |
|
150 | 150 | |
151 | 151 | // Process refunds. |
152 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
153 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
154 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
152 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
153 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
154 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
155 | 155 | $invoice->refund(); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Held funds approved. |
159 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
160 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
161 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
162 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
159 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
160 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
161 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
162 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Held funds declined. |
166 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
167 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
168 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
169 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
166 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
167 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
168 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
169 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
170 | 170 | $invoice->save(); |
171 | 171 | } |
172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param object $payload |
182 | 182 | * @return void |
183 | 183 | */ |
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
184 | + public function validate_ipn_invoice($invoice, $payload) { |
|
185 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
@@ -194,32 +194,32 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function maybe_process_old_ipn() { |
196 | 196 | |
197 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
197 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
198 | 198 | |
199 | 199 | // Only process subscriptions subscriptions. |
200 | - if ( empty( $data['x_subscription_id'] ) ) { |
|
200 | + if (empty($data['x_subscription_id'])) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Check validity. |
205 | - $this->validate_old_ipn_signature( $data ); |
|
205 | + $this->validate_old_ipn_signature($data); |
|
206 | 206 | |
207 | 207 | // Fetch the associated subscription. |
208 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] ); |
|
209 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
208 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']); |
|
209 | + $subscription = new WPInv_Subscription($subscription_id); |
|
210 | 210 | |
211 | 211 | // Abort if it is missing or completed. |
212 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
212 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Payment status. |
217 | - if ( 1 == $data['x_response_code'] ) { |
|
217 | + if (1 == $data['x_response_code']) { |
|
218 | 218 | |
219 | 219 | // Renew the subscription. |
220 | 220 | $subscription->add_payment( |
221 | 221 | array( |
222 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
222 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
223 | 223 | 'gateway' => $this->id, |
224 | 224 | ) |
225 | 225 | ); |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | 240 | */ |
241 | - public function validate_old_ipn_signature( $posted ) { |
|
241 | + public function validate_old_ipn_signature($posted) { |
|
242 | 242 | |
243 | - $signature = $this->get_option( 'signature_key' ); |
|
244 | - if ( ! empty( $signature ) ) { |
|
245 | - $login_id = $this->get_option( 'login_id' ); |
|
246 | - $trans_id = wpinv_clean( $_POST['x_trans_id'] ); |
|
247 | - $amount = wpinv_clean( $_POST['x_amount'] ); |
|
248 | - $hash = hash_hmac( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
243 | + $signature = $this->get_option('signature_key'); |
|
244 | + if (!empty($signature)) { |
|
245 | + $login_id = $this->get_option('login_id'); |
|
246 | + $trans_id = wpinv_clean($_POST['x_trans_id']); |
|
247 | + $amount = wpinv_clean($_POST['x_amount']); |
|
248 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
249 | 249 | |
250 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
251 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
250 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
251 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
252 | 252 | exit; |
253 | 253 | } |
254 | 254 | } |
@@ -260,28 +260,28 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public function validate_ipn() { |
262 | 262 | |
263 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
263 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
264 | 264 | |
265 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
265 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
269 | - $signature = $this->get_option( 'signature_key' ); |
|
269 | + $signature = $this->get_option('signature_key'); |
|
270 | 270 | |
271 | - if ( empty( $signature ) ) { |
|
272 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
271 | + if (empty($signature)) { |
|
272 | + wpinv_error_log('Error: You have not set a signature key'); |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | - $hash = hash_hmac( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
276 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
277 | 277 | |
278 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
279 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
278 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
279 | + wpinv_error_log('Successfully validated the IPN'); |
|
280 | 280 | return true; |
281 | 281 | } |
282 | 282 | |
283 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
284 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
283 | + wpinv_error_log('IPN hash is not valid'); |
|
284 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
285 | 285 | return false; |
286 | 286 | |
287 | 287 | } |
@@ -12,473 +12,473 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | |
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Check PayPal IPN validity. |
|
105 | - */ |
|
106 | - protected function validate_ipn() { |
|
99 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Check PayPal IPN validity. |
|
105 | + */ |
|
106 | + protected function validate_ipn() { |
|
107 | 107 | |
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | - |
|
110 | - // Retrieve the associated invoice. |
|
111 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | - |
|
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | - } |
|
117 | - |
|
118 | - // Validate the IPN. |
|
119 | - $posted['cmd'] = '_notify-validate'; |
|
120 | - |
|
121 | - // Send back post vars to paypal. |
|
122 | - $params = array( |
|
123 | - 'body' => $posted, |
|
124 | - 'timeout' => 60, |
|
125 | - 'httpversion' => '1.1', |
|
126 | - 'compress' => false, |
|
127 | - 'decompress' => false, |
|
128 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | - ); |
|
130 | - |
|
131 | - // Post back to get a response. |
|
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | - |
|
134 | - // Check to see if the request was valid. |
|
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | - return true; |
|
138 | - } |
|
108 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + |
|
110 | + // Retrieve the associated invoice. |
|
111 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
112 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | + |
|
114 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | + } |
|
117 | + |
|
118 | + // Validate the IPN. |
|
119 | + $posted['cmd'] = '_notify-validate'; |
|
120 | + |
|
121 | + // Send back post vars to paypal. |
|
122 | + $params = array( |
|
123 | + 'body' => $posted, |
|
124 | + 'timeout' => 60, |
|
125 | + 'httpversion' => '1.1', |
|
126 | + 'compress' => false, |
|
127 | + 'decompress' => false, |
|
128 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | + ); |
|
130 | + |
|
131 | + // Post back to get a response. |
|
132 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + |
|
134 | + // Check to see if the request was valid. |
|
135 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | + return true; |
|
138 | + } |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | - return false; |
|
143 | - } |
|
140 | + if ( is_wp_error( $response ) ) { |
|
141 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | + return false; |
|
143 | + } |
|
144 | 144 | |
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | - return false; |
|
145 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + return false; |
|
147 | 147 | |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Check currency from IPN matches the invoice. |
|
152 | - * |
|
153 | - * @param WPInv_Invoice $invoice Invoice object. |
|
154 | - * @param string $currency currency to validate. |
|
155 | - */ |
|
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
150 | + /** |
|
151 | + * Check currency from IPN matches the invoice. |
|
152 | + * |
|
153 | + * @param WPInv_Invoice $invoice Invoice object. |
|
154 | + * @param string $currency currency to validate. |
|
155 | + */ |
|
156 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | 159 | |
160 | - /* translators: %s: currency code. */ |
|
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
160 | + /* translators: %s: currency code. */ |
|
161 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | - } |
|
163 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + } |
|
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | - } |
|
166 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Check payment amount from IPN matches the invoice. |
|
171 | - * |
|
172 | - * @param WPInv_Invoice $invoice Invoice object. |
|
173 | - * @param float $amount amount to validate. |
|
174 | - */ |
|
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
169 | + /** |
|
170 | + * Check payment amount from IPN matches the invoice. |
|
171 | + * |
|
172 | + * @param WPInv_Invoice $invoice Invoice object. |
|
173 | + * @param float $amount amount to validate. |
|
174 | + */ |
|
175 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
177 | 177 | |
178 | - /* translators: %s: Amount. */ |
|
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
178 | + /* translators: %s: Amount. */ |
|
179 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | - } |
|
181 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + } |
|
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | - } |
|
184 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Verify receiver email from PayPal. |
|
189 | - * |
|
190 | - * @param WPInv_Invoice $invoice Invoice object. |
|
191 | - * @param string $receiver_email Email to validate. |
|
192 | - */ |
|
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
187 | + /** |
|
188 | + * Verify receiver email from PayPal. |
|
189 | + * |
|
190 | + * @param WPInv_Invoice $invoice Invoice object. |
|
191 | + * @param string $receiver_email Email to validate. |
|
192 | + */ |
|
193 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
198 | 198 | |
199 | - /* translators: %s: email address . */ |
|
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
199 | + /* translators: %s: email address . */ |
|
200 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | - } |
|
202 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + } |
|
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | - } |
|
205 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Handles one time payments. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param array $posted Posted data. |
|
213 | - */ |
|
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
208 | + /** |
|
209 | + * Handles one time payments. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param array $posted Posted data. |
|
213 | + */ |
|
214 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | 215 | |
216 | - // Collect payment details |
|
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
216 | + // Collect payment details |
|
217 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
222 | 222 | |
223 | - // Update the transaction id. |
|
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | - $invoice->save(); |
|
227 | - } |
|
223 | + // Update the transaction id. |
|
224 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | + $invoice->save(); |
|
227 | + } |
|
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | 230 | |
231 | - // Process a refund. |
|
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + // Process a refund. |
|
232 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | - } |
|
236 | + if ( ! $invoice->is_refunded() ) { |
|
237 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | + } |
|
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | - } |
|
240 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | + } |
|
242 | 242 | |
243 | - // Process payments. |
|
244 | - if ( $payment_status == 'completed' ) { |
|
243 | + // Process payments. |
|
244 | + if ( $payment_status == 'completed' ) { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | - } |
|
246 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | + } |
|
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | 251 | |
252 | - $note = ''; |
|
252 | + $note = ''; |
|
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | - } |
|
254 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | + } |
|
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | - } |
|
258 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | + } |
|
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
264 | 264 | |
265 | - } |
|
265 | + } |
|
266 | 266 | |
267 | - // Pending payments. |
|
268 | - if ( $payment_status == 'pending' ) { |
|
267 | + // Pending payments. |
|
268 | + if ( $payment_status == 'pending' ) { |
|
269 | 269 | |
270 | - /* translators: %s: pending reason. */ |
|
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + /* translators: %s: pending reason. */ |
|
271 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | - } |
|
273 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | + } |
|
275 | 275 | |
276 | - /* translators: %s: payment status. */ |
|
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + /* translators: %s: payment status. */ |
|
277 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
278 | 278 | |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Handles one time payments. |
|
283 | - * |
|
284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
285 | - * @param array $posted Posted data. |
|
286 | - */ |
|
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | - } |
|
281 | + /** |
|
282 | + * Handles one time payments. |
|
283 | + * |
|
284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
285 | + * @param array $posted Posted data. |
|
286 | + */ |
|
287 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Handles subscription sign ups. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice Invoice object. |
|
295 | - * @param array $posted Posted data. |
|
296 | - */ |
|
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
291 | + /** |
|
292 | + * Handles subscription sign ups. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice Invoice object. |
|
295 | + * @param array $posted Posted data. |
|
296 | + */ |
|
297 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | 300 | |
301 | - // Make sure the invoice has a subscription. |
|
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + // Make sure the invoice has a subscription. |
|
302 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | - } |
|
304 | + if ( empty( $subscription ) ) { |
|
305 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | + } |
|
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | 309 | |
310 | - // Validate the IPN. |
|
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
310 | + // Validate the IPN. |
|
311 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
314 | 314 | |
315 | - // Activate the subscription. |
|
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | - $subscription->activate(); |
|
315 | + // Activate the subscription. |
|
316 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | + $subscription->activate(); |
|
321 | 321 | |
322 | - // Set the transaction id. |
|
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | - } |
|
322 | + // Set the transaction id. |
|
323 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | + } |
|
327 | 327 | |
328 | - // Update the payment status. |
|
329 | - $invoice->mark_paid(); |
|
328 | + // Update the payment status. |
|
329 | + $invoice->mark_paid(); |
|
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
334 | - } |
|
333 | + wpinv_error_log( 'Subscription started.', false ); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * Handles subscription renewals. |
|
338 | - * |
|
339 | - * @param WPInv_Invoice $invoice Invoice object. |
|
340 | - * @param array $posted Posted data. |
|
341 | - */ |
|
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
336 | + /** |
|
337 | + * Handles subscription renewals. |
|
338 | + * |
|
339 | + * @param WPInv_Invoice $invoice Invoice object. |
|
340 | + * @param array $posted Posted data. |
|
341 | + */ |
|
342 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
343 | 343 | |
344 | - // Make sure the invoice has a subscription. |
|
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
344 | + // Make sure the invoice has a subscription. |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | - } |
|
347 | + if ( empty( $subscription ) ) { |
|
348 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | + } |
|
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | 352 | |
353 | - // PayPal sends a subscr_payment for the first payment too. |
|
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
353 | + // PayPal sends a subscr_payment for the first payment too. |
|
354 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ( $dates as $date ) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | - continue; |
|
365 | - } |
|
363 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | + continue; |
|
365 | + } |
|
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | - } |
|
367 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | + } |
|
371 | 371 | |
372 | - return $invoice->mark_paid(); |
|
373 | - |
|
374 | - } |
|
372 | + return $invoice->mark_paid(); |
|
373 | + |
|
374 | + } |
|
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | - |
|
378 | - // Abort if the payment is already recorded. |
|
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | - } |
|
382 | - |
|
383 | - $args = array( |
|
384 | - 'transaction_id' => $posted['txn_id'], |
|
385 | - 'gateway' => $this->id, |
|
386 | - ); |
|
387 | - |
|
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
376 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | + |
|
378 | + // Abort if the payment is already recorded. |
|
379 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | + } |
|
382 | + |
|
383 | + $args = array( |
|
384 | + 'transaction_id' => $posted['txn_id'], |
|
385 | + 'gateway' => $this->id, |
|
386 | + ); |
|
387 | + |
|
388 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
391 | - return; |
|
392 | - } |
|
390 | + if ( empty( $invoice ) ) { |
|
391 | + return; |
|
392 | + } |
|
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
396 | 396 | |
397 | - $subscription->renew(); |
|
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
397 | + $subscription->renew(); |
|
398 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
399 | 399 | |
400 | - } |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Handles subscription cancelations. |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice Invoice object. |
|
406 | - */ |
|
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
402 | + /** |
|
403 | + * Handles subscription cancelations. |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice Invoice object. |
|
406 | + */ |
|
407 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
408 | 408 | |
409 | - // Make sure the invoice has a subscription. |
|
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | - |
|
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | - } |
|
415 | - |
|
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | - $subscription->cancel(); |
|
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
409 | + // Make sure the invoice has a subscription. |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | + |
|
412 | + if ( empty( $subscription ) ) { |
|
413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | + } |
|
415 | + |
|
416 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | + $subscription->cancel(); |
|
418 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
419 | 419 | |
420 | - } |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * Handles subscription completions. |
|
424 | - * |
|
425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
426 | - * @param array $posted Posted data. |
|
427 | - */ |
|
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
422 | + /** |
|
423 | + * Handles subscription completions. |
|
424 | + * |
|
425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
426 | + * @param array $posted Posted data. |
|
427 | + */ |
|
428 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
429 | 429 | |
430 | - // Make sure the invoice has a subscription. |
|
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
430 | + // Make sure the invoice has a subscription. |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | - } |
|
433 | + if ( empty( $subscription ) ) { |
|
434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | + } |
|
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | - $subscription->complete(); |
|
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
437 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | + $subscription->complete(); |
|
439 | + wpinv_error_log( 'Subscription completed.', false ); |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | - /** |
|
444 | - * Handles subscription fails. |
|
445 | - * |
|
446 | - * @param WPInv_Invoice $invoice Invoice object. |
|
447 | - * @param array $posted Posted data. |
|
448 | - */ |
|
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
443 | + /** |
|
444 | + * Handles subscription fails. |
|
445 | + * |
|
446 | + * @param WPInv_Invoice $invoice Invoice object. |
|
447 | + * @param array $posted Posted data. |
|
448 | + */ |
|
449 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
450 | 450 | |
451 | - // Make sure the invoice has a subscription. |
|
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
451 | + // Make sure the invoice has a subscription. |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | - } |
|
454 | + if ( empty( $subscription ) ) { |
|
455 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | + } |
|
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | - $subscription->failing(); |
|
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
458 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | + $subscription->failing(); |
|
460 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
461 | 461 | |
462 | - } |
|
462 | + } |
|
463 | 463 | |
464 | - /** |
|
465 | - * Handles subscription suspensions. |
|
466 | - * |
|
467 | - * @param WPInv_Invoice $invoice Invoice object. |
|
468 | - * @param array $posted Posted data. |
|
469 | - */ |
|
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
464 | + /** |
|
465 | + * Handles subscription suspensions. |
|
466 | + * |
|
467 | + * @param WPInv_Invoice $invoice Invoice object. |
|
468 | + * @param array $posted Posted data. |
|
469 | + */ |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
471 | 471 | |
472 | - // Make sure the invoice has a subscription. |
|
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
472 | + // Make sure the invoice has a subscription. |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | - } |
|
478 | - |
|
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | - $subscription->cancel(); |
|
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | - } |
|
475 | + if ( empty( $subscription ) ) { |
|
476 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | + } |
|
478 | + |
|
479 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | + $subscription->cancel(); |
|
481 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | + } |
|
483 | 483 | |
484 | 484 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,21 +83,21 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
99 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
100 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function validate_ipn() { |
107 | 107 | |
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
108 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
109 | 109 | |
110 | 110 | // Retrieve the associated invoice. |
111 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
111 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
112 | + $invoice = $this->get_ipn_invoice($posted); |
|
113 | 113 | |
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
114 | + if ($this->gateway->is_sandbox($invoice)) { |
|
115 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Validate the IPN. |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | ); |
130 | 130 | |
131 | 131 | // Post back to get a response. |
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
132 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
133 | 133 | |
134 | 134 | // Check to see if the request was valid. |
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
135 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
136 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
140 | + if (is_wp_error($response)) { |
|
141 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
145 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
146 | 146 | return false; |
147 | 147 | |
148 | 148 | } |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * @param WPInv_Invoice $invoice Invoice object. |
154 | 154 | * @param string $currency currency to validate. |
155 | 155 | */ |
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
156 | + protected function validate_ipn_currency($invoice, $currency) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
159 | 159 | |
160 | 160 | /* translators: %s: currency code. */ |
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
163 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
164 | 164 | } |
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
166 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | * @param WPInv_Invoice $invoice Invoice object. |
173 | 173 | * @param float $amount amount to validate. |
174 | 174 | */ |
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
175 | + protected function validate_ipn_amount($invoice, $amount) { |
|
176 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
177 | 177 | |
178 | 178 | /* translators: %s: Amount. */ |
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
181 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
182 | 182 | } |
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
184 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -190,19 +190,19 @@ discard block |
||
190 | 190 | * @param WPInv_Invoice $invoice Invoice object. |
191 | 191 | * @param string $receiver_email Email to validate. |
192 | 192 | */ |
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
193 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
194 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
197 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
198 | 198 | |
199 | 199 | /* translators: %s: email address . */ |
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
202 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
203 | 203 | } |
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
205 | + wpinv_error_log('Validated PayPal Email', false); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -211,70 +211,70 @@ discard block |
||
211 | 211 | * @param WPInv_Invoice $invoice Invoice object. |
212 | 212 | * @param array $posted Posted data. |
213 | 213 | */ |
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
214 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
215 | 215 | |
216 | 216 | // Collect payment details |
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + $payment_status = strtolower($posted['payment_status']); |
|
218 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
221 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
222 | 222 | |
223 | 223 | // Update the transaction id. |
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
224 | + if (!empty($posted['txn_id'])) { |
|
225 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
226 | 226 | $invoice->save(); |
227 | 227 | } |
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
230 | 230 | |
231 | 231 | // Process a refund. |
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
236 | + if (!$invoice->is_refunded()) { |
|
237 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
238 | 238 | } |
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
240 | + return wpinv_error_log($posted['reason_code'], false); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Process payments. |
244 | - if ( $payment_status == 'completed' ) { |
|
244 | + if ($payment_status == 'completed') { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
246 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
247 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
248 | 248 | } |
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
251 | 251 | |
252 | 252 | $note = ''; |
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
254 | + if (!empty($posted['mc_fee'])) { |
|
255 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
258 | + if (!empty($posted['payer_status'])) { |
|
259 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
260 | 260 | } |
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
263 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
264 | 264 | |
265 | 265 | } |
266 | 266 | |
267 | 267 | // Pending payments. |
268 | - if ( $payment_status == 'pending' ) { |
|
268 | + if ($payment_status == 'pending') { |
|
269 | 269 | |
270 | 270 | /* translators: %s: pending reason. */ |
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
273 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /* translators: %s: payment status. */ |
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
278 | 278 | |
279 | 279 | } |
280 | 280 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
285 | 285 | * @param array $posted Posted data. |
286 | 286 | */ |
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
287 | + protected function ipn_txn_cart($invoice, $posted) { |
|
288 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,43 +294,43 @@ discard block |
||
294 | 294 | * @param WPInv_Invoice $invoice Invoice object. |
295 | 295 | * @param array $posted Posted data. |
296 | 296 | */ |
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log('Processing subscription signup', false); |
|
300 | 300 | |
301 | 301 | // Make sure the invoice has a subscription. |
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
304 | + if (empty($subscription)) { |
|
305 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
306 | 306 | } |
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
309 | 309 | |
310 | 310 | // Validate the IPN. |
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
312 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
313 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
314 | 314 | |
315 | 315 | // Activate the subscription. |
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
316 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
317 | + $subscription->set_date_created(current_time('mysql')); |
|
318 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
319 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
320 | 320 | $subscription->activate(); |
321 | 321 | |
322 | 322 | // Set the transaction id. |
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
323 | + if (!empty($posted['txn_id'])) { |
|
324 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
325 | + $invoice->set_transaction_id($posted['txn_id']); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Update the payment status. |
329 | 329 | $invoice->mark_paid(); |
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
333 | + wpinv_error_log('Subscription started.', false); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,45 +339,45 @@ discard block |
||
339 | 339 | * @param WPInv_Invoice $invoice Invoice object. |
340 | 340 | * @param array $posted Posted data. |
341 | 341 | */ |
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
342 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
343 | 343 | |
344 | 344 | // Make sure the invoice has a subscription. |
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
347 | + if (empty($subscription)) { |
|
348 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
349 | 349 | } |
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
352 | 352 | |
353 | 353 | // PayPal sends a subscr_payment for the first payment too. |
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
355 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
356 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
357 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
358 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
359 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ($dates as $date) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
363 | + if ($date !== $today_date && $date !== $payment_date) { |
|
364 | 364 | continue; |
365 | 365 | } |
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
367 | + if (!empty($posted['txn_id'])) { |
|
368 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
369 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $invoice->mark_paid(); |
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
376 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
377 | 377 | |
378 | 378 | // Abort if the payment is already recorded. |
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
379 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
380 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $args = array( |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | 'gateway' => $this->id, |
386 | 386 | ); |
387 | 387 | |
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
388 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
390 | + if (empty($invoice)) { |
|
391 | 391 | return; |
392 | 392 | } |
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
396 | 396 | |
397 | 397 | $subscription->renew(); |
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + wpinv_error_log('Subscription renewed.', false); |
|
399 | 399 | |
400 | 400 | } |
401 | 401 | |
@@ -404,18 +404,18 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @param WPInv_Invoice $invoice Invoice object. |
406 | 406 | */ |
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
407 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
408 | 408 | |
409 | 409 | // Make sure the invoice has a subscription. |
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
411 | 411 | |
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
412 | + if (empty($subscription)) { |
|
413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
414 | 414 | } |
415 | 415 | |
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
416 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
417 | 417 | $subscription->cancel(); |
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
418 | + wpinv_error_log('Subscription cancelled.', false); |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
426 | 426 | * @param array $posted Posted data. |
427 | 427 | */ |
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
428 | + protected function ipn_txn_subscr_eot($invoice) { |
|
429 | 429 | |
430 | 430 | // Make sure the invoice has a subscription. |
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
433 | + if (empty($subscription)) { |
|
434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
435 | 435 | } |
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
437 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
438 | 438 | $subscription->complete(); |
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
439 | + wpinv_error_log('Subscription completed.', false); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -446,18 +446,18 @@ discard block |
||
446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
447 | 447 | * @param array $posted Posted data. |
448 | 448 | */ |
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
449 | + protected function ipn_txn_subscr_failed($invoice) { |
|
450 | 450 | |
451 | 451 | // Make sure the invoice has a subscription. |
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
454 | + if (empty($subscription)) { |
|
455 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
456 | 456 | } |
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
458 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
459 | 459 | $subscription->failing(); |
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
460 | + wpinv_error_log('Subscription marked as failing.', false); |
|
461 | 461 | |
462 | 462 | } |
463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
467 | 467 | * @param WPInv_Invoice $invoice Invoice object. |
468 | 468 | * @param array $posted Posted data. |
469 | 469 | */ |
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
471 | 471 | |
472 | 472 | // Make sure the invoice has a subscription. |
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
475 | + if (empty($subscription)) { |
|
476 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
477 | 477 | } |
478 | 478 | |
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
479 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
480 | 480 | $subscription->cancel(); |
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
481 | + wpinv_error_log('Subscription cancelled.', false); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | } |